Skip to content

Commit

Permalink
Merge pull request #384 from sot/optional-aca-limits
Browse files Browse the repository at this point in the history
Make ACA penalty limit optional
  • Loading branch information
taldcroft authored Aug 14, 2023
2 parents d52f347 + 348320e commit bdad764
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion proseco/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 19 additions & 22 deletions proseco/characteristics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import json

import agasc
from ska_helpers import chandra_models
from ska_helpers.utils import LazyDict

CCD = {
Expand Down Expand Up @@ -74,13 +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.
chandra_models_version = None
# 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

# The next two characteristics are lazily defined to ensure import succeeds.

Expand All @@ -93,7 +95,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:
Expand All @@ -103,25 +109,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.
Expand Down

0 comments on commit bdad764

Please sign in to comment.