From 92675b80ae48384bb5a5eb4b3ad9a333a4438963 Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Thu, 12 Dec 2024 13:40:11 -0600 Subject: [PATCH] added metadata to model, and included it in printout --- CHANGELOG-unreleased.md | 1 + src/pint/models/model_builder.py | 5 +++++ src/pint/models/timing_model.py | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG-unreleased.md b/CHANGELOG-unreleased.md index c9222a23d..d3f685ee6 100644 --- a/CHANGELOG-unreleased.md +++ b/CHANGELOG-unreleased.md @@ -22,6 +22,7 @@ the released changes. - `add_param` returns the name of the parameter (useful for numbered parameters) - Rerun intermittent failures in CI - micromamba CI environment for testing macOS-latest, without tox +- models now have metadata dictionary ### Fixed - Changed WAVE_OM units from 1/d to rad/d. - When EQUAD is created from TNEQ, has proper TCB->TDB conversion info diff --git a/src/pint/models/model_builder.py b/src/pint/models/model_builder.py index 560b0ab2c..36a7ac5dc 100644 --- a/src/pint/models/model_builder.py +++ b/src/pint/models/model_builder.py @@ -251,6 +251,10 @@ def __call__( if not hasattr(tm, "NoiseComponent_list"): setattr(tm, "NoiseComponent_list", []) + tm.meta["allow_tcb"] = allow_tcb_ + tm.meta["convert_tcb"] = convert_tcb + tm.meta["allow_T2"] = allow_T2 + return tm def _validate_components(self): @@ -851,6 +855,7 @@ def get_model( **kwargs, ) model.name = parfile + model.meta["original_name"] = parfile return model diff --git a/src/pint/models/timing_model.py b/src/pint/models/timing_model.py index 0d3d99431..d6aeb0525 100644 --- a/src/pint/models/timing_model.py +++ b/src/pint/models/timing_model.py @@ -29,6 +29,7 @@ import abc import copy +import datetime import inspect import contextlib from collections import OrderedDict, defaultdict @@ -228,6 +229,8 @@ class TimingModel: ---------- name : str The name of the timing model + meta : dict + A dictionary of metadata component_types : list A list of the distinct categories of component. For example, delay components will be register as 'DelayComponent'. @@ -242,6 +245,9 @@ def __init__(self, name="", components=[]): "First parameter should be the model name, was {!r}".format(name) ) self.name = name + self.meta = { + "read_time": f"{datetime.datetime.now().isoformat()}", + } self.component_types = [] self.top_level_params = [] self.add_param_from_top( @@ -2766,6 +2772,7 @@ def as_parfile( if include_info: info_string = pint.utils.info_string(prefix_string="# ", comment=comment) info_string += f"\n# Format: {format.lower()}" + info_string += "".join([f"\n# {x}: {self.meta[x]}" for x in self.meta]) result_begin = info_string + "\n" else: result_begin = ""