4646@pytest .mark .parametrize ("squeeze_coeffs" , squeeze_coeffs_dic )
4747def test_morphsqueeze (x_morph , x_target , squeeze_coeffs ):
4848 y_target = np .sin (x_target )
49+ y_morph = np .sin (x_morph )
50+ # expected output
51+ y_morph_expected = y_morph
52+ x_morph_expected = x_morph
53+ x_target_expected = x_target
54+ y_target_expected = y_target
55+ # actual output
4956 coeffs = [squeeze_coeffs [f"a{ i } " ] for i in range (len (squeeze_coeffs ))]
5057 squeeze_polynomial = Polynomial (coeffs )
5158 x_squeezed = x_morph + squeeze_polynomial (x_morph )
5259 y_morph = np .sin (x_squeezed )
53- low_extrap = np .where (x_morph < x_squeezed [0 ])[0 ]
54- high_extrap = np .where (x_morph > x_squeezed [- 1 ])[0 ]
55- extrap_index_low_expected = low_extrap [- 1 ] if low_extrap .size else None
56- extrap_index_high_expected = high_extrap [0 ] if high_extrap .size else None
57- x_morph_expected = x_morph
58- y_morph_expected = np .sin (x_morph )
5960 morph = MorphSqueeze ()
6061 morph .squeeze = squeeze_coeffs
6162 x_morph_actual , y_morph_actual , x_target_actual , y_target_actual = morph (
6263 x_morph , y_morph , x_target , y_target
6364 )
64- extrap_index_low = morph .extrap_index_low
65- extrap_index_high = morph .extrap_index_high
66- if extrap_index_low is None :
67- extrap_index_low = 0
68- elif extrap_index_high is None :
69- extrap_index_high = - 1
65+
66+ extrap_low = np .where (x_morph < min (x_squeezed ))[0 ]
67+ extrap_high = np .where (x_morph > max (x_squeezed ))[0 ]
68+ extrap_index_low_expected = extrap_low [- 1 ] if extrap_low .size else 0
69+ extrap_index_high_expected = extrap_high [0 ] if extrap_high .size else - 1
70+
71+ extrapolation_info = morph .extrapolation_info
72+ extrap_index_low_actual = extrapolation_info ["extrap_index_low" ]
73+ extrap_index_high_actual = extrapolation_info ["extrap_index_high" ]
74+
7075 assert np .allclose (
71- y_morph_actual [extrap_index_low + 1 : extrap_index_high ],
72- y_morph_expected [extrap_index_low + 1 : extrap_index_high ],
76+ y_morph_actual [
77+ extrap_index_low_expected + 1 : extrap_index_high_expected
78+ ],
79+ y_morph_expected [
80+ extrap_index_low_expected + 1 : extrap_index_high_expected
81+ ],
7382 atol = 1e-6 ,
7483 )
7584 assert np .allclose (
76- y_morph_actual [:extrap_index_low ],
77- y_morph_expected [:extrap_index_low ],
85+ y_morph_actual [:extrap_index_low_expected ],
86+ y_morph_expected [:extrap_index_low_expected ],
7887 atol = 1e-3 ,
7988 )
8089 assert np .allclose (
81- y_morph_actual [extrap_index_high :],
82- y_morph_expected [extrap_index_high :],
90+ y_morph_actual [extrap_index_high_expected :],
91+ y_morph_expected [extrap_index_high_expected :],
8392 atol = 1e-3 ,
8493 )
85- assert morph .extrap_index_low == extrap_index_low_expected
86- assert morph .extrap_index_high == extrap_index_high_expected
8794 assert np .allclose (x_morph_actual , x_morph_expected )
88- assert np .allclose (x_target_actual , x_target )
89- assert np .allclose (y_target_actual , y_target )
95+ assert np .allclose (x_target_actual , x_target_expected )
96+ assert np .allclose (y_target_actual , y_target_expected )
97+ assert extrap_index_low_actual == extrap_index_low_expected
98+ assert extrap_index_high_actual == extrap_index_high_expected
9099
91100
92101@pytest .mark .parametrize (
@@ -97,23 +106,23 @@ def test_morphsqueeze(x_morph, x_target, squeeze_coeffs):
97106 {"a0" : 0.01 },
98107 lambda x : (
99108 "Warning: points with grid value below "
100- f"{ x [0 ]} will be extrapolated."
109+ f"{ x [0 ]} are extrapolated."
101110 ),
102111 ),
103112 # extrapolate above
104113 (
105114 {"a0" : - 0.01 },
106115 lambda x : (
107116 "Warning: points with grid value above "
108- f"{ x [1 ]} will be extrapolated."
117+ f"{ x [1 ]} are extrapolated."
109118 ),
110119 ),
111120 # extrapolate below and above
112121 (
113122 {"a0" : 0.01 , "a1" : - 0.002 },
114123 lambda x : (
115124 "Warning: points with grid value below "
116- f"{ x [0 ]} and above { x [1 ]} will be "
125+ f"{ x [0 ]} and above { x [1 ]} are "
117126 "extrapolated."
118127 ),
119128 ),
0 commit comments