def test_get_design_from_fslmat(tmp_path): fsl_mat_path = os.path.join(str(tmp_path), 'fsl_mat.txt') matrix = np.ones((5, 5)) with open(fsl_mat_path, 'w') as fsl_mat: fsl_mat.write('/Matrix\n') for row in matrix: for val in row: fsl_mat.write(str(val) + '\t') fsl_mat.write('\n') design_matrix = get_design_from_fslmat(fsl_mat_path) assert design_matrix.shape == matrix.shape
def _make_design_matrix_for_bids_feature(data_dir, subject): # pragma: no cover fsl_design_matrix_path = os.path.join(data_dir, 'derivatives', 'task', subject, 'stopsignal.feat', 'design.mat') design_matrix = get_design_from_fslmat(fsl_design_matrix_path, column_names=None) design_columns = [ 'cond_%02d' % i for i in range(len(design_matrix.columns)) ] design_columns[0] = 'Go' design_columns[4] = 'StopSuccess' design_matrix.columns = design_columns return design_matrix
models, models_run_imgs, models_events, models_confounds = \ first_level_from_bids(data_dir, task_label, space_label, smoothing_fwhm=5.0, derivatives_folder=derivatives_folder) ############################################################################# # Access the model and model arguments of the subject and process events. model, imgs, events, confounds = (models[0], models_run_imgs[0], models_events[0], models_confounds[0]) subject = 'sub-' + model.subject_label import os from nilearn._utils.glm import get_design_from_fslmat fsl_design_matrix_path = os.path.join(data_dir, 'derivatives', 'task', subject, 'stopsignal.feat', 'design.mat') design_matrix = get_design_from_fslmat(fsl_design_matrix_path, column_names=None) ############################################################################# # We identify the columns of the Go and StopSuccess conditions of the # design matrix inferred from the FSL file, to use them later for contrast # definition. design_columns = ['cond_%02d' % i for i in range(len(design_matrix.columns))] design_columns[0] = 'Go' design_columns[4] = 'StopSuccess' design_matrix.columns = design_columns ############################################################################ # First level model estimation (one subject) # ------------------------------------------- # We fit the first level model for one subject. model.fit(imgs, design_matrices=[design_matrix])