Skip to content

Commit

Permalink
Make example_scheduler start with MJD within range of current skybrig…
Browse files Browse the repository at this point in the history
…htness_pre small files
  • Loading branch information
rhiannonlynne committed Sep 20, 2023
1 parent 0255ac3 commit 572d7f9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions schedview/app/sched_maps/sched_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import bokeh.models
import bokeh.plotting
import pandas as pd
import rubin_sim.scheduler.example
from astropy.time import Time
from rubin_sim.scheduler.model_observatory import ModelObservatory
from rubin_sim.scheduler.example import example_scheduler
from uranography.api import ArmillarySphere, HorizonMap, MollweideMap, Planisphere

from schedview.collect import read_scheduler, sample_pickle
Expand Down Expand Up @@ -551,7 +551,7 @@ def make_scheduler_map_figure(
observatory = ModelObservatory(mjd_start=start_mjd, nside=nside)
observatory.mjd = DEFAULT_MJD
conditions = observatory.return_conditions()
scheduler = rubin_sim.scheduler.example.example_scheduler(mjd_start=start_mjd, nside=nside)
scheduler = example_scheduler(mjd_start=start_mjd, nside=nside)
scheduler.update_conditions(conditions)
scheduler.request_observation()
else:
Expand Down
2 changes: 1 addition & 1 deletion schedview/plot/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(self, init_key="AvoidDirectWind", nside=DEFAULT_NSIDE, scheduler=No
self.observatory = None

if scheduler is None:
scheduler = rubin_sim.scheduler.example.example_scheduler(nside=nside)
scheduler = rubin_sim.scheduler.example.example_scheduler(nside=nside, mjd_start=DEFAULT_MJD)
if self.observatory is not None:
conditions = self.observatory.return_conditions()
else:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_compute_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

from schedview.compute.scheduler import create_example, make_scheduler_summary_df, make_unique_survey_name

MJD_SCHED = 60200.2


class TestComputeScheduler(unittest.TestCase):
sample_scheduler = example_scheduler()
sample_scheduler = example_scheduler(mjd_start=MJD_SCHED)
observatory = ModelObservatory()

def test_create_example(self):
Expand All @@ -31,7 +33,7 @@ def test_make_unique_survey_name(self):
self.assertEqual(len(names), len(set(names)))

def test_make_scheduler_summary_df(self):
self.observatory.mjd = 60100.2
self.observatory.mjd = MJD_SCHED
conditions = self.observatory.return_conditions()
reward_df = self.sample_scheduler.make_reward_df(conditions)
summary_df = make_scheduler_summary_df(self.sample_scheduler, conditions, reward_df)
Expand Down
8 changes: 5 additions & 3 deletions tests/test_compute_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@

from schedview.compute.survey import compute_maps, make_survey_reward_df

MJD_SCHED = 60200.2


class TestComputeSurvey(unittest.TestCase):
scheduler = example_scheduler()
scheduler = example_scheduler(mjd_start=MJD_SCHED)
observatory = ModelObservatory()

def test_make_survey_reward_df(self):
self.observatory.mjd = 60200.2
self.observatory.mjd = MJD_SCHED
conditions = self.observatory.return_conditions()
reward_df = make_survey_reward_df(self.scheduler, conditions)
self.assertIsInstance(reward_df, pd.DataFrame)

def test_compute_maps(self):
self.observatory.mjd = 60200.2
self.observatory.mjd = MJD_SCHED
conditions = self.observatory.return_conditions()
survey = self.scheduler.survey_lists[2][2]
survey_maps = compute_maps(survey, conditions, nside=8)
Expand Down
17 changes: 8 additions & 9 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

import astropy.utils.iers
import healpy as hp
import rubin_sim.scheduler.example
from astropy.time import TimeDelta
from rubin_sim.scheduler.features.conditions import Conditions
from rubin_sim.scheduler.model_observatory import ModelObservatory

from rubin_sim.scheduler.example import example_scheduler
from schedview.collect import sample_pickle
from schedview.plot.scheduler import DEFAULT_MJD, SchedulerDisplay

NSIDE = 8

MJD_SCHED = DEFAULT_MJD
astropy.utils.iers.conf.iers_degraded_accuracy = "warn"


class TestSchedulerDisplay(unittest.TestCase):
def test_scheduler_display(self):
mjd = DEFAULT_MJD
mjd = MJD_SCHED
nside = NSIDE

scheduler = rubin_sim.scheduler.example.example_scheduler(nside=nside)
scheduler = example_scheduler(nside=nside, mjd_start=MJD_SCHED)

try:
observatory = ModelObservatory(mjd_start=mjd - 1, nside=nside)
Expand All @@ -46,11 +45,11 @@ def test_scheduler_display(self):

self.assertGreater(len(sched_display.map_keys), 0)

self.assertEqual(sched_display.mjd, DEFAULT_MJD)
self.assertLessEqual(sched_display.conditions.sun_n18_setting, DEFAULT_MJD)
self.assertGreaterEqual(sched_display.conditions.sun_n18_rising, DEFAULT_MJD)
self.assertEqual(sched_display.mjd, MJD_SCHED)
self.assertLessEqual(sched_display.conditions.sun_n18_setting, MJD_SCHED)
self.assertGreaterEqual(sched_display.conditions.sun_n18_rising, MJD_SCHED)

new_mjd = DEFAULT_MJD + 1.1
new_mjd = MJD_SCHED + 1.1
sched_display.mjd = new_mjd
self.assertEqual(sched_display.mjd, new_mjd)
self.assertLessEqual(sched_display.conditions.sun_n18_setting, new_mjd)
Expand Down
7 changes: 4 additions & 3 deletions tests/test_scheduler_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
TEST_PICKLE = "https://www.astronomy.swin.edu.au/~gpoole/rubin_datavis/example_pickle_scheduler.p.xz"
TEST_DATE = datetime(2023, 8, 1, 23, 0)
DEFAULT_TIMEZONE = "America/Santiago"
MJD_SCHED = 60200.2


class TestSchedulerDashboard(unittest.TestCase):
Expand Down Expand Up @@ -90,13 +91,13 @@ def test_title(self):
self.assertEqual(title, expected_title)

def test_make_summary_df(self):
self.scheduler._scheduler = example_scheduler()
self.scheduler._scheduler = example_scheduler(mjd_start=MJD_SCHED)
self.scheduler._conditions = self.observatory.return_conditions()
self.scheduler.make_scheduler_summary_df()
self.assertIsInstance(self.scheduler._scheduler_summary_df, pd.DataFrame)

def test_summary_widget(self):
self.scheduler._scheduler = example_scheduler()
self.scheduler._scheduler = example_scheduler(mjd_start=MJD_SCHED)
self.scheduler._conditions = self.observatory.return_conditions()
self.scheduler._scheduler.update_conditions(self.scheduler._conditions)
scheduler_summary_df = make_scheduler_summary_df(
Expand All @@ -111,7 +112,7 @@ def test_summary_widget(self):
self.assertIsInstance(widget, Tabulator)

def test_compute_survey_maps(self):
self.scheduler._scheduler = example_scheduler()
self.scheduler._scheduler = example_scheduler(mjd_start=MJD_SCHED)
self.scheduler._conditions = self.observatory.return_conditions()
self.scheduler._scheduler.update_conditions(self.scheduler._conditions)
survey = self.scheduler._scheduler.survey_lists[2][3]
Expand Down
4 changes: 3 additions & 1 deletion tests/test_scheduler_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from schedview.collect.scheduler_pickle import read_scheduler

MJD_SCHED = 60200.2


class TestSchedulerPickle(unittest.TestCase):
def test_read_scheduler(self):
Expand All @@ -18,7 +20,7 @@ def test_read_scheduler(self):

def test_bare_scheduler(self):
# Read a file with just a scheduler, no conditions
raw_scheduler = example_scheduler()
raw_scheduler = example_scheduler(mjd_start=MJD_SCHED)
with TemporaryDirectory() as data_dir:
sample_path = os.path.join(data_dir, "sample_scheduler.pickle")
with open(sample_path, "wb") as file_io:
Expand Down

0 comments on commit 572d7f9

Please sign in to comment.