From e76a96cf4e4116da8d007896ba585cc1001c8897 Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Fri, 11 Aug 2023 06:20:53 -0400 Subject: [PATCH 1/2] WIP: make ACA penalty limit optional --- proseco/catalog.py | 2 +- proseco/characteristics.py | 31 +++++++++++++++---------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/proseco/catalog.py b/proseco/catalog.py index 1030446f..9ca75b57 100644 --- a/proseco/catalog.py +++ b/proseco/catalog.py @@ -270,7 +270,7 @@ def get_effective_t_ccd(t_ccd, t_ccd_penalty_limit=None): if t_ccd_penalty_limit is None else t_ccd_penalty_limit ) - if t_ccd > t_limit: + if t_limit is not None and t_ccd > t_limit: return t_ccd + 1 + (t_ccd - t_limit) else: return t_ccd diff --git a/proseco/characteristics.py b/proseco/characteristics.py index 66017a18..ce707b43 100644 --- a/proseco/characteristics.py +++ b/proseco/characteristics.py @@ -1,4 +1,7 @@ +import json + import agasc +from ska_helpers import chandra_models from ska_helpers.utils import LazyDict CCD = { @@ -80,7 +83,8 @@ def _load_bad_star_set(): # can be overridden prior to calling get_aca_catalog(). This module variable # gets set to the actual chandra_models version when the ACA attributes are # first accessed. -chandra_models_version = None +# +# chandra_models_version = None # The next two characteristics are lazily defined to ensure import succeeds. @@ -93,7 +97,11 @@ def _load_bad_star_set(): def __getattr__(name): """Lazily define module attributes for the ACA planning and penalty limits""" - if name in ("aca_t_ccd_penalty_limit", "aca_t_ccd_planning_limit"): + if name in ( + "chandra_models_version", + "aca_t_ccd_penalty_limit", + "aca_t_ccd_planning_limit", + ): _set_aca_limits() return globals()[name] else: @@ -103,25 +111,16 @@ def __getattr__(name): def _set_aca_limits(): """Set global variables for ACA thermal planning and penalty limits""" global chandra_models_version - from xija.get_model_spec import get_xija_model_spec - spec, chandra_models_version = get_xija_model_spec( - "aca", version=chandra_models_version - ) + spec_txt, info = chandra_models.get_data("chandra_models/xija/aca/aca_spec.json") + spec = json.loads(spec_txt) + + chandra_models_version = info["version"] names = ("aca_t_ccd_penalty_limit", "aca_t_ccd_planning_limit") spec_names = ("planning.penalty.high", "planning.warning.high") for name, spec_name in zip(names, spec_names): - try: - limit = spec["limits"]["aacccdpt"][spec_name] - except KeyError: - raise KeyError( - f"unable to find ['limits']['aacccdpt']['{spec_name}'] " - "in the ACA xija model in " - f"chandra_models version {chandra_models_version}." - ) - else: - globals()[name] = limit + globals()[name] = spec["limits"]["aacccdpt"].get(spec_name) # Make sure module-level `dir()` includes the lazy attributes. From 348320e93af2d9e274bc13968c4478ccbd1e014b Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Fri, 11 Aug 2023 06:40:50 -0400 Subject: [PATCH 2/2] Improve description of chandra_models_version --- proseco/characteristics.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/proseco/characteristics.py b/proseco/characteristics.py index ce707b43..11321401 100644 --- a/proseco/characteristics.py +++ b/proseco/characteristics.py @@ -77,14 +77,12 @@ def _load_bad_star_set(): bad_star_set = LazyDict(_load_bad_star_set) -# Version of chandra_models to use for the ACA xija model from which the -# planning and penalty limits are extracted. Default of None means use the -# current flight-approved version. For testing or other rare circumstances this -# can be overridden prior to calling get_aca_catalog(). This module variable -# gets set to the actual chandra_models version when the ACA attributes are -# first accessed. +# READ-ONLY variable which gives the version of chandra_models being use for the ACA +# xija model from which the planning and penalty limits are extracted. This module +# variable is set on demand to the chandra_models repo version. To select a specific +# version set the CHANDRA_MODELS_DEFAULT_VERSION environment variable. # -# chandra_models_version = None +# chandra_models_version # The next two characteristics are lazily defined to ensure import succeeds.