[ENH]: Improve BasePreprocessor #310
No reviewers
Labels
No labels
CRITICAL
Stale
WIP
bug
concept
coordinate
dataset
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
maintenance
maps
marker
mask
on hold
parcellation
preprocess
question
ready
storage
template-space
triage
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
juaml/junifer!310
Loading…
Reference in a new issue
No description provided.
Delete branch "refactor/preprocessor-fit-transform"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR refactors
preprocessmethod of preprocessors to not return "data type" and only return the preprocessed input data. Having to return "data type" forced a concrete preprocessor to only operate on a single "data type" (likeBOLDWarperintroduced in #267) and not allow theonparameter to be exposed to the user (as requested in #301). If a concrete preprocessor adds new "data type" likeBOLD_maskin the "junifer data object" asfMRIPrepConfoundRemover(introduced in #111) does, it will be handled as usual with no changes.A preprocessor should not create new "data types" (which was allowed earlier and hence the restriction) but only create and add "helper data types" like
BOLD_maskwhich happens viaextra_inputof thepreprocessmethod.I think I have an issue with this PR.
How is the
BOLD_maskkept even before the PR? I check thefMRIPrepConfoundRemoverand all we do is add it to theextra_input. But how is this kept???? Is this actually working???Not allowing the preprocessor to "create new datatypes" is a bit strong. Indeed there's no difference between "new data types" and "helper data types".
Since the
inputis not copied forextra_input, it's kept but if we copy it like we do for markers, it won't be kept.The reason is because
BOLDorT1wwould be a "data type" for me but notBOLD_mask. But, we are on the same page with our understanding.We could have the
extra_inputbe returned frompreprocessmethod to make it explicit though. What do you think?Check this out:
This is how we "add" the
BOLD_mask:github.com/juaml/junifer@a7bd0f6449/junifer/preprocess/confounds/fmriprep_confound_remover.py (L575-L580)But this is how we treat the input in the
_fit_transformfunction:github.com/juaml/junifer@a7bd0f6449/junifer/preprocess/base.py (L173-L192)So basically we have
out, which isinput, which is alsoextra_input. We thenpopthetype, modify theextra_inputand re-add thetypetoout.This is madness. My madness, but madness still.
I don't know how to tackle this to make it proper.
Problems we currently have:
input, which is also theoutvariable in two, for no reason.preprocessfunction all the data (input), even if they do not need it.extra_inputvariable.A more declarative way would be to:
inputand the relevantextra_inputto the preprocess function (not all the data)returnedvalues to update theout. Maybe by getting a dictionary of key/value pairs?I agree with the steps and it's similar to what I proposed in the earlier comment.
_fit_transform, we could copy theinputtooutlike we do for DataReader so that we don't lose anything.preprocesswe return the first value as theinputdict (as we do now).preprocesscould be "helper data type(s)" dict or None and we check for it in_fit_transform. If we have it as None, we don't do anything, else we updateout.Perfect!
@fraimondo The latest commits should implement this.
Codecov Report
Attention: Patch coverage is
96.96970%with1 linesin your changes are missing coverage. Please review.Additional details and impacted files
88.95% <96.96%> (+0.05%)Flags with carried forward coverage won't be shown. Click here to find out more.
87.50% <100.00%> (+6.25%)98.74% <100.00%> (-0.04%)38.88% <66.66%> (ø)I still do prefer to have it coded without explicit side-effects as it was before.
Tests are not passing yet, but code is OK from my side.
I debated on this in my head for some time and decided to go with this due to the reduced complexity of having everything in
preprocessand the need to now returnBOLD_maskvia theextra_inputwhich is much more explicit in this.If you feel strongly about it and don't see an upside with the change, I can revert it with the required change.
Was a network issue for downloading assets, nothing from our side. Let's wait and see.