Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions simpeg/directives/_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -2676,8 +2676,14 @@ class ScaleMisfitMultipliers(InversionDirective):
Parameters
----------

path : str
filepath : str
Path to save the chi-factors log file.
nesting : list of lists
Nested list structure that matches the structure of the misfit functions in the inverse problem.
target_chi : float
Target chi-factor for the misfit functions. Misfit functions with chi-factors below this value will be scaled more aggressively.
headers : list of str
List of headers for the chi-factors log file.
"""

def __init__(
Expand All @@ -2695,9 +2701,9 @@ def __init__(
self.headers = headers

if path is None:
path = pathlib.Path("./")
path = pathlib.Path("./ChiFactors.log")

self.filepath = path / "ChiFactors.log"
self.filepath = path

super().__init__(**kwargs)

Expand Down
21 changes: 18 additions & 3 deletions simpeg/directives/_save_geoh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,27 @@ def joint_index(self, value: list[int] | None):


class SaveLogFilesGeoH5(BaseSaveGeoH5):
def __init__(
self,
h5_object,
start_date_time: str,
**kwargs,
):

self.time_stamp = start_date_time
super().__init__(h5_object, **kwargs)

def write(self, iteration: int, **_):
dirpath = Path(self._workspace.h5file).parent
filepath = dirpath / "SimPEG.out"
filepath = dirpath / f"SimPEG_{self.time_stamp}.out"

if iteration == 0:
with open(filepath, "w", encoding="utf-8") as f:
f.write("iteration beta phi_d phi_m time\n")
log = []
with open(dirpath / "SimPEG.log", "r", encoding="utf-8") as file:
with open(
dirpath / f"SimPEG_{self.time_stamp}.log", "r", encoding="utf-8"
) as file:
iteration = 0
for line in file:
val = re.findall(r"[+-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+-]?\d+)", line)
Expand All @@ -420,7 +431,11 @@ def save_log(self):
with fetch_active_workspace(self._workspace, mode="r+") as w_s:
h5_object = w_s.get_entity(self.h5_object)[0]

for file in ["SimPEG.out", "SimPEG.log", "ChiFactors.log"]:
for file in [
f"SimPEG_{self.time_stamp}.out",
f"SimPEG_{self.time_stamp}.log",
f"ChiFactors_{self.time_stamp}.log",
]:
filepath = dirpath / file

if not filepath.is_file():
Expand Down
Loading