@@ -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