Skip to content

Commit 523b9de

Browse files
committed
fix: update get_isovalues method to accept 'where' parameter and add tests for top value retrieval
1 parent 181e813 commit 523b9de

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎LoopStructural/modelling/core/_model_exporter.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_stratigraphic_surfaces(model, units=None, bottoms=True):
3838
units = []
3939
if model.stratigraphic_column is None:
4040
return []
41-
units = model.stratigraphic_column.get_isovalues()
41+
units = model.stratigraphic_column.get_isovalues(where='bottom' if bottoms else 'top')
4242
units_for_group = {}
4343
for name, u in units.items():
4444
if u['group'] not in model:

‎LoopStructural/modelling/core/stratigraphic_column.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,16 +661,29 @@ def from_dict(cls, data):
661661
column.add_element(element)
662662
return column
663663

664-
def get_isovalues(self) -> dict[str, float]:
664+
def get_isovalues(self, where: str = 'bottom') -> dict[str, float]:
665665
"""
666666
Returns a dictionary of isovalues for the stratigraphic units in the column.
667+
668+
Parameters
669+
----------
670+
where : str, optional
671+
'bottom' (default) returns the value at the base of each unit.
672+
'top' returns the value at the top of each unit.
667673
"""
674+
if where not in ('top', 'bottom'):
675+
raise ValueError("Invalid 'where' argument. Use 'top' or 'bottom'.")
668676
surface_values = {}
669677
for g in reversed(self.get_groups()):
670678
v = 0
671679
for u in reversed(g.units):
672-
surface_values[u.name] = {'value':v,'group':g.name,'colour':u.colour}
680+
base = v
673681
v += u.thickness
682+
surface_values[u.name] = {
683+
'value': v if where == 'top' else base,
684+
'group': g.name,
685+
'colour': u.colour,
686+
}
674687
return surface_values
675688

676689
def plot(self,*, ax=None, **kwargs):

‎tests/unit/modelling/test_stratigraphic_column.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,25 @@ def test_get_isovalues_multi_unit_group(self):
444444
assert isovalues["B"]["value"] == 10
445445
assert isovalues["C"]["value"] == 15
446446

447+
def test_get_isovalues_where_top_returns_unit_top(self):
448+
# where='top' must give each unit's top, i.e. base + thickness --
449+
# the same value that where='bottom' (default) gives the next
450+
# (younger) unit as its base.
451+
column = StratigraphicColumn()
452+
column.clear(basement=False)
453+
column.add_unit("A", thickness=10, id=0)
454+
column.add_unit("B", thickness=5, id=1)
455+
column.add_unit("C", thickness=3, id=2)
456+
isovalues = column.get_isovalues(where='top')
457+
assert isovalues["A"]["value"] == 10
458+
assert isovalues["B"]["value"] == 15
459+
assert isovalues["C"]["value"] == 18
460+
461+
def test_get_isovalues_invalid_where_raises(self):
462+
column = self._build_two_group_column()
463+
with pytest.raises(ValueError):
464+
column.get_isovalues(where="middle")
465+
447466

448467
class TestOrderingAndUpdates:
449468
def test_update_order_reorders_elements(self):

0 commit comments

Comments
 (0)