@@ -48,47 +48,54 @@ def test_morphsqueeze(x_morph, x_target, squeeze_coeffs):
4848 y_target = np .sin (x_target )
4949 y_morph = np .sin (x_morph )
5050 # expected output
51- coeffs = [squeeze_coeffs [f"a{ i } " ] for i in range (len (squeeze_coeffs ))]
52- squeeze_polynomial = Polynomial (coeffs )
53- x_squeezed = x_morph + squeeze_polynomial (x_morph )
5451 y_morph_expected = y_morph
5552 x_morph_expected = x_morph
5653 x_target_expected = x_target
5754 y_target_expected = y_target
5855 # actual output
59- morph = MorphSqueeze ()
56+ coeffs = [squeeze_coeffs [f"a{ i } " ] for i in range (len (squeeze_coeffs ))]
57+ squeeze_polynomial = Polynomial (coeffs )
58+ x_squeezed = x_morph + squeeze_polynomial (x_morph )
6059 y_morph = np .sin (x_squeezed )
60+ morph = MorphSqueeze ()
6161 morph .squeeze = squeeze_coeffs
6262 x_morph_actual , y_morph_actual , x_target_actual , y_target_actual = morph (
6363 x_morph , y_morph , x_target , y_target
6464 )
6565
6666 extrap_low = np .where (x_morph < min (x_squeezed ))[0 ]
6767 extrap_high = np .where (x_morph > max (x_squeezed ))[0 ]
68- extrap_index_low = extrap_low [- 1 ] if extrap_low .size else None
69- extrap_index_high = extrap_high [0 ] if extrap_high .size else None
70- if extrap_index_low is None :
71- extrap_index_low = 0
72- elif extrap_index_high is None :
73- extrap_index_high = - 1
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+
7475 assert np .allclose (
75- y_morph_actual [extrap_index_low + 1 : extrap_index_high ],
76- 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+ ],
7782 atol = 1e-6 ,
7883 )
7984 assert np .allclose (
80- y_morph_actual [:extrap_index_low ],
81- y_morph_expected [:extrap_index_low ],
85+ y_morph_actual [:extrap_index_low_expected ],
86+ y_morph_expected [:extrap_index_low_expected ],
8287 atol = 1e-3 ,
8388 )
8489 assert np .allclose (
85- y_morph_actual [extrap_index_high :],
86- y_morph_expected [extrap_index_high :],
90+ y_morph_actual [extrap_index_high_expected :],
91+ y_morph_expected [extrap_index_high_expected :],
8792 atol = 1e-3 ,
8893 )
8994 assert np .allclose (x_morph_actual , x_morph_expected )
9095 assert np .allclose (x_target_actual , x_target_expected )
9196 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
9299
93100
94101@pytest .mark .parametrize (
@@ -99,23 +106,23 @@ def test_morphsqueeze(x_morph, x_target, squeeze_coeffs):
99106 {"a0" : 0.01 },
100107 lambda x : (
101108 "Warning: points with grid value below "
102- f"{ x [0 ]} will be extrapolated."
109+ f"{ x [0 ]} are extrapolated."
103110 ),
104111 ),
105112 # extrapolate above
106113 (
107114 {"a0" : - 0.01 },
108115 lambda x : (
109116 "Warning: points with grid value above "
110- f"{ x [1 ]} will be extrapolated."
117+ f"{ x [1 ]} are extrapolated."
111118 ),
112119 ),
113120 # extrapolate below and above
114121 (
115122 {"a0" : 0.01 , "a1" : - 0.002 },
116123 lambda x : (
117124 "Warning: points with grid value below "
118- f"{ x [0 ]} and above { x [1 ]} will be "
125+ f"{ x [0 ]} and above { x [1 ]} are "
119126 "extrapolated."
120127 ),
121128 ),
0 commit comments