-
Notifications
You must be signed in to change notification settings - Fork 132
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: Resolve numeric overflow in drift estimation node #1324
Conversation
Let's roll it out and come back to this if @effigies disagrees. |
|
||
# Read slope and intercept (see #1315) | ||
slope, intercept = full_img.header.get_slope_inter() | ||
slope = slope if slope is not None else 1.0 | ||
intercept = intercept if intercept is not None else 0.0 | ||
corrected = ( | ||
full_img.get_fdata() * fitted[np.newaxis, np.newaxis, np.newaxis, :] / slope | ||
- intercept | ||
) | ||
full_img.__class__( | ||
(full_img.get_fdata() * fitted[np.newaxis, np.newaxis, np.newaxis, :]).astype( | ||
full_img.header.get_data_dtype() | ||
), | ||
corrected.astype(full_img.header.get_data_dtype()), | ||
full_img.affine, | ||
full_img.header, | ||
).to_filename(self._results['out_full_file']) |
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.
Sorry for the delay. No, you just want:
full_img.__class__(
full_img.get_fdata() * fitted[np.newaxis, np.newaxis, np.newaxis, :],
full_img.affine
full_img.header
).to_filename(self._results['out_full_file'])
You pretty much never want to dynamically coerce the type. All of nibabel's machinery assumes that the data is valid and that the header encodes the intent, and will perform scaling on your behalf if continuous data needs to be discretized into an integer dtype.
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.
I assume that applies the slope and intercept when generating the spatialimage object, correct?
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.
Yes, it will calculate a new slope and intercept based on the min/max values of the data array.
Co-authored-by: Chris Markiewicz <[email protected]>
Addresses the issue reported by @psadil with his proposed solution 1 (considering the slope and intercept).
cc/ @effigies for a correctness check.
Resolves: #1315.