def test_label_matcher_find_op(): with pytest.raises(AssertionError) as e: fa.define_analysis('afq', lambda **kwargs: {}, label_matcher=lambda val: val.startswith('afq ')) assert 'does not detect this operation' in str(e) fa.define_analysis('afq', lambda **kwargs: {}, label_matcher=lambda val: val.startswith('afq'))
def define_analysis(gear_name, acquisition_label, create_inputs): '''Light wrapper around define_analysis that lets us pass in an acquisition_label in to create_inputs. ''' return fa.define_analysis( gear_name, lambda **kwargs: create_inputs(acquisition_label, **kwargs), label=analysis_label(gear_name, acquisition_label))
def dtiinit_inputs(acquisitions, **kwargs): diffusion = fa.find(acquisitions, label='Diffusion') return dict( bvec=diffusion.find_file('*1000.bvec'), bval=diffusion.find_file('*1000.bval'), dwi=diffusion.find_file('*1000.nii.gz'), ), dict( # Here you can add any configuration. So for instance to add robust tensor, do: # fitMethod='rt' ) def afq_inputs(analyses, **kwargs): dtiinit = fa.find(analyses, label=dtiinit_label) return dict(dtiInit_Archive=dtiinit.find_file('dtiInit_*.zip'), ) if __name__ == '__main__': with fa.installed_client(client): ops = [ fa.define_analysis('dtiinit', dtiinit_inputs, label=dtiinit_label), fa.define_analysis('afq', afq_inputs, label=afq_label), ] fa.run(ops, project=fa.find_project(label='HCP_preproc'), session_limit=1)
from scitran_client import ScitranClient import scitran_client.flywheel_analyzer as fa client = ScitranClient('https://flywheel.scitran.stanford.edu') with fa.installed_client(client): D99 = fa.find(client.request( 'sessions/588bd1ac449f9800159305c2/acquisitions').json(), label='atlas') def anatomical_warp_inputs(acquisitions, **kwargs): anatomical = fa.find(acquisitions, label='anatomical_mdeft') return dict( native=anatomical.find_file('*.nii.gz'), standard=D99.find_file('D99_template.nii.gz'), warp_target=D99.find_file('D99_atlas_1.2a.nii.gz'), ) if __name__ == '__main__': with fa.installed_client(client): fa.run([ fa.define_analysis('afni-brain-warp', anatomical_warp_inputs, label='anatomical warp'), ], project=fa.find_project(label='showdes'), max_workers=2)
dtiinit_matcher = prefix_matcher('dtiinit') afq_matcher = prefix_matcher('afq') def dtiinit_inputs(acquisitions, **kwargs): diffusion = fa.find(acquisitions, label='DTI 2mm b1250 84dir(axial)') return dict( bvec=diffusion.find_file('*.bvec'), bval=diffusion.find_file('*.bval'), nifti=diffusion.find_file('*.nii.gz'), ) def afq_inputs(analyses, **kwargs): dtiinit = fa.find(analyses, label=dtiinit_matcher) return dict(dtiInit_Archive=dtiinit.find_file('dtiInit_*.zip'), ) if __name__ == '__main__': with fa.installed_client(client): fa.run([ fa.define_analysis( 'dtiinit', dtiinit_inputs, label_matcher=dtiinit_matcher), fa.define_analysis('afq', afq_inputs, label_matcher=afq_matcher), ], project=fa.find_project(label='ENGAGE'))