Пример #1
0
    def _run_interface(self, runtime):
        src_nii = nb.load(self.inputs.src_file)
        src = NiftiWrapper(src_nii, make_empty=True)
        dest_nii = nb.load(self.inputs.dest_file)
        dest = NiftiWrapper(dest_nii, make_empty=True)
        classes = src.meta_ext.get_valid_classes()
        if self.inputs.include_classes:
            classes = [cls
                       for cls in classes
                       if cls in self.inputs.include_classes
                      ]
        if self.inputs.exclude_classes:
            classes = [cls
                       for cls in classes
                       if not cls in self.inputs.exclude_classes
                      ]

        for cls in classes:
            src_dict = src.meta_ext.get_class_dict(cls)
            dest_dict = dest.meta_ext.get_class_dict(cls)
            dest_dict.update(src_dict)
        # Update the shape and slice dimension to reflect the meta extension update.
        dest.meta_ext.slice_dim = src.meta_ext.slice_dim
        dest.meta_ext.shape = src.meta_ext.shape

        self.out_path = path.join(os.getcwd(),
                                  path.basename(self.inputs.dest_file))
        dest.to_filename(self.out_path)

        return runtime
Пример #2
0
    def _run_interface(self, runtime):
        src_nii = nb.load(self.inputs.src_file)
        src = NiftiWrapper(src_nii, make_empty=True)
        dest_nii = nb.load(self.inputs.dest_file)
        dest = NiftiWrapper(dest_nii, make_empty=True)
        classes = src.meta_ext.get_valid_classes()
        if self.inputs.include_classes:
            classes = [cls
                       for cls in classes
                       if cls in self.inputs.include_classes
                       ]
        if self.inputs.exclude_classes:
            classes = [cls
                       for cls in classes
                       if cls not in self.inputs.exclude_classes
                       ]

        for cls in classes:
            src_dict = src.meta_ext.get_class_dict(cls)
            dest_dict = dest.meta_ext.get_class_dict(cls)
            dest_dict.update(src_dict)
        # Update the shape and slice dimension to reflect the meta extension update.
        dest.meta_ext.slice_dim = src.meta_ext.slice_dim
        dest.meta_ext.shape = src.meta_ext.shape

        self.out_path = op.join(os.getcwd(),
                                op.basename(self.inputs.dest_file))
        dest.to_filename(self.out_path)

        return runtime
Пример #3
0
    def _run_interface(self, runtime):
        src_nii = nb.load(self.inputs.src_file)
        src = NiftiWrapper(src_nii, make_empty=True)
        dest_nii = nb.load(self.inputs.dest_file)
        dest = NiftiWrapper(dest_nii, make_empty=True)
        classes = src.meta_ext.get_valid_classes()
        if self.inputs.include_classes:
            classes = [
                cls for cls in classes if cls in self.inputs.include_classes
            ]
        if self.inputs.exclude_classes:
            classes = [
                cls for cls in classes
                if not cls in self.inputs.exclude_classes
            ]

        for cls in classes:
            src_dict = src.meta_ext.get_class_dict(cls)
            dest_dict = dest.meta_ext.get_class_dict(cls)
            dest_dict.update(src_dict)

        self.out_path = path.join(os.getcwd(),
                                  path.basename(self.inputs.dest_file))
        dest.to_filename(self.out_path)

        return runtime
Пример #4
0
 def _run_interface(self, runtime):
     src = NiftiWrapper.from_filename(self.inputs.src_file)
     dest_nii = nb.load(self.inputs.dest_file)
     dest = NiftiWrapper(dest_nii, make_empty=True)
     classes = src.meta_ext.get_valid_classes()
     if self.inputs.include_classes:
         classes = [cls 
                    for cls in classes 
                    if cls in self.inputs.include_classes
                   ]
     if self.inputs.exclude_classes:
         classes = [cls 
                    for cls in classes 
                    if not cls in self.inputs.exclude_classes
                   ]
     
     for cls in classes:
         src_dict = src.meta_ext.get_class_dict(cls)
         dest_dict = dest.meta_ext.get_class_dict(cls)
         dest_dict.update(src_dict)
         
     self.out_path = path.join(os.getcwd(), 
                               path.basename(self.inputs.dest_file))
     dest.to_filename(self.out_path)
     
     return runtime
Пример #5
0
    def _run_interface(self, runtime):
        src_paths = self._get_filelist(self.inputs.dicom_files)
        stacks = dcmstack.parse_and_stack(src_paths)

        self.out_list = []
        for key, stack in list(stacks.items()):
            nw = NiftiWrapper(stack.to_nifti(embed_meta=True))
            const_meta = nw.meta_ext.get_class_dict(("global", "const"))
            out_path = self._get_out_path(const_meta)
            if not self.inputs.embed_meta:
                nw.remove_extension()
            nb.save(nw.nii_img, out_path)
            self.out_list.append(out_path)

        return runtime
Пример #6
0
    def _run_interface(self, runtime):
        src_paths = self._get_filelist(self.inputs.dicom_files)
        stacks = dcmstack.parse_and_stack(src_paths)

        self.out_list = []
        for key, stack in stacks.iteritems():
            nw = NiftiWrapper(stack.to_nifti(embed_meta=True))
            const_meta = nw.meta_ext.get_class_dict(('global', 'const'))
            out_path =  self._get_out_path(const_meta)
            if not self.inputs.embed_meta:
                nw.remove_extension()
            nb.save(nw.nii_img, out_path)
            self.out_list.append(out_path)

        return runtime
Пример #7
0
    def _run_interface(self, runtime):
        self.out_list = []
        nii = nb.load(self.inputs.in_file)
        nw = NiftiWrapper(nii, make_empty=True)
        split_dim = None
        if self.inputs.split_dim == traits.Undefined:
            split_dim = None
        else:
            split_dim = self.inputs.split_dim
        for split_idx, split_nw in enumerate(nw.split(split_dim)):
            const_meta = split_nw.meta_ext.get_class_dict(("global", "const"))
            out_path = self._get_out_path(const_meta, idx=split_idx)
            nb.save(split_nw.nii_img, out_path)
            self.out_list.append(out_path)

        return runtime
def metaread(nifti):
    """
    Combines metadata read from the header, populates the SPM slice timing
    correction inputs and outputs the time corrected epi image.
    Uses dcmstack.lookup to get TR and slice times, and NiftiWrapper to get
    image dimensions (number of slices is the z [2]).
    """

    from nipype.interfaces import dcmstack
    from dcmstack.dcmmeta import NiftiWrapper
    nii = NiftiWrapper.from_filename(nifti)
    imdims = nii.meta_ext.shape
    sliceno = imdims[2]
    mid_slice = int(sliceno / 2)
    lookup = dcmstack.LookupMeta()
    lookup.inputs.meta_keys = {
        'RepetitionTime': 'TR',
        'CsaImage.MosaicRefAcqTimes': 'ST'
    }
    lookup.inputs.in_file = nifti
    lookup.run()
    slicetimes = [int(lookup.result['ST'][0][x])
                  for x in range(0, imdims[2])]  #Converts slice times to ints.
    tr = lookup.result['TR'] / 1000  #Converts tr to seconds.
    ta = tr - (tr / sliceno)
    return (sliceno, slicetimes, tr, ta, mid_slice)
Пример #9
0
    def _run_interface(self, runtime):
        self.out_list = []
        nii = nb.load(self.inputs.in_file)
        nw = NiftiWrapper(nii, make_empty=True)
        split_dim = None
        if self.inputs.split_dim == traits.Undefined:
            split_dim = None
        else:
            split_dim = self.inputs.split_dim
        for split_idx, split_nw in enumerate(nw.split(split_dim)):
            const_meta = split_nw.meta_ext.get_class_dict(('global', 'const'))
            out_path = self._get_out_path(const_meta, idx=split_idx)
            nb.save(split_nw.nii_img, out_path)
            self.out_list.append(out_path)

        return runtime
Пример #10
0
 def _run_interface(self, runtime):
     niis = [nb.load(fn) for fn in self.inputs.in_files]
     nws = [NiftiWrapper(nii, make_empty=True) for nii in niis]
     if self.inputs.sort_order:
         sort_order = self.inputs.sort_order
         if isinstance(sort_order, (str, bytes)):
             sort_order = [sort_order]
         nws.sort(key=make_key_func(sort_order))
     if self.inputs.merge_dim == traits.Undefined:
         merge_dim = None
     else:
         merge_dim = self.inputs.merge_dim
     merged = NiftiWrapper.from_sequence(nws, merge_dim)
     const_meta = merged.meta_ext.get_class_dict(("global", "const"))
     self.out_path = self._get_out_path(const_meta)
     nb.save(merged.nii_img, self.out_path)
     return runtime
Пример #11
0
    def _run_interface(self, runtime):
        # If the 'meta_keys' input is a list, covert it to a dict
        self._make_name_map()
        nw = NiftiWrapper.from_filename(self.inputs.in_file)
        self.result = {}
        for meta_key, out_name in list(self._meta_keys.items()):
            self.result[out_name] = nw.meta_ext.get_values(meta_key)

        return runtime
Пример #12
0
    def _run_interface(self, runtime):
        #If the 'meta_keys' input is a list, covert it to a dict
        self._make_name_map()
        nw = NiftiWrapper.from_filename(self.inputs.in_file)
        self.result = {}
        for meta_key, out_name in self._meta_keys.iteritems():
            self.result[out_name] = nw.meta_ext.get_values(meta_key)

        return runtime
    def get_tr_and_sliceorder(dicom_files):
        import numpy as np
        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
 def get_tr_and_sliceorder(nifti_file):
     import numpy as np
     import os
     import dcmstack, dicom
     from dcmstack.dcmmeta import NiftiWrapper
     nii = NiftiWrapper.from_filename(nifti_file)
     f = open("slicetiming.txt", "w")
     f.write("\n".join(["%g"%(i/1000.) for i in nii.meta_ext.get_values('CsaImage.MosaicRefAcqTimes')[1]]) + "\n")
     f.close()
     tr = nii.meta_ext.get_values('RepetitionTime')
     return tr/1000., os.path.abspath("slicetiming.txt")
Пример #15
0
 def _run_interface(self, runtime):
     src_paths = self._get_filelist(self.inputs.dicom_files)
     include_regexes = dcmstack.default_key_incl_res
     if isdefined(self.inputs.include_regexes):
         include_regexes += self.inputs.include_regexes
     exclude_regexes = dcmstack.default_key_excl_res
     if isdefined(self.inputs.exclude_regexes):
         exclude_regexes += self.inputs.exclude_regexes
     meta_filter = dcmstack.make_key_regex_filter(exclude_regexes, include_regexes)
     stack = dcmstack.DicomStack(meta_filter=meta_filter)
     for src_path in src_paths:
         src_dcm = dicom.read_file(src_path, force=True)
         stack.add_dcm(src_dcm)
     nii = stack.to_nifti(embed_meta=True)
     nw = NiftiWrapper(nii)
     self.out_path = self._get_out_path(nw.meta_ext.get_class_dict(("global", "const")))
     if not self.inputs.embed_meta:
         nw.remove_extension()
     nb.save(nii, self.out_path)
     return runtime
 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
Пример #17
0
 def _run_interface(self, runtime):
     src_paths = self._get_filelist(self.inputs.dicom_files)
     include_regexes = dcmstack.default_key_incl_res
     if isdefined(self.inputs.include_regexes):
         include_regexes += self.inputs.include_regexes
     exclude_regexes = dcmstack.default_key_excl_res
     if isdefined(self.inputs.exclude_regexes):
         exclude_regexes += self.inputs.exclude_regexes
     meta_filter = dcmstack.make_key_regex_filter(exclude_regexes,
                                                  include_regexes)
     stack = dcmstack.DicomStack(meta_filter=meta_filter)
     for src_path in src_paths:
         src_dcm = dicom.read_file(src_path, force=True)
         stack.add_dcm(src_dcm)
     nii = stack.to_nifti(embed_meta=True)
     nw = NiftiWrapper(nii)
     self.out_path = \
         self._get_out_path(nw.meta_ext.get_class_dict(('global', 'const')))
     if not self.inputs.embed_meta:
         nw.remove_extension()
     nb.save(nii, self.out_path)
     return runtime
Пример #18
0
 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
Пример #19
0
 def _run_interface(self, runtime):
     niis = [nb.load(fn) for fn in self.inputs.in_files]
     nws = [NiftiWrapper(nii, make_empty=True) for nii in niis]
     if self.inputs.sort_order:
         sort_order = self.inputs.sort_order
         if isinstance(sort_order, str):
             sort_order = [sort_order]
         nws.sort(key=make_key_func(sort_order))
     if self.inputs.merge_dim == traits.Undefined:
         merge_dim = None
     else:
         merge_dim = self.inputs.merge_dim
     merged = NiftiWrapper.from_sequence(nws, merge_dim)
     const_meta = merged.meta_ext.get_class_dict(("global", "const"))
     self.out_path = self._get_out_path(const_meta)
     nb.save(merged.nii_img, self.out_path)
     return runtime
Пример #20
0
def extract_meta(func):
    """Extracts meta-data from niftis that were created from dcmstack_

Parameters
----------

func : String
       Filename of nifti image created from dcmstack_

Returns
-------

so : List of Integers
     Slice order of nifti

tr : Float
     Repetition Time (TR) in seconds

.. _dcmstack: https://github.com/moloney/dcmstack

"""
    from nibabel import load
    import numpy as np
    from dcmstack.dcmmeta import NiftiWrapper
    sliceorders = []
    trs = []
    if not isinstance(func, list):
        func = [func]
    for f in func:
        img = load(f)
        wrp = NiftiWrapper(img)
        sliceorder = np.argsort(
            wrp.meta_ext.get_values('CsaImage.MosaicRefAcqTimes')[0]).tolist()
        sliceorders.append(sliceorder)
        tr = wrp.meta_ext.get_values('RepetitionTime')
        trs.append(tr)
    so = sliceorders[0]
    if np.sum(np.diff(sliceorders, axis=0)):
        raise Exception("The functional runs have different slice orders!")
    if np.sum(np.diff(trs)):
        raise Exception("The functional runs have different TRs!")
    else:
        return so, trs[0] / 1000.
Пример #21
0
	print(gtab.bvals) # Printing bvals on console
	print(gtab.bvecs) # Printing bvecs on console

	S0s = data[:, :, :, gtab.b0s_mask] # Used to tell which part of the data contains b0s
	print(S0s.shape) # Verifying the dimensions of S0s to determine the number of b0s
	nib.save(nib.Nifti1Image(S0s, img.affine), subject+'_b0_AP.nii.gz') # Just for necessary
	src = join(home, '.dipy', subject + '_b0_AP.nii.gz') # Where the source file is
	dst = join(dname, subject + "_b0_AP.nii.gz") # The new destination for the file
	shutil.move(src, dst) # Moving the file to the right directory

	#############################################################
	#                        Merging                            #
	#############################################################
	fb0AP = join(dname, subject + '_b0_AP.nii.gz') # The b0AP image is saved in this variable
	fb0PA = join(dname, subject + '_DWI_b0_PA.nii.gz') # The b0PA image is saved in this variable
	b0AP = NiftiWrapper.from_filename(fb0AP) # Loading the image in this variable
	b0PA = NiftiWrapper.from_filename(fb0PA) # Loading the image in this variable
	print(b0AP.nii_img.get_shape()) # Size of data
	print(b0PA.nii_img.get_shape()) # Size of data
	print(b0AP.get_meta('EchoTime')) # Echo time
	print(b0PA.get_meta('EchoTime')) # Echo time
	b0APPA = NiftiWrapper.from_sequence([b0AP, b0PA]) # Merging of the two b0 files
	print(b0APPA.nii_img.get_shape()) # Size of data
	print(b0APPA.get_meta('EchoTime', index = (0, 0, 0, 0))) # Echo time
	print(b0APPA.get_meta('EchoTime', index = (0, 0, 0, 1))) # Echo time

	#############################################################
	# 						Topup								#
	#############################################################

Пример #22
0
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")
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")