Skip to content

Commit 47be99a

Browse files
author
Lachlan Grose
committed
fix: add option to pass a dataframe directly to the create and add methods
1 parent 3be6cf1 commit 47be99a

1 file changed

Lines changed: 89 additions & 36 deletions

File tree

LoopStructural/modelling/core/geological_model.py

Lines changed: 89 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import numpy as np
88
import pandas as pd
9-
from typing import List
9+
from typing import List, Optional
1010
import pathlib
1111
from ...modelling.features.fault import FaultSegment
1212

@@ -654,8 +654,9 @@ def set_stratigraphic_column(self, stratigraphic_column, cmap="tab20"):
654654

655655
def create_and_add_foliation(
656656
self,
657-
series_surface_data: str,
657+
series_surface_name: str,
658658
*,
659+
series_surface_data: pd.DataFrame = None,
659660
interpolatortype: str = "FDI",
660661
nelements: int = 1000,
661662
tol=None,
@@ -665,8 +666,18 @@ def create_and_add_foliation(
665666
"""
666667
Parameters
667668
----------
668-
series_surface_data : string
669+
series_surface_name : string
669670
corresponding to the feature_name in the data
671+
series_surface_data : pd.DataFrame, optional
672+
data frame containing the surface data
673+
interpolatortype : str
674+
the type of interpolator to use, default is 'FDI'
675+
nelements : int
676+
the number of elements to use in the series surface
677+
tol : float, optional
678+
tolerance for the solver, if not specified uses the model default
679+
faults : list, optional
680+
list of faults to be used in the series surface, if not specified uses the model faults
670681
kwargs
671682
672683
Returns
@@ -697,16 +708,18 @@ def create_and_add_foliation(
697708
bounding_box=self.bounding_box,
698709
interpolatortype=interpolatortype,
699710
nelements=nelements,
700-
name=series_surface_data,
711+
name=series_surface_name,
701712
model=self,
702713
**kwargs,
703714
)
704715
# add data
705-
series_data = self.data[self.data["feature_name"] == series_surface_data]
706-
if series_data.shape[0] == 0:
716+
if series_surface_data is None:
717+
series_surface_data = self.data[self.data["feature_name"] == series_surface_name]
718+
719+
if series_surface_data.shape[0] == 0:
707720
logger.warning("No data for {series_surface_data}, skipping")
708721
return
709-
series_builder.add_data_from_data_frame(series_data)
722+
series_builder.add_data_from_data_frame(series_surface_data)
710723
self._add_faults(series_builder, features=faults)
711724

712725
# build feature
@@ -722,8 +735,9 @@ def create_and_add_foliation(
722735

723736
def create_and_add_fold_frame(
724737
self,
725-
foldframe_data,
738+
fold_frame_name:str,
726739
*,
740+
fold_frame_data=None,
727741
interpolatortype="FDI",
728742
nelements=1000,
729743
tol=None,
@@ -733,10 +747,24 @@ def create_and_add_fold_frame(
733747
"""
734748
Parameters
735749
----------
736-
foldframe_data : string
750+
fold_frame_name : string
737751
unique string in feature_name column
738-
739-
kwargs
752+
fold_frame_data : pandas data frame
753+
if not specified uses the model data
754+
interpolatortype : str
755+
the type of interpolator to use, default is 'FDI'
756+
nelements : int
757+
the number of elements to use in the fold frame
758+
tol : float, optional
759+
tolerance for the solver
760+
buffer : float
761+
buffer to add to the bounding box of the fold frame
762+
**kwargs : dict
763+
additional parameters to be passed to the
764+
:class:`LoopStructural.modelling.features.builders.StructuralFrameBuilder`
765+
and :meth:`LoopStructural.modelling.features.builders.StructuralFrameBuilder.setup`
766+
and the interpolator, such as `domain` or `tol`
767+
740768
741769
Returns
742770
-------
@@ -753,14 +781,18 @@ def create_and_add_fold_frame(
753781
fold_frame_builder = StructuralFrameBuilder(
754782
interpolatortype=interpolatortype,
755783
bounding_box=self.bounding_box.with_buffer(buffer),
756-
name=foldframe_data,
784+
name=fold_frame_name,
757785
frame=FoldFrame,
758786
nelements=nelements,
759787
model=self,
760788
**kwargs,
761789
)
762790
# add data
763-
fold_frame_data = self.data[self.data["feature_name"] == foldframe_data]
791+
if fold_frame_data is None:
792+
fold_frame_data = self.data[self.data["feature_name"] == fold_frame_name]
793+
if fold_frame_data.shape[0] == 0:
794+
logger.warning(f"No data for {fold_frame_name}, skipping")
795+
return
764796
fold_frame_builder.add_data_from_data_frame(fold_frame_data)
765797
self._add_faults(fold_frame_builder[0])
766798
self._add_faults(fold_frame_builder[1])
@@ -777,9 +809,9 @@ def create_and_add_fold_frame(
777809

778810
def create_and_add_folded_foliation(
779811
self,
780-
foliation_data,
812+
foliation_name,
781813
*,
782-
814+
foliation_data=None,
783815
interpolatortype="DFI",
784816
nelements=10000,
785817
buffer=0.1,
@@ -836,12 +868,16 @@ def create_and_add_folded_foliation(
836868
bounding_box=self.bounding_box.with_buffer(buffer),
837869
nelements=nelements,
838870
fold=fold,
839-
name=foliation_data,
871+
name=foliation_name,
840872
svario=svario,
841873
model=self,
842874
**kwargs,
843875
)
844-
876+
if foliation_data is None:
877+
foliation_data = self.data[self.data["feature_name"] == foliation_name]
878+
if foliation_data.shape[0] == 0:
879+
logger.warning(f"No data for {foliation_name}, skipping")
880+
return
845881
series_builder.add_data_from_data_frame(
846882
self.data[self.data["feature_name"] == foliation_data]
847883
)
@@ -862,8 +898,9 @@ def create_and_add_folded_foliation(
862898

863899
def create_and_add_folded_fold_frame(
864900
self,
865-
fold_frame_data,
901+
fold_frame_name: str,
866902
*,
903+
fold_frame_data: Optional[pd.DataFrame] = None,
867904
interpolatortype="FDI",
868905
nelements=10000,
869906
fold_frame=None,
@@ -874,14 +911,22 @@ def create_and_add_folded_fold_frame(
874911
875912
Parameters
876913
----------
877-
fold_frame_data : string
914+
fold_frame_name : string
878915
name of the feature to be added
879-
916+
fold_frame_data : pandas data frame, optional
917+
data frame containing the fold frame data, if not specified uses the model data
918+
interpolatortype : str
919+
the type of interpolator to use, default is 'FDI' (unused) 5/6/2025
880920
fold_frame : StructuralFrame, optional
881921
the fold frame for the fold if not specified uses last feature added
882-
883-
kwargs : dict
884-
parameters passed to child functions
922+
nelements : int
923+
the number of elements to use in the fold frame
924+
tol : float, optional
925+
tolerance for the solver, if not specified uses the model default
926+
**kwargs : dict
927+
additional parameters to be passed to the
928+
:class:`LoopStructural.modelling.features.builders.StructuralFrameBuilder`
929+
and :meth:`LoopStructural.modelling.features.builders.StructuralFrameBuilder.setup`
885930
886931
Returns
887932
-------
@@ -922,15 +967,15 @@ def create_and_add_folded_fold_frame(
922967
interpolatortype=interpolatortypes,
923968
bounding_box=self.bounding_box.with_buffer(kwargs.get("buffer", 0.1)),
924969
nelements=[nelements, nelements, nelements],
925-
name=fold_frame_data,
970+
name=fold_frame_name,
926971
fold=fold,
927972
frame=FoldFrame,
928973
model=self,
929974
**kwargs,
930975
)
931-
fold_frame_builder.add_data_from_data_frame(
932-
self.data[self.data["feature_name"] == fold_frame_data]
933-
)
976+
if fold_frame_data is None:
977+
fold_frame_data = self.data[self.data["feature_name"] == fold_frame_name]
978+
fold_frame_builder.add_data_from_data_frame(fold_frame_data)
934979

935980
for i in range(3):
936981
self._add_faults(fold_frame_builder[i])
@@ -1281,9 +1326,10 @@ def create_and_add_domain_fault(
12811326

12821327
def create_and_add_fault(
12831328
self,
1284-
fault_surface_data,
1285-
displacement,
1329+
fault_name: str,
1330+
displacement: float,
12861331
*,
1332+
fault_data:Optional[pd.DataFrame] = None,
12871333
interpolatortype="FDI",
12881334
tol=None,
12891335
fault_slip_vector=None,
@@ -1306,9 +1352,12 @@ def create_and_add_fault(
13061352
"""
13071353
Parameters
13081354
----------
1309-
fault_surface_data : string
1355+
fault_name : string
13101356
name of the fault surface data in the dataframe
13111357
displacement : displacement magnitude
1358+
displacement magnitude of the fault, in model units
1359+
fault_data : pd.DataFrame, optional
1360+
data frame containing the fault data, if not specified uses the model data
13121361
major_axis : [type], optional
13131362
[description], by default None
13141363
minor_axis : [type], optional
@@ -1335,7 +1384,7 @@ def create_and_add_fault(
13351384
if "fault_vectical_radius" in kwargs and intermediate_axis is None:
13361385
intermediate_axis = kwargs["fault_vectical_radius"]
13371386

1338-
logger.info(f'Creating fault "{fault_surface_data}"')
1387+
logger.info(f'Creating fault "{fault_name}"')
13391388
logger.info(f"Displacement: {displacement}")
13401389
logger.info(f"Tolerance: {tol}")
13411390
logger.info(f"Fault function: {faultfunction}")
@@ -1360,7 +1409,7 @@ def create_and_add_fault(
13601409
# tol *= 0.1*minor_axis
13611410

13621411
if displacement == 0:
1363-
logger.warning(f"{fault_surface_data} displacement is 0")
1412+
logger.warning(f"{fault_name} displacement is 0")
13641413

13651414
if "data_region" in kwargs:
13661415
kwargs.pop("data_region")
@@ -1370,14 +1419,18 @@ def create_and_add_fault(
13701419
interpolatortype,
13711420
bounding_box=self.bounding_box,
13721421
nelements=kwargs.pop("nelements", 1e4),
1373-
name=fault_surface_data,
1422+
name=fault_name,
13741423
model=self,
13751424
**kwargs,
13761425
)
1377-
fault_frame_data = self.data.loc[self.data["feature_name"] == fault_surface_data].copy()
1426+
if fault_data is None:
1427+
fault_data = self.data[self.data["feature_name"] == fault_name]
1428+
if fault_data.shape[0] == 0:
1429+
logger.warning(f"No data for {fault_name}, skipping")
1430+
return
1431+
13781432
self._add_faults(fault_frame_builder, features=faults)
13791433
# add data
1380-
fault_frame_data = self.data.loc[self.data["feature_name"] == fault_surface_data].copy()
13811434

13821435
if fault_center is not None and ~np.isnan(fault_center).any():
13831436
fault_center = self.scale(fault_center, inplace=False)
@@ -1388,7 +1441,7 @@ def create_and_add_fault(
13881441
if intermediate_axis:
13891442
intermediate_axis = intermediate_axis / self.scale_factor
13901443
fault_frame_builder.create_data_from_geometry(
1391-
fault_frame_data=fault_frame_data,
1444+
fault_frame_data=fault_data,
13921445
fault_center=fault_center,
13931446
fault_normal_vector=fault_normal_vector,
13941447
fault_slip_vector=fault_slip_vector,

0 commit comments

Comments
 (0)