From 09b843580d6067f66df851a92e0a66b6cedf0832 Mon Sep 17 00:00:00 2001 From: Paul Huwe <42071634+PaulHuwe@users.noreply.github.com> Date: Tue, 14 May 2024 16:38:07 -0400 Subject: [PATCH] RCAL-831: Add statistics field to TVAC and FPS Models (#351) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CHANGES.rst | 2 ++ src/roman_datamodels/maker_utils/_fps.py | 10 ++++++++- .../maker_utils/_fps_common_meta.py | 19 +++++++++++++++++ src/roman_datamodels/maker_utils/_tvac.py | 10 ++++++++- .../maker_utils/_tvac_common_meta.py | 21 ++++++++++++++++++- 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 2731ee6e..338eaa0d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,8 @@ - Separated TVAC and FPS into their own makers to freeze from from main development. [#347] +- Added statistics blocks to the TVAC and FS models. [#351] + - Fix bug that prevented proper handling of ``np.NDArray``\s. [#350] diff --git a/src/roman_datamodels/maker_utils/_fps.py b/src/roman_datamodels/maker_utils/_fps.py index 26f1e76f..7aaecbe4 100644 --- a/src/roman_datamodels/maker_utils/_fps.py +++ b/src/roman_datamodels/maker_utils/_fps.py @@ -58,7 +58,14 @@ def mk_fps_common_meta(**kwargs): dict (defined by the ground_common-1.0.0 schema) """ # prevent circular import - from ._fps_common_meta import mk_fps_cal_step, mk_fps_exposure, mk_fps_guidestar, mk_fps_ref_file, mk_fps_wfi_mode + from ._fps_common_meta import ( + mk_fps_cal_step, + mk_fps_exposure, + mk_fps_guidestar, + mk_fps_ref_file, + mk_fps_statistics, + mk_fps_wfi_mode, + ) meta = mk_fps_basic_meta(**kwargs) meta["cal_step"] = mk_fps_cal_step(**kwargs.get("cal_step", {})) @@ -66,6 +73,7 @@ def mk_fps_common_meta(**kwargs): meta["guidestar"] = mk_fps_guidestar(**kwargs.get("guidestar", {})) meta["instrument"] = mk_fps_wfi_mode(**kwargs.get("instrument", {})) meta["ref_file"] = mk_fps_ref_file(**kwargs.get("ref_file", {})) + meta["statistics"] = mk_fps_statistics(**kwargs.get("statistics", {})) meta["hdf5_meta"] = kwargs.get("hdf5_meta", {"test": NOSTR}) meta["hdf5_telemetry"] = kwargs.get("hdf5_telemetry", NOSTR) meta["gw_meta"] = kwargs.get("gw_meta", {"test": NOSTR}) diff --git a/src/roman_datamodels/maker_utils/_fps_common_meta.py b/src/roman_datamodels/maker_utils/_fps_common_meta.py index f47f4ec2..135c26d6 100644 --- a/src/roman_datamodels/maker_utils/_fps_common_meta.py +++ b/src/roman_datamodels/maker_utils/_fps_common_meta.py @@ -1,5 +1,6 @@ import numpy as np from astropy import time +from astropy import units as u from roman_datamodels import stnode @@ -57,6 +58,24 @@ def mk_fps_guidestar(**kwargs): return guide +def mk_fps_statistics(**kwargs): + """ + Create a dummy Statistics instance with valid values for attributes + required by the schema. Utilized by the model maker utilities below. + + Returns + ------- + roman_datamodels.stnode.FpsStatistics + """ + stats = stnode.FpsStatistics() + stats["mean_counts_per_sec"] = kwargs.get("mean_counts_per_sec", NONUM * (u.DN / u.s)) + stats["median_counts_per_sec"] = kwargs.get("median_counts_per_sec", NONUM * (u.DN / u.s)) + stats["min_counts"] = kwargs.get("min_counts", u.Quantity(NONUM, u.DN, dtype=np.int32)) + stats["max_counts"] = kwargs.get("max_counts", u.Quantity(NONUM, u.DN, dtype=np.int32)) + + return stats + + def mk_fps_wfi_mode(**kwargs): """ Create a dummy WFI mode instance with valid values for attributes diff --git a/src/roman_datamodels/maker_utils/_tvac.py b/src/roman_datamodels/maker_utils/_tvac.py index 3426cd40..0bcf654f 100644 --- a/src/roman_datamodels/maker_utils/_tvac.py +++ b/src/roman_datamodels/maker_utils/_tvac.py @@ -104,7 +104,14 @@ def mk_tvac_common_meta(**kwargs): dict (defined by the ground_common-1.0.0 schema) """ # prevent circular import - from ._tvac_common_meta import mk_tvac_cal_step, mk_tvac_exposure, mk_tvac_guidestar, mk_tvac_ref_file, mk_tvac_wfi_mode + from ._tvac_common_meta import ( + mk_tvac_cal_step, + mk_tvac_exposure, + mk_tvac_guidestar, + mk_tvac_ref_file, + mk_tvac_statistics, + mk_tvac_wfi_mode, + ) meta = mk_tvac_basic_meta(**kwargs) meta["cal_step"] = mk_tvac_cal_step(**kwargs.get("cal_step", {})) @@ -112,6 +119,7 @@ def mk_tvac_common_meta(**kwargs): meta["guidestar"] = mk_tvac_guidestar(**kwargs.get("guidestar", {})) meta["instrument"] = mk_tvac_wfi_mode(**kwargs.get("instrument", {})) meta["ref_file"] = mk_tvac_ref_file(**kwargs.get("ref_file", {})) + meta["statistics"] = mk_tvac_statistics(**kwargs.get("statistics", {})) meta["hdf5_meta"] = kwargs.get("hdf5_meta", {"test": NOSTR}) meta["hdf5_telemetry"] = kwargs.get("hdf5_telemetry", NOSTR) meta["gw_meta"] = kwargs.get("gw_meta", {"test": NOSTR}) diff --git a/src/roman_datamodels/maker_utils/_tvac_common_meta.py b/src/roman_datamodels/maker_utils/_tvac_common_meta.py index 437dc8cb..9febba78 100644 --- a/src/roman_datamodels/maker_utils/_tvac_common_meta.py +++ b/src/roman_datamodels/maker_utils/_tvac_common_meta.py @@ -1,5 +1,6 @@ import numpy as np from astropy import time +from astropy import units as u from roman_datamodels import stnode @@ -35,7 +36,7 @@ def mk_tvac_exposure(**kwargs): def mk_tvac_guidestar(**kwargs): """ - Create a dummy BaseGuidestar instance with valid values for attributes + Create a dummy Guidestar instance with valid values for attributes required by the schema. Utilized by the model maker utilities below. Returns @@ -57,6 +58,24 @@ def mk_tvac_guidestar(**kwargs): return guide +def mk_tvac_statistics(**kwargs): + """ + Create a dummy Statistics instance with valid values for attributes + required by the schema. Utilized by the model maker utilities below. + + Returns + ------- + roman_datamodels.stnode.TvacStatistics + """ + stats = stnode.TvacStatistics() + stats["mean_counts_per_sec"] = kwargs.get("mean_counts_per_sec", NONUM * (u.DN / u.s)) + stats["median_counts_per_sec"] = kwargs.get("median_counts_per_sec", NONUM * (u.DN / u.s)) + stats["min_counts"] = kwargs.get("min_counts", u.Quantity(NONUM, u.DN, dtype=np.int32)) + stats["max_counts"] = kwargs.get("max_counts", u.Quantity(NONUM, u.DN, dtype=np.int32)) + + return stats + + def mk_tvac_wfi_mode(**kwargs): """ Create a dummy WFI mode instance with valid values for attributes