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] Fix PSC normalization when a high-pass filter is applied #4116
Conversation
ymzayek
commented
Nov 23, 2023
- Closes [BUG] NiftiSpheresMasker - Combination of percent signal change normalization and high-pass filtering only outputs signals in incorrect range. #4087
👋 @ymzayek Thanks for creating a PR! Until this PR is ready for review, you can include the [WIP] tag in its title, or leave it as a github draft. Please make sure it is compliant with our contributing guidelines. In particular, be sure it checks the boxes listed below.
For new features:
For bug fixes:
We will review it as quick as possible, feel free to ping us with questions if needed. |
Is it valid to just add back the original mean to the signal for calculating PSC? |
Or alternatively pass the original mean signal and subtract that from the filtered signal like was suggested in the issue? But that doesn't center around 0 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4116 +/- ##
==========================================
- Coverage 92.10% 92.07% -0.03%
==========================================
Files 144 144
Lines 16368 16368
Branches 3427 3427
==========================================
- Hits 15075 15071 -4
- Misses 754 756 +2
- Partials 539 541 +2 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
I will need to do some experiment around this to see what's the most sensible way to move forward. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default of detrend is True
so the current changes are
- not really correctly tested in
test_clean_psc
- doesn't address the bug of the original issue
I tried to add a test with butterworth filter and we ended up with very wonky means (number around -100 or 100).
I have also discovered the psc output will have really wild numbers if we have means less than 1. This standardization method might need a new review @bthirion
The change looks good, bit we should probably test all relevant configurations. Best, |
For tests: - make sure the signal is not detrended in test so psc is tested in isolation - add butterworth filter as a special case to the test For code: - streamline the logic of standardisation so we make sure mean signals are added back only when using psc and when butterworth filter or detrend was done. - remove the mean_signals parameter from standardize_signal but calculate it inside the function. This is due to signal butterworth filter will have a non-zero mean that is really close to zero. - make sure `filter_type` returns the correct filter that's applied. Before, we relied on the check in the butterworth function to apply things correctly
It took me a long time to wrap my head around before and after holiday but I have found a satisfying solution. The correct tests broke lots of things but luckily the solution turned out to be quite simple after I figured thins out. For tests:
For code:
@ymzayek Have a look and see if this is good to go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for digging into this I did not spot any issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@htwangtw thanks a lot! The changes look good and I checked the plots and they are as expected! I just added a whatsnew and will resolve the conflicts, then merge when everything is green