Skip to content

Commit 56f2682

Browse files
committed
adding placeholder to associate data with a stratigraphic unit
add ability to map group name to features e.g. Group 1: feature_name Make arguments named only Update stratigraphic surfaces to use new stratigraphic column
1 parent 80da409 commit 56f2682

2 files changed

Lines changed: 64 additions & 48 deletions

File tree

LoopStructural/modelling/core/geological_model.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,9 @@ def set_stratigraphic_column(self, stratigraphic_column, cmap="tab20"):
526526
colour=stratigraphic_column[g][u].get("colour", None),
527527
thickness=thickness,
528528
)
529+
self.stratigraphic_column.add_unconformity(
530+
name=''.join([g, 'unconformity']),
531+
)
529532

530533

531534
def create_and_add_foliation(
@@ -1704,31 +1707,20 @@ def get_stratigraphic_surfaces(self, units: List[str] = [], bottoms: bool = True
17041707
units = []
17051708
if self.stratigraphic_column is None:
17061709
return []
1707-
for group in self.stratigraphic_column.keys():
1708-
if group == "faults":
1710+
units = self.stratigraphic_column.get_isovalues()
1711+
for name, u in units.items():
1712+
if u['group'] not in self:
1713+
logger.warning(f"Group {u['group']} not found in model")
17091714
continue
1710-
for series in self.stratigraphic_column[group].values():
1711-
series['feature_name'] = group
1712-
units.append(series)
1713-
unit_table = pd.DataFrame(units)
1714-
for u in unit_table['feature_name'].unique():
1715-
1716-
values = unit_table.loc[unit_table['feature_name'] == u, 'min' if bottoms else 'max']
1717-
if 'name' not in unit_table.columns:
1718-
unit_table['name'] = unit_table['feature_name']
1719-
1720-
names = unit_table[unit_table['feature_name'] == u]['name']
1721-
values = values.loc[~np.logical_or(values == np.inf, values == -np.inf)]
1722-
surfaces.extend(
1723-
self.get_feature_by_name(u).surfaces(
1724-
values.to_list(),
1725-
self.bounding_box,
1726-
name=names.loc[values.index].to_list(),
1727-
colours=unit_table.loc[unit_table['feature_name'] == u, 'colour'].tolist()[
1728-
1:
1729-
], # we don't isosurface basement, no value
1730-
)
1731-
)
1715+
feature = self.get_feature_by_name(u['group'])
1716+
1717+
surfaces.extend(feature.surfaces([u['value']],
1718+
self.bounding_box,
1719+
name=name,
1720+
colours=[u['colour']]
1721+
))
1722+
1723+
17321724

17331725
return surfaces
17341726

LoopStructural/modelling/core/stratigraphic_column.py

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class StratigraphicUnit(StratigraphicColumnElement):
4747
A class to represent a stratigraphic unit.
4848
"""
4949

50-
def __init__(self, *, uuid=None, name=None, colour=None, thickness=None):
50+
def __init__(self, *, uuid=None, name=None, colour=None, thickness=None, data=None):
5151
"""
5252
Initializes the StratigraphicUnit with a name and an optional description.
5353
"""
@@ -57,6 +57,7 @@ def __init__(self, *, uuid=None, name=None, colour=None, thickness=None):
5757
colour = rng.random(3)
5858
self.colour = colour
5959
self.thickness = thickness
60+
self.data = data
6061
self.element_type = StratigraphicColumnElementType.UNIT
6162

6263
def to_dict(self):
@@ -137,6 +138,18 @@ def from_dict(cls, data):
137138
)
138139
uuid = data.get("uuid", None)
139140
return cls(uuid=uuid, name=name, unconformity_type=unconformity_type)
141+
class StratigraphicGroup:
142+
"""
143+
A class to represent a group of stratigraphic units.
144+
This class is not fully implemented and serves as a placeholder for future development.
145+
"""
146+
147+
def __init__(self, name=None, units=None):
148+
"""
149+
Initializes the StratigraphicGroup with a name and an optional list of units.
150+
"""
151+
self.name = name
152+
self.units = units if units is not None else []
140153

141154

142155
class StratigraphicColumn:
@@ -150,13 +163,15 @@ def __init__(self):
150163
Initializes the StratigraphicColumn with a name and a list of layers.
151164
"""
152165
self.order = [StratigraphicUnit(name='Basement', colour='grey', thickness=np.inf),StratigraphicUnconformity(name='Base Unconformity', unconformity_type=UnconformityType.ERODE)]
166+
self.group_mapping = {}
153167
def clear(self):
154168
"""
155169
Clears the stratigraphic column, removing all elements.
156170
"""
157171
self.order = [StratigraphicUnit(name='Basement', colour='grey', thickness=np.inf),StratigraphicUnconformity(name='Base Unconformity', unconformity_type=UnconformityType.ERODE)]
172+
self.group_mapping = {}
158173

159-
def add_unit(self, name, colour, thickness=None, where='top'):
174+
def add_unit(self, name,*, colour=None, thickness=None, where='top'):
160175
unit = StratigraphicUnit(name=name, colour=colour, thickness=thickness)
161176

162177
if where == 'top':
@@ -178,7 +193,7 @@ def remove_unit(self, uuid):
178193
return True
179194
return False
180195

181-
def add_unconformity(self, name, unconformity_type=UnconformityType.ERODE, where='top' ):
196+
def add_unconformity(self, name, *, unconformity_type=UnconformityType.ERODE, where='top' ):
182197
unconformity = StratigraphicUnconformity(
183198
uuid=None, name=name, unconformity_type=unconformity_type
184199
)
@@ -226,31 +241,41 @@ def get_elements(self):
226241

227242
def get_groups(self):
228243
groups = []
229-
group = []
244+
i=0
245+
group = StratigraphicGroup(
246+
name=(
247+
f'Group_{i}'
248+
if f'Group_{i}' not in self.group_mapping
249+
else self.group_mapping[f'Group_{i}']
250+
)
251+
)
230252
for e in self.order:
231253
if isinstance(e, StratigraphicUnit):
232-
group.append(e)
254+
group.units.append(e)
233255
else:
234-
if group:
256+
if group.units:
235257
groups.append(group)
236-
group = []
258+
i+=1
259+
group = StratigraphicGroup(
260+
name=(
261+
f'Group_{i}'
262+
if f'Group_{i}' not in self.group_mapping
263+
else self.group_mapping[f'Group_{i}']
264+
)
265+
)
237266
if group:
238267
groups.append(group)
239268
return groups
240269

241270
def get_unitname_groups(self):
242-
groups = []
271+
groups = self.get_groups()
272+
groups_list = []
243273
group = []
244-
for e in self.order:
245-
if isinstance(e, StratigraphicUnit):
246-
group.append(e.name)
247-
else:
248-
if group:
249-
groups.append(group)
250-
group = []
251-
if group:
252-
groups.append(group)
253-
return groups
274+
for g in groups:
275+
group = [u.name for u in g.units if isinstance(u, StratigraphicUnit)]
276+
groups_list.append(group)
277+
return groups_list
278+
254279

255280
def __getitem__(self, uuid):
256281
"""
@@ -289,7 +314,6 @@ def update_element(self, unit_data: Dict):
289314
unit_data.get('unconformity_type', element.unconformity_type.value)
290315
)
291316

292-
293317
def __str__(self):
294318
"""
295319
Returns a string representation of the stratigraphic column, listing all elements.
@@ -320,20 +344,20 @@ def from_dict(cls, data):
320344
element = StratigraphicUnit.from_dict(element_data)
321345
column.add_element(element)
322346
return column
323-
347+
324348
def get_isovalues(self) -> Dict[str, float]:
325349
"""
326350
Returns a dictionary of isovalues for the stratigraphic units in the column.
327351
"""
328352
surface_values = {}
329353
for g in reversed(self.get_groups()):
330354
v = 0
331-
for u in g:
332-
surface_values[u.name] = v
355+
for u in g.units:
356+
surface_values[u.name] = {'value':v,'group':g.name,'colour':u.colour}
333357
v += u.thickness
334358
return surface_values
335-
336-
def plot(self, ax=None, **kwargs):
359+
360+
def plot(self,*, ax=None, **kwargs):
337361
import matplotlib.pyplot as plt
338362
from matplotlib import cm
339363
from matplotlib.patches import Polygon

0 commit comments

Comments
 (0)