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.
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 of these optional 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?
How to solve this issue
When an optional file is present in the file mapping section, its key will always be in the config.json
created by Brainlife. But instead of being null
if the file doesn't exist (since it's an optional file, app users don't have to provide it, so it can be null
), its value is the path to where the file should be. So, when the files are marked as "optional" in Brainlife, it's up to the App developer to deal with the possibility that the file does not exist, it's not hard coded in Brainlife.
To deal the possibility that the file doesn’t exist, use if os.path.exists(path)
in main
of your Python file:
calibration_file = config.pop('calibration')
if os.path.exists(calibration_file) is False:
calibration_file = None
However, with the function os.path.exist()
, if the value of the optional file is None
, an error is raised. This case will happen when the App is run locally. So, to prevent that, we need to check beforehand if the parameter is None
(see Handling optional file).