Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Apply dyn bgd bonus imposter check #208

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading