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",