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,REF] start changing how to handle resampling #439

Merged
merged 10 commits into from
Feb 23, 2021

Conversation

jdkent
Copy link
Member

@jdkent jdkent commented Feb 4, 2021

Closes #438

Changes proposed in this pull request:

  • check if resampling is necessary (and raise error if resampling is not requested)
  • add resampling kwargs for user flexibility
  • TODO: decide where to pass resampling arguments (should they be passed through the fit method or should we make it a part of initializing the estimator object so the user's decision is saved in a more permanent way? and to keep the fit method clean)

nimare/base.py Outdated Show resolved Hide resolved
Copy link
Member

@tsalo tsalo left a comment

Choose a reason for hiding this comment

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

One minor change that will hopefully fix the tests, and one other thing I think we should discuss before merging.

nimare/base.py Outdated Show resolved Hide resolved
nimare/base.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Feb 5, 2021

Codecov Report

Merging #439 (a3bf504) into master (106b516) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #439      +/-   ##
==========================================
+ Coverage   82.50%   82.56%   +0.06%     
==========================================
  Files          40       40              
  Lines        3892     3907      +15     
==========================================
+ Hits         3211     3226      +15     
  Misses        681      681              
Impacted Files Coverage Δ
nimare/base.py 85.79% <100.00%> (+1.38%) ⬆️

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 106b516...a3bf504. Read the comment docs.

nimare/base.py Outdated Show resolved Hide resolved
@tsalo
Copy link
Member

tsalo commented Feb 5, 2021

The docs failure seems to be the random bug documented in #418. I still don't have a solution, so I think we can just restart the CI and it might go away.

Copy link
Contributor

@tyarkoni tyarkoni left a comment

Choose a reason for hiding this comment

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

Looks good, with exception of one minor tweak to the logic when passing resample__ kwargs. (I left a couple of other comments you can respond to or ignore as you see fit).

nimare/base.py Outdated
self.resample = kwargs.get("resample", False)

# defaults for resampling images (nilearn's defaults do not work well)
self.resample_kwargs = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to expose these to users? If not, maybe self._resample_kwargs? I forget what the conventions we're using are; if this is how we're doing it elsewhere, then it's fine this way.

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch! I do not think I want to expose this to users, and yes you are right that appears to be the convention, changed!

nimare/base.py Outdated

# defaults for resampling images (nilearn's defaults do not work well)
self.resample_kwargs = {
k.split("resample__")[1]: v for k, v in kwargs.items() if k.startswith("resample__")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the or here will force the user to specify both arguments even if they only want to override one default (and they may not realize that, which is likely to lead to unintended behavior). Probably better to create the default dict and then update it with any matching argument names in kwargs.

Copy link
Member Author

Choose a reason for hiding this comment

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

great point, changed it so there is a default dict and arguments can update that dict.

nimare/base.py Outdated
if not self.resample:
check_imgs = {img: nb.load(img) for img in self.inputs_[name]}
check_imgs["reference_masker"] = mask_img
_check_same_fov(**check_imgs, raise_error=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's pretty trivial, and would only slightly improve readability, but to save the del call later you could just pass reference_masker as an argument directly to _check_same_fov instead of adding it to check_imgs, since you remove it right away

Copy link
Member Author

Choose a reason for hiding this comment

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

clean code is happy code :), changed.

- change resample_kwargs to _resample_kwargs
- improve readability of _check_fov
- update instead of overwrite defaults
@tyarkoni tyarkoni merged commit b69cedd into neurostuff:master Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IBMA estimators resampling input (potentially non-optimally)
3 participants