@@ -59,9 +59,16 @@ def load_model_from_json(file_path: str):
59
59
# Create a mapping from surface points to their names
60
60
surface_point_names = {}
61
61
for sp in data ['surface_points' ]:
62
- surface_point_names [sp ['id' ]] = next ((name for series in data ['series' ]
63
- for name in series ['surfaces' ]
64
- if name in surface_names ), "surface_0" )
62
+ # Find the surface name that corresponds to this ID
63
+ surface_name = None
64
+ for series in data ['series' ]:
65
+ for i , name in enumerate (series ['surfaces' ]):
66
+ if i == sp ['id' ]: # Match the ID with the index in the series
67
+ surface_name = name
68
+ break
69
+ if surface_name is not None :
70
+ break
71
+ surface_point_names [sp ['id' ]] = surface_name if surface_name is not None else f"surface_{ sp ['id' ]} "
65
72
66
73
# Load surface points and orientations
67
74
surface_points = JsonIO ._load_surface_points (data ['surface_points' ], surface_point_names )
@@ -114,13 +121,13 @@ def load_model_from_json(file_path: str):
114
121
return model
115
122
116
123
@staticmethod
117
- def _load_surface_points (surface_points_data : List [SurfacePoint ], id_to_name : Dict [int , str ]):
124
+ def _load_surface_points (surface_points_data : List [SurfacePoint ], id_to_name : Optional [ Dict [int , str ]] = None ):
118
125
"""
119
126
Load surface points from JSON data.
120
127
121
128
Args:
122
129
surface_points_data (List[SurfacePoint]): List of surface point dictionaries
123
- id_to_name (Dict[int, str]): Mapping from surface IDs to names
130
+ id_to_name (Optional[ Dict[int, str]] ): Optional mapping from surface IDs to names
124
131
125
132
Returns:
126
133
SurfacePointsTable: A new SurfacePointsTable instance
@@ -132,7 +139,7 @@ def _load_surface_points(surface_points_data: List[SurfacePoint], id_to_name: Di
132
139
from gempy .core .data .surface_points import SurfacePointsTable
133
140
134
141
# Validate data structure
135
- required_fields = {'x' , 'y' , 'z' , 'nugget' , 'id' } # Add 'id' back to required fields
142
+ required_fields = {'x' , 'y' , 'z' , 'nugget' , 'id' }
136
143
for i , sp in enumerate (surface_points_data ):
137
144
missing_fields = required_fields - set (sp .keys ())
138
145
if missing_fields :
@@ -149,7 +156,13 @@ def _load_surface_points(surface_points_data: List[SurfacePoint], id_to_name: Di
149
156
y = np .array ([sp ['y' ] for sp in surface_points_data ])
150
157
z = np .array ([sp ['z' ] for sp in surface_points_data ])
151
158
nugget = np .array ([sp ['nugget' ] for sp in surface_points_data ])
152
- names = [id_to_name .get (sp ['id' ], "surface_0" ) for sp in surface_points_data ]
159
+
160
+ # Handle names based on whether id_to_name mapping is provided
161
+ if id_to_name is not None :
162
+ names = [id_to_name .get (sp ['id' ], f"surface_{ sp ['id' ]} " ) for sp in surface_points_data ]
163
+ else :
164
+ # If no mapping provided, use surface IDs as names
165
+ names = [f"surface_{ sp ['id' ]} " for sp in surface_points_data ]
153
166
154
167
# Create SurfacePointsTable
155
168
return SurfacePointsTable .from_arrays (
@@ -161,13 +174,13 @@ def _load_surface_points(surface_points_data: List[SurfacePoint], id_to_name: Di
161
174
)
162
175
163
176
@staticmethod
164
- def _load_orientations (orientations_data : List [Orientation ], id_to_name : Dict [int , str ]):
177
+ def _load_orientations (orientations_data : List [Orientation ], id_to_name : Optional [ Dict [int , str ]] = None ):
165
178
"""
166
179
Load orientations from JSON data.
167
180
168
181
Args:
169
182
orientations_data (List[Orientation]): List of orientation dictionaries
170
- id_to_name (Dict[int, str]): Mapping from surface IDs to names
183
+ id_to_name (Optional[ Dict[int, str]] ): Optional mapping from surface IDs to names
171
184
172
185
Returns:
173
186
OrientationsTable: A new OrientationsTable instance
@@ -179,7 +192,7 @@ def _load_orientations(orientations_data: List[Orientation], id_to_name: Dict[in
179
192
from gempy .core .data .orientations import OrientationsTable
180
193
181
194
# Validate data structure
182
- required_fields = {'x' , 'y' , 'z' , 'G_x' , 'G_y' , 'G_z' , 'nugget' , 'polarity' , 'id' } # Add 'id' back to required fields
195
+ required_fields = {'x' , 'y' , 'z' , 'G_x' , 'G_y' , 'G_z' , 'nugget' , 'polarity' , 'id' }
183
196
for i , ori in enumerate (orientations_data ):
184
197
missing_fields = required_fields - set (ori .keys ())
185
198
if missing_fields :
@@ -201,7 +214,13 @@ def _load_orientations(orientations_data: List[Orientation], id_to_name: Dict[in
201
214
G_y = np .array ([ori ['G_y' ] for ori in orientations_data ])
202
215
G_z = np .array ([ori ['G_z' ] for ori in orientations_data ])
203
216
nugget = np .array ([ori ['nugget' ] for ori in orientations_data ])
204
- names = [id_to_name .get (ori ['id' ], "surface_0" ) for ori in orientations_data ]
217
+
218
+ # Handle names based on whether id_to_name mapping is provided
219
+ if id_to_name is not None :
220
+ names = [id_to_name .get (ori ['id' ], f"surface_{ ori ['id' ]} " ) for ori in orientations_data ]
221
+ else :
222
+ # If no mapping provided, use surface IDs as names
223
+ names = [f"surface_{ ori ['id' ]} " for ori in orientations_data ]
205
224
206
225
# Apply polarity to gradients
207
226
for i , ori in enumerate (orientations_data ):
0 commit comments