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 3 Next »

Even when an App runs locally, the parameters of the functions used are stored in a config file in JSON format (config.json.example). But this file doesn’t support all the Python types (for instance the numpy.nd.arrays and the tuples).

So we have to convert these values in the Python file.

Case of numpy nd.array

In the config.json.example, it is not possible to enter directly a numpy.nd.array, so we enter a list of floats instead:

{
"param_origin": [0., 0., 0.] 
}

And in the Python file this list will be converted into a numpy.nd.array:

if isinstance(config['param_origin'], list):
    config['param_origin'] = np.array(config['param_origin'])

The part when we test if config['param_origin'] is a list is here to make this condition only used when the App is run locally.

Case of a slice

Here again it is impossible to enter a slice in the config.json.example, so in this file we enter:

{
"param_picks_by_channel_indices": "0, 10, 2"
}

And in the Python file, this string will be converted into a slice. First we convert it into a list and then into a slice.

For instance:

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)

In this case, these lines of code are used to convert the string to a slice when the App runs locally but also on Brainlife.

Case of a tuple

It is also impossible to enter a tuple in a json file, so instead the we enter:

{
"param_baseline": [null, 0]
}

And then we convert this list into a tuple in the Python file:

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

  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.