Skip to content

Commit

Permalink
fix: adding surface getters
Browse files Browse the repository at this point in the history
also removed some old code for reusing supports
model.to_dict() is more simplified now.
To get the other data use specific getters
  • Loading branch information
lachlangrose committed Mar 11, 2024
1 parent 4b50d91 commit 6c75d4b
Showing 1 changed file with 66 additions and 18 deletions.
84 changes: 66 additions & 18 deletions LoopStructural/modelling/core/geological_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
import pandas as pd

from typing import List

from ...modelling.features.fault import FaultSegment

Expand Down Expand Up @@ -149,15 +149,7 @@ def __init__(
# )

# self.bounding_box /= self.scale_factor
self.support = {}
self.reuse_supports = reuse_supports
if self.reuse_supports:
logger.warning(
"Supports are shared between geological features \n"
"this may cause unexpected behaviour and should only\n"
"be use by advanced users"
)
logger.info("Reusing interpolation supports: {}".format(self.reuse_supports))

self.stratigraphic_column = None

self.tol = 1e-10 * np.max(self.bounding_box.maximum - self.bounding_box.origin)
Expand All @@ -175,12 +167,12 @@ def to_dict(self):
json = {}
json["model"] = {}
json["model"]["features"] = [f.name for f in self.features]
json["model"]["data"] = self.data.to_json()
json["model"]["origin"] = self.origin.tolist()
json["model"]["maximum"] = self.maximum.tolist()
json["model"]["nsteps"] = self.nsteps
# json["model"]["data"] = self.data.to_json()
# json["model"]["origin"] = self.origin.tolist()
# json["model"]["maximum"] = self.maximum.tolist()
# json["model"]["nsteps"] = self.nsteps
json["model"]["stratigraphic_column"] = self.stratigraphic_column
json["features"] = [f.to_json() for f in self.features]
# json["features"] = [f.to_json() for f in self.features]
return json

# @classmethod
Expand Down Expand Up @@ -1590,7 +1582,7 @@ def evaluate_fault_displacements(self, points, scale=True):
vals[~np.isnan(disp)] += disp[~np.isnan(disp)]
return vals * -self.scale_factor # convert from restoration magnutude to displacement

def get_feature_by_name(self, feature_name):
def get_feature_by_name(self, feature_name) -> GeologicalFeature:
"""Returns a feature from the mode given a name
Expand All @@ -1611,8 +1603,7 @@ def get_feature_by_name(self, feature_name):
if feature_index > -1:
return self.features[feature_index]
else:
logger.error(f"{feature_name} does not exist!")
return None
raise ValueError(f"{feature_name} does not exist!")

def evaluate_feature_value(self, feature_name, xyz, scale=True):
"""Evaluate the scalar value of the geological feature given the name at locations
Expand Down Expand Up @@ -1727,3 +1718,60 @@ def update(self, verbose=False, progressbar=True):
f.builder.up_to_date()
if verbose:
print(f"Model update took: {time.time()-start} seconds")

def stratigraphic_ids(self):
"""Return a list of all stratigraphic ids in the model
Returns
-------
ids : list
list of unique stratigraphic ids
"""
ids = []
for group in self.stratigraphic_column.keys():
if group == "faults":
continue
for name, series in self.stratigraphic_column[group].items():
ids.append([series["id"], group, name, series['min'], series['max']])
return ids

def get_fault_surfaces(self, faults: List[str] = []):
surfaces = []
if len(faults) == 0:
faults = self.fault_names()

for f in faults:
surfaces.extend(self.get_feature_by_name(f).surfaces([0], self.bounding_box))
return surfaces

def get_stratigraphic_surfaces(self, units: List[str] = [], bottoms: bool = True):
## TODO change the stratigraphic column to its own class and have methods to get the relevant surfaces
surfaces = []
units = []
for group in self.stratigraphic_column.keys():
if group == "faults":
continue
for series in self.stratigraphic_column[group].values():
series['feature_name'] = group
units.append(series)
unit_table = pd.DataFrame(units)
for u in unit_table['feature_name'].unique():

values = unit_table.loc[unit_table['feature_name'] == u, 'min' if bottoms else 'max']
if 'name' not in unit_table.columns:
unit_table['name'] = unit_table['feature_name']

names = unit_table[unit_table['feature_name'] == u]['name']
values = values.loc[~np.logical_or(values == np.inf, values == -np.inf)]
surfaces.extend(
self.get_feature_by_name(u).surfaces(
values.to_list(), self.bounding_box, name=names.loc[values.index].to_list()
)
)

return surfaces

def get_block_model(self):
grid = self.bounding_box.vtk
grid['id'] = self.evaluate_model(grid.points)
return grid, self.stratigraphic_ids()

0 comments on commit 6c75d4b

Please sign in to comment.