Skip to content

Commit 84da8c5

Browse files
authored
Geological feature fault bug (#177)
* fix: check fault trace length before fitting polyline * fix: set feature faults to builder faults before building
1 parent 27347ef commit 84da8c5

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

LoopStructural/modelling/features/builders/_base_builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def build_arguments(self, build_arguments):
4141
self._up_to_date = False
4242

4343
def update(self):
44+
self._feature.faults = self.faults
4445
self.build(**self.build_arguments)
4546

4647
def build(self, **kwargs):

LoopStructural/modelling/features/builders/_fault_builder.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,27 +139,29 @@ def create_data_from_geometry(
139139
"You cannot model a fault without defining the orientation of the fault\n\
140140
Defaulting to a vertical fault"
141141
)
142-
coefficients = np.polyfit(
143-
fault_frame_data.loc[trace_mask, "X"],
144-
fault_frame_data.loc[trace_mask, "Y"],
145-
1,
146-
)
147-
slope, intercept = coefficients
142+
if fault_frame_data.loc[trace_mask, :].shape[0] > 3:
148143

149-
# Create a direction vector using the slope
150-
direction_vector = np.array([1, slope])
151-
direction_vector /= np.linalg.norm(direction_vector)
152-
print(f"Fault dip: {fault_dip}")
153-
vector_data = np.array(
154-
[
144+
coefficients = np.polyfit(
145+
fault_frame_data.loc[trace_mask, "X"],
146+
fault_frame_data.loc[trace_mask, "Y"],
147+
1,
148+
)
149+
slope, intercept = coefficients
150+
151+
# Create a direction vector using the slope
152+
direction_vector = np.array([1, slope])
153+
direction_vector /= np.linalg.norm(direction_vector)
154+
print(f"Fault dip: {fault_dip}")
155+
vector_data = np.array(
155156
[
156-
direction_vector[1],
157-
-direction_vector[0],
158-
np.sin(np.deg2rad(fault_dip)),
157+
[
158+
direction_vector[1],
159+
-direction_vector[0],
160+
np.sin(np.deg2rad(fault_dip)),
161+
]
159162
]
160-
]
161-
)
162-
vector_data /= np.linalg.norm(vector_data, axis=1)[:, None]
163+
)
164+
vector_data /= np.linalg.norm(vector_data, axis=1)[:, None]
163165

164166
fault_normal_vector = np.mean(vector_data, axis=0)
165167

@@ -500,6 +502,11 @@ def add_fault_trace_anisotropy(self, w: float = 1.0):
500502
_description_, by default 1.0
501503
"""
502504
trace_data = self.builders[0].data.loc[self.builders[0].data["val"] == 0, :]
505+
if trace_data.shape[0] < 2:
506+
logger.warning(
507+
f"Only {trace_data.shape[0]} point on fault trace, cannot add fault trace anisotropy. Need at least 3 points"
508+
)
509+
return
503510
coefficients = np.polyfit(
504511
trace_data["X"],
505512
trace_data["Y"],
@@ -526,7 +533,13 @@ def add_fault_dip_anisotropy(self, dip: np.ndarray, w: float = 1.0):
526533
w : float, optional
527534
_description_, by default 1.0
528535
"""
536+
529537
trace_data = self.builders[0].data.loc[self.builders[0].data["val"] == 0, :]
538+
if trace_data.shape[0] < 2:
539+
logger.warning(
540+
f'Only {trace_data.shape[0]} point on fault trace, cannot add fault trace anisotropy. Need at least 3 points'
541+
)
542+
return
530543
coefficients = np.polyfit(
531544
trace_data["X"],
532545
trace_data["Y"],

0 commit comments

Comments
 (0)