Skip to content

Commit 18c46ca

Browse files
committed
fix: add geodataframetoproject for calculating contacts and guess columns./layers
1 parent dc6730a commit 18c46ca

File tree

3 files changed

+299
-17
lines changed

3 files changed

+299
-17
lines changed

loopstructural/gui/map2loop_tools/basal_contacts_widget.py

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
from loopstructural.gui.modelling.model_definition import fault_layers
99

10+
from ...main.helpers import ColumnMatcher, get_layer_names
1011
from ...main.m2l_api import extract_basal_contacts
12+
from ...main.vectorLayerWrapper import addGeoDataFrameToproject
1113

1214

1315
class BasalContactsWidget(QWidget):
@@ -58,10 +60,31 @@ def __init__(self, parent=None, data_manager=None):
5860
# Connect signals
5961
self.geologyLayerComboBox.layerChanged.connect(self._on_geology_layer_changed)
6062
self.runButton.clicked.connect(self._run_extractor)
61-
63+
self._guess_layers()
6264
# Set up field combo boxes
6365
self._setup_field_combo_boxes()
6466

67+
def _guess_layers(self):
68+
"""Attempt to auto-select layers based on common naming conventions."""
69+
if not self.data_manager:
70+
return
71+
72+
# Attempt to find geology layer
73+
geology_layer_names = get_layer_names(self.geologyLayerComboBox)
74+
geology_matcher = ColumnMatcher(geology_layer_names)
75+
geology_layer_match = geology_matcher.find_match('GEOLOGY')
76+
if geology_layer_match:
77+
geology_layer = self.data_manager.find_layer_by_name(geology_layer_match)
78+
self.geologyLayerComboBox.setLayer(geology_layer)
79+
80+
# Attempt to find faults layer
81+
fault_layer_names = get_layer_names(self.faultsLayerComboBox)
82+
fault_layer_matcher = ColumnMatcher(fault_layer_names)
83+
fault_layer_match = fault_layer_matcher.find_match('FAULTS')
84+
if fault_layer_match:
85+
faults_layer = self.data_manager.find_layer_by_name(fault_layer_match)
86+
self.faultsLayerComboBox.setLayer(faults_layer)
87+
6588
def _setup_field_combo_boxes(self):
6689
"""Set up field combo boxes to link to their respective layers."""
6790
geology = self.geologyLayerComboBox.currentLayer()
@@ -76,9 +99,20 @@ def _setup_field_combo_boxes(self):
7699

77100
def _on_geology_layer_changed(self):
78101
"""Update field combo boxes when geology layer changes."""
102+
from ...main.helpers import ColumnMatcher
103+
79104
layer = self.geologyLayerComboBox.currentLayer()
80105
self.unitNameFieldComboBox.setLayer(layer)
81106

107+
# Auto-detect appropriate fields
108+
if layer:
109+
fields = [field.name() for field in layer.fields()]
110+
matcher = ColumnMatcher(fields)
111+
112+
# Auto-select UNITNAME field
113+
if unit_match := matcher.find_match('UNITNAME'):
114+
self.unitNameFieldComboBox.setField(unit_match)
115+
82116
def _run_extractor(self):
83117
"""Run the basal contacts extraction algorithm."""
84118
# Validate inputs
@@ -98,16 +132,37 @@ def _run_extractor(self):
98132
stratigraphic_order = (
99133
self.data_manager._stratigraphic_column.get_unit_names() if self.data_manager else []
100134
)
101-
extract_basal_contacts(
135+
136+
# Check if user wants all contacts or just basal contacts
137+
all_contacts = self.allContactsCheckBox.isChecked()
138+
if all_contacts:
139+
stratigraphic_order = list(set([g[unit_name_field] for g in geology.getFeatures()]))
140+
result = extract_basal_contacts(
102141
geology=geology,
103142
stratigraphic_order=stratigraphic_order,
104143
faults=faults,
105144
ignore_units=ignore_units,
106145
unit_name_field=unit_name_field,
107-
all_contacts=False,
146+
all_contacts=all_contacts,
108147
updater=lambda message: QMessageBox.information(self, "Extraction Progress", message),
109148
)
110149

150+
# Show success message based on what was extracted
151+
if all_contacts and result:
152+
addGeoDataFrameToproject(result['all_contacts'], "All contacts")
153+
contact_type = "all contacts and basal contacts"
154+
else:
155+
addGeoDataFrameToproject(result['basal_contacts'], "Basal contacts")
156+
157+
contact_type = "basal contacts"
158+
159+
if result:
160+
QMessageBox.information(
161+
self,
162+
"Success",
163+
f"Successfully extracted {contact_type}!",
164+
)
165+
111166
def get_parameters(self):
112167
"""Get current widget parameters.
113168
@@ -127,6 +182,7 @@ def get_parameters(self):
127182
'unit_name_field': self.unitNameFieldComboBox.currentField(),
128183
'faults_layer': self.faultsLayerComboBox.currentLayer(),
129184
'ignore_units': ignore_units,
185+
'all_contacts': self.allContactsCheckBox.isChecked(),
130186
}
131187

132188
def set_parameters(self, params):
@@ -141,6 +197,7 @@ def set_parameters(self, params):
141197
self.geologyLayerComboBox.setLayer(params['geology_layer'])
142198
if 'faults_layer' in params and params['faults_layer']:
143199
self.faultsLayerComboBox.setLayer(params['faults_layer'])
144-
145200
if 'ignore_units' in params and params['ignore_units']:
146201
self.ignoreUnitsLineEdit.setText(', '.join(params['ignore_units']))
202+
if 'all_contacts' in params:
203+
self.allContactsCheckBox.setChecked(params['all_contacts'])

loopstructural/gui/map2loop_tools/basal_contacts_widget.ui

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,43 @@
5353
</property>
5454
</widget>
5555
</item>
56-
57-
58-
<item row="4" column="0">
56+
<item row="3" column="0">
5957
<widget class="QLabel" name="ignoreUnitsLabel">
6058
<property name="text">
6159
<string>Units to Ignore:</string>
6260
</property>
6361
</widget>
6462
</item>
65-
<item row="4" column="1">
63+
<item row="3" column="1">
6664
<widget class="QLineEdit" name="ignoreUnitsLineEdit">
6765
<property name="placeholderText">
6866
<string>Comma-separated list of units to ignore</string>
6967
</property>
7068
</widget>
7169
</item>
70+
<item row="4" column="0">
71+
<widget class="QLabel" name="contactTypeLabel">
72+
<property name="text">
73+
<string>Contact Type:</string>
74+
</property>
75+
</widget>
76+
</item>
77+
<item row="4" column="1">
78+
<widget class="QCheckBox" name="allContactsCheckBox">
79+
<property name="text">
80+
<string>Extract All Contacts (not just basal)</string>
81+
</property>
82+
<property name="checked">
83+
<bool>false</bool>
84+
</property>
85+
</widget>
86+
</item>
7287
</layout>
7388
</item>
7489
<item>
7590
<widget class="QPushButton" name="runButton">
7691
<property name="text">
77-
<string>Extract Basal Contacts</string>
92+
<string>Extract Contacts</string>
7893
</property>
7994
</widget>
8095
</item>

0 commit comments

Comments
 (0)