@@ -676,6 +676,44 @@ def test_coreg_add(self) -> None:
676
676
vshift5 = vshift3 + vshift3
677
677
assert vshift5 .to_matrix ()[2 , 3 ] == vshift * 4
678
678
679
+ def test_pipeline_consistency (self ) -> None :
680
+ """Check that pipelines properties are respected: reflectivity, fusion of same coreg"""
681
+
682
+ # Test 1: Fusion of same coreg
683
+ # Many vertical shifts
684
+ many_vshifts = coreg .VerticalShift () + coreg .VerticalShift () + coreg .VerticalShift ()
685
+ many_vshifts .fit (** self .fit_params , random_state = 42 )
686
+ aligned_dem , _ = many_vshifts .apply (self .tba .data , transform = self .ref .transform , crs = self .ref .crs )
687
+
688
+ # The last steps should have shifts of EXACTLY zero
689
+ assert many_vshifts .pipeline [1 ]._meta ["vshift" ] == pytest .approx (0 , abs = 10e-5 )
690
+ assert many_vshifts .pipeline [2 ]._meta ["vshift" ] == pytest .approx (0 , abs = 10e-5 )
691
+
692
+ # Many horizontal + vertical shifts
693
+ many_nks = coreg .NuthKaab () + coreg .NuthKaab () + coreg .NuthKaab ()
694
+ many_nks .fit (** self .fit_params , random_state = 42 )
695
+ aligned_dem , _ = many_nks .apply (self .tba .data , transform = self .ref .transform , crs = self .ref .crs )
696
+
697
+ # The last steps should have shifts of NEARLY zero
698
+ assert many_nks .pipeline [1 ]._meta ["vshift" ] == pytest .approx (0 , abs = 0.02 )
699
+ assert many_nks .pipeline [1 ]._meta ["offset_east_px" ] == pytest .approx (0 , abs = 0.02 )
700
+ assert many_nks .pipeline [1 ]._meta ["offset_north_px" ] == pytest .approx (0 , abs = 0.02 )
701
+ assert many_nks .pipeline [2 ]._meta ["vshift" ] == pytest .approx (0 , abs = 0.02 )
702
+ assert many_nks .pipeline [2 ]._meta ["offset_east_px" ] == pytest .approx (0 , abs = 0.02 )
703
+ assert many_nks .pipeline [2 ]._meta ["offset_north_px" ] == pytest .approx (0 , abs = 0.02 )
704
+
705
+ # Test 2: Reflectivity
706
+ # Those two pipelines should give almost the same result
707
+ nk_vshift = coreg .NuthKaab () + coreg .VerticalShift ()
708
+ vshift_nk = coreg .VerticalShift () + coreg .NuthKaab ()
709
+
710
+ nk_vshift .fit (** self .fit_params , random_state = 42 )
711
+ aligned_dem , _ = nk_vshift .apply (self .tba .data , transform = self .ref .transform , crs = self .ref .crs )
712
+ vshift_nk .fit (** self .fit_params , random_state = 42 )
713
+ aligned_dem , _ = vshift_nk .apply (self .tba .data , transform = self .ref .transform , crs = self .ref .crs )
714
+
715
+ assert np .allclose (nk_vshift .to_matrix (), vshift_nk .to_matrix (), atol = 10e-1 )
716
+
679
717
680
718
class TestBlockwiseCoreg :
681
719
ref , tba , outlines = load_examples () # Load example reference, to-be-aligned and mask.
0 commit comments