From 307e4c06cafee10ad562ef1cf90920fc75c387e2 Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Thu, 7 Mar 2024 06:43:28 -0500 Subject: [PATCH] Apply dyn bgd T_ccd bonus for imposter checks Also make imposter message match starcheck --- sparkles/aca_check_table.py | 22 ---------------------- sparkles/checks.py | 29 +++++++++++++++++++++++++---- sparkles/tests/test_checks.py | 5 ++++- sparkles/tests/test_review.py | 9 ++------- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/sparkles/aca_check_table.py b/sparkles/aca_check_table.py index 3396554..da60129 100644 --- a/sparkles/aca_check_table.py +++ b/sparkles/aca_check_table.py @@ -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 @@ -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.""" @@ -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) diff --git a/sparkles/checks.py b/sparkles/checks.py index c0a5b63..0fc283a 100644 --- a/sparkles/checks.py +++ b/sparkles/checks.py @@ -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 @@ -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""" @@ -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 diff --git a/sparkles/tests/test_checks.py b/sparkles/tests/test_checks.py index 8b67254..ef4ca7e 100644 --- a/sparkles/tests/test_checks.py +++ b/sparkles/tests/test_checks.py @@ -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 diff --git a/sparkles/tests/test_review.py b/sparkles/tests/test_review.py index 47df199..3b621c1 100644 --- a/sparkles/tests/test_review.py +++ b/sparkles/tests/test_review.py @@ -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"}, @@ -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"}, @@ -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",