Skip to content

Commit

Permalink
Merge pull request #215 from sot/rolled-dyn-bgd
Browse files Browse the repository at this point in the history
Apply dynamic background bonus to rolled "n_stars"
  • Loading branch information
jeanconn authored Nov 26, 2024
2 parents 6a502c8 + ab4628e commit 97424df
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
18 changes: 16 additions & 2 deletions sparkles/roll_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from proseco.characteristics import CCD
from Quaternion import Quat

from sparkles.aca_check_table import get_t_ccds_bonus


def logical_intervals(vals, x=None):
"""Determine contiguous intervals during which ``vals`` is True.
Expand Down Expand Up @@ -350,7 +352,13 @@ def get_roll_options(
return

P2 = -np.log10(self.acqs.calc_p_safe())
n_stars = guide_count(self.guides["mag"], self.guides.t_ccd, self.is_ER)
t_ccds_bonus = get_t_ccds_bonus(
self.guides["mag"],
self.guides.t_ccd,
self.dyn_bgd_n_faint,
self.dyn_bgd_dt_ccd,
)
n_stars = guide_count(self.guides["mag"], t_ccds_bonus, self.is_ER)

cand_idxs = self.get_candidate_better_stars()
roll_intervals, self.roll_info = self.get_roll_intervals(
Expand Down Expand Up @@ -404,8 +412,14 @@ def get_roll_options(
aca_rolled = get_aca_catalog(**kwargs)

P2_rolled = -np.log10(aca_rolled.acqs.calc_p_safe())
t_ccds_bonus_rolled = get_t_ccds_bonus(
aca_rolled.guides["mag"],
aca_rolled.guides.t_ccd,
aca_rolled.dyn_bgd_n_faint,
aca_rolled.dyn_bgd_dt_ccd,
)
n_stars_rolled = guide_count(
aca_rolled.guides["mag"], aca_rolled.guides.t_ccd, count_9th=self.is_ER
aca_rolled.guides["mag"], t_ccds_bonus_rolled, count_9th=self.is_ER
)

improvement = calc_improve_metric(n_stars, P2, n_stars_rolled, P2_rolled)
Expand Down
54 changes: 54 additions & 0 deletions sparkles/tests/test_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,60 @@ def test_roll_options_with_monitor_star():
acar.get_roll_options()


def test_roll_options_use_dyn_bgd_n_faint():
"""Test that the roll options use dyn_bgd_n_faint in the catalog
selection and the n_stars value. This test uses an artificially large
dyn_bgd_t_ccd of -10 accentuate the differences."""

kwargs = {
"att": [-0.63787389, 0.07940607, -0.10873119, 0.75828036],
"date": "2024:316",
"detector": "ACIS-S",
"dither": (16, 16),
"focus_offset": 0,
"sim_offset": 0,
"man_angle": 5,
"n_acq": 8,
"n_fid": 3,
"n_guide": 5,
"obsid": 30580,
"t_ccd": -6.0,
}

aca1_n_faint = 0
aca1 = get_aca_catalog(**kwargs, dyn_bgd_n_faint=aca1_n_faint, dyn_bgd_dt_ccd=-10)
acar1 = aca1.get_review_table()
acar1.get_roll_options()

aca2_n_faint = 3
aca2 = get_aca_catalog(**kwargs, dyn_bgd_n_faint=aca2_n_faint, dyn_bgd_dt_ccd=-10)
acar2 = aca2.get_review_table()
acar2.get_roll_options()

assert acar1.dyn_bgd_n_faint == aca1_n_faint
assert acar2.dyn_bgd_n_faint == aca2_n_faint
for roll_option in acar1.roll_options:
assert roll_option["acar"].dyn_bgd_n_faint == aca1_n_faint
for roll_option in acar2.roll_options:
assert roll_option["acar"].dyn_bgd_n_faint == aca2_n_faint

aca1_n_stars = [roll_option["n_stars"] for roll_option in acar1.roll_options]
aca2_n_stars = [roll_option["n_stars"] for roll_option in acar2.roll_options]

# In these cases the roll options are the same.
assert len(aca1_n_stars) == len(aca2_n_stars)

# But the guide count of the last one is not.
assert np.allclose(
np.array(aca1_n_stars),
np.array([1.5302331230204111, 1.5302331230204111, 2.5306029287208744]),
)
assert np.allclose(
np.array(aca2_n_stars),
np.array([1.5302331230204111, 1.5302331230204111, 3.530615379948673]),
)


def test_uniform_roll_options(proseco_agasc_1p7):
"""Use obsid 22508 as a test case for failing to find a roll option using
the 'uniq_ids' algorithm and falling through to a 'uniform' search.
Expand Down

0 comments on commit 97424df

Please sign in to comment.