@@ -246,6 +246,7 @@ def create_data_from_geometry(
246246 fault_dip = 90 ,
247247 fault_dip_anisotropy = 1.0 ,
248248 fault_pitch = None ,
249+ plane_line_threshold = 0.05 ,
249250 ):
250251 """
251252 Generate the required data for building a fault frame with the specified parameters.
@@ -294,25 +295,23 @@ def create_data_from_geometry(
294295 ].to_numpy ()
295296 self .fault_dip = fault_dip
296297 if fault_normal_vector is None :
297- if fault_frame_data .loc [
298- np .logical_and (fault_frame_data ["coord" ] == 0 , fault_frame_data ["gx" ].notna ())].shape [0 ]> 0 :
298+ gx_mask = np .logical_and (fault_frame_data ["coord" ] == 0 , fault_frame_data ["gx" ].notna ())
299+ nx_mask = np .logical_and (fault_frame_data ["coord" ] == 0 , fault_frame_data ["nx" ].notna ())
300+ value_mask = np .logical_and (fault_frame_data ["coord" ] == 0 , fault_frame_data ["val" ] == 0 )
301+ if fault_frame_data .loc [gx_mask ].empty :
299302 fault_normal_vector = fault_frame_data .loc [
300- np . logical_and ( fault_frame_data [ "coord" ] == 0 , fault_frame_data [ "gx" ]. notna ()) ,
303+ gx_mask ,
301304 ["gx" , "gy" , "gz" ],
302305 ].to_numpy ().mean (axis = 0 )
303- elif fault_frame_data .loc [
304- np .logical_and (fault_frame_data ["coord" ] == 0 , fault_frame_data ["nx" ].notna ())].shape [0 ]> 0 :
306+ elif fault_frame_data .loc [nx_mask ].empty :
305307 fault_normal_vector = fault_frame_data .loc [
306- np . logical_and ( fault_frame_data [ "coord" ] == 0 , fault_frame_data [ "nx" ]. notna ()) ,
308+ nx_mask ,
307309 ["nx" , "ny" , "nz" ],
308310 ].to_numpy ().mean (axis = 0 )
309311
310312 else :
311313 fault_surface_pts = fault_frame_data .loc [
312- np .logical_and (
313- fault_frame_data ["coord" ] == 0 ,
314- fault_frame_data ["val" ] == 0 ,
315- ),
314+ value_mask ,
316315 ["X" , "Y" , "Z" ],
317316 ].to_numpy ()
318317 fault_surface_pts = fault_surface_pts [
@@ -324,40 +323,25 @@ def create_data_from_geometry(
324323 cov_matrix = pts_3d .T @ pts_3d
325324 eigenvalues , eigenvectors = np .linalg .eigh (cov_matrix )
326325 # If points span a surface, use the smallest eigenvector as plane normal
327- if eigenvalues [- 1 ] > 0 and (eigenvalues [1 ] / eigenvalues [- 1 ]) > 0.05 :
326+ if eigenvalues [- 1 ] > 0 and (eigenvalues [1 ] / eigenvalues [- 1 ]) > plane_line_threshold :
328327 fault_normal_vector = eigenvectors [:, 0 ]
329- else :
330- # Fall back to line-on-map strike logic
331- pts = fault_trace - fault_trace .mean (axis = 0 )
332- cov_matrix = pts .T @ pts
333- eigenvalues , eigenvectors = np .linalg .eigh (cov_matrix )
334- strike_vector = eigenvectors [:, np .argmax (eigenvalues )]
335- strike_vector = np .append (strike_vector , 0 ) # Add z component
336- strike_vector /= np .linalg .norm (strike_vector )
337-
338- fault_normal_vector = np .cross (strike_vector , [0 , 0 , 1 ])
339- rotation_matrix = rotation (
340- strike_vector [None , :], np .array ([90 - fault_dip ])
341- )
342- fault_normal_vector = np .einsum (
343- "ijk,ik->ij" , rotation_matrix , fault_normal_vector [None , :]
344- )[0 ]
345- else :
346- # Fall back to line-on-map strike logic
347- pts = fault_trace - fault_trace .mean (axis = 0 )
348- cov_matrix = pts .T @ pts
349- eigenvalues , eigenvectors = np .linalg .eigh (cov_matrix )
350- strike_vector = eigenvectors [:, np .argmax (eigenvalues )]
351- strike_vector = np .append (strike_vector , 0 ) # Add z component
352- strike_vector /= np .linalg .norm (strike_vector )
353-
354- fault_normal_vector = np .cross (strike_vector , [0 , 0 , 1 ])
355- rotation_matrix = rotation (
356- strike_vector [None , :], np .array ([90 - fault_dip ])
357- )
358- fault_normal_vector = np .einsum (
359- "ijk,ik->ij" , rotation_matrix , fault_normal_vector [None , :]
360- )[0 ]
328+
329+ if fault_normal_vector is None :
330+ # Fall back to line-on-map strike logic
331+ pts = fault_trace - fault_trace .mean (axis = 0 )
332+ cov_matrix = pts .T @ pts
333+ eigenvalues , eigenvectors = np .linalg .eigh (cov_matrix )
334+ strike_vector = eigenvectors [:, np .argmax (eigenvalues )]
335+ strike_vector = np .append (strike_vector , 0 ) # Add z component
336+ strike_vector /= np .linalg .norm (strike_vector )
337+
338+ fault_normal_vector = np .cross (strike_vector , [0 , 0 , 1 ])
339+ rotation_matrix = rotation (
340+ strike_vector [None , :], np .array ([90 - fault_dip ])
341+ )
342+ fault_normal_vector = np .einsum (
343+ "ijk,ik->ij" , rotation_matrix , fault_normal_vector [None , :]
344+ )[0 ]
361345
362346 if not isinstance (fault_normal_vector , np .ndarray ):
363347 fault_normal_vector = np .array (fault_normal_vector )
0 commit comments