Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Reduce user-defined mask when there is no good signal #172

Merged
merged 11 commits into from
Dec 18, 2018

Conversation

tsalo
Copy link
Member

@tsalo tsalo commented Dec 14, 2018

Closes #171.

Changes proposed in this pull request:

  • When there are voxels in the user-defined mask with no good signal (as determined by make_adaptive_mask), they will now be removed from the mask used in tedana.

@tsalo
Copy link
Member Author

tsalo commented Dec 14, 2018

We're going to need to update test_make_adaptive_mask. Does anyone have any ideas for a good test?

@codecov
Copy link

codecov bot commented Dec 15, 2018

Codecov Report

Merging #172 into master will increase coverage by 0.12%.
The diff coverage is 90.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #172      +/-   ##
==========================================
+ Coverage   52.59%   52.71%   +0.12%     
==========================================
  Files          32       32              
  Lines        1905     1912       +7     
==========================================
+ Hits         1002     1008       +6     
- Misses        903      904       +1
Impacted Files Coverage Δ
tedana/workflows/tedana.py 12.59% <0%> (-0.1%) ⬇️
tedana/utils.py 98.13% <100%> (+0.11%) ⬆️
tedana/tests/test_utils.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e259ec...6f26e3f. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 15, 2018

Codecov Report

Merging #172 into master will increase coverage by 0.06%.
The diff coverage is 76.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #172      +/-   ##
==========================================
+ Coverage   52.59%   52.66%   +0.06%     
==========================================
  Files          32       32              
  Lines        1905     1914       +9     
==========================================
+ Hits         1002     1008       +6     
- Misses        903      906       +3
Impacted Files Coverage Δ
tedana/workflows/tedana.py 12.4% <0%> (-0.3%) ⬇️
tedana/utils.py 98.13% <100%> (+0.11%) ⬆️
tedana/tests/test_utils.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e259ec...22bda31. Read the comment docs.

@tsalo tsalo requested a review from emdupre December 17, 2018 19:40
Copy link
Member

@emdupre emdupre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pulling this patch together ! I think it looks great. Had a few questions / comments for future additions, but it'd be good to have this fix merged in since it's a super annoying bug 🐛

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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a "#TODO" about asking them to visually inspect the mask ? This is something we should include in the visual reports, eventually.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, although we aren't actually writing out the masks at the moment. I was planning to incorporate writing out the masks and other intermediate outputs into verbose in a future PR, but can at least write out the masks with verbose in this one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I misinterpreted your comment. I'll add a comment to the code.

@@ -133,8 +133,7 @@ def test_make_adaptive_mask():
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our test is failing, here, since we're now hitting this "bad voxel" condition, I suppose ? This is probably actually fine for now since it covers more lines of code, but we could add a "#TODO" here about testing with a mask that does not include bad voxels.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a lot of voxels in the mask had bad data, so the mask file didn't match up with the adaptive mask. I'll add a TODO.

@@ -285,6 +285,9 @@ 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(mask.astype(int), op.join(out_dir, 'mask.nii'), ref_img)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a benefit in writing out the mask ? Either it's user-provided or effectively just the adaptive mask, no ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the regular mask? There's probably no reason to write it out. I'll drop that one.

@emdupre
Copy link
Member

emdupre commented Dec 18, 2018

This is great ! Thanks @tsalo ✨ Merging !

@emdupre emdupre merged commit 1bc32e4 into ME-ICA:master Dec 18, 2018
@tsalo tsalo deleted the fix-masking branch December 31, 2018 20:23
@jbteves jbteves added breaking change WIll make a non-trivial change to outputs and removed output-change labels Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change WIll make a non-trivial change to outputs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when voxels in explicit mask do not have "good" signal in any echoes
3 participants