-
Notifications
You must be signed in to change notification settings - Fork 42
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
Re-organize coreg.py #329
Re-organize coreg.py #329
Conversation
…ordingly. Make non-resampling possible for NuthKaab.
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.
Thanks for the small fixes @rhugonnet !
Now there's a weird thing, you need to approve again, as I can't approve the PR myself 😆
We also need to fix the test error.
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.
A lot of great work, Amaury! I have some comments but generally I agree with all decisions made.
As you may notice, I've been out of the game for a while so some comments/questions may be self-explanatory to you and Romain at this point. I'm trying my best to get back!
Some tests fail. I've checked all of them:
|
@adehecq, do you want to merge anyway and add an issue ASAP, since this seems unrelated to your PR? The only consequence is an ugly "Faling" badge on the front page. |
For the errors in We also had to change this test in this PR for it to pass ( @pytest.mark.parametrize("rst_and_truenodata", [(ref_dem, 0), (tba_dem, 0), (ddem, 2316)]) # type: ignore
# Note: Following PR #329, no gaps on DEM edges after coregistration One way to be sure: you could run your tests locally with/without the PR (main and this branch) to check if it fails? And I agree for leaving aside the weird error in |
Just checked this: with the same environment, all tests passing on the |
Actually, all the tests that were failing except the one linked to GlacioHack/geoutils#326 were due to the changes in this PR. I fixed them all. |
Now I'll open a PR from a new branch pulling the latest GeoUtils, to see if releasing a new GeoUtils version will fix the issue and if it will create others. |
Summary
This PR is a (big) step towards making the use of coreg simpler and more consistent, as stated in #327.
NB: Some previous commits were accidentally added to this PR, to see the actual changes, use this link.
Here is a summary of the main changes:
apply
andfit
functions accept either an xdem.DEM instance, or a numpy array, transform and CRS, i.e. the minimum information required to convert the output to a Raster/DEM (only array and transform were needed before).Replace-> actually reverted to old implementation, that is much faster. I left the xdem option commented, and could be reverted once xdem terrain attributes are sped-up, but in any case, it seems sufficient and more computationally efficient, to use a simplecalculate_slope_and_aspect
with xdem.terrain attributesnp.gradient
rather than more complex gradient. Renamed the function to_calculate_slope_and_aspect_nuthkaab
to avoid misuse as discussed inxdem.coreg.calculate_slope_and_aspect
should (soon) be deprecated. #150.resample
to the apply methods to avoid resampling the data (and hence spreading NaNs). This is currently implemented forBiasCorr
,Deramp
,ZScaleCorr
andNuthKaab
. Resampling is necessary for all non-rigid transformations. In the case ofNuthKaab
, the output DEM has a different transform (and hence must be reprojected before calculating a ddem). This is useful if other processing follow the coregistration such as a second coreg method or regridding.dem_coregistration
function to use apply's optionresample=False
and take as input xdem.DEM instances on top of filenames.dem_coregistration
since it's not used at the moment. The idea was possibly to allow two different inlier_masks for the horizontal vs vertical alignment.filter_by_range
,filtered_slope
,apply_xy_shift
,apply_z_shift
,dilate_mask
option, duplicates of deramping)resample
option,create_inlier_mask
anddem_coregistration
).To be addressed later
calculate_ddem_stats
incoreg.apply
to get standard statistics -> This is more complex than expected, because reference DEM and inlier_mask are unknown inapply
.fit
to return coregistered DEM, so thatapply
is optional (to avoid re-doing calculation) -> turns out it only matters for CoregPipeline and NuthKaab (in the latter case, the shift is calculated in one go withapply
instead of sequentially, so it may be beneficial).Coreg.error
to not require re-runningapply
another time. -> will be addressed latermask_as_array
?resample
argumentnp.nanmedian
in N&K a parameter