Skip to content

Commit

Permalink
fix: process data doesn't allow bad formatted
Browse files Browse the repository at this point in the history
stratigraphic order
  • Loading branch information
Lachlan Grose committed Sep 27, 2021
1 parent 01005b3 commit b9f8364
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 30 deletions.
45 changes: 35 additions & 10 deletions LoopStructural/modelling/input/process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def __init__( self,
The processor will generate the best possible data set given the input data. If you only want to build a fault
network then only fault locations, orientations edges and properties are required
"""

self._stratigraphic_order = stratigraphic_order
self._stratigraphic_order = None
self.stratigraphic_order = stratigraphic_order
self._thicknesses = thicknesses
self._use_thickness = use_thickness
if self.thicknesses is None:
Expand All @@ -85,7 +85,8 @@ def __init__( self,
self._fault_properties = None
self.fault_properties = fault_properties
self._fault_network = None
self.set_fault_network(fault_edges,fault_edge_properties)# = fault_graph
if fault_edges is not None and fault_edge_properties is not None:
self.set_fault_network(fault_edges,fault_edge_properties)# = fault_graph
self._fault_stratigraphy = fault_stratigraphy
self._intrusions = intrusions
self._thicknesses = thicknesses
Expand All @@ -96,7 +97,21 @@ def __init__( self,
self._foliation_properties = {} #empty dictionary of foliation parameters
self.foliation_properties = None

@property
def stratigraphic_order(self):
return self._stratigraphic_order

@stratigraphic_order.setter
def stratigraphic_order(self, stratigraphic_order):
if isinstance(stratigraphic_order[0][1],list) == False:
raise TypeError('Stratigraphic_order must of the format [[(\'group_name\',[\'unit1\',\'unit2\']),(\'group_name2\',[\'unit3\',\'unit4\'])]]')
if isinstance(stratigraphic_order,list) == False:
raise TypeError('Stratigraphic_order must be a list')
if isinstance(stratigraphic_order[0][1][0],str) == False:
raise TypeError('Stratigraphic_order elements must be strings')
self._stratigraphic_order = stratigraphic_order


@property
def colours(self):
return self._colours
Expand All @@ -119,10 +134,12 @@ def stratigraphic_column(self):
for name, sg in self._stratigraphic_order:
stratigraphic_column[name] = {}
for g in reversed(sg):
stratigraphic_column[name][g] = {'max': val[g]+self.thicknesses[g], 'min': val[g] , 'id': unit_id, 'colour':self.colours[g]}
if g in self.thicknesses:
stratigraphic_column[name][g] = {'max': val[g]+self.thicknesses[g], 'min': val[g] , 'id': unit_id, 'colour':self.colours[g]}
unit_id += 1
# add faults into the column
stratigraphic_column['faults'] = self.fault_properties.to_dict('index')
if self.fault_properties is not None:
stratigraphic_column['faults'] = self.fault_properties.to_dict('index')
return stratigraphic_column


Expand Down Expand Up @@ -280,8 +297,10 @@ def data(self):
before any of the calculated attributes are accessed
"""
dataframes = []
dataframes.append(self.contacts)
dataframes.append(self.contact_orientations)
if self.contacts is not None:
dataframes.append(self.contacts)
if self.contact_orientations is not None:
dataframes.append(self.contact_orientations)
if self.fault_orientations is not None:
dataframes.append(self.fault_orientations)
if self.fault_locations is not None:
Expand Down Expand Up @@ -310,7 +329,7 @@ def vector_scale(self,vector_scale):
@property
def stratigraphic_name(self):
names = []
for sg in self._stratigraphic_order:
for name, sg in self._stratigraphic_order:
for g in sg:
names.append(g)
return names
Expand All @@ -330,8 +349,12 @@ def _stratigraphic_value(self):
for name, sg in self._stratigraphic_order:
value = 0. #reset for each supergroup
for g in reversed(sg):
stratigraphic_value[g] = value #+ self._thicknesses[g]
value+=self._thicknesses[g]
if g not in self._thicknesses:
logger.warning('No thicknesses for {}'.format(g))
stratigraphic_value[g] = np.nan
else:
stratigraphic_value[g] = value #+ self._thicknesses[g]
value+=self._thicknesses[g]
return stratigraphic_value

def _update_feature_names(self,dataframe):
Expand Down Expand Up @@ -386,6 +409,8 @@ def contacts(self,contacts):

@property
def contact_orientations(self):
if self._contact_orientations is None:
return None
contact_orientations = self._contact_orientations.copy()
#scale
contact_orientations.loc[~np.isnan(contact_orientations['nz']),['nx', 'ny', 'nz']]*=self.vector_scale*\
Expand Down
30 changes: 11 additions & 19 deletions tests/unit_tests/input/test_data_processor.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
# from LoopStructural.modelling import ProcessInputData
# import pandas as pd
# import numpy as np
from LoopStructural.modelling import ProcessInputData
import pandas as pd
import numpy as np

# contacts -
# contacts=None
# contact_orientations = None
# stratigraphic_order = None
# fault_orientations = None
# fault_locations = None
# fault_properties = None
# fault_edges = None
# intrusions = None
# fault_stratigraphy = None
# thicknesses = None
# colours = None

# def test_create_processor():
# contacts = np.zeros(
# ProcessInputData(
def test_create_processor():
df = pd.DataFrame(np.random.rand(10,3),columns=['X','Y','Z'])
df['name'] = ['unit_{}'.format(name%2) for name in range(10)]
stratigraphic_order = [('sg',['unit_0','unit_1'])]
thicknesses = {'unit_0':1.,'unit_1':0.5}
processor = ProcessInputData(contacts=df,stratigraphic_order=stratigraphic_order,thicknesses=thicknesses)
assert((processor.data['val'].unique() == np.array([0.5,0])).all())

1 change: 0 additions & 1 deletion tests/unit_tests/modelling/test_geological_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ def test_element_number_FDI():
def test_buffer():
model = GeologicalModel([0,0,0],[5,5,5],rescale=True)
interpolator = model.get_interpolator(interpolatortype='FDI',nelements=1e5,buffer=0.2)
print(interpolator.support.origin)
assert np.sum(interpolator.support.origin + .2) == 0

0 comments on commit b9f8364

Please sign in to comment.