@@ -35,9 +35,41 @@ def sample_surface_points():
35
35
36
36
37
37
@pytest .fixture
38
- def sample_json_data (sample_surface_points ):
38
+ def sample_orientations ():
39
+ """Create sample orientation data for testing."""
40
+ x = np .array ([0.5 , 1.5 , 2.5 , 3.5 ])
41
+ y = np .array ([0.5 , 1.5 , 2.5 , 3.5 ])
42
+ z = np .array ([0.5 , 1.5 , 2.5 , 3.5 ])
43
+ G_x = np .array ([0 , 0 , 0 , 0 ])
44
+ G_y = np .array ([0 , 0 , 0 , 0 ])
45
+ G_z = np .array ([1 , 1 , - 1 , 1 ]) # One reversed orientation
46
+ ids = np .array ([0 , 1 , 1 , 2 ]) # Three different surfaces
47
+ nugget = np .array ([0.01 , 0.01 , 0.01 , 0.01 ])
48
+
49
+ # Create name to id mapping
50
+ name_id_map = {f"surface_{ id } " : id for id in np .unique (ids )}
51
+
52
+ # Create an OrientationsTable
53
+ orientations = gp .data .OrientationsTable .from_arrays (
54
+ x = x ,
55
+ y = y ,
56
+ z = z ,
57
+ G_x = G_x ,
58
+ G_y = G_y ,
59
+ G_z = G_z ,
60
+ names = [f"surface_{ id } " for id in ids ],
61
+ nugget = nugget ,
62
+ name_id_map = name_id_map
63
+ )
64
+
65
+ return orientations , x , y , z , G_x , G_y , G_z , ids , nugget , name_id_map
66
+
67
+
68
+ @pytest .fixture
69
+ def sample_json_data (sample_surface_points , sample_orientations ):
39
70
"""Create sample JSON data for testing."""
40
- _ , x , y , z , ids , nugget , _ = sample_surface_points
71
+ _ , x_sp , y_sp , z_sp , ids_sp , nugget_sp , _ = sample_surface_points
72
+ _ , x_ori , y_ori , z_ori , G_x , G_y , G_z , ids_ori , nugget_ori , _ = sample_orientations
41
73
42
74
return {
43
75
"metadata" : {
@@ -48,16 +80,28 @@ def sample_json_data(sample_surface_points):
48
80
},
49
81
"surface_points" : [
50
82
{
51
- "x" : float (x [i ]),
52
- "y" : float (y [i ]),
53
- "z" : float (z [i ]),
54
- "id" : int (ids [i ]),
55
- "nugget" : float (nugget [i ])
83
+ "x" : float (x_sp [i ]),
84
+ "y" : float (y_sp [i ]),
85
+ "z" : float (z_sp [i ]),
86
+ "id" : int (ids_sp [i ]),
87
+ "nugget" : float (nugget_sp [i ])
56
88
}
57
- for i in range (len (x ))
89
+ for i in range (len (x_sp ))
90
+ ],
91
+ "orientations" : [
92
+ {
93
+ "x" : float (x_ori [i ]),
94
+ "y" : float (y_ori [i ]),
95
+ "z" : float (z_ori [i ]),
96
+ "G_x" : float (G_x [i ]),
97
+ "G_y" : float (G_y [i ]),
98
+ "G_z" : float (G_z [i ]),
99
+ "id" : int (ids_ori [i ]),
100
+ "nugget" : float (nugget_ori [i ]),
101
+ "polarity" : 1 # Always set to 1 since we're testing the raw G_z values
102
+ }
103
+ for i in range (len (x_ori ))
58
104
],
59
- "orientations" : [],
60
- "faults" : [],
61
105
"series" : [],
62
106
"grid_settings" : {
63
107
"regular_grid_resolution" : [10 , 10 , 10 ],
@@ -84,6 +128,25 @@ def test_surface_points_loading(sample_surface_points, sample_json_data):
84
128
assert surface_points .name_id_map == loaded_surface_points .name_id_map , "Name to ID mappings don't match"
85
129
86
130
131
+ def test_orientations_loading (sample_orientations , sample_json_data ):
132
+ """Test loading orientations from JSON data."""
133
+ orientations , _ , _ , _ , _ , _ , _ , _ , _ , name_id_map = sample_orientations
134
+
135
+ # Load orientations from JSON
136
+ loaded_orientations = JsonIO ._load_orientations (sample_json_data ["orientations" ])
137
+
138
+ # Verify all data matches
139
+ assert np .allclose (orientations .xyz [:, 0 ], loaded_orientations .xyz [:, 0 ]), "X coordinates don't match"
140
+ assert np .allclose (orientations .xyz [:, 1 ], loaded_orientations .xyz [:, 1 ]), "Y coordinates don't match"
141
+ assert np .allclose (orientations .xyz [:, 2 ], loaded_orientations .xyz [:, 2 ]), "Z coordinates don't match"
142
+ assert np .allclose (orientations .grads [:, 0 ], loaded_orientations .grads [:, 0 ]), "G_x values don't match"
143
+ assert np .allclose (orientations .grads [:, 1 ], loaded_orientations .grads [:, 1 ]), "G_y values don't match"
144
+ assert np .allclose (orientations .grads [:, 2 ], loaded_orientations .grads [:, 2 ]), "G_z values don't match"
145
+ assert np .array_equal (orientations .ids , loaded_orientations .ids ), "IDs don't match"
146
+ assert np .allclose (orientations .nugget , loaded_orientations .nugget ), "Nugget values don't match"
147
+ assert orientations .name_id_map == loaded_orientations .name_id_map , "Name to ID mappings don't match"
148
+
149
+
87
150
def test_surface_points_saving (tmp_path , sample_surface_points , sample_json_data ):
88
151
"""Test saving surface points to JSON file."""
89
152
surface_points , _ , _ , _ , _ , _ , _ = sample_surface_points
@@ -131,4 +194,63 @@ def test_missing_surface_points_data():
131
194
]
132
195
133
196
with pytest .raises (ValueError ):
134
- JsonIO ._load_surface_points (invalid_data )
197
+ JsonIO ._load_surface_points (invalid_data )
198
+
199
+
200
+ def test_invalid_orientations_data ():
201
+ """Test handling of invalid orientation data."""
202
+ invalid_data = [
203
+ {
204
+ "x" : 1.0 ,
205
+ "y" : 1.0 ,
206
+ "z" : 1.0 ,
207
+ "G_x" : 0.0 ,
208
+ "G_y" : 0.0 ,
209
+ "G_z" : "invalid" , # Should be float
210
+ "id" : 0 ,
211
+ "nugget" : 0.01 ,
212
+ "polarity" : 1
213
+ }
214
+ ]
215
+
216
+ with pytest .raises (ValueError ):
217
+ JsonIO ._load_orientations (invalid_data )
218
+
219
+
220
+ def test_missing_orientations_data ():
221
+ """Test handling of missing orientation data."""
222
+ invalid_data = [
223
+ {
224
+ "x" : 1.0 ,
225
+ "y" : 1.0 ,
226
+ "z" : 1.0 ,
227
+ "G_x" : 0.0 ,
228
+ # Missing G_y and G_z
229
+ "id" : 0 ,
230
+ "nugget" : 0.01 ,
231
+ "polarity" : 1
232
+ }
233
+ ]
234
+
235
+ with pytest .raises (ValueError ):
236
+ JsonIO ._load_orientations (invalid_data )
237
+
238
+
239
+ def test_invalid_orientation_polarity ():
240
+ """Test handling of invalid orientation polarity."""
241
+ invalid_data = [
242
+ {
243
+ "x" : 1.0 ,
244
+ "y" : 1.0 ,
245
+ "z" : 1.0 ,
246
+ "G_x" : 0.0 ,
247
+ "G_y" : 0.0 ,
248
+ "G_z" : 1.0 ,
249
+ "id" : 0 ,
250
+ "nugget" : 0.01 ,
251
+ "polarity" : 2 # Should be 1 or -1
252
+ }
253
+ ]
254
+
255
+ with pytest .raises (ValueError ):
256
+ JsonIO ._load_orientations (invalid_data )
0 commit comments