This is a collaborative space. In order to contribute, send an email to maximilien.chaumon@icm-institute.org
On any page, type the letter L on your keyboard to add a "Label" to the page, which will make search easier.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

When an App is registered on Brainlife, a config.json is automatically created based on the info the App creator enters via the BL GUI. There are four types of parameters:

  • NUMBER

  • STRING

  • ENUM

  • BOOL

So, it is impossible to enter a list of int or a numpy nd.array for instance. So, the values must be converted.

For now, we have decided not to read and convert Python dictionaries, so the BL user won’t be able to give a dictionary as a parameter value.

Case of a numpy.nd.array

It is impossible to enter a np.nd.array in BL. So we register such parameter as a STRING and ask the user to enter floats separated by a comma: 10, 15, 20. In the config.json, such parameter will be written as:

{
"param_notch_widths": "10, 15, 20"
}

It was decided to enter numpy.nd.array this way on BL to differentiate it from the way it was entered in the config.json.example when the App is run locally (see Parameters conversion).

In the Python file, we added:

if isinstance(config['param_notch_widths'], str):
    config['param_notch_widths'] = list(map(float, config['param_notch_widths'].split(', ')))
    config['param_notch_widths'] = np.array(config['param_notch_widths'])

Case of a slice

It is also impossible to enter directly a slice on BL. So we enter the parameter as a STRING. In the config.json, such parameter is written as follows:

{
config['param_picks_by_channel_indices']: "0, 10, 2"
}

This parameter is entered the same way as a numpy.nd.array. So far it is not an issue because no parameter is either a numpy.nd.array or a slice.

In the Python file, we added:

if isinstance(picks, str) and picks.find(",") != -1 and picks.find("[") == -1 and picks is not None:
    picks = list(map(int, picks.split(', ')))
    if len(picks) == 2:
        config['param_picks_by_channel_indices'] = slice(picks[0], picks[1])
    elif len(picks) == 3:
        config['param_picks_by_channel_indices'] = slice(picks[0], picks[1], picks[2])
    else:
        value_error_message = f"If you want to select channels using a slice, you must give two or three elements."
        raise ValueError(value_error_message)

Case of a tuple

A tuple can not be entered on BL. So we registered the parameter as a STRING. In the config.json, such parameter is written as follows:

{
"param_baseline": 0, None 
}

To convert it into a tuple, in the Python file we added:

if config['param_baseline'] is not None:
    config['param_baseline'] = tuple(config['param_baseline'])

Case of a list of integers/floats

On Brainlife, when we enter a list, we have to use the type STRING and so the list is considered as a string, so they need to be converted.

Indeed, a list of floats or integers are written as follows in the config.json:

{
param_picks_by_channel_types_or_names = "[0, 2, 1]"
}

So, we first need to convert it into a list and then convert the elements of the list into the right type.

For a list of strings:

if isinstance(picks, str) and picks.find("[") != -1 and picks is not None:
    picks = picks.replace('[', '')
    picks = picks.replace(']', '')
    picks = picks.replace("'", '')
    config['param_picks_by_channel_types_or_names'] = list(map(str, picks.split(', ')))

If you want to convert it into a list of floats or ints, just replace str in list(map(str, picks.split(', '))) by the type you want.

Cases when a parameter can be two types

When the App is run locally, this configuration is not an issue, but on Brainlife when you define the parameter, it must be either STRING or NUMBER. So when a parameter can be both a str or a float/ int, we registered it as a STRING on BL, and then we convert it as a floator int.

But we must be careful: we only want to convert a str into float/int when the App runs on BL. For instance the parameter param_filter_length can be “auto”, a str with the duration in s, or ms, or a int. So to be sure that the conversion into float happens only on Brainlife and only when the user does want to use a float:

if config['param_filter_length'] != "auto" and config['param_filter_length'].find("s") == -1:
    config['param_filter_length'] = int(config['param_filter_length'])
  • No labels