Skip to content

Commit 62e8f04

Browse files
committed
feat: enable no vertical shift in NuthKaab coreg
1 parent a147a5f commit 62e8f04

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

xdem/coreg/affine.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ def _nuth_kaab_iteration_step(
454454
aspect: NDArrayf,
455455
res: tuple[int, int],
456456
params_fit_bin: InFitOrBinDict,
457+
apply_vertical_shift: bool = True,
457458
) -> tuple[tuple[float, float, float], float]:
458459
"""
459460
Iteration step of Nuth and Kääb (2011), passed to the iterate_method function.
@@ -466,6 +467,7 @@ def _nuth_kaab_iteration_step(
466467
:param slope_tan: Array of slope tangent.
467468
:param aspect: Array of aspect.
468469
:param res: Resolution of DEM.
470+
:param apply_vertical_shift: Whether to apply the vertical shift or not (default is True).
469471
"""
470472

471473
# Calculate the elevation difference with offsets
@@ -497,7 +499,7 @@ def _nuth_kaab_iteration_step(
497499
new_coords_offsets = (
498500
coords_offsets[0] + easting_offset * res[0],
499501
coords_offsets[1] + northing_offset * res[1],
500-
float(vshift),
502+
float(vshift) if apply_vertical_shift else 0,
501503
)
502504

503505
# Compute statistic on offset to know if it reached tolerance
@@ -520,6 +522,7 @@ def nuth_kaab(
520522
params_random: InRandomDict,
521523
z_name: str,
522524
weights: NDArrayf | None = None,
525+
apply_vertical_shift: bool = True,
523526
**kwargs: Any,
524527
) -> tuple[tuple[float, float, float], int]:
525528
"""
@@ -565,7 +568,14 @@ def nuth_kaab(
565568
res = _res(transform)
566569
# Iterate through method of Nuth and Kääb (2011) until tolerance or max number of iterations is reached
567570
assert sub_aux_vars is not None # Mypy: dictionary cannot be None here
568-
constant_inputs = (sub_dh_interpolator, sub_aux_vars["slope_tan"], sub_aux_vars["aspect"], res, params_fit_or_bin)
571+
constant_inputs = (
572+
sub_dh_interpolator,
573+
sub_aux_vars["slope_tan"],
574+
sub_aux_vars["aspect"],
575+
res,
576+
params_fit_or_bin,
577+
apply_vertical_shift,
578+
)
569579
final_offsets = _iterate_method(
570580
method=_nuth_kaab_iteration_step,
571581
iterating_input=initial_offset,
@@ -1287,6 +1297,7 @@ def __init__(
12871297
bin_sizes: int | dict[str, int | Iterable[float]] = 72,
12881298
bin_statistic: Callable[[NDArrayf], np.floating[Any]] = np.nanmedian,
12891299
subsample: int | float = 5e5,
1300+
apply_vertical_shift: bool = True,
12901301
) -> None:
12911302
"""
12921303
Instantiate a new Nuth and Kääb (2011) coregistration object.
@@ -1299,8 +1310,11 @@ def __init__(
12991310
:param bin_sizes: Size (if integer) or edges (if iterable) for binning variables later passed in .fit().
13001311
:param bin_statistic: Statistic of central tendency (e.g., mean) to apply during the binning.
13011312
:param subsample: Subsample the input for speed-up. <1 is parsed as a fraction. >1 is a pixel count.
1313+
:param apply_vertical_shift: Whether to apply the vertical shift or not (default is True).
13021314
"""
13031315

1316+
self.apply_vertical_shift = apply_vertical_shift
1317+
13041318
# Input checks
13051319
_check_inputs_bin_before_fit(
13061320
bin_before_fit=bin_before_fit, fit_optimizer=fit_optimizer, bin_sizes=bin_sizes, bin_statistic=bin_statistic
@@ -1390,6 +1404,7 @@ def _fit_rst_pts(
13901404
params_fit_or_bin=params_fit_or_bin,
13911405
max_iterations=self._meta["inputs"]["iterative"]["max_iterations"],
13921406
tolerance=self._meta["inputs"]["iterative"]["tolerance"],
1407+
apply_vertical_shift=self.apply_vertical_shift,
13931408
)
13941409

13951410
# Write output to class

0 commit comments

Comments
 (0)