Although an App runs smoothly locally, when you try to run it on BL errors can occur. Here are the errors I came across and the way I solved them.
Null value of an optional parameter
When an optional parameter is not given (the input field stays empty), it is not written as null
in the config.json
file generated by Brainlife but it is written as ““
. So it is considered as a string by the Python code and an error occurs.
Case of a NUMBER parameter
For instance, the app-maxfilter takes the parameter st_duration
as optional. This parameter is either a float
or None
. Locally, in the config.json.example
, when this parameter is not given it is written as:
"param_st_duration": null
And when maxfilter.py
parses the config.json.example,
the value of this parameter is None
.
When this App was registered on BL, the st_duration
parameter was entered as follows:
But, when no value was entered when executing the App, this parameter was written as follows in the config.json
:
"param_st_duration": "",
Then the value of this parameter is passed to the MNE function MaxFilter, which reads it as a string instead of None
and an error is raised because the function expects a float or None
:
ValueError: could not convert string to float
So, to circumvent this issue, I add the following lines to maxfilter.py
:
if config['param_st_duration'] == "": param_st_duration = None else: param_st_duration = config['param_st_duration']
Case of a STRING parameter
app-maxfilter takes another optional parameter (param_regularize
), and this time it is either a string
or None
. In this case, you can also add in the Python file:
if config['param_regularize'] == "": param_regularize = None else: param_regularize = config['param_regularize']
and enter the parameter as follows in BL:
Case of an ENUM parameter
When it is possible, meaning when your parameter is optional and the App user can choose between fixed values of the parameter, set this parameter to ENUM and select ‘optional’ when registering your App on BL:
Then, let the user choose between the fixed values of the parameter or an empty field, don’t propose None
or null
because in the config.json
it will be written as:
"param_regularize": "None"/"null"
instead of simply null
.
Then, when you want this parameter to be None
, just select the option don’t specify
when you execute the App.
If you choose to enter your parameter as an ENUM parameter, no need to modify your Python file the way it is presented for a STRING parameter and a NUMBER parameter.
Error when an optional file is not available in a dataset
In a BL datatype, some files are mandatory whereas other are optional.
For instance, for the neuro/meg/fif
datatype, the meg file in FIF format is required whereas channels.tsv
, headshape.pos
, coordsystem.json
, calibration_meg.dat
, crosstalk_meg.fif
, and destination.fif
are optional.
When I registered my App on BL, for instance app-maxfilter
, I defined the input as follows:
Then I execute my job on BL. When the dataset I choose to run my App on has the calibration, destination, and crosstalk files it works. But if one ot these optionnal files is missing, I get the error:
OSError: trans file "../605db81c7503897f9beb333f/6011c463c08103cd2aba03ea/destination.fif" not found
This file is supposed to be optional, so why an error is raised when it is not provided?
ask BL team
Error when running a pipeline with optional files
The Apps created as part of the MEEG Brainlife project are supposed to be run one after another. Thus the output of an App will be the input of another.
To test how it works, I decided to apply app-bad-channels
and then app-maxfilter
First attempt:
app-bad-channels:
no optional files present in file mappingapp-maxfilter
: no optional files listes in file mapping
Result: it works fine
Second attempt:
app-bad-channels
: optional files present in file mappingapp-maxfilter
: optional files present in file mapping
Result: app-bad-channels
works but app-maxfilter
failed:
OSError: trans file "../60618e5b750389e448ebecd7/out_dir_bad_channels/destination.fif" not found
The optional file is indeed not in out_dir_bad_channels
.
The only way to solve this issue is to save in the output directory the files you want to use as optional inputs of the next App. So here, the destination file must be saved in outdir_bad_channels
0 Comments