Skip to content

Commit

Permalink
fix: making code compatible with linter
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlangrose committed Feb 9, 2024
1 parent ea6dffc commit 716038e
Show file tree
Hide file tree
Showing 23 changed files with 271 additions and 467 deletions.
6 changes: 3 additions & 3 deletions LoopStructural/interpolators/_interpolator_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def create_interpolator(
support=None,
buffer: float = 0.2,
):
if interpolatortype == None:
if interpolatortype is None:
raise ValueError("No interpolator type specified")
if boundingbox == None:
if boundingbox is None:
raise ValueError("No bounding box specified")
if nelements == None:
if nelements is None:
raise ValueError("No number of elements specified")
if isinstance(interpolatortype, str):
interpolatortype = interpolator_string_map[interpolatortype]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def evaluate_shape_derivatives(self, locations, elements=None):
M[:, :, 1:] = self.vertices[self.elements[elements], :][:, :3, :]
points_ = np.ones((locations.shape[0], 3))
points_[:, 1:] = locations
minv = np.linalg.inv(M)
# minv = np.linalg.inv(M)
# c = np.einsum("lij,li->lj", minv, points_)

vertices = self.nodes[self.elements[tri][:, :3]]
Expand Down
1 change: 0 additions & 1 deletion LoopStructural/modelling/features/_geological_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def evaluate_gradient(self, pos: np.ndarray) -> np.ndarray:
v = np.zeros(pos.shape)
v[:] = np.nan
mask = self._calculate_mask(pos)
original_pos = pos.copy()
pos, axis, angle = self._apply_faults(pos)
if mask.dtype not in [int, bool]:
logger.error(f"Unable to evaluate gradient for {self.name}")
Expand Down
8 changes: 3 additions & 5 deletions LoopStructural/modelling/features/builders/_base_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def update(self):
self.build(**self.build_arguments)

def build(self, **kwargs):
raise NotImplementedError(
"BaseBuilder should be inherited and build method overwritten"
)
raise NotImplementedError("BaseBuilder should be inherited and build method overwritten")

@property
def name(self):
Expand All @@ -66,13 +64,13 @@ def up_to_date(self, callback=None):
for f in self.faults:
f.builder.up_to_date(callback=callback)
# has anything changed in the builder since we built the feature? if so update
if self._up_to_date == False:
if not self._up_to_date:
self.update()
if callable(callback):
callback(1)
return
# check if the interpolator is up to date, if not solve
if self._interpolator.up_to_date == False:
if not self._interpolator.up_to_date:
self.update()
if callable(callback):
callback(1)
Expand Down
74 changes: 20 additions & 54 deletions LoopStructural/modelling/features/builders/_fault_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,11 @@ def __init__(
self.frame.model = model
self.model = model
self.origin = np.array([np.nan, np.nan, np.nan])
self.maximum = np.array(
[np.nan, np.nan, np.nan]
) # self.model.bounding_box[1, :]
self.maximum = np.array([np.nan, np.nan, np.nan]) # self.model.bounding_box[1, :]
# define a maximum area to mesh adding buffer to model
# buffer = .2
self.minimum_origin = bounding_box.with_buffer(fault_bounding_box_buffer).origin
self.maximum_maximum = bounding_box.with_buffer(
fault_bounding_box_buffer
).maximum
self.maximum_maximum = bounding_box.with_buffer(fault_bounding_box_buffer).maximum

self.fault_normal_vector = None
self.fault_slip_vector = None
Expand All @@ -68,9 +64,7 @@ def __init__(

def update_geometry(self, points):
self.origin = np.nanmin(np.array([np.min(points, axis=0), self.origin]), axis=0)
self.maximum = np.nanmax(
np.array([np.max(points, axis=0), self.maximum]), axis=0
)
self.maximum = np.nanmax(np.array([np.max(points, axis=0), self.maximum]), axis=0)
self.origin[self.origin < self.minimum_origin] = self.minimum_origin[
self.origin < self.minimum_origin
]
Expand Down Expand Up @@ -117,24 +111,18 @@ def create_data_from_geometry(
intermediate_axis : double
fault volume radius in the slip direction
"""
trace_mask = np.logical_and(
fault_frame_data["coord"] == 0, fault_frame_data["val"] == 0
)
trace_mask = np.logical_and(fault_frame_data["coord"] == 0, fault_frame_data["val"] == 0)
logger.info(f"There are {np.sum(trace_mask)} points on the fault trace")
if np.sum(trace_mask) == 0:
logger.error(
"You cannot model a fault without defining the location of the fault"
)
logger.error("You cannot model a fault without defining the location of the fault")
raise ValueError("There are no points on the fault trace")

# get all of the gradient data associated with the fault trace
if fault_normal_vector is None:
gradient_mask = np.logical_and(
fault_frame_data["coord"] == 0, ~np.isnan(fault_frame_data["gz"])
)
vector_data = fault_frame_data.loc[
gradient_mask, ["gx", "gy", "gz"]
].to_numpy()
vector_data = fault_frame_data.loc[gradient_mask, ["gx", "gy", "gz"]].to_numpy()
normal_mask = np.logical_and(
fault_frame_data["coord"] == 0, ~np.isnan(fault_frame_data["nz"])
)
Expand Down Expand Up @@ -196,26 +184,18 @@ def create_data_from_geometry(
trace_mask = np.logical_and(
fault_frame_data["coord"] == 0, fault_frame_data["val"] == 0
)
fault_center = (
fault_frame_data.loc[trace_mask, ["X", "Y", "Z"]]
.mean(axis=0)
.to_numpy()
)
fault_center = fault_frame_data.loc[trace_mask, ["X", "Y", "Z"]].mean(axis=0).to_numpy()

self.fault_normal_vector = fault_normal_vector
self.fault_slip_vector = fault_slip_vector

self.fault_centre = fault_center
if major_axis is None:
fault_trace = fault_frame_data.loc[
np.logical_and(
fault_frame_data["coord"] == 0, fault_frame_data["val"] == 0
),
np.logical_and(fault_frame_data["coord"] == 0, fault_frame_data["val"] == 0),
["X", "Y"],
].to_numpy()
distance = np.linalg.norm(
fault_trace[:, None, :] - fault_trace[None, :, :], axis=2
)
distance = np.linalg.norm(fault_trace[:, None, :] - fault_trace[None, :, :], axis=2)
if len(distance) == 0 or np.sum(distance) == 0:
logger.warning("There is no fault trace for {}".format(self.name))
# this can mean there is only a single data point for
Expand All @@ -230,15 +210,11 @@ def create_data_from_geometry(
logger.warning(f"Fault major axis using map length: {major_axis}")

if minor_axis is None:
logger.info(
f"Fault minor axis not set, using half major axis: {major_axis/2}"
)
logger.info(f"Fault minor axis not set, using half major axis: {major_axis/2}")
minor_axis = major_axis / 2.0
if intermediate_axis is None:
intermediate_axis = major_axis
logger.info(
f"Fault intermediate axis not set, using major axis: {intermediate_axis}"
)
logger.info(f"Fault intermediate axis not set, using major axis: {intermediate_axis}")
self.fault_minor_axis = minor_axis
self.fault_major_axis = major_axis
self.fault_intermediate_axis = intermediate_axis
Expand Down Expand Up @@ -309,20 +285,18 @@ def create_data_from_geometry(
fault_frame_data["coord"] == 0,
~np.isnan(fault_frame_data["nx"]),
)
fault_frame_data.loc[mask, ["gx", "gy", "gz"]] = (
fault_frame_data.loc[mask, ["nx", "ny", "nz"]]
)
fault_frame_data.loc[mask, ["gx", "gy", "gz"]] = fault_frame_data.loc[
mask, ["nx", "ny", "nz"]
]

fault_frame_data.loc[mask, ["nx", "ny", "nz"]] = np.nan
mask = np.logical_and(
fault_frame_data["coord"] == 0,
~np.isnan(fault_frame_data["gx"]),
)
fault_frame_data.loc[mask, ["gx", "gy", "gz"]] /= minor_axis * 0.5
if points == False:
logger.info(
"Rescaling fault norm constraint length for fault frame"
)
if not points:
logger.info("Rescaling fault norm constraint length for fault frame")
mask = np.logical_and(
fault_frame_data["coord"] == 0,
~np.isnan(fault_frame_data["gx"]),
Expand Down Expand Up @@ -415,12 +389,8 @@ def create_data_from_geometry(
]
strike_vector /= major_axis
if intermediate_axis is not None:
fault_depth[0, :] = (
fault_center[:3] + fault_slip_vector * intermediate_axis
)
fault_depth[1, :] = (
fault_center[:3] - fault_slip_vector * intermediate_axis
)
fault_depth[0, :] = fault_center[:3] + fault_slip_vector * intermediate_axis
fault_depth[1, :] = fault_center[:3] - fault_slip_vector * intermediate_axis
fault_frame_data.loc[
len(fault_frame_data),
["X", "Y", "Z", "feature_name", "val", "coord", "w"],
Expand Down Expand Up @@ -543,9 +513,7 @@ def add_fault_trace_anisotropy(self, w: float = 1.0):
anisotropy_feature = AnalyticalGeologicalFeature(
vector=vector_data, origin=[0, 0, 0], name="fault_trace_anisotropy"
)
self.builders[0].add_orthogonal_feature(
anisotropy_feature, w=w, region=None, step=1, B=0
)
self.builders[0].add_orthogonal_feature(anisotropy_feature, w=w, region=None, step=1, B=0)

def add_fault_dip_anisotropy(self, dip: np.ndarray, w: float = 1.0):
"""_summary_
Expand Down Expand Up @@ -576,9 +544,7 @@ def add_fault_dip_anisotropy(self, dip: np.ndarray, w: float = 1.0):
anisotropy_feature = AnalyticalGeologicalFeature(
vector=vector_data, origin=[0, 0, 0], name="fault_dip_anisotropy"
)
self.builders[0].add_orthogonal_feature(
anisotropy_feature, w=w, region=None, step=1, B=0
)
self.builders[0].add_orthogonal_feature(anisotropy_feature, w=w, region=None, step=1, B=0)

def update(self):
for i in range(3):
Expand Down
Loading

0 comments on commit 716038e

Please sign in to comment.