Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Status
colourRed
titleDraft

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:

...

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. However, he can use a dictionary if he uses the App locally (see https://icm-institute.atlassian.net/wiki/pages/resumedraft.action?draftId=1562771457).

Python dictionaries are used in app-temporal-filtering to define optionally the parameters of an IIR filter, but also in app-make-epochs to define the threshold values for each type of channel to use to detect bad channels. So, it is important to find a way to make possible to use dictionaries on BL.

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:

...

Info

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 when the App runs locally) and it is easier to convert it into a numpy.nd.array.

In the Python file, we added:

...

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

...

written as follows:

Code Block
{
"param_baseline": "0, None" 
}

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

Code Block
if isinstance(config['param_baseline'], str):
    param_baseline = list(map(str, config['param_baseline'].split(', ')))
    param_baseline = [None if i=='None' else i for i in param_baseline]
    param_baseline = [float(i) if isinstance(i, str) else i for i in param_baseline]
    config['param_baseline'] = tuple(param_baseline)

The first step is to convert it into a list and then convert the elements of the list into the right type. For tuple parameters in which their elements are the same type, there is no need to compute the two list comprehensions:

Code Block
if isinstance(config['param_tuple_floats'], str):
    config['param_tuple_floats'] = list(map(str, config['param_tuple_floats'].split(', ')))
    config['param_tuple_floats'] = tuple(config['param_tuple_floats'])
Info

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

Case of a list of integers/floats or strings

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

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

Code Block
{
param_picks_by_channel_types_or_names: "[0, 2, 1]"
}

and a list of str:

Code Block
{
list_of_strings: "[a, b, c]" 
}
Note

Don’t surround the elements in the list by quotes.

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:

Code Block
if isinstance(picks, str) and picks.find("[") != -1 and picks is not None:
    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.

If the list is empty, the user must enter []. In the Python code it will be converted into an empty list:

Code Block
if config['param_extended_proj'] == '[]':
    config['param_extended_proj'] = [] 

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 a STRING or NUMBER. So , a NUMBER, a BOOLEAN, or an ENUM.

Case when a parameter is either a str or a float/int

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 into a float or 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:

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

Case when a parameter is either a str or a bool

When a parameter can be both a str or a bool, we registered it as a STRING or ENUM on BL (either way, it is considered as a str), and then we convert it into a bool.

For instance the parameter param_proj can be “delayed”, or a bool. So, we registered it as an ENUM parameter and convert "True” and “False“ into a bool:

Code Block
if config['param_proj'] == "True":
    config['param_proj'] = True
elif config['param_proj'] == "False":
    config['param_proj'] = False