@@ -32,9 +32,10 @@ def get_mvi_params(tmp_path: Path) -> MVIInversionOptions:
3232 n_lines = 2 ,
3333 inversion_type = "magnetic_vector" ,
3434 )
35- tmi_channel = survey .add_data (
36- {"tmi" : {"values" : np .random .rand (survey .n_vertices )}}
37- )
35+ with geoh5 .open ():
36+ tmi_channel = survey .add_data (
37+ {"tmi" : {"values" : np .random .rand (survey .n_vertices )}}
38+ )
3839 params = MVIInversionOptions (
3940 geoh5 = geoh5 ,
4041 data_object = survey ,
@@ -50,51 +51,54 @@ def get_mvi_params(tmp_path: Path) -> MVIInversionOptions:
5051def test_mask (tmp_path : Path ):
5152 params = get_mvi_params (tmp_path )
5253 geoh5 = params .geoh5
53- locations = InversionLocations (geoh5 , params )
54- loc_mask = [0 , 1 , 1 , 0 ]
55- locations .mask = loc_mask
56- assert isinstance (locations .mask , np .ndarray )
57- assert locations .mask .dtype == bool
58- loc_mask = [0 , 1 , 2 , 3 ]
59- with pytest .raises (ValueError ) as excinfo :
54+ with geoh5 .open ():
55+ locations = InversionLocations (geoh5 , params )
56+ loc_mask = [0 , 1 , 1 , 0 ]
6057 locations .mask = loc_mask
61- assert "Badly formed" in str (excinfo .value )
58+ assert isinstance (locations .mask , np .ndarray )
59+ assert locations .mask .dtype == bool
60+ loc_mask = [0 , 1 , 2 , 3 ]
61+ with pytest .raises (ValueError ) as excinfo :
62+ locations .mask = loc_mask
63+ assert "Badly formed" in str (excinfo .value )
6264
6365
6466def test_get_locations (tmp_path : Path ):
6567 params = get_mvi_params (tmp_path )
6668 geoh5 = params .geoh5
67- locs = np .ones ((10 , 3 ), dtype = float )
68- points_object = Points .create (geoh5 , name = "test-data" , vertices = locs )
69- locations = InversionLocations (geoh5 , params )
70- dlocs = locations .get_locations (points_object )
71- np .testing .assert_allclose (locs , dlocs )
69+ with geoh5 .open ():
70+ locs = np .ones ((10 , 3 ), dtype = float )
71+ points_object = Points .create (geoh5 , name = "test-data" , vertices = locs )
72+ locations = InversionLocations (geoh5 , params )
73+ dlocs = locations .get_locations (points_object )
74+ np .testing .assert_allclose (locs , dlocs )
7275
73- xg , yg = np .meshgrid (np .arange (5 ) + 0.5 , np .arange (5 ) + 0.5 )
74- locs = np .c_ [xg .ravel (), yg .ravel (), np .zeros (25 )]
75- grid_object = Grid2D .create (
76- geoh5 ,
77- origin = [0 , 0 , 0 ],
78- u_cell_size = 1.0 ,
79- v_cell_size = 1.0 ,
80- u_count = 5 ,
81- v_count = 5 ,
82- rotation = 0.0 ,
83- dip = 0.0 ,
84- )
85- dlocs = locations .get_locations (grid_object )
86- np .testing .assert_allclose (dlocs , locs )
76+ xg , yg = np .meshgrid (np .arange (5 ) + 0.5 , np .arange (5 ) + 0.5 )
77+ locs = np .c_ [xg .ravel (), yg .ravel (), np .zeros (25 )]
78+ grid_object = Grid2D .create (
79+ geoh5 ,
80+ origin = [0 , 0 , 0 ],
81+ u_cell_size = 1.0 ,
82+ v_cell_size = 1.0 ,
83+ u_count = 5 ,
84+ v_count = 5 ,
85+ rotation = 0.0 ,
86+ dip = 0.0 ,
87+ )
88+ dlocs = locations .get_locations (grid_object )
89+ np .testing .assert_allclose (dlocs , locs )
8790
8891
8992def test_filter (tmp_path : Path ):
9093 params = get_mvi_params (tmp_path )
9194 geoh5 = params .geoh5
92- locations = InversionLocations (geoh5 , params )
93- test_data = np .array ([0 , 1 , 2 , 3 , 4 , 5 ])
94- locations .mask = np .array ([0 , 0 , 1 , 1 , 1 , 0 ])
95- filtered_data = locations .filter (test_data )
96- assert np .all (filtered_data == [2 , 3 , 4 ])
95+ with geoh5 .open ():
96+ locations = InversionLocations (geoh5 , params )
97+ test_data = np .array ([0 , 1 , 2 , 3 , 4 , 5 ])
98+ locations .mask = np .array ([0 , 0 , 1 , 1 , 1 , 0 ])
99+ filtered_data = locations .filter (test_data )
100+ assert np .all (filtered_data == [2 , 3 , 4 ])
97101
98- test_data = {"key" : test_data }
99- filtered_data = locations .filter (test_data )
100- assert np .all (filtered_data ["key" ] == [2 , 3 , 4 ])
102+ test_data = {"key" : test_data }
103+ filtered_data = locations .filter (test_data )
104+ assert np .all (filtered_data ["key" ] == [2 , 3 , 4 ])
0 commit comments