Skip to content

Commit

Permalink
Implement use of an initial fid drift correction
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanconn committed Oct 13, 2023
1 parent 85c79be commit 0c86b27
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
25 changes: 23 additions & 2 deletions proseco/fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
Get a catalog of fid lights.
"""

import os
import weakref

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

from . import characteristics as ACA
from . import characteristics_acq as ACQ
Expand Down Expand Up @@ -316,7 +319,7 @@ def get_fid_candidates(self):
Result is updating self.cand_fids.
"""
yang, zang = get_fid_positions(
self.detector, self.focus_offset, self.sim_offset
self.detector, self.focus_offset, self.sim_offset, self.t_ccd_acq, self.date
)
row, col = yagzag_to_pixels(yang, zang, allow_bad=True)
ids = np.arange(len(yang), dtype=np.int64) + 1 # E.g. 1 to 6 for ACIS
Expand Down Expand Up @@ -472,7 +475,7 @@ def set_spoilers_score(self, fid):
)


def get_fid_positions(detector, focus_offset, sim_offset):
def get_fid_positions(detector, focus_offset, sim_offset, t_ccd_acq=None, date=None):
"""Calculate the fid light positions for all fids for ``detector``.
This is adapted from the Matlab
Expand Down Expand Up @@ -518,4 +521,22 @@ def get_fid_positions(detector, focus_offset, sim_offset):

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"):
raise ValueError(
f'PROSECO_ENABLE_FID_DRIFT env var must be either "True" or "False" '
f"got {enable_fid_drift}"
)

# The env var is still just a string so do a string equals on it
if enable_fid_drift_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"
)
dy, dz = get_drift(date, t_ccd_acq)
yang += dy
zang += dz

return yang, zang
5 changes: 5 additions & 0 deletions proseco/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ def use_fixed_chandra_models(monkeypatch):
monkeypatch.setenv("CHANDRA_MODELS_DEFAULT_VERSION", "3.48")


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


# By default test with the latest AGASC version available including release candidates
@pytest.fixture(autouse=True)
def proseco_agasc_rc(monkeypatch):
Expand Down
20 changes: 18 additions & 2 deletions proseco/tests/test_fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
from ..fid import get_fid_catalog, get_fid_positions
from .test_common import DARK40, OBS_INFO, STD_INFO, mod_std_info

# Reference fid positions for spoiling tests
# 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"
FIDS = get_fid_catalog(stars=StarsTable.empty(), **STD_INFO)

# Do not use the AGASC supplement in testing by default since mags can change
os.environ[agasc.SUPPLEMENT_ENABLED_ENV] = "False"


def test_get_fid_position():
def test_get_fid_position(monkeypatch):
"""
Compare computed fid positions to flight values from starcheck reports.
"""
Expand Down Expand Up @@ -48,6 +50,20 @@ def test_get_fid_position():
assert np.allclose(yang[fidset], [-1174, 1224, -1177], rtol=0, atol=1.1)
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")
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)


def test_get_initial_catalog():
"""Test basic catalog with no stars in field using standard 2-4-5 config."""
Expand Down

0 comments on commit 0c86b27

Please sign in to comment.