Skip to content

Commit

Permalink
Merge pull request #1874 from dlakaplan/modelmeta
Browse files Browse the repository at this point in the history
Added metadata to model, and included it in printout
  • Loading branch information
abhisrkckl authored Dec 18, 2024
2 parents a990a53 + 92675b8 commit aa2eda3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/pint/models/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -851,6 +855,7 @@ def get_model(
**kwargs,
)
model.name = parfile
model.meta["original_name"] = parfile

return model

Expand Down
7 changes: 7 additions & 0 deletions src/pint/models/timing_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import abc
import copy
import datetime
import inspect
import contextlib
from collections import OrderedDict, defaultdict
Expand Down Expand Up @@ -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'.
Expand All @@ -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(
Expand Down Expand Up @@ -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 = ""
Expand Down

0 comments on commit aa2eda3

Please sign in to comment.