From da9525fedea764d7939475988632bd4ef74a3aca Mon Sep 17 00:00:00 2001 From: domfournier Date: Wed, 11 Mar 2026 09:07:19 -0700 Subject: [PATCH] Store and re-use datetime --- simpeg/directives/_directives.py | 12 +++++++++--- simpeg/directives/_save_geoh5.py | 21 ++++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/simpeg/directives/_directives.py b/simpeg/directives/_directives.py index 00340066e1..e70bb9a1a2 100644 --- a/simpeg/directives/_directives.py +++ b/simpeg/directives/_directives.py @@ -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__( @@ -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) diff --git a/simpeg/directives/_save_geoh5.py b/simpeg/directives/_save_geoh5.py index a06a48c77b..8647c96993 100644 --- a/simpeg/directives/_save_geoh5.py +++ b/simpeg/directives/_save_geoh5.py @@ -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) @@ -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():