def get_tr_and_sliceorder(dicom_files, convention="french"): import numpy as np import dcmstack, dicom from dcmstack.dcmmeta import NiftiWrapper nii_wrp = NiftiWrapper.from_filename(dicom_files) if convention == "french": sliceorder = np.argsort(np.argsort(nii_wrp.meta_ext.get_values('CsaImage.MosaicRefAcqTimes')[0])).tolist() elif convention == "SPM": sliceorder = np.argsort(nii_wrp.meta_ext.get_values('CsaImage.MosaicRefAcqTimes')[0]).tolist() tr = nii_wrp.meta_ext.get_values('RepetitionTime') return tr/1000.,sliceorder get_meta = pe.Node(util.Function(input_names=['dicom_files', 'convention'], output_names=['tr', 'sliceorder'], function=get_tr_and_sliceorder), name="get_meta") get_meta.inputs.convention = "french" wf.connect(datagrabber, "resting_nifti", get_meta, "dicom_files") preproc = create_rest_prep(name="bips_resting_preproc", fieldmap=False) zscore = preproc.get_node('z_score') preproc.remove_nodes([zscore]) mod_realign = preproc.get_node("mod_realign") mod_realign.plugin_args = {"submit_specs":"request_memory=4000\n"} # inputs preproc.inputs.inputspec.motion_correct_node = 'nipy' ad = preproc.get_node('artifactdetect') preproc.disconnect(mod_realign,'parameter_source', ad,'parameter_source') ad.inputs.parameter_source = "NiPy" preproc.inputs.inputspec.realign_parameters = {"loops":[5], "speedup":[5]} preproc.inputs.inputspec.do_whitening = False preproc.inputs.inputspec.timepoints_to_remove = 4 preproc.inputs.inputspec.smooth_type = 'susan' preproc.inputs.inputspec.do_despike = False preproc.inputs.inputspec.surface_fwhm = 0.0 preproc.inputs.inputspec.num_noise_components = 6 preproc.inputs.inputspec.regress_before_PCA = False preproc.get_node('fwhm_input').iterables = ('fwhm', [5]) preproc.get_node('take_mean_art').get_node('strict_artifact_detect').inputs.save_plot = True #preproc.get_node('take_mean_art').get_node('strict_artifact_detect').overwrite=True preproc.inputs.inputspec.ad_normthresh = 1 preproc.inputs.inputspec.ad_zthresh = 3 preproc.inputs.inputspec.do_slicetime = True preproc.inputs.inputspec.compcor_select = [True, True] preproc.inputs.inputspec.filter_type = 'fsl' preproc.get_node('bandpass_filter').iterables = [('highpass_freq', [0.01]), ('lowpass_freq', [0.1])] # preproc.inputs.inputspec.highpass_freq = 0.01 # preproc.inputs.inputspec.lowpass_freq = 0.1 #[motion_params, composite_norm, compcorr_components, global_signal, art_outliers, motion derivatives] preproc.inputs.inputspec.reg_params = [True, True, True, False, True, False] preproc.inputs.inputspec.fssubject_dir = freesurferdir wf.connect(get_meta, "tr", preproc, "inputspec.tr") wf.connect(get_meta, "sliceorder", preproc, "inputspec.sliceorder") wf.connect(subject_id_infosource, "subject_id", preproc, 'inputspec.fssubject_id') wf.connect(datagrabber, "resting_nifti", preproc, "inputspec.func") # report_wf = create_preproc_report_wf(resultsdir + "/reports") # report_wf.inputs.inputspec.fssubjects_dir = preproc.inputs.inputspec.fssubject_dir def pick_full_brain_ribbon(l): import os for path in l: if os.path.split(path)[1] == "ribbon.mgz": return path # wf.connect(preproc,"artifactdetect.plot_files", report_wf, "inputspec.art_detect_plot") # wf.connect(preproc,"take_mean_art.weighted_mean.mean_image", report_wf, "inputspec.mean_epi") # wf.connect(preproc,("getmask.register.out_reg_file", list_to_filename), report_wf, "inputspec.reg_file") # wf.connect(preproc,("getmask.fssource.ribbon",pick_full_brain_ribbon), report_wf, "inputspec.ribbon") # wf.connect(preproc,("CompCor.tsnr.tsnr_file", list_to_filename), report_wf, "inputspec.tsnr_file") # wf.connect(subject_id_infosource, "subject_id", report_wf, "inputspec.subject_id") ds = pe.Node(nio.DataSink(), name="datasink", overwrite=True) ds.inputs.base_directory = os.path.join(resultsdir, "volumes") wf.connect(preproc, 'bandpass_filter.out_file', ds, "preprocessed_resting") wf.connect(preproc, 'getmask.register.out_fsl_file', ds, "func2anat_transform") wf.connect(preproc, 'outputspec.mask', ds, "epi_mask") wf.write_graph() wf.run(plugin="MultiProc")
import dcmstack, dicom from dcmstack.dcmmeta import NiftiWrapper nii_wrp = NiftiWrapper.from_filename(dicom_files) sliceorder = np.argsort(nii_wrp.meta_ext.get_values("CsaImage.MosaicRefAcqTimes")[0]).tolist() tr = nii_wrp.meta_ext.get_values("RepetitionTime") return tr / 1000.0, sliceorder get_meta = pe.Node( util.Function(input_names=["dicom_files"], output_names=["tr", "sliceorder"], function=get_tr_and_sliceorder), name="get_meta", ) wf.connect(datagrabber, "resting_nifti", get_meta, "dicom_files") preproc = create_rest_prep(name="bips_resting_preproc", fieldmap=False) zscore = preproc.get_node("z_score") preproc.remove_nodes([zscore]) mod_realign = preproc.get_node("mod_realign") mod_realign.plugin_args = {"submit_specs": "request_memory=4000\n"} # inputs preproc.inputs.inputspec.motion_correct_node = "nipy" preproc.inputs.inputspec.realign_parameters = {"loops": [5], "speedup": [5]} preproc.inputs.inputspec.do_whitening = False preproc.inputs.inputspec.timepoints_to_remove = 4 preproc.inputs.inputspec.smooth_type = "susan" preproc.inputs.inputspec.do_despike = False preproc.inputs.inputspec.surface_fwhm = 0.0 preproc.inputs.inputspec.num_noise_components = 6
def get_tr_and_sliceorder(dicom_files, convention="french"): import numpy as np import dcmstack, dicom from dcmstack.dcmmeta import NiftiWrapper nii_wrp = NiftiWrapper.from_filename(dicom_files) if convention == "french": sliceorder = np.argsort( np.argsort( nii_wrp.meta_ext.get_values('CsaImage.MosaicRefAcqTimes') [0])).tolist() elif convention == "SPM": sliceorder = np.argsort( nii_wrp.meta_ext.get_values('CsaImage.MosaicRefAcqTimes') [0]).tolist() tr = nii_wrp.meta_ext.get_values('RepetitionTime') return tr / 1000., sliceorder get_meta = pe.Node(util.Function(input_names=['dicom_files', 'convention'], output_names=['tr', 'sliceorder'], function=get_tr_and_sliceorder), name="get_meta") get_meta.inputs.convention = "french" wf.connect(datagrabber, "resting_nifti", get_meta, "dicom_files") preproc = create_rest_prep(name="bips_resting_preproc", fieldmap=False) zscore = preproc.get_node('z_score') preproc.remove_nodes([zscore]) mod_realign = preproc.get_node("mod_realign") mod_realign.plugin_args = {"submit_specs": "request_memory=4000\n"} # inputs preproc.inputs.inputspec.motion_correct_node = 'nipy' ad = preproc.get_node('artifactdetect') preproc.disconnect(mod_realign, 'parameter_source', ad, 'parameter_source') ad.inputs.parameter_source = "NiPy" preproc.inputs.inputspec.realign_parameters = { "loops": [5], "speedup": [5] } preproc.inputs.inputspec.do_whitening = False preproc.inputs.inputspec.timepoints_to_remove = 4 preproc.inputs.inputspec.smooth_type = 'susan' preproc.inputs.inputspec.do_despike = False preproc.inputs.inputspec.surface_fwhm = 0.0 preproc.inputs.inputspec.num_noise_components = 6 preproc.inputs.inputspec.regress_before_PCA = False preproc.get_node('fwhm_input').iterables = ('fwhm', [5]) preproc.get_node('take_mean_art').get_node( 'strict_artifact_detect').inputs.save_plot = True #preproc.get_node('take_mean_art').get_node('strict_artifact_detect').overwrite=True preproc.inputs.inputspec.ad_normthresh = 1 preproc.inputs.inputspec.ad_zthresh = 3 preproc.inputs.inputspec.do_slicetime = True preproc.inputs.inputspec.compcor_select = [True, True] preproc.inputs.inputspec.filter_type = 'fsl' preproc.get_node('bandpass_filter').iterables = [('highpass_freq', [0.01]), ('lowpass_freq', [0.1])] # preproc.inputs.inputspec.highpass_freq = 0.01 # preproc.inputs.inputspec.lowpass_freq = 0.1 #[motion_params, composite_norm, compcorr_components, global_signal, art_outliers, motion derivatives] preproc.inputs.inputspec.reg_params = [ True, True, True, False, True, False ] preproc.inputs.inputspec.fssubject_dir = freesurferdir wf.connect(get_meta, "tr", preproc, "inputspec.tr") wf.connect(get_meta, "sliceorder", preproc, "inputspec.sliceorder") wf.connect(subject_id_infosource, "subject_id", preproc, 'inputspec.fssubject_id') wf.connect(datagrabber, "resting_nifti", preproc, "inputspec.func") # report_wf = create_preproc_report_wf(resultsdir + "/reports") # report_wf.inputs.inputspec.fssubjects_dir = preproc.inputs.inputspec.fssubject_dir def pick_full_brain_ribbon(l): import os for path in l: if os.path.split(path)[1] == "ribbon.mgz": return path # wf.connect(preproc,"artifactdetect.plot_files", report_wf, "inputspec.art_detect_plot") # wf.connect(preproc,"take_mean_art.weighted_mean.mean_image", report_wf, "inputspec.mean_epi") # wf.connect(preproc,("getmask.register.out_reg_file", list_to_filename), report_wf, "inputspec.reg_file") # wf.connect(preproc,("getmask.fssource.ribbon",pick_full_brain_ribbon), report_wf, "inputspec.ribbon") # wf.connect(preproc,("CompCor.tsnr.tsnr_file", list_to_filename), report_wf, "inputspec.tsnr_file") # wf.connect(subject_id_infosource, "subject_id", report_wf, "inputspec.subject_id") ds = pe.Node(nio.DataSink(), name="datasink", overwrite=True) ds.inputs.base_directory = os.path.join(resultsdir, "volumes") wf.connect(preproc, 'bandpass_filter.out_file', ds, "preprocessed_resting") wf.connect(preproc, 'getmask.register.out_fsl_file', ds, "func2anat_transform") wf.connect(preproc, 'outputspec.mask', ds, "epi_mask") wf.write_graph() wf.run(plugin="MultiProc")
elif convention == "SPM": sliceorder = np.argsort( nii_wrp.meta_ext.get_values('CsaImage.MosaicRefAcqTimes') [0]).tolist() tr = nii_wrp.meta_ext.get_values('RepetitionTime') return tr / 1000., sliceorder get_meta = pe.Node(util.Function(input_names=['dicom_files', 'convention'], output_names=['tr', 'sliceorder'], function=get_tr_and_sliceorder), name="get_meta") get_meta.inputs.convention = "french" wf.connect(datagrabber, "resting_nifti", get_meta, "dicom_files") preproc = create_rest_prep(name="bips_resting_preproc", fieldmap=False) zscore = preproc.get_node('z_score') preproc.remove_nodes([zscore]) mod_realign = preproc.get_node("mod_realign") mod_realign.plugin_args = {"submit_specs": "request_memory=4000\n"} # inputs preproc.inputs.inputspec.motion_correct_node = 'nipy' ad = preproc.get_node('artifactdetect') preproc.disconnect(mod_realign, 'parameter_source', ad, 'parameter_source') ad.inputs.parameter_source = "NiPy" preproc.inputs.inputspec.realign_parameters = { "loops": [5], "speedup": [5]