@@ -101,3 +101,45 @@ def test_smear_with_morph_func():
101101 assert np .allclose (y0 , y1 , atol = 1e-3 ) # numerical error -> 1e-4
102102 # verify morphed param
103103 assert np .allclose (smear , morphed_cfg ["smear" ], atol = 1e-1 )
104+
105+
106+ def test_squeeze_with_morph_func ():
107+ squeeze_init = [0 , - 0.001 , - 0.0001 , 0.0001 ]
108+ x_morph = np .linspace (0 , 10 , 101 )
109+ y_morph = 2 * np .sin (
110+ x_morph + x_morph * (- 0.01 ) - 0.0001 * x_morph ** 2 + 0.0002 * x_morph ** 3
111+ )
112+ expected_squeeze = [0 , - 0.01 , - 0.0001 , 0.0002 ]
113+ expected_scale = 1 / 2
114+ x_target = x_morph .copy ()
115+ y_target = np .sin (x_target )
116+ cfg = morph_default_config (scale = 1.1 , squeeze = squeeze_init ) # off init
117+ morph_rv = morph (x_morph , y_morph , x_target , y_target , ** cfg )
118+ morphed_cfg = morph_rv ["morphed_config" ]
119+ # verified they are morphable
120+ x1 , y1 , x0 , y0 = morph_rv ["morph_chain" ].xyallout
121+ assert np .allclose (x0 , x1 )
122+ assert np .allclose (y0 , y1 , atol = 1e-3 ) # numerical error -> 1e-4
123+ # verify morphed param
124+ assert np .allclose (expected_squeeze , morphed_cfg ["squeeze" ], atol = 1e-4 )
125+ assert np .allclose (expected_scale , morphed_cfg ["scale" ], atol = 1e-4 )
126+
127+
128+ def test_funcy_with_morph_func ():
129+ def linear_function (x , y , scale , offset ):
130+ return (scale * x ) * y + offset
131+
132+ x_morph = np .linspace (0 , 10 , 101 )
133+ y_morph = np .sin (x_morph )
134+ x_target = x_morph .copy ()
135+ y_target = np .sin (x_target ) * 2 * x_target + 0.4
136+ cfg = morph_default_config (parameters = {"scale" : 1.2 , "offset" : 0.1 })
137+ cfg ["function" ] = linear_function
138+ morph_rv = morph (x_morph , y_morph , x_target , y_target , ** cfg )
139+ morphed_cfg = morph_rv ["morphed_config" ]
140+ x1 , y1 , x0 , y0 = morph_rv ["morph_chain" ].xyallout
141+ assert np .allclose (x0 , x1 )
142+ assert np .allclose (y0 , y1 , atol = 1e-6 )
143+ fitted_parameters = morphed_cfg ["parameters" ]
144+ assert np .allclose (fitted_parameters ["scale" ], 2 , atol = 1e-6 )
145+ assert np .allclose (fitted_parameters ["offset" ], 0.4 , atol = 1e-6 )
0 commit comments