Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions LoopStructural/modelling/core/geological_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import json
import pathlib
import warnings

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -834,8 +835,9 @@ def set_stratigraphic_column(self, stratigraphic_column, cmap="tab20"):
# if the colour for a unit hasn't been specified we can just sample from
# a colour map e.g. tab20
logger.info("Adding stratigraphic column to model")
raise DeprecationWarning(
"set_stratigraphic_column is deprecated, use model.stratigraphic_column.add_units instead"
warnings.warn(
"set_stratigraphic_column is deprecated, use model.stratigraphic_column.add_units instead",
DeprecationWarning,
)
for i, g in enumerate(stratigraphic_column.keys()):
if g == 'faults':
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/input/test_data_processor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pandas as pd

from LoopStructural import GeologicalModel
from LoopStructural.modelling import ProcessInputData
from LoopStructural.utils import rng

Expand All @@ -14,3 +15,27 @@ def test_create_processor():
contacts=df, stratigraphic_order=stratigraphic_order, thicknesses=thicknesses
)
assert (processor.data["val"].unique() == np.array([0.5, 0])).all()


def test_from_processor_populates_stratigraphic_column():
"""
Regression test: from_processor crashed with a DeprecationWarning raised by
set_stratigraphic_column when assigning the processor's column to the model.
"""
df = pd.DataFrame(rng.random(size=(10, 3)), columns=["X", "Y", "Z"])
df["name"] = [f"unit_{name % 2}" for name in range(10)]
stratigraphic_order = [("sg", ["unit_0", "unit_1", "basement"])]
thicknesses = {"unit_0": 1.0, "unit_1": 0.5}
processor = ProcessInputData(
contacts=df,
stratigraphic_order=stratigraphic_order,
thicknesses=thicknesses,
origin=np.zeros(3),
maximum=np.ones(3),
)

model = GeologicalModel.from_processor(processor)

unit_names = [unit.name for unit in model.stratigraphic_column.order if hasattr(unit, "name")]
assert "unit_0" in unit_names
assert "unit_1" in unit_names
Loading