From a2099cd0477a18a6448d5e556795b0e40a1f05a6 Mon Sep 17 00:00:00 2001 From: Lachlan Grose Date: Mon, 7 Feb 2022 14:43:53 +1100 Subject: [PATCH] fix: bug with calculating average fault ori --- LoopStructural/modelling/core/geological_model.py | 6 +++--- LoopStructural/modelling/fault/fault_builder.py | 4 +++- tests/unit_tests/modelling/test_faults_segment.py | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/LoopStructural/modelling/core/geological_model.py b/LoopStructural/modelling/core/geological_model.py index d5a26fd1d..4dfff29b4 100644 --- a/LoopStructural/modelling/core/geological_model.py +++ b/LoopStructural/modelling/core/geological_model.py @@ -1401,7 +1401,7 @@ def create_and_add_fault( fault_frame_data["coord"] == 0, ~np.isnan(fault_frame_data["nz"]) ) vector_data = np.vstack([vector_data,fault_frame_data.loc[mask2, ["nx", "ny", "nz"]].to_numpy()]) - fault_normal_vector = np.mean(vector_data,axis=1) + fault_normal_vector = np.mean(vector_data,axis=0) logger.info(f'Fault normal vector: {fault_normal_vector}') mask = np.logical_and( @@ -1433,9 +1433,9 @@ def create_and_add_fault( fault_slip_vector = dip_vector[:, 0] logger.info(f'Estimated fault slip vector: {fault_slip_vector}') - if fault_center is not None: + if fault_center is not None and ~np.isnan(fault_center).any(): fault_center = self.scale(fault_center, inplace=False) - if fault_center is None: + else: # if we haven't defined a fault centre take the center of mass for lines assocaited with # the fault trace if ( diff --git a/LoopStructural/modelling/fault/fault_builder.py b/LoopStructural/modelling/fault/fault_builder.py index 5aecb3fdc..3fb2f5d1e 100644 --- a/LoopStructural/modelling/fault/fault_builder.py +++ b/LoopStructural/modelling/fault/fault_builder.py @@ -103,7 +103,9 @@ def create_data_from_geometry( fault_trace[:, None, :] - fault_trace[None, :, :], axis=2 ) if len(distance) == 0 or np.sum(distance) == 0: - logger.error("There is no fault trace for {}".format(self.name)) + logger.warning("There is no fault trace for {}".format(self.name)) + # this can mean there is only a single data point for the fault, its not critical + # but probably means the fault isn't well defined. # add any data anyway - usually just orientation data self.add_data_from_data_frame(data) self.origin = self.model.bounding_box[0, :] diff --git a/tests/unit_tests/modelling/test_faults_segment.py b/tests/unit_tests/modelling/test_faults_segment.py index a60e3e39e..f9387e9f1 100644 --- a/tests/unit_tests/modelling/test_faults_segment.py +++ b/tests/unit_tests/modelling/test_faults_segment.py @@ -8,6 +8,8 @@ def test_create_and_add_fault(): data = pd.DataFrame( [ [0.5, 0.5, 0.5, 0, 1, 0, 0, "fault", 0], + # [0.5, 0.5, 0.5, 0, 1, 0, 0, "fault", 0], + [0.5, 0.5, 0.5, 1, 0, 0, 1, "fault", 0], [0.5, 0.5, 0.5, 0, 0, 1, 2, "fault", 0], ], @@ -21,3 +23,6 @@ def test_create_and_add_fault(): # force_mesh_geometry=True ) assert isinstance(model["fault"], FaultSegment) + +if __name__ == "__main__": + test_create_and_add_fault() \ No newline at end of file