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

Add --masktype option to control adaptive mask method #1057

Merged
merged 29 commits into from
Apr 8, 2024

Conversation

tsalo
Copy link
Member

@tsalo tsalo commented Mar 10, 2024

Closes #312. I'd like to look into R-squared again at some point, but I think this is a solid improvement to the adaptive mask.

Changes proposed in this pull request:

  • Add a new CLI argument, --masktype to both tedana and t2smap. This parameter accepts one or more values, like --gscontrol. The valid values are "dropout" (the current method), "decay" (flag any echoes that do not decrease in mean value), and "none" (set adaptive mask value to all echoes, for testing and the like).
    • If you use more than one method, the function will just take the elementwise minimum value from all of the method-specific adaptive masks.
  • Implement a "decay" method for the adaptive mask, which calculates an array reflecting the first echo where mean signal does not decrease from the last echo.
  • Remove getsum parameter from make_adaptive_mask. We don't use getsum=False outside of tests, so we really don't need it.

@tsalo tsalo added the enhancement issues describing possible enhancements to the project label Mar 10, 2024
tedana/utils.py Show resolved Hide resolved
tedana/utils.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Mar 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.75%. Comparing base (f084dc4) to head (a0d5f79).
Report is 35 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1057      +/-   ##
==========================================
+ Coverage   89.68%   89.75%   +0.06%     
==========================================
  Files          26       26              
  Lines        3482     3505      +23     
  Branches      615      620       +5     
==========================================
+ Hits         3123     3146      +23     
  Misses        211      211              
  Partials      148      148              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tsalo tsalo marked this pull request as ready for review March 10, 2024 17:50
Copy link
Member

@handwerkerd handwerkerd left a comment

Choose a reason for hiding this comment

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

Mostly looks good. I do want several people to compare the masks on real data to make sure nothing unexpected is happening. This change really shouldn't shrink the masks much, so, if it does, that's concerning.

tedana/utils.py Outdated Show resolved Hide resolved
tedana/utils.py Outdated
last_decreasing_echo[last_decreasing_echo == 0] = n_echos # if no increase, set to n_echos

# Retain the more conservative of the two adaptive mask estimates
masksum = np.minimum(masksum, last_decreasing_echo)
Copy link
Member

Choose a reason for hiding this comment

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

Might want to make a second warning message if last_decreasing_echo removes nontrivially more voxels than the other threshold. I'm viewing that as a sign that something is wrong with the data.

Copy link
Member

Choose a reason for hiding this comment

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

I think we'll want to log the voxel counts with each different method. I wrote some code for that, but it was a bit ugly and I think it might be easier to do as a separate PR once all current adaptive mask PRs are merged.

tedana/utils.py Outdated Show resolved Hide resolved
@handwerkerd
Copy link
Member

Thinking this over more: The code for these changes in simple, but this can non-trivially affect results in ways that are worth testing. One option to consider is that you tweak this PR to make it possible for an end-user to try the current adaptive mask, and several other options using t2smap (This could be hacky change to a couple of functions and the t2smap CLI/API, I could see either removing all of that or just the CLI/API option before merging.). It could also be tweaked to log the mask sizes & size differences with each option. Then it would be easy for several of us to run t2smap on a lot of data and compare the adaptive masks.

Depending on timing we could attempt to either have results to discuss by next Thursday's dev call or prod people to try this at the dev call. Thoughts?

Co-authored-by: Dan Handwerker <7406227+handwerkerd@users.noreply.github.com>
@handwerkerd handwerkerd added the breaking change WIll make a non-trivial change to outputs label Mar 13, 2024
tedana/utils.py Outdated Show resolved Hide resolved
@handwerkerd handwerkerd added the bug issues describing a bug or error found in the project label Mar 14, 2024
@handwerkerd handwerkerd removed the bug issues describing a bug or error found in the project label Mar 17, 2024
@tsalo
Copy link
Member Author

tsalo commented Mar 29, 2024

Based on our developer meeting a couple of weeks ago, I've added a --masktype parameter to control how the adaptive mask is generated. @handwerkerd could you take another look at some point?

EDIT: I've also made the old behavior (--masktype dropout) the default, so this should no longer change the results.

@tsalo tsalo removed the breaking change WIll make a non-trivial change to outputs label Mar 29, 2024
@tsalo tsalo changed the title Enhance adaptive mask by flagging echoes where signal does not decrease Add --masktype option to control adaptive mask method Mar 29, 2024
@tsalo tsalo requested a review from handwerkerd April 4, 2024 11:54
Copy link
Member

@handwerkerd handwerkerd left a comment

Choose a reason for hiding this comment

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

I have a bunch of comments, but, overall, this is good. The only major thing is that I don't think it will be possible to select decay and dropout through the CLI.

Also, after starting this, I realized it would be slightly nicer to merge #1060 first since you'll pretty much have to re-write #1060 to fit with these changes. Changed my mind on this. It would be easier to merge this with the updated doc strings and parameters and then align the other masking PRs to fit within these updates.

tedana/workflows/tedana.py Show resolved Hide resolved
tedana/utils.py Outdated Show resolved Hide resolved
tedana/utils.py Outdated Show resolved Hide resolved
tedana/utils.py Outdated Show resolved Hide resolved
tedana/utils.py Outdated Show resolved Hide resolved
tedana/utils.py Show resolved Hide resolved
tedana/utils.py Outdated Show resolved Hide resolved
tedana/utils.py Outdated Show resolved Hide resolved
tedana/utils.py Outdated Show resolved Hide resolved
@tsalo
Copy link
Member Author

tsalo commented Apr 5, 2024

I think I've addressed everything, and I updated the t2smap integration test to use both dropout and decay to ensure that the parser could handle multiple values.

Copy link
Member

@handwerkerd handwerkerd left a comment

Choose a reason for hiding this comment

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

I noticed a few more things, but this is getting close.

tedana/utils.py Outdated Show resolved Hide resolved
tedana/utils.py Outdated Show resolved Hide resolved
tedana/workflows/tedana.py Outdated Show resolved Hide resolved
tedana/workflows/t2smap.py Outdated Show resolved Hide resolved
tedana/utils.py Outdated
last_decreasing_echo[last_decreasing_echo == 0] = n_echos # if no increase, set to n_echos

# Retain the more conservative of the two adaptive mask estimates
masksum = np.minimum(masksum, last_decreasing_echo)
Copy link
Member

Choose a reason for hiding this comment

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

I think we'll want to log the voxel counts with each different method. I wrote some code for that, but it was a bit ugly and I think it might be easier to do as a separate PR once all current adaptive mask PRs are merged.

tsalo and others added 5 commits April 5, 2024 14:53
Co-authored-by: Dan Handwerker <7406227+handwerkerd@users.noreply.github.com>
Co-authored-by: Dan Handwerker <7406227+handwerkerd@users.noreply.github.com>
Co-authored-by: Dan Handwerker <7406227+handwerkerd@users.noreply.github.com>
Co-authored-by: Dan Handwerker <7406227+handwerkerd@users.noreply.github.com>
@tsalo tsalo requested a review from handwerkerd April 5, 2024 19:13
Copy link
Member

@handwerkerd handwerkerd left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@eurunuela eurunuela left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @tsalo!

@tsalo tsalo merged commit 6abcfd1 into ME-ICA:main Apr 8, 2024
16 checks passed
@tsalo tsalo deleted the fix-adaptive-mask branch April 8, 2024 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement issues describing possible enhancements to the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use overall signal decay in adaptive mask creation
3 participants