示例#1
0
def test_cosine_drift():
    # add something so that when the tests are launched
    #from a different directory
    spm_drifts = DESIGN_MATRIX['cosbf_dt_1_nt_20_hcut_0p1']
    tim = np.arange(20)
    P = 10  # period is half the time, gives us an order 4
    nistats_drifts = _cosine_drift(P, tim)
    assert_almost_equal(spm_drifts[:, 1:], nistats_drifts[:, :-1])
示例#2
0
def test_cosine_drift():
    # add something so that when the tests are launched
    #from a different directory
    spm_drifts = DESIGN_MATRIX['cosbf_dt_1_nt_20_hcut_0p1']
    tim = np.arange(20)
    P = 10  # period is half the time, gives us an order 4
    nistats_drifts = _cosine_drift(P, tim)
    assert_almost_equal(spm_drifts[:, 1:], nistats_drifts[:, : - 1])
示例#3
0
def test_cosine_drift():
    # add something so that when the tests are launched
    #from a different directory
    spm_drifts = DESIGN_MATRIX['cosbf_dt_1_nt_20_hcut_0p1']
    frame_times = np.arange(20)
    high_pass_frequency = .1
    nistats_drifts = _cosine_drift(high_pass_frequency, frame_times)
    assert_almost_equal(spm_drifts[:, 1:], nistats_drifts[:, :-2])
示例#4
0
def _run_preproc_in_parallel(run, event, conf, func, ricor, task, space, conf_vars, mask, hp_cutoff,
                             add_motion_outliers, smoothing_fwhm, df_filter, slice_time_ref, tr, logger):
    
    logger.info(f"Preprocessing run {run+1} ...")
    
    if 'fs' in space:
        func_ts = np.vstack([d.data[np.newaxis, :] for
                             d in nib.load(func).darrays])
    else:                       
        if not np.all(nib.load(func).affine == mask.affine):
            print(f"Resampling run {run+1} to mask affine, because they are different")
            func = image.resample_img(func, target_affine=mask.affine, target_shape=mask.shape)
                                                               
        func_ts = masking.apply_mask(
            imgs=func,
            mask_img=mask,
            smoothing_fwhm=smoothing_fwhm
        )

    n_vols = func_ts.shape[0]
    start_time = slice_time_ref * tr
    end_time = (n_vols - 1 + slice_time_ref) * tr
    frame_times = np.linspace(start_time, end_time, n_vols)

    event = pd.read_csv(event, sep='\t')
    if df_filter is not None: 
        event = df_filter(event)

    conf = pd.read_csv(conf, sep='\t')    
    all_conf_vars = conf_vars

    if add_motion_outliers:
        mo = [col for col in conf.columns if 'motion_outlier' in col]
        if len(mo) > 0:
            logger.info(f"Adding {len(mo)} motion outliers to design for run {run+1}.")
        all_conf_vars += mo

    if hp_cutoff is None:
        all_conf_vars += [col for col in conf.columns if 'cosine' in col]
        conf = conf.loc[:, all_conf_vars].fillna(0)
        conf = pd.concat((conf, cos_df), axis=1)
    else:
        conf = conf.loc[:, all_conf_vars].fillna(0)
        cos = _cosine_drift(hp_cutoff, frame_times)[:, :-1]
        cos_names = [f'cosine{ic}'.zfill(3) for ic in range(cos.shape[1])]
        cos_df = pd.DataFrame(data=cos, columns=cos_names, index=conf.index)
        conf = pd.concat((conf, cos_df), axis=1)
    
    if ricor is not None:
        ricor_df = pd.read_csv(ricor, sep='\t')
        conf = pd.concat((conf, ricor_df), axis=1)
    
    return func_ts, conf, event