From a7f064788be3aca17679cf74c1ada71f02889533 Mon Sep 17 00:00:00 2001 From: Spencer Griswold Date: Fri, 12 Jan 2024 14:53:47 -0500 Subject: [PATCH 1/2] Added metadata member for config exports --- python/asteria/simulation.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/asteria/simulation.py b/python/asteria/simulation.py index 470b8bc..0d91507 100644 --- a/python/asteria/simulation.py +++ b/python/asteria/simulation.py @@ -30,6 +30,11 @@ class Simulation: def __init__(self, config=None, *, model=None, distance=10 * u.kpc, res_dt=2 * u.ms, flavors=None, hierarchy=None, interactions=Interactions, mixing_scheme=None, mixing_angle=None, E=None, Emin=None, Emax=None, dE=None, t=None, tmin=None, tmax=None, dt=None, geomfile=None, effvolfile=None): + self.metadata = {key: str(val) for key, val in locals().items() if + val is not None and + key not in ['self', 'E', 't']} + self.metadata.update({'interactions': ', '.join([item.name for item in interactions])}) + self.param = {} if model and not config: @@ -43,6 +48,7 @@ def __init__(self, config=None, *, model=None, distance=10 * u.kpc, res_dt=2 * u E = np.arange(_Emin, _Emax + _dE, _dE) * u.MeV elif not E: E = np.arange(0, 100, 1) * u.MeV + self.metadata.update({'Emin': 0 * u.MeV, 'Emax': 100 * u.MeV, 'dE': 1 * u.ms}) if not t and None in (tmin, tmax, dt): raise ValueError("Missing or incomplete energy range definition. Use argument `t` or " @@ -58,6 +64,7 @@ def __init__(self, config=None, *, model=None, distance=10 * u.kpc, res_dt=2 * u else: t = np.arange(-1, 1, 0.001) * u.s _dt = 1 * u.ms + self.metadata.update({'tmin': -1 * u.s, 'tmax': 1 * u.s, 'dt': 1 * u.ms}) self.source = Source(model['name'], model['param']) self.distance = distance From a3056fa8f5df56ddee4e85b6af68526ea566f3e0 Mon Sep 17 00:00:00 2001 From: Spencer Griswold Date: Fri, 12 Jan 2024 15:02:07 -0500 Subject: [PATCH 2/2] Update model param formatting --- python/asteria/simulation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/asteria/simulation.py b/python/asteria/simulation.py index 0d91507..9084673 100644 --- a/python/asteria/simulation.py +++ b/python/asteria/simulation.py @@ -38,6 +38,9 @@ def __init__(self, config=None, *, model=None, distance=10 * u.kpc, res_dt=2 * u self.param = {} if model and not config: + self.metadata.update({'model': {'name': model['name'], + 'param': '; '.join([f"{key}, {val}" for key, val in model['param'].items()])} + }) if not E and None in (Emin, Emax, dE): raise ValueError("Missing or incomplete energy range definition. Use argument `E` or " "arguments `Emin`, `Emax`, `dE")