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

Add Option to Disable Vertical Shift in Nuth and Kääb Coregistration #687

Merged
merged 4 commits into from
Feb 26, 2025

Conversation

vschaffn
Copy link
Contributor

Resolves #686.

Summary

This PR introduces a new feature to the Nuth and Kääb (2011) coregistration method, allowing users to optionally disable the vertical shift during the coregistration process. A new boolean parameter apply_vertical_shift has been added to control whether the vertical translation (shift in the z-axis) should be applied.

Key Changes

  • Added apply_vertical_shift to the constructor of the NuthKaab class, defaulting to True to maintain the current behavior (vertical shift enabled by default).
  • Modified method _nuth_kaab_iteration_step to conditionally apply the vertical shift based on the value of apply_vertical_shift.
    If the parameter is not provided, the default behavior (applying the vertical shift) remains unchanged, ensuring no impact on existing usage.

Usage example

coreg_method = xdem.coreg.NuthKaab(apply_vertical_shift=False)
coreg_method.fit(dem, dem_tba)
aligned_dem = coreg_method.apply(dem_tba)

in coreg_method.info():
image

Copy link
Contributor

@adebardo adebardo left a comment

Choose a reason for hiding this comment

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

Could you please add some unit tests ?

@adebardo
Copy link
Contributor

adebardo commented Feb 24, 2025

Hello @rhugonnet ,
Regarding the message left on the issue, during coregistration, the Z shift is not disabled; it is only disabled for the final result at the apply stage.

Does this ticket suit you as it is? (with unit tests added)

@vschaffn
Copy link
Contributor Author

@adebardo I added a test to ensure that the vertical shift is 0 if apply_vertical_shift is False, and the horizontal shifts are the same with or without applying vertical shift.

@rhugonnet
Copy link
Member

@adebardo You mean it's not disabled because we still remove the vertical median here?

dh_step -= vshift

Hmm... by having the modification within the _nuth_kaab_iteration_step loop as done here, the resulting behaviour was difficult to grasp for me.

If the objective is simply not to apply a vertical shift, should we update this line instead directly in the NuthKaab class:

output_affine = OutAffineDict(shift_x=-easting_offset, shift_y=-northing_offset, shift_z=vertical_offset)

with shift_z=vertical_offset if apply_vertical_shift else 0.

The behaviour should be the same, and we wouldn't have to modify anything but this line.

@rhugonnet
Copy link
Member

rhugonnet commented Feb 24, 2025

Or, I'm just realizing now, were you worried about the fact that the logging info would show a vertical shift at each iteration if the vertical shift is not modified within the function?
It'd be OK with me if a vertical shift value is shown during the iterations even for apply_vertical_shift=False, as it's simply about applying it!

@rhugonnet
Copy link
Member

Ah and finally we should add the parameter apply_vertical_shift to the CoregDict parameters so that it shows in info() and such with other metadata (see: https://xdem.readthedocs.io/en/stable/coregistration.html#coregistration-metadata).

The steps are simply:

  • Adding apply_vertical_shift here:
    class InAffineDict(TypedDict, total=False):
  • Adding a corresponding text here:
    dict_key_to_str = {
  • And updating __init__ so that the parameter is passed to super() like the other ones 😉

(For the record, there's a wiki on coregistration with all steps described here: https://github.com/GlacioHack/xdem/wiki/Things-to-know-on-coregistration-class-structure#steps-to-add-a-new-coreg-subclass)

@vschaffn
Copy link
Contributor Author

@rhugonnet Thank you for the instructions ! I added the parameter apply_vshift as a boolean to ther CoregDict parameters.

@adebardo adebardo dismissed their stale review February 25, 2025 16:41

I don't know how to use github very well, sorry

@adebardo adebardo merged commit 535c8f9 into GlacioHack:main Feb 26, 2025
16 checks passed
@vschaffn vschaffn deleted the 686-z_correction branch February 26, 2025 08:42
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.

Add apply_z_correction parameter to coreg.workflows.dem_coregistration function
3 participants