Skip to content

Initial shift in case of CoregPipeline - #992

Open
marinebcht wants to merge 9 commits into
GlacioHack:mainfrom
marinebcht:801_initial_shift_coreg_pipeline
Open

Initial shift in case of CoregPipeline#992
marinebcht wants to merge 9 commits into
GlacioHack:mainfrom
marinebcht:801_initial_shift_coreg_pipeline

Conversation

@marinebcht

@marinebcht marinebcht commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Resolves #801

This PR proposes the option to use the initial_shift parameter in a coregistration pipeline.

Behavior

  • Accepted : initial_shift in the first method of the Pipeline
  • Not accepted : initial_shift in all other method after

Error message : No initial shift can be initialized in a coregistration pipeline other than for the first element.

Development Information

Initial Shift management

Currently, removing all the initial shift was done in:

  • Coreg.__add__ : to manage coreg1 + coreg2
  • CoregPipeline.__add__ : to manage coreg1 + coreg2 + coreg3 (= coregPipeline1 + coreg3) and CoregPileline(list_of_coreg)

I kept this strategy but without deleting the initial_shift for the:

  • self initial_shift in Coreg.__add__
  • first coreg (pipeline[0]) initial_shift in CoregPipeline.__add__

Preprocessing

Had to remove the preprocess in the CoregPipeline.fit() here and only use the existing preprocess in the Coreg.fit() to have the same result between coreg1 + x and coreg1 in case of an initial_shift
image

Comment thread xdem/coreg/base.py
reference_elev = reference_elev.translate(-shift_x, -shift_y) # type: ignore
initial_shift_apply = True
else:
transform = _translate(transform, xoff=-shift_x, yoff=-shift_y)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Case if ref_dem is an array

Comment thread xdem/coreg/base.py
# We only run this step if it's not the last, otherwise it is unused!
if i != (len(self.pipeline) - 1):
if isinstance(tba_dem_mod, gpd.GeoDataFrame):
if isinstance(tba_dem_mod, (Raster, gpd.GeoDataFrame, PointCloud)):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fit the apply returns management

Comment thread xdem/coreg/blockwise.py
shift_z = coreg.meta["outputs"]["affine"].get("shift_z", np.nan)

x, y = (
x, y = to_be_aligned_elev.transform * (

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

CI problem: see #994

Comment thread tests/test_dem.py
assert dem_aligned.raster_equal(manually_aligned, warn_failure_reason=True)

@staticmethod
@pytest.mark.parametrize(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

move the "tests" in test_affine with the others

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I created a new pipeline.py module in #759. I'm going to have fun merging 😅

@marinebcht marinebcht changed the title [WIP] Initial shift in case of CoregPipeline Initial shift in case of CoregPipeline Aug 20, 2026
Comment thread xdem/coreg/base.py
for method in pipelines[1:]:
if "affine" in method.meta["inputs"] and "initial_shift" in method.meta["inputs"]["affine"]:
warnings.warn(
message="No initial shift can be initialized in a coregistration pipeline other "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we need to more precise on what is done: We override. And repeat for every step:
"No initial shift can be defined in a coregistration pipeline other than for the first step. Overridding to initial_shift=None for step number {X}. Remove initial shift parameters outside of the first step to silence this warning."

@rhugonnet rhugonnet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great, thanks! As I commented separately before, I still think we need to move the logic to CoregPipeline.__init__, because this is the function that actually chains the step, and its class description is public.

So someone could do CoregPipeline([NuthKaab(), NuthKaab(initial_shift=(2, 2, 2))]) and it would not raise an error/warning, yet be correctly documented code. This would be a problem.

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.

Initial shift in case of CoregPipeline

2 participants