From 9c10d900109ce4f5682a300d5d72d6d1780a7e30 Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Tue, 15 Aug 2023 09:51:57 -0400 Subject: [PATCH 1/2] Add test of optional ACA limits --- proseco/tests/test_catalog.py | 59 ++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/proseco/tests/test_catalog.py b/proseco/tests/test_catalog.py index 7fc4144d..34a8bd68 100644 --- a/proseco/tests/test_catalog.py +++ b/proseco/tests/test_catalog.py @@ -1,19 +1,15 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst import copy import os - -import matplotlib -from Quaternion import Quat - -matplotlib.use("agg") # noqa - -import pickle +import pickle # noqa from pathlib import Path import agasc +import matplotlib import mica.starcheck import numpy as np import pytest +from Quaternion import Quat from .. import characteristics as ACA from ..catalog import ACATable, get_aca_catalog @@ -21,6 +17,9 @@ from ..fid import FidTable, get_fid_catalog from .test_common import DARK40, OBS_INFO, STD_INFO, mod_std_info +# Switch the matplotlib backend to Agg +matplotlib.pyplot.switch_backend("agg") + HAS_SC_ARCHIVE = Path(mica.starcheck.starcheck.FILES["data_root"]).exists() TEST_COLS = "slot idx id type sz yang zang dim res halfw".split() @@ -398,6 +397,52 @@ def test_big_sim_offset(): assert aca.target_name == "Target Name" +def test_optional_penalty_limit(): + """Check that the optional penalty limit is supported correctly.""" + try: + _test_optional_penalty_limit() + finally: + # Reset ACA limits characteristics that get set above + ACA._set_aca_limits() + + # Back to values from conftest.py + assert ACA.chandra_models_version == "3.48" + assert ACA.aca_t_ccd_penalty_limit == -5.5 + + +def _test_optional_penalty_limit(): + import json + + from ska_helpers import chandra_models, paths + from ska_helpers.utils import temp_env_var + + version = "3.49" + repo_path = paths.chandra_models_repo_path() + + with chandra_models.get_local_repo(repo_path, version) as (repo, repo_path_local): + path_aca_spec = ( + Path(repo_path_local) / "chandra_models" / "xija" / "aca" / "aca_spec.json" + ) + text_aca_spec = path_aca_spec.read_text() + aca_spec = json.loads(text_aca_spec) + del aca_spec["limits"]["aacccdpt"]["planning.penalty.high"] + repo.git.checkout("HEAD", b="test_branch") + path_aca_spec.write_text(json.dumps(aca_spec, indent=4)) + repo.git.add(path_aca_spec) + repo.git.commit("-m", "test commit") + + with temp_env_var("CHANDRA_MODELS_REPO_DIR", repo_path_local): + with temp_env_var("CHANDRA_MODELS_DEFAULT_VERSION", "test_branch"): + ACA._set_aca_limits() + assert ACA.aca_t_ccd_penalty_limit is None + assert ACA.chandra_models_version == "test_branch" + + aca = get_aca_catalog(**STD_INFO, dark=DARK40) + assert aca.t_ccd_acq == aca.t_ccd_eff_acq + assert aca.t_ccd_guide == aca.t_ccd_eff_guide + assert aca.t_ccd_penalty_limit is None + + @pytest.mark.parametrize("call_t_ccd", [True, False]) def test_calling_with_t_ccd_acq_guide(call_t_ccd): """Test that calling get_aca_catalog with t_ccd or t_ccd_acq/guide args sets all From 7b8198ec1a4387332e0e5dbe1cb56baf97da2fc8 Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Tue, 15 Aug 2023 09:58:19 -0400 Subject: [PATCH 2/2] Comment tweaks --- proseco/tests/test_catalog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proseco/tests/test_catalog.py b/proseco/tests/test_catalog.py index 34a8bd68..ec23f24c 100644 --- a/proseco/tests/test_catalog.py +++ b/proseco/tests/test_catalog.py @@ -1,7 +1,7 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst import copy import os -import pickle # noqa +import pickle from pathlib import Path import agasc @@ -17,7 +17,7 @@ from ..fid import FidTable, get_fid_catalog from .test_common import DARK40, OBS_INFO, STD_INFO, mod_std_info -# Switch the matplotlib backend to Agg +# Ensure all plotting is to a non-interactive backend matplotlib.pyplot.switch_backend("agg") HAS_SC_ARCHIVE = Path(mica.starcheck.starcheck.FILES["data_root"]).exists()