Skip to content

Commit 3c482aa

Browse files
authored
feat: build a model with only faults (6.5) (#143)
* feat: build a model with only faults In the map workflow, an empty stratigraphic column no longer needs the geology layer, the structure layer or basal contacts. The build skips the contacts and thickness calculation and the stratigraphic feature, and builds the faults. Step 5 does not offer the stratigraphic surfaces or the block model when the model has only faults. * fix: review fixes for the model of faults only - Set the column of the model before the early return, so the model does not keep the units of the last build. - Correct valid: include the parametric faults, and check each fault trace, not only the last one. - Remove the second check of the unit names in names_to_refresh. - Add a test that builds parametric faults with an empty column.
1 parent 6cbcbb4 commit 3c482aa

7 files changed

Lines changed: 84 additions & 17 deletions

File tree

‎loopstructural/gui/modelling/steps/checks.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,18 @@ def check_data(data_manager, model_manager=None) -> StepCheck:
6565
def check_stratigraphy(data_manager, model_manager=None) -> StepCheck:
6666
"""Step 2: the column and the results that come from it."""
6767
problems, todo = [], []
68+
unit_names = data_manager.get_stratigraphic_unit_names()
69+
if not unit_names:
70+
# The step is optional: a model of faults only has no column
71+
todo.append(
72+
"Add units to the stratigraphic column. This step is optional if you model "
73+
"only faults."
74+
)
75+
return StepCheck(tuple(problems), tuple(todo))
6876
if data_manager.get_layer_role(layer_roles.GEOLOGY) is None:
6977
todo.append("Select the geology layer.")
7078
if data_manager.get_layer_role(layer_roles.STRUCTURE) is None:
7179
todo.append("Select the structure layer.")
72-
unit_names = data_manager.get_stratigraphic_unit_names()
73-
if not unit_names:
74-
todo.append("Add units to the stratigraphic column.")
7580
problems.extend(_out_of_date_messages(data_manager))
7681

7782
contact_units = set(data_manager.get_unique_basal_units())

‎loopstructural/gui/modelling/steps/export_panel.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,30 @@ def set_model_solved(self, solved):
169169
)
170170
for tab_index in range(self.tabs.count()):
171171
self.tabs.widget(tab_index).setEnabled(self._model_solved and self._task is None)
172+
# A model of faults only has no units: no stratigraphic surfaces, no block model
173+
has_units = not solved or self._has_stratigraphic_features()
174+
if has_units and not self.surface_strat.isEnabled():
175+
self.surface_strat.setChecked(True)
176+
self.surface_strat.setEnabled(has_units)
177+
if not has_units:
178+
self.surface_strat.setChecked(False)
179+
self.tabs.setTabEnabled(1, has_units)
180+
if not has_units:
181+
self.hint.setText("The model has faults only, so the block model is not offered.")
172182
if self._model_solved:
173183
self._set_plane_defaults()
174184

185+
def _has_stratigraphic_features(self):
186+
"""Return False if every feature of the model is a fault."""
187+
manager = self.model_manager
188+
if manager is None:
189+
return True
190+
faults = set(getattr(manager, 'faults', {}) or {}) | set(
191+
getattr(manager, 'parametric_faults', {}) or {}
192+
)
193+
names = [f.name for f in manager.features() if not f.name.startswith('__')]
194+
return any(name not in faults for name in names)
195+
175196
def _plane_values(self):
176197
return tuple(w.value() for w in self.section_origin) + (self.section_size.value(),)
177198

‎loopstructural/main/derived_refresh.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ def names_to_refresh(data_manager) -> List[str]:
3131
because the layer is an input of the user.
3232
- Thickness: only when it is out of date. A thickness that was never
3333
calculated can be typed, so the build does not calculate it.
34+
35+
With no units in the column (a model of faults only), nothing comes from
36+
the column, so the list is empty.
3437
"""
3538
derived = data_manager.derived
3639
names = []
40+
if not data_manager.get_stratigraphic_unit_names():
41+
return names
3742
if (
3843
data_manager.layer_roles.contacts_source == layer_roles.CONTACTS_FROM_GEOLOGY
39-
and data_manager.get_stratigraphic_unit_names()
4044
and data_manager.get_layer_role(layer_roles.GEOLOGY) is not None
4145
and data_manager.get_layer_role(layer_roles.GEOLOGY_UNIT_FIELD)
4246
and derived.status(derived_data.BASAL_CONTACTS) != derived_data.CURRENT

‎loopstructural/main/model_manager.py‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,14 @@ def update_foliation_features(self):
11061106
and the basal contacts and structural orientations data.
11071107
This method will automatically add unconformities based on the stratigraphic column.
11081108
"""
1109+
if self.stratigraphic_column is not None:
1110+
# also for an empty column, so the model does not keep the units
1111+
# of the last build
1112+
self.model.stratigraphic_column = self.stratigraphic_column
1113+
# A model with faults only has no column, or a column with no units
1114+
if self.stratigraphic_column is None or not self.stratigraphic_column.get_groups():
1115+
self._emit('foliation_features_updated')
1116+
return
11091117
stratigraphic_column = {}
11101118
# Take each unit's training value straight from `get_isovalues()`
11111119
# (LoopStructural core), which is what labels the extracted
@@ -1719,18 +1727,19 @@ def model_state(self) -> str:
17191727

17201728
@property
17211729
def valid(self):
1722-
valid = True
1723-
if len(self.groups) == 0:
1724-
valid = False
1725-
if len(self.stratigraphy) == 0:
1726-
valid = False
1727-
if len(self.faults) > 0:
1728-
for _fault_name, fault_data in self.faults.items():
1729-
if 'data' in fault_data and not fault_data['data'].empty:
1730-
valid = True
1731-
else:
1732-
valid = False
1733-
return valid
1730+
"""True if the model has stratigraphy or faults, and each fault trace has data.
1731+
1732+
A model with faults only (traces or parametric faults) has no groups
1733+
and no stratigraphy.
1734+
"""
1735+
if any(
1736+
'data' not in fault_data or fault_data['data'].empty
1737+
for fault_data in self.faults.values()
1738+
):
1739+
return False
1740+
has_stratigraphy = len(self.groups) > 0 and len(self.stratigraphy) > 0
1741+
has_faults = len(self.faults) > 0 or len(self.parametric_faults) > 0
1742+
return has_stratigraphy or has_faults
17341743

17351744
def update_model(
17361745
self,

‎tests/qgis/test_parametric_fault.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ def test_the_fault_is_built_with_constraints(self, manager):
6262
manager.update_model(notify_observers=False)
6363
assert 'F1' in _names(manager)
6464

65+
def test_a_model_of_faults_only_with_an_empty_column(self, manager):
66+
column = StratigraphicColumn()
67+
column.clear(basement=False)
68+
manager.stratigraphic_column = column
69+
manager.add_parametric_fault(_spec())
70+
manager.update_model(notify_observers=False)
71+
manager.update_all_features(notify_observers=False)
72+
assert 'F1' in _names(manager)
73+
# no stratigraphic feature
74+
assert all(name.startswith(('F1', '__')) for name in _names(manager))
75+
assert manager.model.stratigraphic_column is column
76+
assert manager.valid
77+
assert manager.model_state == 'solved'
78+
6579
def test_the_fault_surface_is_where_the_fault_is(self, manager):
6680
manager.add_parametric_fault(_spec())
6781
manager.update_model(notify_observers=False)

‎tests/unit/test_build_plan.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ def test_no_column_calculates_no_contacts(self, dm):
176176
dm.units = []
177177
assert names_to_refresh(dm) == []
178178

179+
def test_no_column_calculates_no_thickness_even_if_out_of_date(self, dm):
180+
dm.derived.record(derived_data.BASAL_CONTACTS)
181+
dm.derived.record(derived_data.THICKNESS)
182+
dm.inputs = {'unit_order': []}
183+
dm.units = []
184+
assert names_to_refresh(dm) == []
185+
179186
def test_no_geology_layer_calculates_no_contacts(self, dm):
180187
dm.layer_roles.values[layer_roles.GEOLOGY] = None
181188
assert names_to_refresh(dm) == []

‎tests/unit/test_step_checks.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,16 @@ def map_layers(self, dm, request):
119119
def test_an_empty_column_is_not_started(self, dm):
120120
check = checks.check_stratigraphy(dm)
121121
assert check.status == Status.NOT_STARTED
122-
assert 'Add units to the stratigraphic column.' in check.todo
122+
assert any(t.startswith('Add units to the stratigraphic column.') for t in check.todo)
123+
assert 'optional' in check.todo[0]
124+
125+
def test_an_empty_column_does_not_ask_for_layers_or_contacts(self, dm):
126+
todo = checks.check_stratigraphy(dm).todo
127+
assert len(todo) == 1
128+
assert not checks.check_stratigraphy(dm).problems
123129

124130
def test_missing_map_layers_are_a_todo(self, dm):
131+
dm.units = ['a']
125132
todo = checks.check_stratigraphy(dm).todo
126133
assert 'Select the geology layer.' in todo
127134
assert 'Select the structure layer.' in todo

0 commit comments

Comments
 (0)