Skip to content

Commit b9f8364

Browse files
author
Lachlan Grose
committed
fix: process data doesn't allow bad formatted
stratigraphic order
1 parent 01005b3 commit b9f8364

3 files changed

Lines changed: 46 additions & 30 deletions

File tree

LoopStructural/modelling/input/process_data.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def __init__( self,
6060
The processor will generate the best possible data set given the input data. If you only want to build a fault
6161
network then only fault locations, orientations edges and properties are required
6262
"""
63-
64-
self._stratigraphic_order = stratigraphic_order
63+
self._stratigraphic_order = None
64+
self.stratigraphic_order = stratigraphic_order
6565
self._thicknesses = thicknesses
6666
self._use_thickness = use_thickness
6767
if self.thicknesses is None:
@@ -85,7 +85,8 @@ def __init__( self,
8585
self._fault_properties = None
8686
self.fault_properties = fault_properties
8787
self._fault_network = None
88-
self.set_fault_network(fault_edges,fault_edge_properties)# = fault_graph
88+
if fault_edges is not None and fault_edge_properties is not None:
89+
self.set_fault_network(fault_edges,fault_edge_properties)# = fault_graph
8990
self._fault_stratigraphy = fault_stratigraphy
9091
self._intrusions = intrusions
9192
self._thicknesses = thicknesses
@@ -96,7 +97,21 @@ def __init__( self,
9697
self._foliation_properties = {} #empty dictionary of foliation parameters
9798
self.foliation_properties = None
9899

100+
@property
101+
def stratigraphic_order(self):
102+
return self._stratigraphic_order
99103

104+
@stratigraphic_order.setter
105+
def stratigraphic_order(self, stratigraphic_order):
106+
if isinstance(stratigraphic_order[0][1],list) == False:
107+
raise TypeError('Stratigraphic_order must of the format [[(\'group_name\',[\'unit1\',\'unit2\']),(\'group_name2\',[\'unit3\',\'unit4\'])]]')
108+
if isinstance(stratigraphic_order,list) == False:
109+
raise TypeError('Stratigraphic_order must be a list')
110+
if isinstance(stratigraphic_order[0][1][0],str) == False:
111+
raise TypeError('Stratigraphic_order elements must be strings')
112+
self._stratigraphic_order = stratigraphic_order
113+
114+
100115
@property
101116
def colours(self):
102117
return self._colours
@@ -119,10 +134,12 @@ def stratigraphic_column(self):
119134
for name, sg in self._stratigraphic_order:
120135
stratigraphic_column[name] = {}
121136
for g in reversed(sg):
122-
stratigraphic_column[name][g] = {'max': val[g]+self.thicknesses[g], 'min': val[g] , 'id': unit_id, 'colour':self.colours[g]}
137+
if g in self.thicknesses:
138+
stratigraphic_column[name][g] = {'max': val[g]+self.thicknesses[g], 'min': val[g] , 'id': unit_id, 'colour':self.colours[g]}
123139
unit_id += 1
124140
# add faults into the column
125-
stratigraphic_column['faults'] = self.fault_properties.to_dict('index')
141+
if self.fault_properties is not None:
142+
stratigraphic_column['faults'] = self.fault_properties.to_dict('index')
126143
return stratigraphic_column
127144

128145

@@ -280,8 +297,10 @@ def data(self):
280297
before any of the calculated attributes are accessed
281298
"""
282299
dataframes = []
283-
dataframes.append(self.contacts)
284-
dataframes.append(self.contact_orientations)
300+
if self.contacts is not None:
301+
dataframes.append(self.contacts)
302+
if self.contact_orientations is not None:
303+
dataframes.append(self.contact_orientations)
285304
if self.fault_orientations is not None:
286305
dataframes.append(self.fault_orientations)
287306
if self.fault_locations is not None:
@@ -310,7 +329,7 @@ def vector_scale(self,vector_scale):
310329
@property
311330
def stratigraphic_name(self):
312331
names = []
313-
for sg in self._stratigraphic_order:
332+
for name, sg in self._stratigraphic_order:
314333
for g in sg:
315334
names.append(g)
316335
return names
@@ -330,8 +349,12 @@ def _stratigraphic_value(self):
330349
for name, sg in self._stratigraphic_order:
331350
value = 0. #reset for each supergroup
332351
for g in reversed(sg):
333-
stratigraphic_value[g] = value #+ self._thicknesses[g]
334-
value+=self._thicknesses[g]
352+
if g not in self._thicknesses:
353+
logger.warning('No thicknesses for {}'.format(g))
354+
stratigraphic_value[g] = np.nan
355+
else:
356+
stratigraphic_value[g] = value #+ self._thicknesses[g]
357+
value+=self._thicknesses[g]
335358
return stratigraphic_value
336359

337360
def _update_feature_names(self,dataframe):
@@ -386,6 +409,8 @@ def contacts(self,contacts):
386409

387410
@property
388411
def contact_orientations(self):
412+
if self._contact_orientations is None:
413+
return None
389414
contact_orientations = self._contact_orientations.copy()
390415
#scale
391416
contact_orientations.loc[~np.isnan(contact_orientations['nz']),['nx', 'ny', 'nz']]*=self.vector_scale*\
Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
# from LoopStructural.modelling import ProcessInputData
2-
# import pandas as pd
3-
# import numpy as np
1+
from LoopStructural.modelling import ProcessInputData
2+
import pandas as pd
3+
import numpy as np
44

5-
# contacts -
6-
# contacts=None
7-
# contact_orientations = None
8-
# stratigraphic_order = None
9-
# fault_orientations = None
10-
# fault_locations = None
11-
# fault_properties = None
12-
# fault_edges = None
13-
# intrusions = None
14-
# fault_stratigraphy = None
15-
# thicknesses = None
16-
# colours = None
17-
18-
# def test_create_processor():
19-
# contacts = np.zeros(
20-
# ProcessInputData(
5+
def test_create_processor():
6+
df = pd.DataFrame(np.random.rand(10,3),columns=['X','Y','Z'])
7+
df['name'] = ['unit_{}'.format(name%2) for name in range(10)]
8+
stratigraphic_order = [('sg',['unit_0','unit_1'])]
9+
thicknesses = {'unit_0':1.,'unit_1':0.5}
10+
processor = ProcessInputData(contacts=df,stratigraphic_order=stratigraphic_order,thicknesses=thicknesses)
11+
assert((processor.data['val'].unique() == np.array([0.5,0])).all())
12+

tests/unit_tests/modelling/test_geological_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,4 @@ def test_element_number_FDI():
4444
def test_buffer():
4545
model = GeologicalModel([0,0,0],[5,5,5],rescale=True)
4646
interpolator = model.get_interpolator(interpolatortype='FDI',nelements=1e5,buffer=0.2)
47-
print(interpolator.support.origin)
4847
assert np.sum(interpolator.support.origin + .2) == 0

0 commit comments

Comments
 (0)