def test_design_warnings(): """ test that warnings are correctly raised upon weird design specification """ condition = ([-25, 20, 36.5], [0, 0, 0], [1, 1, 1]) frame_times = np.linspace(0, 69, 70) hrf_model = 'spm' with warnings.catch_warnings(record=True): warnings.simplefilter("always") with pytest.warns(UserWarning): compute_regressor(condition, hrf_model, frame_times) condition = ([-25, -25, 36.5], [0, 0, 0], [1, 1, 1]) with warnings.catch_warnings(record=True): warnings.simplefilter("always") with pytest.warns(UserWarning): compute_regressor(condition, hrf_model, frame_times)
def test_make_regressor_3(): """ test the generated regressor """ condition = ([1, 20, 36.5], [2, 2, 2], [1, 1, 1]) frame_times = np.linspace(0, 138, 70) hrf_model = 'fir' reg, reg_names = compute_regressor(condition, hrf_model, frame_times, fir_delays=np.arange(4)) assert_array_equal(np.sum(reg, 0), np.array([3, 3, 3, 3])) assert len(reg_names) == 4 reg_, reg_names_ = compute_regressor(condition, hrf_model, frame_times, fir_delays=np.arange(4), oversampling=50.) assert_array_equal(reg, reg_)
def test_make_regressor_2(): """ test the generated regressor """ condition = ([1, 20, 36.5], [0, 0, 0], [1, 1, 1]) frame_times = np.linspace(0, 69, 70) hrf_model = 'spm' reg, reg_names = compute_regressor(condition, hrf_model, frame_times) assert_almost_equal(reg.sum() * 50, 3, 1) assert reg_names[0] == 'cond'
def _convolve_regressors(events, hrf_model, frame_times, fir_delays=[0], min_onset=-24, oversampling=50): """ Creation of a matrix that comprises the convolution of the conditions onset with a certain hrf model Parameters ---------- events : DataFrame instance, Events data describing the experimental paradigm see nistats.experimental_paradigm to check the specification for these to be valid paradigm descriptors hrf_model : {'spm', 'spm + derivative', 'spm + derivative + dispersion', 'glover', 'glover + derivative', 'glover + derivative + dispersion', 'fir', None} String that specifies the hemodynamic response function frame_times : array of shape (n_scans,) The targeted timing for the design matrix. fir_delays : array-like of shape (n_onsets,), optional, In case of FIR design, yields the array of delays used in the FIR model (in scans). min_onset : float, optional (default: -24), Minimal onset relative to frame_times[0] (in seconds) events that start before frame_times[0] + min_onset are not considered. oversampling: int optional, default:50, Oversampling factor used in temporal convolutions. Returns ------- regressor_matrix : array of shape (n_scans, n_regressors), Contains the convolved regressors associated with the experimental conditions. regressor_names : list of strings, The regressor names, that depend on the hrf model used if 'glover' or 'spm' then this is identical to the input names if 'glover + derivative' or 'spm + derivative', a second name is output i.e. '#name_derivative' if 'spm + derivative + dispersion' or 'glover + derivative + dispersion', a third name is used, i.e. '#name_dispersion' if 'fir', the regressos are numbered accoding to '#name_#delay' """ regressor_names = [] regressor_matrix = None trial_type, onset, duration, modulation = check_events(events) for condition in np.unique(trial_type): condition_mask = (trial_type == condition) exp_condition = (onset[condition_mask], duration[condition_mask], modulation[condition_mask]) reg, names = compute_regressor(exp_condition, hrf_model, frame_times, con_id=condition, fir_delays=fir_delays, oversampling=oversampling, min_onset=min_onset) regressor_names += names if regressor_matrix is None: regressor_matrix = reg else: regressor_matrix = np.hstack((regressor_matrix, reg)) return regressor_matrix, regressor_names