Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ def _toggle_detached(self):
if reply != QMessageBox.StandardButton.Yes:
return
manager.attach_feature(name)
push_info("Feature", f"'{name}' follows the stratigraphic column again. Rebuild the model.")
push_info(
"Feature", f"'{name}' follows the stratigraphic column again. Rebuild the model."
)
elif manager.detach_feature(name):
push_info("Feature", f"'{name}' is detached. Its data is a fixed copy.")
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def _build_status_icon(color: str, *, filled: bool, mark: str = None) -> QIcon:
'initialized': "Model status: initialized (not solved)",
'solved': "Model status: solved",
'stale': (
"Model status: faults, stratigraphic column or input data changed — "
"rebuild the model"
"Model status: faults, stratigraphic column or input data changed — " "rebuild the model"
),
}

Expand Down Expand Up @@ -524,9 +523,7 @@ def _confirm_bounding_box_contains_data(self):
)
return reply == QMessageBox.StandardButton.Yes

def _run_model_task(
self, target, *, title, initial_label, cancellable=True, on_success=None
):
def _run_model_task(self, target, *, title, initial_label, cancellable=True, on_success=None):
"""Run `target(progress_callback)` on a background QThread with a
non-modal progress dialog, so the rest of QGIS stays usable. Both
Initialize Model and Solve Model share this: they disable each other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,17 +535,20 @@ def _setup_common_fields(self, layout):
self.weight_spin.setDecimals(3)
self.weight_spin.setRange(0.001, 1000.0)
self.weight_spin.setSingleStep(0.1)
self.weight_spin.setValue(
self.existing_data.get('weight', constraints.DEFAULT_WEIGHT)
)
self.weight_spin.setValue(self.existing_data.get('weight', constraints.DEFAULT_WEIGHT))
self.weight_spin.setToolTip("How much the constraint counts in the interpolation.")
form.addRow("Weight:", self.weight_spin)

self.z_source_combo = QComboBox()
for source in constraints.Z_SOURCES:
self.z_source_combo.addItem(constraints.Z_LABELS[source], source)
self.z_source_combo.setCurrentIndex(
max(self.z_source_combo.findData(self.existing_data.get('z_source', constraints.Z_LAYER)), 0)
max(
self.z_source_combo.findData(
self.existing_data.get('z_source', constraints.Z_LAYER)
),
0,
)
)
self.z_source_combo.setToolTip(
"Where the Z of the points comes from: the geometry of the layer, the DEM "
Expand All @@ -561,7 +564,9 @@ def _setup_common_fields(self, layout):
layout.addLayout(form)

def update_z_value_state():
self.z_value_spin.setEnabled(self.z_source_combo.currentData() == constraints.Z_CONSTANT)
self.z_value_spin.setEnabled(
self.z_source_combo.currentData() == constraints.Z_CONSTANT
)

self.z_source_combo.currentIndexChanged.connect(update_z_value_state)
update_z_value_state()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def _apply_contacts_source(self, source):
else:
configure_layer_combo(
self.basalContactsLayer,
QgsMapLayerProxyModel.Filter.LineLayer | QgsMapLayerProxyModel.Filter.PointLayer,
QgsMapLayerProxyModel.Filter.LineLayer
| QgsMapLayerProxyModel.Filter.PointLayer,
allow_empty=True,
)
self.groupBox_basalContacts.setTitle("Basal contacts")
Expand Down
9 changes: 5 additions & 4 deletions loopstructural/gui/modelling/modelling_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ def _visible_indices(self):
def _neighbour(self, direction, index=None):
"""Return the index of the next visible step, or ``index`` if there is none."""
index = self.current_index if index is None else index
candidates = [
i for i in self._visible_indices() if (i - index) * direction > 0
]
candidates = [i for i in self._visible_indices() if (i - index) * direction > 0]
if not candidates:
return index
return min(candidates, key=lambda i: abs(i - index))
Expand All @@ -162,7 +160,10 @@ def _apply_workflow_mode(self, mode):
for page in self.pages:
self.step_bar.set_step_visible(page.key, page.key in visible)
self.data_step.set_workflow_mode(mode)
if self.stack.currentIndex() >= 0 and self.pages[self.stack.currentIndex()].key not in visible:
if (
self.stack.currentIndex() >= 0
and self.pages[self.stack.currentIndex()].key not in visible
):
self.go_to(self.stack.currentIndex())
else:
self.refresh_status()
Expand Down
18 changes: 12 additions & 6 deletions loopstructural/gui/modelling/steps/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ def __init__(self, parent=None, **kwargs):
self.fault_layers.faultTraceLayer.layerChanged.connect(self.update_topology_button)
self.fault_layers.faultNameField.fieldChanged.connect(self.update_topology_button)
if self.data_manager is not None:
self.data_manager.layer_roles.attach(lambda _role, _value: self.update_topology_button())
self.data_manager.layer_roles.attach(
lambda _role, _value: self.update_topology_button()
)
self.update_topology_button()

self.adjacency = FaultAdjacencyTab(self, data_manager=self.data_manager)
Expand All @@ -274,7 +276,11 @@ def _fault_traces(self):
def update_topology_button(self, *_args):
"""Enable the button when the fault layer and the name field are set."""
traces = self._fault_traces()
layer = self.data_manager.get_layer_role(layer_roles.FAULT_TRACES) if self.data_manager else None
layer = (
self.data_manager.get_layer_role(layer_roles.FAULT_TRACES)
if self.data_manager
else None
)
if layer is None or not traces.get('fault_name_field'):
self.topology_button.setEnabled(False)
self.topology_button.setToolTip(
Expand All @@ -289,11 +295,11 @@ def update_topology_button(self, *_args):
def _calculate_topology(self):
self.message_bar.clearWidgets()
try:
result = calculate_from_data_manager(
self.data_manager, self.tolerance_spin_box.value()
)
result = calculate_from_data_manager(self.data_manager, self.tolerance_spin_box.value())
except FaultTopologyError as error:
self.message_bar.pushMessage("Fault topology", str(error), level=Qgis.MessageLevel.Critical)
self.message_bar.pushMessage(
"Fault topology", str(error), level=Qgis.MessageLevel.Critical
)
return
text, warn = result_message(result)
self.message_bar.pushMessage(
Expand Down
4 changes: 1 addition & 3 deletions loopstructural/gui/modelling/steps/section_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ def _save_state(self):
self._settings_key, {key: self.is_open(key) for key in self._sections}
)

def add_section(
self, widget, key, title, *, summary=None, collapsed=False, index=None
):
def add_section(self, widget, key, title, *, summary=None, collapsed=False, index=None):
"""Add a section and return its group box.

``widget`` is the content, or a `QgsCollapsibleGroupBox` that the stack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from .init_from_field_dialog import InitFromLayerFieldDialog
from .stratigraphic_unit import StratigraphicUnitWidget


# The values of the "Style by" combo
STYLE_COLOUR = 'colour'
STYLE_ORDER = 'order'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
render_histogram,
)


class ObjectPropertiesWidget(QWidget):
"""The properties of the selected viewer object.

Expand Down
5 changes: 4 additions & 1 deletion loopstructural/main/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def has_weight(layer_type):
"""Return True if a row of the type `layer_type` has a weight."""
return layer_type not in UNWEIGHTED_TYPES


# The keys of a row that name a field of the layer, for each type. A row
# without these keys is not complete.
REQUIRED_FIELDS = {
Expand All @@ -85,7 +86,9 @@ def has_weight(layer_type):

def missing_fields(layer_data):
"""Return the keys that a row needs and does not have."""
return [key for key in REQUIRED_FIELDS.get(layer_data.get('type'), ()) if not layer_data.get(key)]
return [
key for key in REQUIRED_FIELDS.get(layer_data.get('type'), ()) if not layer_data.get(key)
]


def solver_for(layer_type):
Expand Down
4 changes: 1 addition & 3 deletions tests/qgis/test_fault_topology_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
def page():
project = QgsProject.instance()
model_manager = GeologicalModelManager()
data_manager = ModellingDataManager(
project=project, mapCanvas=Mock(), logger=Mock()
)
data_manager = ModellingDataManager(project=project, mapCanvas=Mock(), logger=Mock())
data_manager.set_model_manager(model_manager)
return FaultsStep(None, data_manager=data_manager, model_manager=model_manager)

Expand Down
8 changes: 2 additions & 6 deletions tests/qgis/test_manual_foliations.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ def test_a_pairwise_inequality_needs_the_admm_solver(self, manager, monkeypatch)
assert kwargs == {'solver': 'admm'}
assert 'pair_id' in data

def test_with_the_native_solver_a_pairwise_inequality_needs_no_admm(
self, manager, monkeypatch
):
def test_with_the_native_solver_a_pairwise_inequality_needs_no_admm(self, manager, monkeypatch):
monkeypatch.setattr(solver_choice, 'use_native', lambda setting: True)
df = _points(order=lambda p: 1 if p.x < 50 else 2)
layer = {'type': 'Pairwise Inequality', 'pair_field': 'order', 'df': df}
Expand All @@ -199,9 +197,7 @@ def test_a_feature_from_value_and_normal_layers_solves_without_a_column(self, ma
'vector_z_field': 'nz',
'df': _points(nx=lambda p: 1.0, ny=lambda p: 0.0, nz=lambda p: 0.0),
}
manager.add_foliation(
's1', {'values': values, 'normals': normals}, use_z_coordinate=True
)
manager.add_foliation('s1', {'values': values, 'normals': normals}, use_z_coordinate=True)
manager.update_all_features(notify_observers=False)
result = manager.model['s1'].evaluate_value(np.array([[50.0, 50.0, 0.0]]))
assert not np.any(np.isnan(result))
Loading