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
Motion correction (using fsl.MCFLIRT) in a workflow returns TypeError: can't pickle instancemethod objects.
I have tried splicing apart each section of the workflow and it seems like there is something about MCFLIRT when combined with MapNode that is giving rise to the issue (MCFLIRT on its own runs without issue, as best I can tell).
I suspect that as I build onto the workflow, there will continue to be issues with pickle and instancemethod inclusions -- that is, I don't think this is a problem specific to MCFLIRT.
Script/Workflow details/How to replicate the behavior
importos# system functionsimportjson# reading exp infoimportnipype.interfaces.ioasnio# Data i/oimportnipype.interfaces.fslasfsl# fslimportnipype.interfaces.utilityasutil# utilityimportnipype.pipeline.engineaspe# pypeline enginefromnipypeimportconfig#set output file format to compressed NIFTI.fsl.FSLCommand.set_default_output_type('NIFTI_GZ')
# Where the input data comes fromdata_dir=os.path.abspath('../ds000224_R1.0.2')
# Where the outputs goeswithinSubjectResults_dir=os.path.abspath('../fsl_datasink')
# Working Directoryworkingdir=os.path.abspath('../fsl_working_dir/working_dir')
# Crash RecordscrashRecordsDir=os.path.abspath('../fsl_working_dir/crash_dumps')
# subject directoriessubject_list= ['MSC01']
#tasktask='memoryfaces'#List of functional scansfunc_scan= [1,2]
# TR of functional imageswithopen(data_dir+'/task-'+task+'_bold.json', 'rt') asfp:
task_info=json.load(fp)
TR=task_info['RepetitionTime']
# TemplatesmfxTemplateBrain='/usr/local/fsl/data/standard/MNI152_T1_2mm.nii.gz'strippedmfxTemplateBrain='/usr/local/fsl/data/standard/MNI152_T1_2mm_brain.nii.gz'mniConfig='T1_2_MNI152_2mm'mniMask='/usr/local/fsl/data/standard/MNI152_T1_2mm_brain_mask_dil.nii.gz'# ## Functions#function to pick the first file from a list of filesdefpickfirst(files):
returnfiles[0]
#function to return the 1 based index of the middle volumedefgetmiddlevolume(func):
fromnibabelimportloadfuncfile=func[0]
_,_,_,timepoints=load(funcfile).get_shape()
return (timepoints/2)-1# ## Preprocessing Workflow#Master nodepreproc=pe.Workflow(name='preproc')
#input utility nodeinputnode=pe.Node(interface=util.IdentityInterface(fields=['func',
'struct',]),
name='inputspec')
#Extract the middle volume of the first run as the referenceextract_ref=pe.Node(interface=fsl.ExtractROI(t_size=1),
name='extractref')
#Realign the functional runs to the middle volume of the first runmotion_correct=pe.MapNode(interface=fsl.MCFLIRT(save_mats=True,
save_plots=True),
name='motion_correct',
iterfield= ['in_file'])
# ## META workflow# Set up infosource to iterate over 'subject_id'sinfosource=pe.Node(interface=util.IdentityInterface(fields=['subject_id']),
name="infosource")
infosource.iterables= ('subject_id', subject_list)
# SelectFiles - to grab the data (alternative to DataGrabber)struct='sub-{subject_id}/ses-struct01/anat/sub-{subject_id}_ses-struct01_run-01_T1w.nii.gz'func='sub-{subject_id}/ses-func*/func/sub-{subject_id}_ses-func*_task-memoryfaces_bold.nii.gz'evs='sub-{subject_id}/ses-func*/func/sub-{subject_id}_ses-func*_task-memoryfaces_events.tsv'templates= {'struct': struct,
'func': func,
'evs': evs}
selectfiles=pe.Node(interface=nio.SelectFiles(templates,
base_directory=data_dir),
name="selectfiles")
#DataSink --- stores important outputsdatasink=pe.Node(interface=nio.DataSink(base_directory=withinSubjectResults_dir,),
name="datasink")
preproc.connect([(infosource, selectfiles, [('subject_id', 'subject_id')]),
(infosource, datasink, [('subject_id', 'container')]),
(selectfiles, inputnode, [('struct','struct'),
('func', 'func')]),
(inputnode, extract_ref,[(('func',pickfirst), 'in_file')]),
(inputnode, extract_ref, [(('func', getmiddlevolume), 't_min')]),
(inputnode, motion_correct, [('func', 'in_file')]),
(extract_ref, motion_correct, [('roi_file', 'ref_file')]),
(motion_correct, datasink, [('par_file', 'motion_correct.par_file')]),
(motion_correct, datasink, [('out_file', 'motion_correct.out_file')])
])
# Create preproc analysis output graphpreproc.write_graph(graph2use='colored', format='png', simple_form=True, dotfilename='./graph_preproc.dot')
preproc.run()
The text was updated successfully, but these errors were encountered:
Some investigating has lead me to think that using MapNode leads to the TypeError: can't pickle instancemethod objects. error. Is there a work around for this?
Summary & Actual behavior
Motion correction (using fsl.MCFLIRT) in a workflow returns
TypeError: can't pickle instancemethod objects
.I have tried splicing apart each section of the workflow and it seems like there is something about MCFLIRT when combined with
MapNode
that is giving rise to the issue (MCFLIRT on its own runs without issue, as best I can tell).I suspect that as I build onto the workflow, there will continue to be issues with
pickle
andinstancemethod
inclusions -- that is, I don't think this is a problem specific to MCFLIRT.Platform details:
Execution environment
macOS mojave
python 2.7
Script/Workflow details/How to replicate the behavior
The text was updated successfully, but these errors were encountered: