Skip to content

Commit

Permalink
Found and fixed a bug with sun_ra_start so that it's set using mjd_st…
Browse files Browse the repository at this point in the history
…art, instead of current mjd.

black
  • Loading branch information
rhiannonlynne committed Sep 1, 2024
1 parent 449779c commit bd40341
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,12 @@ def __init__(
good_mjd, to_set_mjd = self.check_mjd(to_set_mjd)
self.mjd = to_set_mjd

sun_moon_info = self.almanac.get_sun_moon_positions(mjd)
# Create the map of the season offsets - this map is constant
ra, dec = _hpid2_ra_dec(nside, np.arange(hp.nside2npix(self.nside)))
ra_deg = np.degrees(ra)
self.season_map = calc_season(ra_deg, [self.mjd_start], self.mjd_start).flatten()
# Set the sun_ra_start information, for the rolling footprints
sun_moon_info = self.almanac.get_sun_moon_positions(self.mjd_start)
self.sun_ra_start = sun_moon_info["sun_RA"] + 0
# Conditions object to update and return on request
# (at present, this is not updated -- recreated, below).
Expand Down
15 changes: 7 additions & 8 deletions tests/scheduler/test_comcam_surveys.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os
import unittest

import numpy as np
from astropy.time import Time

from rubin_scheduler.data import get_data_dir
from rubin_scheduler.scheduler import sim_runner
from rubin_scheduler.scheduler.example import (
get_comcam_sv_schedulers,
Expand All @@ -15,12 +13,9 @@
from rubin_scheduler.scheduler.schedulers import ComCamFilterSched
from rubin_scheduler.utils import survey_start_mjd

SAMPLE_BIG_DATA_FILE = os.path.join(get_data_dir(), "scheduler/dust_maps/dust_nside_32.npz")


class TestComCamSurveys(unittest.TestCase):

@unittest.skipUnless(os.path.isfile(SAMPLE_BIG_DATA_FILE), "Test data not available.")
def test_model_observatory_conveniences(self):
"""Test the model observatory convenience functions."""

Expand All @@ -29,19 +24,24 @@ def test_model_observatory_conveniences(self):
survey_start = survey_start_mjd()
survey_start = np.floor(survey_start) + 0.5
dayobs = Time(survey_start, format="mjd", scale="utc").iso[:10]
survey_start = Time(f"{dayobs}T12:00:00", format="isot", scale="utc").mjd
observatory = get_model_observatory(dayobs=dayobs, survey_start=survey_start)
conditions = observatory.return_conditions()
assert conditions.mjd == observatory.mjd
# The model observatory automatically advanced to -12 deg sunset
assert (conditions.mjd - survey_start) < 1
sun_ra_start = conditions.sun_ra_start
mjd_start = observatory.mjd_start

newday = survey_start + 4
new_dayobs = Time(newday, format="mjd", scale="utc").iso[:10]
newday = Time(f"{new_dayobs}T12:00:00", format="isot", scale="utc").mjd
observatory = get_model_observatory(dayobs=new_dayobs, survey_start=survey_start)
conditions = observatory.return_conditions()
assert (conditions.mjd - newday) < 1
# Check that advancing the day did not change the expected location
# of the sun at the *start* of the survey
assert conditions.mjd_start == mjd_start
assert conditions.sun_ra_start == sun_ra_start

# And update observatory to sunset, using a filter scheduler
# that only has 'g' available
Expand All @@ -58,9 +58,8 @@ def test_comcam_sv_sched(self):
survey_start = survey_start_mjd()
survey_start = np.floor(survey_start) + 0.5
dayobs = Time(survey_start, format="mjd", scale="utc").iso[:10]
survey_start_mjd = Time(f"{dayobs}T12:00:00", format="isot", scale="utc").mjd
scheduler, filter_scheduler = get_comcam_sv_schedulers()
observatory = get_model_observatory(dayobs=dayobs, survey_start=survey_start_mjd)
observatory = get_model_observatory(dayobs=dayobs, survey_start=survey_start)
observatory = update_model_observatory_sunset(observatory, filter_scheduler)

observatory, scheduler, observations = sim_runner(
Expand Down

0 comments on commit bd40341

Please sign in to comment.