Skip to content

Commit

Permalink
fix: updating logging
Browse files Browse the repository at this point in the history
log_to_file should be used to create a log for loopstructural
the log has been improved
  • Loading branch information
Lachlan Grose committed Jan 19, 2022
1 parent e2a585d commit f77f915
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LoopStructural/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

ch = logging.StreamHandler()
formatter = logging.Formatter(
"%(asctime)s ~ %(name)-12s ~ %(levelname)-10s ~ %(message)s"
"%(levelname)s: %(asctime)s: %(filename)s:%(lineno)d -- %(message)s"
)
ch.setFormatter(formatter)
ch.setLevel(logging.WARNING)
Expand Down
28 changes: 24 additions & 4 deletions LoopStructural/modelling/core/geological_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ def from_map2loop_directory(
the created geological model and a dictionary of the map2loop data
"""
from LoopStructural.modelling.input.map2loop_processor import Map2LoopProcessor

log_to_file(f"{m2l_directory}/loopstructural_log.txt")
logger.info('Creating model from m2l directory')
processor = Map2LoopProcessor(m2l_directory, use_thickness)
processor._gradient = gradient
processor.vector_scale = vector_scale
Expand Down Expand Up @@ -255,9 +256,11 @@ def from_map2loop_directory(

@classmethod
def from_processor(cls, processor):
logger.info('Creating model from processor')
model = GeologicalModel(processor.origin, processor.maximum)
model.data = processor.data
for i in processor.fault_network.faults:
logger.info(f"Adding fault {i}")
model.create_and_add_fault(
i,
**processor.fault_properties.to_dict("index")[i],
Expand Down Expand Up @@ -303,6 +306,7 @@ def from_processor(cls, processor):
faults = None
if processor.fault_stratigraphy is not None:
faults = processor.fault_stratigraphy[s]
logger.info(f'Adding foliation {s}')
f = model.create_and_add_foliation(
s, **processor.foliation_properties[s], faults=faults
)
Expand Down Expand Up @@ -1335,6 +1339,18 @@ def create_and_add_fault(
fault : FaultSegment
created fault
"""
logger.info(f'Creating fault "{fault_surface_data}"')
logger.info(f'Displacement: {displacement}')
logger.info(f'Tolerance: {tol}')
logger.info(f'Fault function: {faultfunction}')
logger.info(f'Fault slip vector: {fault_slip_vector}')
logger.info(f'Fault center: {fault_center}')
logger.info(f'Major axis: {major_axis}')
logger.info(f'Minor axis: {minor_axis}')
logger.info(f'Intermediate axis: {intermediate_axis}')
for k, v in kwargs.items():
logger.info(f'{k}: {v}')

if tol is None:
tol = self.tol
self.parameters["features"].append(
Expand Down Expand Up @@ -1365,6 +1381,12 @@ def create_and_add_fault(
fault_frame_data = self.data[
self.data["feature_name"] == fault_surface_data
].copy()
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')
raise ValueError(f'There are no points on the fault trace')

mask = np.logical_and(
fault_frame_data["coord"] == 0, ~np.isnan(fault_frame_data["gz"])
)
Expand Down Expand Up @@ -1404,9 +1426,7 @@ def create_and_add_fault(
# if we haven't defined a fault centre take the center of mass for lines assocaited with
# the fault trace
if (
"centreEasting" in kwargs
and "centreNorthing" in kwargs
and "centreAltitude" in kwargs
~np.isnan(kwargs.get("centreEasting",np.nan)) and ~np.isnan(kwargs.get('centreNorthing',np.nan)) and ~np.isnan(kwargs.get('centreAltitude',np.nan))
):
fault_center = self.scale(
np.array(
Expand Down
1 change: 1 addition & 0 deletions LoopStructural/modelling/fault/fault_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ def set_mesh_geometry(self, buffer, rotation):
length = np.max(self.maximum - self.origin)
# for builder in self.builders:
# all three coordinates share the same support
print(self.maximum,self.origin)
self.builders[0].set_interpolation_geometry(
self.origin - length * buffer, self.maximum + length * buffer, rotation
)
Expand Down
2 changes: 1 addition & 1 deletion LoopStructural/modelling/input/map2loop_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def process_downthrow_direction(self, fault_properties, fault_orientations):
"""
for fname in fault_properties.index:
if fault_properties.loc[fname, "downthrow_dir"] == 1.0:
logger.info("Estimating downthrow direction using fault intersections")
logger.info(f"{fname}: Estimating downthrow direction using fault intersections")
# fault_intersection_angles[f]
if (
np.abs(
Expand Down
8 changes: 6 additions & 2 deletions LoopStructural/utils/logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import LoopStructural

import os

def get_levels():
"""dict for converting to logger levels from string
Expand Down Expand Up @@ -29,7 +29,7 @@ def getLogger(name):
return logger


def log_to_file(filename, level="info"):
def log_to_file(filename, overwrite=True, level="info"):
"""Set the logging parameters for log file
Expand All @@ -40,6 +40,10 @@ def log_to_file(filename, level="info"):
level : str, optional
'info', 'warning', 'error', 'debug' mapped to logging levels, by default 'info'
"""
logger = getLogger(__name__)
if os.path.isfile(filename):
logger.warning('Overwriting existing logfile. To avoid this, set overwrite=False')
os.remove(filename)
levels = get_levels()
level = levels.get(level, logging.WARNING)
fh = logging.FileHandler(filename)
Expand Down

0 comments on commit f77f915

Please sign in to comment.