Skip to content

Commit

Permalink
pre-computed ddfs for longer potential date range
Browse files Browse the repository at this point in the history
  • Loading branch information
yoachim committed Oct 18, 2023
1 parent 4d3dc3d commit 3e3f708
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
26 changes: 23 additions & 3 deletions rubin_sim/scheduler/surveys/ddf_presched.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
__all__ = ("generate_ddf_scheduled_obs",)

import os
import warnings

import numpy as np

from rubin_sim.data import get_data_dir
from rubin_sim.scheduler.utils import scheduled_observation
from rubin_sim.utils import calc_season, ddf_locations
from rubin_sim.utils import calc_season, ddf_locations, survey_start_mjd


def ddf_slopes(ddf_name, raw_obs, night_season):
Expand Down Expand Up @@ -78,8 +79,9 @@ def ddf_slopes(ddf_name, raw_obs, night_season):
for season in np.unique(round_season):
in_season = np.where(round_season == season)
cumulative = np.cumsum(raw_obs[in_season])
cumulative = cumulative / cumulative.max() * season_vals[season]
cumulative_desired[in_season] = cumulative + np.max(cumulative_desired)
if cumulative.max() > 0:
cumulative = cumulative / cumulative.max() * season_vals[season]
cumulative_desired[in_season] = cumulative + np.max(cumulative_desired)

if ddf_name == "COSMOS":
# looks like COSMOS has no in-season time for 10 at the current start mjd.
Expand Down Expand Up @@ -267,6 +269,8 @@ def generate_ddf_scheduled_obs(
nvis_master=[8, 10, 20, 20, 24, 18],
filters="ugrizy",
nsnaps=[1, 2, 2, 2, 2, 2],
mjd_start=None,
survey_length=10.0,
):
"""
Expand Down Expand Up @@ -300,10 +304,17 @@ def generate_ddf_scheduled_obs(
The filter names.
nsnaps : list of ints ([1, 2, 2, 2, 2, 2])
The number of snaps to use per filter
mjd_start : float
Starting MJD of the survey. Default None, which calls rubin_sim.utils.survey_start_mjd
survey_length : float
Length of survey (years). Default 10.
"""
if data_file is None:
data_file = os.path.join(get_data_dir(), "scheduler", "ddf_grid.npz")

if mjd_start is None:
mjd_start = survey_start_mjd()

flush_length = flush_length # days
mjd_tol = mjd_tol / 60 / 24.0 # minutes to days
expt = expt
Expand All @@ -316,6 +327,15 @@ def generate_ddf_scheduled_obs(
ddf_data = np.load(data_file)
ddf_grid = ddf_data["ddf_grid"].copy()

mjd_max = mjd_start + survey_length * 365.25

# check if our pre-computed grid is over the time range we think we are scheduling for
if (ddf_grid["mjd"].min() > mjd_start) | (ddf_grid["mjd"].max() < mjd_max):
warnings.warn("Pre-computed DDF properties don't match requested survey times")

in_range = np.where((ddf_grid["mjd"] >= mjd_start) & (ddf_grid["mjd"] <= mjd_max))
ddf_grid = ddf_grid[in_range]

all_scheduled_obs = []
for ddf_name in ["ELAISS1", "XMM_LSS", "ECDFS", "COSMOS", "EDFS_a"]:
print("Optimizing %s" % ddf_name)
Expand Down
5 changes: 4 additions & 1 deletion rubin_sim/scheduler/surveys/generate_ddf_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@
sys.stdout.write(text)
sys.stdout.flush()

sm.set_ra_dec_mjd(ras, decs, mjd, degrees=False)
try:
sm.set_ra_dec_mjd(ras, decs, mjd, degrees=False)
except ValueError:
sm.sun_alt = 12.
if sm.sun_alt > sun_limit:
mags.append(sm.return_mags()["g"] * 0)
airmasses.append(sm.airmass * 0)
Expand Down

0 comments on commit 3e3f708

Please sign in to comment.