Skip to content

Commit 8bbc429

Browse files
committed
load strat column from shapefile
1 parent 4db4a62 commit 8bbc429

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

loopstructural/gui/modelling/modelling_widget.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,37 @@ def onFaultTraceLayerChanged(self, layer):
228228

229229
def onUnitFieldChanged(self, field):
230230
unique_values = set()
231+
attributes = {}
231232
layer = self.unitNameField.layer()
232233
if layer:
234+
fields = {}
235+
fields['unitname'] = layer.fields().indexFromName(field)
236+
if 'LS_thickness' in [field.name() for field in layer.fields()]:
237+
fields['thickness'] = layer.fields().indexFromName('LS_thickness')
238+
if 'LS_order' in [field.name() for field in layer.fields()]:
239+
fields['order'] = layer.fields().indexFromName('LS_order')
240+
if 'LS_colour' in [field.name() for field in layer.fields()]:
241+
fields['colour'] = layer.fields().indexFromName('LS_colour')
233242
field_index = layer.fields().indexFromName(field)
243+
234244
for feature in layer.getFeatures():
235245
unique_values.add(str(feature[field_index]))
246+
attributes[str(feature[field_index])] = {}
247+
for k in fields:
248+
attributes[str(feature[field_index])][k] = feature[fields[k]]
236249
colours = random_hex_colour(n=len(unique_values))
237250
self._units = dict(
238251
zip(
239252
list(unique_values),
240253
[
241-
{'thickness': 10.0, 'order': i, 'name': u, 'color': colours[i]}
254+
{
255+
'thickness': attributes[u]['thickness']
256+
if 'thickness' in attributes[u]
257+
else 10.0,
258+
'order': attributes[u]['order'] if 'order' in attributes[u] else i,
259+
'name': u,
260+
'colour': attributes[u]['colour'] if 'colour' in attributes[u] else colours[i],
261+
}
242262
for i, u in enumerate(unique_values)
243263
],
244264
)
@@ -361,7 +381,7 @@ def create_color_picker(unit):
361381
def pick_color():
362382
color = QColorDialog.getColor()
363383
if color.isValid():
364-
self._units[unit]['color'] = color.name()
384+
self._units[unit]['colour'] = color.name()
365385
self._initialiseStratigraphicColumn()
366386

367387
return pick_color
@@ -376,7 +396,7 @@ def pick_color():
376396
down = QPushButton("↓")
377397
color_picker = QPushButton("Pick Colour")
378398
# Set background color for the row
379-
background_color = value.get('color', "#ffffff")
399+
background_color = value.get('colour', "#ffffff")
380400
label.setStyleSheet(f"background-color: {background_color};")
381401
spin_box.setStyleSheet(f"background-color: {background_color};")
382402
order.setStyleSheet(f"background-color: {background_color};")
@@ -438,7 +458,7 @@ def onSaveModel(self):
438458
def saveThicknessOrder(self):
439459
layer = self.basalContactsLayer.currentLayer()
440460
layer.startEditing()
441-
field_names = ["LS_thickness", "LS_order"]
461+
field_names = ["LS_thickness", "LS_order","LS_colour"]
442462
for field_name in field_names:
443463

444464
if field_name not in [field.name() for field in layer.fields()]:
@@ -450,11 +470,11 @@ def saveThicknessOrder(self):
450470
if feature.attributeMap().get(self.unitNameField.currentField()) == unit:
451471
feature[field_names[0]] = value['thickness']
452472
feature[field_names[1]] = value['order']
453-
473+
feature[field_names[2]] = value['colour']
454474
layer.updateFeature(feature)
455475
layer.commitChanges()
456476
layer.updateFields()
457-
self.logger(message=f"Thickness and order saved to {layer.name()}", log_level=1, push=True)
477+
self.logger(message=f"Thickness, colour and order saved to {layer.name()}", log_level=1, push=True)
458478

459479
def onPathTextChanged(self, text):
460480
self.outputPath = text

loopstructural/main/loopstructuralwrapper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,17 @@ def __init__(
4747
contact_locations = contact_locations.rename(columns={columnmap['unitname']: 'name'})[
4848
['X', 'Y', 'Z', 'name']
4949
]
50+
else:
51+
contact_locations = None
5052
if fault_data is not None and columnmap['faultname'] in fault_data:
5153
fault_data = fault_data.rename(columns={columnmap['faultname']: 'fault_name'})[
5254
['X', 'Y', 'Z', 'fault_name']
5355
]
5456
if np.all(fault_data['fault_name'].isna()):
5557
raise ValueError('Fault column name is all None. Check the column name')
58+
else:
59+
fault_data = None
60+
5661
if (
5762
contact_orientations is not None
5863
and columnmap['structure_unitname'] in contact_orientations
@@ -76,6 +81,8 @@ def __init__(
7681
raise ValueError('Strike column name is all None. Check the column name')
7782
if dip_direction:
7883
contact_orientations['strike'] = contact_orientations['strike'] + 90
84+
else:
85+
contact_orientations = None
7986
faults = []
8087
for fault_name in fault_properties.keys():
8188
fault = fault_properties[fault_name]

0 commit comments

Comments
 (0)