Skip to content

Commit

Permalink
Merge pull request #153 from sot/use-rounded-checks
Browse files Browse the repository at this point in the history
Use rounded values for checks where appropriate
  • Loading branch information
taldcroft authored May 24, 2021
2 parents c44fa5c + 728676a commit 8b77b7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
13 changes: 8 additions & 5 deletions sparkles/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ def sign(axis):

for axis in ('row', 'col'):
track_delta = abs(track_lims[axis]) - abs(entry[axis])
track_delta = np.round(track_delta, decimals=1) # Official check is to 1 decimal
for delta_lim, category in ((3.0, 'critical'),
(5.0, 'info')):
if track_delta < delta_lim:
Expand Down Expand Up @@ -981,6 +982,7 @@ def check_acq_p2(self):
"""
P2 = -np.log10(self.acqs.calc_p_safe())
P2 = np.round(P2, decimals=2) # Official check is to 2 decimals
obs_type = 'OR' if self.is_OR else 'ER'
P2_lim = 2.0 if self.is_OR else 3.0
if P2 < P2_lim:
Expand Down Expand Up @@ -1015,16 +1017,17 @@ def check_guide_count(self):
"""
obs_type = 'ER' if self.is_ER else 'OR'
if self.is_ER and self.guide_count_9th < 3.0:
count_9th_lim = 3.0
if self.is_ER and np.round(self.guide_count_9th, decimals=2) < count_9th_lim:
# Determine the threshold 9th mag equivalent value at the effective guide t_ccd
mag9 = snr_mag_for_t_ccd(self.guides.t_ccd, 9.0, -10.9)
self.add_message(
'critical',
f'{obs_type} count of 9th ({mag9:.1f} for {self.guides.t_ccd:.1f}C) '
f'mag guide stars {self.guide_count_9th:.2f} < 3.0')
f'mag guide stars {self.guide_count_9th:.2f} < {count_9th_lim}')

count_lim = 4.0 if self.is_OR else 6.0
if self.guide_count < count_lim:
if np.round(self.guide_count, decimals=2) < count_lim:
self.add_message(
'critical',
f'{obs_type} count of guide stars {self.guide_count:.2f} < {count_lim}')
Expand Down Expand Up @@ -1061,7 +1064,7 @@ def check_pos_err_guide(self, star):
pos_err = star['POS_ERR'] * 0.001
for limit, category in ((2.0, 'critical'),
(1.25, 'warning')):
if pos_err > limit:
if np.round(pos_err, decimals=2) > limit:
self.add_message(
category,
f'Guide star {agasc_id} POS_ERR {pos_err:.2f}, limit {limit} arcsec',
Expand Down Expand Up @@ -1090,7 +1093,7 @@ def imposter_offset(cand_mag, imposter_mag):
offset = imposter_offset(star['mag'], star['imp_mag'])
for limit, category in ((4.0, 'critical'),
(2.5, 'warning')):
if offset > limit:
if np.round(offset, decimals=1) > limit:
self.add_message(
category,
f'Guide star imposter offset {offset:.1f}, limit {limit} arcsec',
Expand Down
23 changes: 16 additions & 7 deletions sparkles/tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import numpy as np
import agasc
import pytest

from chandra_aca.transform import mag_to_count_rate
from proseco import get_aca_catalog
Expand Down Expand Up @@ -309,7 +310,8 @@ def test_guide_edge_check():
'text': 'included guide ID(s): [101 102 103 104 105 106]'}]


def test_imposters_on_guide():
@pytest.mark.parametrize('exp_warn', [False, True])
def test_imposters_on_guide(exp_warn):
"""Test the check for imposters by adding one imposter to a fake star"""
stars = StarsTable.empty()
# Add two stars because separate P2 tests seem to break with just one star
Expand All @@ -318,16 +320,23 @@ def test_imposters_on_guide():
cnt = mag_to_count_rate(mag)
stars.add_fake_star(id=110, row=100, col=-200, mag=mag)
dark_with_badpix = DARK40.copy()
dark_with_badpix[100 + 512, -200 + 512] = cnt * 0.1
dark_with_badpix[100 + 512, -201 + 512] = cnt * 0.1
# Add an imposter that is just over the limit (2.62) for exp_warn=True, else
# add imposter that is exactly at the limit (2.52) which rounds to 2.5 => no
# warning.
scale = 0.105 if exp_warn else 0.1
dark_with_badpix[100 + 512, -200 + 512] = cnt * scale
dark_with_badpix[100 + 512, -201 + 512] = cnt * scale
aca = get_aca_catalog(**mod_std_info(n_fid=0, n_guide=8), stars=stars, dark=dark_with_badpix,
raise_exc=True)
aca = ACAReviewTable(aca)
aca.check_imposters_guide(aca.guides.get_id(110))
assert len(aca.messages) == 1
msg = aca.messages[0]
assert msg['category'] == 'warning'
assert 'Guide star imposter offset' in msg['text']
if exp_warn:
assert len(aca.messages) == 1
msg = aca.messages[0]
assert msg['category'] == 'warning'
assert msg['text'] == 'Guide star imposter offset 2.6, limit 2.5 arcsec'
else:
assert len(aca.messages) == 0


def test_bad_star_set():
Expand Down

0 comments on commit 8b77b7b

Please sign in to comment.