diff --git a/.circleci/tedana_outputs_verbose.txt b/.circleci/tedana_outputs_verbose.txt index 26eda3590..be908d46f 100644 --- a/.circleci/tedana_outputs_verbose.txt +++ b/.circleci/tedana_outputs_verbose.txt @@ -1,4 +1,5 @@ __meica_mix.1D +adaptive_mask.nii betas_OC.nii betas_hik_OC.nii comp_table_ica.txt diff --git a/tedana/tests/test_utils.py b/tedana/tests/test_utils.py index a9d65d505..280639d6c 100644 --- a/tedana/tests/test_utils.py +++ b/tedana/tests/test_utils.py @@ -130,11 +130,11 @@ def test_make_adaptive_mask(): assert np.allclose(counts, np.array([13564, 3977, 5060, 41749])) # test user-defined mask + # TODO: Add mask file with no bad voxels to test against mask, masksum = utils.make_adaptive_mask(data, mask=pjoin(datadir, 'mask.nii.gz'), minimum=False, getsum=True) - assert np.allclose(mask, nib.load(pjoin(datadir, - 'mask.nii.gz')).get_data().flatten()) + assert np.allclose(mask, masksum.astype(bool)) def test_make_min_mask(): diff --git a/tedana/utils.py b/tedana/utils.py index c81db91e3..8d1faa8eb 100644 --- a/tedana/utils.py +++ b/tedana/utils.py @@ -1,17 +1,20 @@ """ Utilities for tedana package """ -import nibabel as nib +import logging + import numpy as np -from nibabel.filename_parser import splitext_addext -from nilearn._utils import check_niimg from scipy import stats from scipy.optimize import leastsq +import nibabel as nib +from nilearn._utils import check_niimg +from nibabel.filename_parser import splitext_addext from sklearn.utils import check_array from tedana.due import due, BibTeX FORMATS = {'.nii': 'NIFTI'} +LGR = logging.getLogger(__name__) def get_dtype(data): @@ -150,6 +153,13 @@ def make_adaptive_mask(data, mask=None, minimum=True, getsum=False): # if the user has supplied a binary mask mask = load_image(mask).astype(bool) masksum = masksum * mask + # reduce mask based on masksum + # TODO: Use visual report to make checking the reduced mask easier + if np.any(masksum[mask] == 0): + n_bad_voxels = np.sum(masksum[mask] == 0) + LGR.warning('{0} voxels in user-defined mask do not have good ' + 'signal. Removing voxels from mask.'.format(n_bad_voxels)) + mask = masksum.astype(bool) if getsum: return mask, masksum diff --git a/tedana/workflows/tedana.py b/tedana/workflows/tedana.py index d3f5ca014..304d4fae1 100644 --- a/tedana/workflows/tedana.py +++ b/tedana/workflows/tedana.py @@ -285,6 +285,8 @@ def tedana_workflow(data, tes, mask=None, mixm=None, ctab=None, manacc=None, mask, masksum = utils.make_adaptive_mask(catd, mask=mask, minimum=False, getsum=True) LGR.debug('Retaining {}/{} samples'.format(mask.sum(), n_samp)) + if verbose: + io.filewrite(masksum, op.join(out_dir, 'adaptive_mask.nii'), ref_img) os.chdir(out_dir) @@ -319,6 +321,8 @@ def tedana_workflow(data, tes, mask=None, mixm=None, ctab=None, manacc=None, t2s, t2sG, stabilize, ref_img, tes=tes, kdaw=kdaw, rdaw=rdaw, ste=ste, wvpca=wvpca) + + LGR.info('Computing ICA of dimensionally reduced data') mmix_orig, fixed_seed = decomposition.tedica(n_components, dd, fixed_seed)