def design_matrix( misc_file, output_file, session, paradigm_file, frametimes, hrf_model="Canonical", drift_model="Blank", add_regs=None, drift_order=2, hfcut=128, fir_delays=[0], fir_duration=1., model="default", add_reg_names=None, verbose=0): """ Estimation of the design matrix and update of misc info Parameters ---------- misc_file: string, path of misc info file that is updated with info on design matrix output_file: string, path of the (.csv) file where the design matrix shall be written session: string, id of the session paradigm_file: string, path of (.csv) paradigm-describing file or None, if no such file exists concerning the following parameters, please refer to nipy.neurospin.utils.design_matrix Returns ------- dmtx: nipy.neurospin.utils.design_matrix.DesignMatrix instance """ import nipy.neurospin.utils.design_matrix as dm # get the condition names misc = ConfigObj(misc_file) if session.isdigit(): _session = int(session) else: _session = misc["sessions"].index(session) _names = misc["tasks"] # get the paradigm if isinstance(paradigm_file, basestring): _paradigm = dm.load_protocol_from_csv_file(paradigm_file, _session) else: _paradigm = None # compute the design matrix dmtx = dm.DesignMatrix(frametimes, _paradigm, hrf_model=hrf_model, drift_model=drift_model, hfcut=hfcut, drift_order=drift_order, fir_delays=fir_delays, fir_duration=fir_duration, cond_ids=_names, add_regs=add_regs, add_reg_names=add_reg_names) dmtx.estimate() # write the design matrix dmtx.write_csv(output_file) # write some info in the misc file if not misc.has_key(model): misc[model] = {} misc[model]["regressors_%s" % session] = dmtx.names misc[model]["design matrix cond"] = dmtx.design_cond misc.write() return dmtx
# confounds hrf_model = 'Canonical With Derivative' drift_model = "Cosine" hfcut = 128 # write directory swd = tempfile.mkdtemp() print 'Computation will be performed in temporary directory: %s' % swd ######################################## # Design matrix ######################################## print 'Loading design matrix...' paradigm = dm.load_protocol_from_csv_file(paradigm_file, session=0) design_matrix = dm.DesignMatrix( frametimes, paradigm, hrf_model=hrf_model, drift_model=drift_model, hfcut=hfcut) design_matrix.show() pylab.savefig(op.join(swd, 'design_matrix.png')) # design_matrix.save(...) ######################################## # Mask the data ######################################## print 'Computing a brain mask...' mask_path = op.join(swd, 'mask.nii') mask_array = compute_mask_files( data_path, mask_path, False, 0.4, 0.9)