Skip to content

Commit 6c75d4b

Browse files
committed
fix: adding surface getters
also removed some old code for reusing supports model.to_dict() is more simplified now. To get the other data use specific getters
1 parent 4b50d91 commit 6c75d4b

File tree

1 file changed

+66
-18
lines changed

1 file changed

+66
-18
lines changed

LoopStructural/modelling/core/geological_model.py

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import numpy as np
88
import pandas as pd
9-
9+
from typing import List
1010

1111
from ...modelling.features.fault import FaultSegment
1212

@@ -149,15 +149,7 @@ def __init__(
149149
# )
150150

151151
# self.bounding_box /= self.scale_factor
152-
self.support = {}
153-
self.reuse_supports = reuse_supports
154-
if self.reuse_supports:
155-
logger.warning(
156-
"Supports are shared between geological features \n"
157-
"this may cause unexpected behaviour and should only\n"
158-
"be use by advanced users"
159-
)
160-
logger.info("Reusing interpolation supports: {}".format(self.reuse_supports))
152+
161153
self.stratigraphic_column = None
162154

163155
self.tol = 1e-10 * np.max(self.bounding_box.maximum - self.bounding_box.origin)
@@ -175,12 +167,12 @@ def to_dict(self):
175167
json = {}
176168
json["model"] = {}
177169
json["model"]["features"] = [f.name for f in self.features]
178-
json["model"]["data"] = self.data.to_json()
179-
json["model"]["origin"] = self.origin.tolist()
180-
json["model"]["maximum"] = self.maximum.tolist()
181-
json["model"]["nsteps"] = self.nsteps
170+
# json["model"]["data"] = self.data.to_json()
171+
# json["model"]["origin"] = self.origin.tolist()
172+
# json["model"]["maximum"] = self.maximum.tolist()
173+
# json["model"]["nsteps"] = self.nsteps
182174
json["model"]["stratigraphic_column"] = self.stratigraphic_column
183-
json["features"] = [f.to_json() for f in self.features]
175+
# json["features"] = [f.to_json() for f in self.features]
184176
return json
185177

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

1593-
def get_feature_by_name(self, feature_name):
1585+
def get_feature_by_name(self, feature_name) -> GeologicalFeature:
15941586
"""Returns a feature from the mode given a name
15951587
15961588
@@ -1611,8 +1603,7 @@ def get_feature_by_name(self, feature_name):
16111603
if feature_index > -1:
16121604
return self.features[feature_index]
16131605
else:
1614-
logger.error(f"{feature_name} does not exist!")
1615-
return None
1606+
raise ValueError(f"{feature_name} does not exist!")
16161607

16171608
def evaluate_feature_value(self, feature_name, xyz, scale=True):
16181609
"""Evaluate the scalar value of the geological feature given the name at locations
@@ -1727,3 +1718,60 @@ def update(self, verbose=False, progressbar=True):
17271718
f.builder.up_to_date()
17281719
if verbose:
17291720
print(f"Model update took: {time.time()-start} seconds")
1721+
1722+
def stratigraphic_ids(self):
1723+
"""Return a list of all stratigraphic ids in the model
1724+
1725+
Returns
1726+
-------
1727+
ids : list
1728+
list of unique stratigraphic ids
1729+
"""
1730+
ids = []
1731+
for group in self.stratigraphic_column.keys():
1732+
if group == "faults":
1733+
continue
1734+
for name, series in self.stratigraphic_column[group].items():
1735+
ids.append([series["id"], group, name, series['min'], series['max']])
1736+
return ids
1737+
1738+
def get_fault_surfaces(self, faults: List[str] = []):
1739+
surfaces = []
1740+
if len(faults) == 0:
1741+
faults = self.fault_names()
1742+
1743+
for f in faults:
1744+
surfaces.extend(self.get_feature_by_name(f).surfaces([0], self.bounding_box))
1745+
return surfaces
1746+
1747+
def get_stratigraphic_surfaces(self, units: List[str] = [], bottoms: bool = True):
1748+
## TODO change the stratigraphic column to its own class and have methods to get the relevant surfaces
1749+
surfaces = []
1750+
units = []
1751+
for group in self.stratigraphic_column.keys():
1752+
if group == "faults":
1753+
continue
1754+
for series in self.stratigraphic_column[group].values():
1755+
series['feature_name'] = group
1756+
units.append(series)
1757+
unit_table = pd.DataFrame(units)
1758+
for u in unit_table['feature_name'].unique():
1759+
1760+
values = unit_table.loc[unit_table['feature_name'] == u, 'min' if bottoms else 'max']
1761+
if 'name' not in unit_table.columns:
1762+
unit_table['name'] = unit_table['feature_name']
1763+
1764+
names = unit_table[unit_table['feature_name'] == u]['name']
1765+
values = values.loc[~np.logical_or(values == np.inf, values == -np.inf)]
1766+
surfaces.extend(
1767+
self.get_feature_by_name(u).surfaces(
1768+
values.to_list(), self.bounding_box, name=names.loc[values.index].to_list()
1769+
)
1770+
)
1771+
1772+
return surfaces
1773+
1774+
def get_block_model(self):
1775+
grid = self.bounding_box.vtk
1776+
grid['id'] = self.evaluate_model(grid.points)
1777+
return grid, self.stratigraphic_ids()

0 commit comments

Comments
 (0)