-
Notifications
You must be signed in to change notification settings - Fork 41
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 CoregPipeline
to work with biascorr
methods
#424
Conversation
Awesome! Great that you're splitting up the regular coreg and the pipeline/blockwise test cases into multiple classes. That makes it much cleaner! I wonder if they should maybe be in different files, potentially mirroring the coreg submodule structure. I mean, coreg is getting quite big:
Maybe it would be better to have multiple test files to make it less of a monster? |
Agreed! I'll fully mirror the folder structure of |
Alright, all done following #413 (comment)! |
# Assert that the combined vertical shift is 2 | ||
assert pipeline2.to_matrix()[2, 3] == 2.0 | ||
|
||
all_coregs = [ |
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.
New from here to test_pipeline_pts
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.
Looking good !
@@ -723,13 +711,28 @@ def __add__(self, other: CoregType) -> CoregPipeline: | |||
raise ValueError(f"Incompatible add type: {type(other)}. Expected 'Coreg' subclass") | |||
return CoregPipeline([self, other]) | |||
|
|||
@property |
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.
This was in the wrong spot (needs to be at Coreg
level I think, not Affine/NonAffine
!).
@@ -1316,13 +1359,55 @@ def copy(self: CoregType) -> CoregType: | |||
|
|||
return new_coreg | |||
|
|||
def _parse_bias_vars(self, step: int, bias_vars: dict[str, NDArrayf] | None) -> dict[str, NDArrayf]: |
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 non-public CoregPipeline
method that makes the pipeline work smoothly for both fit
and apply
} | ||
super().__init__(meta=meta_bin_and_fit) # type: ignore | ||
|
||
# Update attributes | ||
self._fit_or_bin = fit_or_bin | ||
self._is_affine = False | ||
|
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.
Used to have these two here to override Coreg.fit()
and .apply()
(and not only the ._fit_func()
, ._apply_func()
), but now that bias_vars
has been moved to Coreg
directly, there is no need for them anymore.
Tests all passing, the current error comes from SciPy: scipy/scipy#19103 |
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 didn't manage to look at the tests yet. I will try to do tomorrow. But the changes in the code itself seems alright.
Well done ! 🙌
I just had a look at the tests (as you said not easy to spot the actual changes with all the shuffling around, thanks for pointing to the most important part). |
Maybe a minor comment. Should we expand the docstrings at the beginning of each coreg submodule to better explain what it contains? |
Yes, we need to do this! Opened #434 |
This PR makes
CoregPipeline
work withBiasCorr
classes, and makesCoreg
's behaviour consistent withbias_vars
at all levels.It also renames
coreg/pipelines.py
intocoreg/workflows.py
to avoid confusion.In short, regarding core functionalities, this PR:
bias_vars
argument directly intoCoreg.fit()
and.apply()
, and all subclasses to match signature (even if never used inAffineCoreg
, checked directly inCoreg.fit()
and.apply()
and raises a warning if abias_vars
was passed for nothing). This resulted in the removal ofBiasCorr.fit()
andBiasCorr.apply()
that were originally overriddingCoreg
to definebias_vars
.Coreg._meta["bias_vars"]
(that used to be stored during.fit()
) intoCoreg._meta["bias_var_names"]
which can be optionally defined directly at instantiation, e.g.BiasCorr1D(bias_var_names=["slope"])
. This allows to explicitly define which variablesbias_vars
(that are named because passed as adict
) are associated to each bias-correction method in a pipeline. For other cases, it is not necessary and can just use what is passed tofit()
. If it is defined, however, the two inputs need to be consistent (or raises an error).Coreg
class attribute_needs_vars
to differentiate between coregistration methods that need bias variables to run (e.g.,BiasCorr1D
) and those who don't (e.g.,NuthKaab
orDeramp
, even though one is affine and the other non-affine).CoregPipeline._parse_bias_vars()
method to parse the bias variables needed for a pipeline step (works for bothfit
andapply
), or raise appropriate errors.For tests, the PR:
xdem/coreg
to sort the big mess!Coreg
subclasses can be combined, including those requiring abias_vars
,bias_vars
is incorrectly defined (in a pipeline or in a single biascorr class),Resolves #413
Resolves #405
Opened #427