From 7d6420459841687d5e7ab996f30f201c29de8ea3 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Fri, 1 Nov 2024 14:42:56 -0400 Subject: [PATCH 1/2] Calculate rolled n_stars with dyn bonus --- sparkles/roll_optimize.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/sparkles/roll_optimize.py b/sparkles/roll_optimize.py index fa149ff..0020fd3 100644 --- a/sparkles/roll_optimize.py +++ b/sparkles/roll_optimize.py @@ -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. @@ -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( @@ -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) From ab4628e8d2f629d6c42d9d1af60f0064c9e7261c Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Fri, 1 Nov 2024 14:43:28 -0400 Subject: [PATCH 2/2] Add test that rolled n_stars uses dyn bonus --- sparkles/tests/test_review.py | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/sparkles/tests/test_review.py b/sparkles/tests/test_review.py index 0603cbd..ca5cf0e 100644 --- a/sparkles/tests/test_review.py +++ b/sparkles/tests/test_review.py @@ -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.