@@ -59,8 +59,7 @@ def test_euler_inversion_with_numeric_derivatives(euler):
5959 npt .assert_allclose (euler .location_ [:2 ], dipole_coordinates [:2 ], rtol = 0.01 )
6060 npt .assert_allclose (euler .location_ [2 ], dipole_coordinates [2 ], rtol = 0.05 )
6161 npt .assert_allclose (euler .base_level_ , true_base_level , rtol = 0.01 )
62- if hasattr (euler , "structural_index_" ):
63- assert euler .structural_index_ == 3
62+ assert euler .structural_index_ == 3
6463
6564
6665@pytest .mark .parametrize (
@@ -107,8 +106,45 @@ def test_euler_inversion_with_analytic_derivatives(euler):
107106 npt .assert_allclose (euler .location_ [:2 ], masses_coordinates [:2 ], rtol = 0.01 )
108107 npt .assert_allclose (euler .location_ [2 ], masses_coordinates [2 ], rtol = 0.05 )
109108 npt .assert_allclose (euler .base_level_ , base_level , rtol = 0.01 )
110- if hasattr (euler , "structural_index_" ):
111- assert euler .structural_index_ == 2
109+ assert euler .structural_index_ == 2
110+
111+
112+
113+ @pytest .mark .parametrize (
114+ "euler" ,
115+ [
116+ EulerInversion (structural_index = 3 , max_iterations = 1 ),
117+ EulerInversion (max_iterations = 1 ),
118+ ],
119+ ids = ("fixed_SI" , "estimate_SI" ),
120+ )
121+ def test_euler_inversion_convergence_warning (euler ):
122+ "Check that a warning is raised when the method exits without convergence"
123+ # Add dipole source
124+ dipole_coordinates = (10e3 , 15e3 , - 10e3 )
125+ inc , dec = - 40 , 15
126+ dipole_moments = magnetic_angles_to_vec (1.0e14 , inc , dec )
127+ region = [- 100e3 , 100e3 , - 80e3 , 80e3 ]
128+ coordinates = vd .grid_coordinates (region , spacing = 500 , extra_coords = 500 )
129+ b = dipole_magnetic (coordinates , dipole_coordinates , dipole_moments , field = "b" )
130+ # Add a fixed base level
131+ true_base_level = 200 # nT
132+ anomaly = total_field_anomaly (b , inc , dec ) + true_base_level
133+ anomaly += np .random .default_rng (42 ).normal (0 , 20 , anomaly .shape )
134+ grid = vd .make_xarray_grid (
135+ coordinates , anomaly , data_names = "tfa" , extra_coords_names = "upward"
136+ )
137+ grid ["d_east" ] = derivative_easting (grid .tfa )
138+ grid ["d_north" ] = derivative_northing (grid .tfa )
139+ grid ["d_up" ] = derivative_upward (grid .tfa )
140+ table = vd .grid_to_table (grid )
141+ coordinates = (table .easting , table .northing , table .upward )
142+ with pytest .warns (UserWarning , match = "Euler Inversion exited" ):
143+ euler .fit (
144+ (table .easting , table .northing , table .upward ),
145+ (table .tfa , table .d_east , table .d_north , table .d_up ),
146+ )
147+
112148
113149
114150def test_euler_deconvolution_with_numeric_derivatives ():
@@ -139,8 +175,6 @@ def test_euler_deconvolution_with_numeric_derivatives():
139175 )
140176 npt .assert_allclose (euler .location_ , dipole_coordinates , rtol = 0.01 )
141177 npt .assert_allclose (euler .base_level_ , true_base_level , rtol = 0.01 )
142- if hasattr (euler , "structural_index_" ):
143- npt .assert_allclose (euler .structural_index_ , 3 , rtol = 0.01 )
144178
145179
146180def test_euler_deconvolution_with_analytic_derivatives ():
@@ -172,5 +206,3 @@ def test_euler_deconvolution_with_analytic_derivatives():
172206 )
173207 npt .assert_allclose (euler .location_ , masses_coordinates , atol = 1.0e-3 , rtol = 1.0e-3 )
174208 npt .assert_allclose (euler .base_level_ , 0.0 , atol = 1.0e-3 , rtol = 1.0e-3 )
175- if hasattr (euler , "structural_index_" ):
176- npt .assert_allclose (euler .structural_index_ , 2 , rtol = 0.01 )
0 commit comments