Skip to content

Commit

Permalink
Apply dyn bgd T_ccd bonus for imposter checks
Browse files Browse the repository at this point in the history
Also make imposter message match starcheck
  • Loading branch information
taldcroft committed Mar 7, 2024
1 parent 1d650e6 commit 307e4c0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
22 changes: 0 additions & 22 deletions sparkles/aca_check_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import numpy as np
from astropy.table import Column
from chandra_aca.dark_model import dark_temp_scale
from chandra_aca.star_probs import guide_count
from chandra_aca.transform import yagzag_to_pixels
from proseco.catalog import ACATable
Expand Down Expand Up @@ -107,8 +106,6 @@ def __init__(self, *args, **kwargs):
del self["idx"]
self.rename_column("idx_temp", "idx")

self.adjust_guide_imp_mag_for_bonus_stars()

@property
def t_ccds_bonus(self):
"""Effective T_ccd for each guide star, including dynamic background bonus."""
Expand Down Expand Up @@ -168,22 +165,3 @@ def add_row_col(self):
index = self.colnames.index("zang") + 1
self.add_column(Column(row, name="row"), index=index)
self.add_column(Column(col, name="col"), index=index + 1)

def adjust_guide_imp_mag_for_bonus_stars(self):
"""Adjust the guide star imposter magnitudes in-place for dyn bgd bonus.
mag0 = MAG0 - 2.5 * np.log10(count_rate / ACA_CNT_RATE_MAG0)
mag1 = MAG0 - 2.5 * np.log10(count_rate * scale / ACA_CNT_RATE_MAG0)
MAG0 - 2.5 * (np.log10(count_rate / ACA_CNT_RATE_MAG0) + np.log10(scale))
mag0 - 2.5 * np.log10(scale)
"""

if self.dyn_bgd_n_faint == 0:
return

t_ccd = self.guides.t_ccd
for entry, t_ccd_bonus in zip(self.guides, self.t_ccds_bonus):
if t_ccd_bonus != t_ccd:
# count scaling factor to convert from t_ccd to t_ccd_bonus
scale = dark_temp_scale(t_ccd, t_ccd_bonus)
entry["imp_mag"] -= 2.5 * np.log10(scale)
29 changes: 25 additions & 4 deletions sparkles/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
import proseco.characteristics as ACA
from chandra_aca.dark_model import dark_temp_scale
from chandra_aca.transform import mag_to_count_rate, snr_mag_for_t_ccd
from proseco.core import ACACatalogTableRow, StarsTableRow

Expand Down Expand Up @@ -377,6 +378,21 @@ def check_pos_err_guide(acar: ACACheckTable, star: StarsTableRow) -> list[Messag
return msgs


def adjust_imp_mag_for_t_ccds_bonus(imp_mag, t_ccd, t_ccd_bonus):
"""Adjust the guide star imposter magnitudes in-place for dyn bgd bonus.
mag0 = MAG0 - 2.5 * np.log10(count_rate / ACA_CNT_RATE_MAG0)
mag1 = MAG0 - 2.5 * np.log10(count_rate * scale / ACA_CNT_RATE_MAG0)
MAG0 - 2.5 * (np.log10(count_rate / ACA_CNT_RATE_MAG0) + np.log10(scale))
mag0 - 2.5 * np.log10(scale)
"""
if t_ccd_bonus != t_ccd:
# count scaling factor to convert from t_ccd to t_ccd_bonus
scale = dark_temp_scale(t_ccd, t_ccd_bonus)
imp_mag -= 2.5 * np.log10(scale)
return imp_mag


def check_imposters_guide(acar: ACACheckTable, star: StarsTableRow) -> list[Message]:
"""Warn on stars with larger imposter centroid offsets"""

Expand All @@ -395,15 +411,20 @@ def imposter_offset(cand_mag, imposter_mag):

msgs = []
agasc_id = star["id"]
idx = acar.get_id(agasc_id)["idx"]
offset = imposter_offset(star["mag"], star["imp_mag"])
idx = acar.guides.get_id_idx(agasc_id)
imp_mag = adjust_imp_mag_for_t_ccds_bonus(
star["imp_mag"], acar.guides.t_ccd, acar.t_ccds_bonus[idx]
)
offset = imposter_offset(star["mag"], imp_mag)
for limit, category in ((4.0, "critical"), (2.5, "warning")):
if np.round(offset, decimals=1) > limit:
msgs += [
Message(
category,
f"Guide star imposter offset {offset:.1f}, limit {limit} arcsec",
idx=idx,
f"Imposter mag {imp_mag:.1f} centroid offset {offset:.1f} "
f"row, col ({star['imp_r']:4.0f}, {star['imp_c']:4.0f}) "
f"star ({star['row']:4.0f}, {star['col']:4.0f})",
idx=acar.get_id(agasc_id)["idx"],
)
]
break
Expand Down
5 changes: 4 additions & 1 deletion sparkles/tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,10 @@ def test_imposters_on_guide(exp_warn, aca_review_table):
assert len(acar.messages) == 1
msg = acar.messages[0]
assert msg["category"] == "warning"
assert msg["text"] == "Guide star imposter offset 2.6, limit 2.5 arcsec"
assert msg["text"] == (
"Imposter mag 9.7 centroid offset 2.6 row, col "
"( 100, -201) star ( 100, -200)"
)
else:
assert len(acar.messages) == 0

Expand Down
9 changes: 2 additions & 7 deletions sparkles/tests/test_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def test_review_catalog(proseco_agasc_1p7, tmpdir):
acar.run_aca_review()
assert acar.messages == [
{
"text": "Guide star imposter offset 2.6, limit 2.5 arcsec",
"category": "warning",
"text": "Imposter mag 11.4 centroid offset 2.6 row, col (-333, 21) star (-329, 22)",
"idx": 4,
},
{"text": "P2: 3.33 less than 4.0 for ER", "category": "warning"},
Expand Down Expand Up @@ -336,8 +336,8 @@ def test_run_aca_review_function(proseco_agasc_1p7, tmpdir):
assert exc is None
assert acar.messages == [
{
"text": "Guide star imposter offset 2.6, limit 2.5 arcsec",
"category": "warning",
"text": "Imposter mag 11.4 centroid offset 2.6 row, col (-333, 21) star (-329, 22)",
"idx": 4,
},
{"text": "P2: 3.33 less than 4.0 for ER", "category": "warning"},
Expand Down Expand Up @@ -375,11 +375,6 @@ def test_run_aca_review_dyn_bgd_n_faint(proseco_agasc_1p7, tmpdir):
# guide count and new info message
assert acar.messages == [
{"text": "Using dyn_bgd_n_faint=2 (call_args val=0)", "category": "info"},
{
"text": "Guide star imposter offset 2.6, limit 2.5 arcsec",
"category": "warning",
"idx": 4,
},
{"text": "P2: 3.33 less than 4.0 for ER", "category": "warning"},
{
"text": "ER count of 9th (8.9 for -9.9C) mag guide stars 1.91 < 3.0",
Expand Down

0 comments on commit 307e4c0

Please sign in to comment.