Skip to content

Commit

Permalink
Update to use new get_fid_offset function in chandra_aca
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanconn committed Oct 17, 2023
1 parent 0c86b27 commit f39da1e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
18 changes: 9 additions & 9 deletions proseco/fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import weakref

import numpy as np
from chandra_aca.fid_drift import get_drift
from chandra_aca.drift import get_fid_offset
from chandra_aca.transform import yagzag_to_pixels
from cxotime import CxoTime

Expand Down Expand Up @@ -521,21 +521,21 @@ def get_fid_positions(detector, focus_offset, sim_offset, t_ccd_acq=None, date=N

yang, zang = np.degrees(yfid) * 3600, np.degrees(zfid) * 3600

# Apply fid drift
enable_fid_drift_env = os.environ.get("PROSECO_ENABLE_FID_DRIFT", "True")
if enable_fid_drift_env not in ("True", "False"):
# Apply fid offset
enable_fid_offset_env = os.environ.get("PROSECO_ENABLE_FID_OFFSET", "True")
if enable_fid_offset_env not in ("True", "False"):
raise ValueError(
f'PROSECO_ENABLE_FID_DRIFT env var must be either "True" or "False" '
f"got {enable_fid_drift}"
f'PROSECO_ENABLE_FID_OFFSET env var must be either "True" or "False" '
f"got {enable_fid_offset_env}"
)

# The env var is still just a string so do a string equals on it
if enable_fid_drift_env == "True":
if enable_fid_offset_env == "True":
if t_ccd_acq is None or date is None:
raise ValueError(
"t_ccd_acq and date must be provided if fid drift is enabled"
"t_ccd_acq and date must be provided if fid offset is enabled"
)
dy, dz = get_drift(date, t_ccd_acq)
dy, dz = get_fid_offset(date, t_ccd_acq)
yang += dy
zang += dz

Expand Down
2 changes: 1 addition & 1 deletion proseco/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def use_fixed_chandra_models(monkeypatch):

@pytest.fixture(autouse=True)
def disable_fid_drift(monkeypatch):
monkeypatch.setenv("PROSECO_ENABLE_FID_DRIFT", "False")
monkeypatch.setenv("PROSECO_ENABLE_FID_OFFSET", "False")


# By default test with the latest AGASC version available including release candidates
Expand Down
14 changes: 4 additions & 10 deletions proseco/tests/test_fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Reference fid positions for spoiling tests. Because this is done outside
# a test the fixture to generally disable fid drift is not in effect.
os.environ["PROSECO_ENABLE_FID_DRIFT"] = "False"
os.environ["PROSECO_ENABLE_FID_OFFSET"] = "False"
FIDS = get_fid_catalog(stars=StarsTable.empty(), **STD_INFO)

# Do not use the AGASC supplement in testing by default since mags can change
Expand Down Expand Up @@ -51,18 +51,12 @@ def test_get_fid_position(monkeypatch):
assert np.allclose(zang[fidset], [-468, -460, 561], rtol=0, atol=1.1)

yang1, zang1 = get_fid_positions("ACIS-S", focus_offset=0.0, sim_offset=0.0)
monkeypatch.setenv("CHANDRA_MODELS_DEFAULT_VERSION", "fid-drift")
monkeypatch.setenv("PROSECO_ENABLE_FID_DRIFT", "True")
monkeypatch.setenv("PROSECO_ENABLE_FID_OFFSET", "True")
yang2, zang2 = get_fid_positions(
"ACIS-S", focus_offset=0.0, sim_offset=0.0, date="2023:235", t_ccd_acq=-13.65
)
yang3, zang3 = get_fid_positions(
"ACIS-S", focus_offset=0.0, sim_offset=0.0, date="2019:001", t_ccd_acq=-13.65
)
assert np.allclose(yang1, yang3, rtol=0, atol=0.1)
assert np.allclose(zang1, zang3, rtol=0, atol=0.1)
assert np.allclose(yang1 - yang2, -36.35, rtol=0, atol=0.1)
assert np.allclose(zang1 - zang2, -11.83, rtol=0, atol=0.1)
assert np.allclose(yang1 - yang2, -33.16, rtol=0, atol=0.1)
assert np.allclose(zang1 - zang2, -9.83, rtol=0, atol=0.1)


def test_get_initial_catalog():
Expand Down

0 comments on commit f39da1e

Please sign in to comment.