def __img_to_tseries(self, filename_img, mask_img, confounds_filename=None, smoothing_fwhm=None, strategy=["minimal"], chunksize=3000): img = nb.load(filename_img) img = resample_to_img(img, mask_img) if confounds_filename is not None: confounds = load_confounds(confounds_filename, strategy=strategy) masker = NiftiMasker(mask_img, smoothing_fwhm=smoothing_fwhm) masker.fit(img) masker.mask_img_ = mask_img tseries = masker.transform(img) if confounds_filename is not None: confounds=confounds.values tseries = clean(tseries, confounds=confounds) else: tseries = clean(tseries) tseries = self.__normalize_data(tseries) darr_tseries = da.from_array(tseries, chunks=(chunksize, tseries.shape[1])) return darr_tseries
def test_high_level_glm_one_session(): shapes, rk = [(7, 8, 9, 15)], 3 mask, fmri_data, design_matrices = generate_fake_fmri_data_and_design(shapes, rk) # Give an unfitted NiftiMasker as mask_img and check that we get an error masker = NiftiMasker(mask) with pytest.raises(ValueError, match="It seems that NiftiMasker has not been fitted."): single_session_model = FirstLevelModel(mask_img=masker).fit( fmri_data[0], design_matrices=design_matrices[0]) # Give a fitted NiftiMasker with a None mask_img_ attribute # and check that the masker parameters are overriden by the # FirstLevelModel parameters masker.fit() masker.mask_img_ = None with pytest.warns(UserWarning, match="Parameter memory of the masker overriden"): single_session_model = FirstLevelModel(mask_img=masker).fit( fmri_data[0], design_matrices=design_matrices[0]) # Give a fitted NiftiMasker masker = NiftiMasker(mask) masker.fit() single_session_model = FirstLevelModel(mask_img=masker).fit( fmri_data[0], design_matrices=design_matrices[0]) assert single_session_model.masker_ == masker # Call with verbose (improve coverage) single_session_model = FirstLevelModel(mask_img=None, verbose=1).fit( fmri_data[0], design_matrices=design_matrices[0]) single_session_model = FirstLevelModel(mask_img=None).fit( fmri_data[0], design_matrices=design_matrices[0]) assert isinstance(single_session_model.masker_.mask_img_, Nifti1Image) single_session_model = FirstLevelModel(mask_img=mask).fit( fmri_data[0], design_matrices=design_matrices[0]) z1 = single_session_model.compute_contrast(np.eye(rk)[:1]) assert isinstance(z1, Nifti1Image)