@@ -125,9 +125,7 @@ def __init__(
125
125
self .features = []
126
126
self .feature_name_index = {}
127
127
self ._data = pd .DataFrame () # None
128
-
129
128
130
-
131
129
self .stratigraphic_column = None
132
130
133
131
self .tol = 1e-10 * np .max (self .bounding_box .maximum - self .bounding_box .origin )
@@ -179,8 +177,40 @@ def __str__(self):
179
177
def _ipython_key_completions_ (self ):
180
178
return self .feature_name_index .keys ()
181
179
182
-
180
+ def prepare_data (self , data : pd .DataFrame ) -> pd .DataFrame :
181
+ data = data .copy ()
182
+ data [['X' , 'Y' , 'Z' ]] = self .bounding_box .project (data [['X' , 'Y' , 'Z' ]].to_numpy ())
183
183
184
+ if "type" in data :
185
+ logger .warning ("'type' is deprecated replace with 'feature_name' \n " )
186
+ data .rename (columns = {"type" : "feature_name" }, inplace = True )
187
+ if "feature_name" not in data :
188
+ logger .error ("Data does not contain 'feature_name' column" )
189
+ raise BaseException ("Cannot load data" )
190
+ for h in all_heading ():
191
+ if h not in data :
192
+ data [h ] = np .nan
193
+ if h == "w" :
194
+ data [h ] = 1.0
195
+ if h == "coord" :
196
+ data [h ] = 0
197
+ if h == "polarity" :
198
+ data [h ] = 1.0
199
+ # LS wants polarity as -1 or 1, change 0 to -1
200
+ data .loc [data ["polarity" ] == 0 , "polarity" ] = - 1.0
201
+ data .loc [np .isnan (data ["w" ]), "w" ] = 1.0
202
+ if "strike" in data and "dip" in data :
203
+ logger .info ("Converting strike and dip to vectors" )
204
+ mask = np .all (~ np .isnan (data .loc [:, ["strike" , "dip" ]]), axis = 1 )
205
+ data .loc [mask , gradient_vec_names ()] = (
206
+ strikedip2vector (data .loc [mask , "strike" ], data .loc [mask , "dip" ])
207
+ * data .loc [mask , "polarity" ].to_numpy ()[:, None ]
208
+ )
209
+ data .drop (["strike" , "dip" ], axis = 1 , inplace = True )
210
+ data [['X' , 'Y' , 'Z' , 'val' , 'nx' , 'ny' , 'nz' , 'gx' , 'gy' , 'gz' , 'tx' , 'ty' , 'tz' ]] = data [
211
+ ['X' , 'Y' , 'Z' , 'val' , 'nx' , 'ny' , 'nz' , 'gx' , 'gy' , 'gz' , 'tx' , 'ty' , 'tz' ]
212
+ ].astype (float )
213
+ return data
184
214
@classmethod
185
215
def from_processor (cls , processor ):
186
216
"""Builds a model from a :class:`LoopStructural.modelling.input.ProcessInputData` object
@@ -473,40 +503,9 @@ def data(self, data: pd.DataFrame):
473
503
raise BaseException ("Cannot load data" )
474
504
logger .info (f"Adding data to GeologicalModel with { len (data )} data points" )
475
505
self ._data = data .copy ()
476
- self ._data [['X' ,'Y' ,'Z' ]] = self .bounding_box .project (self ._data [['X' ,'Y' ,'Z' ]].to_numpy ())
477
-
478
-
479
- if "type" in self ._data :
480
- logger .warning ("'type' is deprecated replace with 'feature_name' \n " )
481
- self ._data .rename (columns = {"type" : "feature_name" }, inplace = True )
482
- if "feature_name" not in self ._data :
483
- logger .error ("Data does not contain 'feature_name' column" )
484
- raise BaseException ("Cannot load data" )
485
- for h in all_heading ():
486
- if h not in self ._data :
487
- self ._data [h ] = np .nan
488
- if h == "w" :
489
- self ._data [h ] = 1.0
490
- if h == "coord" :
491
- self ._data [h ] = 0
492
- if h == "polarity" :
493
- self ._data [h ] = 1.0
494
- # LS wants polarity as -1 or 1, change 0 to -1
495
- self ._data .loc [self ._data ["polarity" ] == 0 , "polarity" ] = - 1.0
496
- self ._data .loc [np .isnan (self ._data ["w" ]), "w" ] = 1.0
497
- if "strike" in self ._data and "dip" in self ._data :
498
- logger .info ("Converting strike and dip to vectors" )
499
- mask = np .all (~ np .isnan (self ._data .loc [:, ["strike" , "dip" ]]), axis = 1 )
500
- self ._data .loc [mask , gradient_vec_names ()] = (
501
- strikedip2vector (self ._data .loc [mask , "strike" ], self ._data .loc [mask , "dip" ])
502
- * self ._data .loc [mask , "polarity" ].to_numpy ()[:, None ]
503
- )
504
- self ._data .drop (["strike" , "dip" ], axis = 1 , inplace = True )
505
- self ._data [['X' , 'Y' , 'Z' , 'val' , 'nx' , 'ny' , 'nz' , 'gx' , 'gy' , 'gz' , 'tx' , 'ty' , 'tz' ]] = (
506
- self ._data [
507
- ['X' , 'Y' , 'Z' , 'val' , 'nx' , 'ny' , 'nz' , 'gx' , 'gy' , 'gz' , 'tx' , 'ty' , 'tz' ]
508
- ].astype (float )
509
- )
506
+ # self._data[['X','Y','Z']] = self.bounding_box.project(self._data[['X','Y','Z']].to_numpy())
507
+
508
+
510
509
511
510
def set_model_data (self , data ):
512
511
logger .warning ("deprecated method. Model data can now be set using the data attribute" )
@@ -623,7 +622,7 @@ def create_and_add_foliation(
623
622
if series_surface_data .shape [0 ] == 0 :
624
623
logger .warning ("No data for {series_surface_data}, skipping" )
625
624
return
626
- series_builder .add_data_from_data_frame (series_surface_data )
625
+ series_builder .add_data_from_data_frame (self . prepare_data ( series_surface_data ) )
627
626
self ._add_faults (series_builder , features = faults )
628
627
629
628
# build feature
@@ -697,7 +696,7 @@ def create_and_add_fold_frame(
697
696
if fold_frame_data .shape [0 ] == 0 :
698
697
logger .warning (f"No data for { fold_frame_name } , skipping" )
699
698
return
700
- fold_frame_builder .add_data_from_data_frame (fold_frame_data )
699
+ fold_frame_builder .add_data_from_data_frame (self . prepare_data ( fold_frame_data ) )
701
700
self ._add_faults (fold_frame_builder [0 ])
702
701
self ._add_faults (fold_frame_builder [1 ])
703
702
self ._add_faults (fold_frame_builder [2 ])
@@ -783,7 +782,10 @@ def create_and_add_folded_foliation(
783
782
logger .warning (f"No data for { foliation_name } , skipping" )
784
783
return
785
784
series_builder .add_data_from_data_frame (
786
- foliation_data )
785
+ self .prepare_data (
786
+ foliation_data
787
+ )
788
+ )
787
789
self ._add_faults (series_builder )
788
790
# series_builder.add_data_to_interpolator(True)
789
791
# build feature
@@ -878,7 +880,7 @@ def create_and_add_folded_fold_frame(
878
880
)
879
881
if fold_frame_data is None :
880
882
fold_frame_data = self .data [self .data ["feature_name" ] == fold_frame_name ]
881
- fold_frame_builder .add_data_from_data_frame (fold_frame_data )
883
+ fold_frame_builder .add_data_from_data_frame (self . prepare_data ( fold_frame_data ) )
882
884
883
885
for i in range (3 ):
884
886
self ._add_faults (fold_frame_builder [i ])
@@ -1331,7 +1333,7 @@ def create_and_add_fault(
1331
1333
if fault_data .shape [0 ] == 0 :
1332
1334
logger .warning (f"No data for { fault_name } , skipping" )
1333
1335
return
1334
-
1336
+
1335
1337
self ._add_faults (fault_frame_builder , features = faults )
1336
1338
# add data
1337
1339
@@ -1344,7 +1346,7 @@ def create_and_add_fault(
1344
1346
if intermediate_axis :
1345
1347
intermediate_axis = intermediate_axis
1346
1348
fault_frame_builder .create_data_from_geometry (
1347
- fault_frame_data = fault_data ,
1349
+ fault_frame_data = self . prepare_data ( fault_data ) ,
1348
1350
fault_center = fault_center ,
1349
1351
fault_normal_vector = fault_normal_vector ,
1350
1352
fault_slip_vector = fault_slip_vector ,
@@ -1397,9 +1399,8 @@ def rescale(self, points: np.ndarray, *, inplace: bool = False) -> np.ndarray:
1397
1399
points : np.array((N,3),dtype=double)
1398
1400
1399
1401
"""
1400
-
1402
+
1401
1403
return self .bounding_box .reproject (points ,inplace = inplace )
1402
-
1403
1404
1404
1405
# TODO move scale to bounding box/transformer
1405
1406
def scale (self , points : np .ndarray , * , inplace : bool = False ) -> np .ndarray :
@@ -1418,7 +1419,6 @@ def scale(self, points: np.ndarray, *, inplace: bool = False) -> np.ndarray:
1418
1419
1419
1420
"""
1420
1421
return self .bounding_box .project (np .array (points ).astype (float ),inplace = inplace )
1421
-
1422
1422
1423
1423
def regular_grid (self , * , nsteps = None , shuffle = True , rescale = False , order = "C" ):
1424
1424
"""
0 commit comments