You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue is potentially related to #3301. I would like to use nipype.algorithms.modelgen.SpecifySPMModel to set up my design matrix. I noticed that the class itself is able to handle relative filepaths for its argument functional_runs, but not when being inside a node. Is this an expected behavior?
How to replicate the behavior
importnipype.interfaces.matlabasnimfromnilearn.datasetsimportfetch_spm_auditoryfromnilearn.imageimportconcat_imgsfromnipype.algorithmsimportmodelgenfromnipype.interfaces.baseimportBunchfromnipypeimportNodefromnipype.algorithms.modelgenimportSpecifySPMModelimportosmlab=nim.MatlabCommand()
nim.MatlabCommand.set_default_matlab_cmd('/opt/matlab/R2022a/bin/matlab')
# get data (this will automatically create a separate data directory)subject_data=fetch_spm_auditory(data_dir='./data')
# create .nii file and save to data dir. We pretend this would be two different runsfmri_img=concat_imgs(subject_data.func)
fmri_img.to_filename('./data/functional2.nii')
fmri_img.to_filename('./data/functional3.nii')
# taken from docs: https://nipype.readthedocs.io/en/latest/api/generated/nipype.algorithms.modelgen.html#specifyspmmodels=modelgen.SpecifySPMModel()
s.inputs.input_units='secs's.inputs.output_units='scans's.inputs.high_pass_filter_cutoff=128.s.inputs.functional_runs= ['./data/functional2.nii', './data/functional3.nii']
s.inputs.time_repetition=6s.inputs.concatenate_runs=Trueevs_run2=Bunch(conditions=['cond1'], onsets=[[2, 50, 100, 180]], durations=[[1]])
evs_run3=Bunch(conditions=['cond1'], onsets=[[30, 40, 100, 150]], durations=[[1]])
s.inputs.subject_info= [evs_run2, evs_run3]
s.run()
# but when we put the same code into a node it will failmodel_specifier=Node(SpecifySPMModel(input_units='secs',
output_units='scans',
high_pass_filter_cutoff=128,
functional_runs= ['./data/functional2.nii', './data/functional3.nii'],
time_repetition=6,
concatenate_runs=True,
subject_info=[evs_run2, evs_run3]),
name='model_specifier')
model_specifier.run()
Actual behavior
model_specifier.run() results in TraitError: Each element of the 'functional_runs' trait of a SpecifySPMModelInputSpec instance must be a list of items which are a pathlike object or string representing an existing file or a pathlike object or string representing an existing file, but a value of '/tmp/tmprbnvs25y/model_specifier/functional2.nii' <class 'str'> was specified.
Expected behavior
As a user I would expect that model_specifier.run() should run successfully just like s.run() , because the only difference between the first and the second case is that the latter is packed inside a Node, everything else is the same. One can fix this by Node(SpecifySPMModel(functional_runs=...) with absolute paths like such:
@effigies Alright thanks! I wonder if one could adapt the Error message for this case as tmp/tmprbnvs25y/model_specifier/functional2.nii is a symbolic link pointing to an existing file so I couldn't really understanding what's going on.
Perhaps one could implement a method within the Node() class that checks if the provided paths are absolute or relative and throw an error for the latter case. One could use os.path.isabs() for example.
Relative paths are frequently used for output filenames. I don't think we could make it an error without breaking that use case.
You could dig through the traceback and find where we make the inputs absolute, and put that in a try/catch block and provide a better error message than the more opaque TraitError.
I should note though that Nipype 1 is in maintenance mode and it will probably die by the time Python 3.11 hits end-of-life. In my opinion, a better use of time would be to work to improve Pydra and write Tasks (which replaces Interfaces and Nodes) to cover your use cases.
Summary
This issue is potentially related to #3301. I would like to use
nipype.algorithms.modelgen.SpecifySPMModel
to set up my design matrix. I noticed that the class itself is able to handle relative filepaths for its argumentfunctional_runs
, but not when being inside a node. Is this an expected behavior?How to replicate the behavior
Actual behavior
model_specifier.run()
results inTraitError: Each element of the 'functional_runs' trait of a SpecifySPMModelInputSpec instance must be a list of items which are a pathlike object or string representing an existing file or a pathlike object or string representing an existing file, but a value of '/tmp/tmprbnvs25y/model_specifier/functional2.nii' <class 'str'> was specified.
Expected behavior
As a user I would expect that
model_specifier.run()
should run successfully just likes.run()
, because the only difference between the first and the second case is that the latter is packed inside a Node, everything else is the same. One can fix this byNode(SpecifySPMModel(functional_runs=...)
with absolute paths like such:But as a user I would not expect to do this,
Script/Workflow details
Please put URL to code or code here (if not too long).
Platform details:
Execution environment
Choose one
The text was updated successfully, but these errors were encountered: