Skip to content

Commit 6eda8b6

Browse files
authored
Merge pull request #462 from lsst/tickets/SP-2165
tickets/SP-2165: Set up automatic pre-night opsim simulations for lsstcam
2 parents 9f11788 + 4310505 commit 6eda8b6

File tree

5 files changed

+42
-20
lines changed

5 files changed

+42
-20
lines changed

batch/run_prenight_sims.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ conda activate /sdf/data/rubin/shared/scheduler/envs/prenight
2929

3030
set -o xtrace
3131

32+
export TELESCOPE=$1
3233
export AWS_PROFILE=prenight
3334
WORK_DIR=$(date '+/sdf/data/rubin/shared/scheduler/prenight/work/run_prenight_sims/%Y-%m-%dT%H%M%S' --utc)
3435
echo "Working in $WORK_DIR"
@@ -55,7 +56,7 @@ TS_FBS_UTILS_TAG=$(curl -s https://api.github.com/repos/lsst-ts/ts_fbs_utils/tag
5556
pip install --no-deps --target=${PACKAGE_DIR} git+https://github.com/lsst-ts/ts_fbs_utils.git@${TS_FBS_UTILS_TAG}
5657

5758
# Get the scheduler configuration script
58-
SCHEDULER_CONFIG_SCRIPT=$(scheduler_config_at_time latiss)
59+
SCHEDULER_CONFIG_SCRIPT=$(scheduler_config_at_time ${TELESCOPE})
5960

6061
# Get the path to prenight_sim as provided by the current environment,
6162
# so we do not accidentally run one from the adjusted PATH below.
@@ -67,6 +68,6 @@ export PYTHONPATH=${PACKAGE_DIR}:${PYTHONPATH}
6768
export PATH=${PACKAGE_DIR}/bin:${PATH}
6869
printenv > env.out
6970
date --iso=s
70-
time ${PRENIGHT_SIM} --scheduler auxtel.pickle.xz --opsim None --repo=${TS_CONFIG_OCS_REPO} --script ${SCHEDULER_CONFIG_SCRIPT} --config_version ${TS_CONFIG_OCS_VERSION} 2>&1 > ${WORK_DIR}/prenight_sim.out
71+
time ${PRENIGHT_SIM} --scheduler ${TELESCOPE}.pickle.xz --opsim None --repo=${TS_CONFIG_OCS_REPO} --script ${SCHEDULER_CONFIG_SCRIPT} --config_version ${TS_CONFIG_OCS_VERSION} --telescope ${TELESCOPE} 2>&1 > ${WORK_DIR}/prenight_sim.out
7172
date --iso=s
7273
echo "******* END of run_prenight_sims.sh *********"

rubin_sim/sim_archive/prenight.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ def prenight_sim_cli(cli_args: list = []) -> None:
344344
)
345345
parser.add_argument("--scheduler", type=str, default=None, help="pickle file of the scheduler to run.")
346346
parser.add_argument("--config_version", type=str, default=None, help="Version of ts_config_ocs used.")
347+
parser.add_argument("--telescope", type=str, default=None, help="Telescope scheduled.")
347348

348349
# Configure logging
349350
stream_handler = logging.StreamHandler()
@@ -388,31 +389,34 @@ def prenight_sim_cli(cli_args: list = []) -> None:
388389
opsim_db = None if args.opsim in ("", "None") else args.opsim
389390

390391
scheduler_file = args.scheduler
392+
opsim_metadata = {"telescope": args.telescope}
391393
if args.repo is not None:
392394
if os.path.exists(scheduler_file):
393395
raise ValueError(f"File {scheduler_file} already exists!")
394396

395397
if args.config_version is not None:
396398
scheduler: CoreScheduler = get_scheduler_instance_from_path(args.script)
397399
save_scheduler(scheduler, scheduler_file)
398-
opsim_metadata = {
399-
"opsim_config_repository": args.repo,
400-
"opsim_config_script": args.script,
401-
"opsim_config_version": args.config_version,
402-
}
400+
opsim_metadata.update(
401+
{
402+
"opsim_config_repository": args.repo,
403+
"opsim_config_script": args.script,
404+
"opsim_config_version": args.config_version,
405+
}
406+
)
403407
elif args.branch is not None:
404408
scheduler: CoreScheduler = get_scheduler(args.repo, args.script, args.branch)
405409
save_scheduler(scheduler, scheduler_file)
406410

407-
opsim_metadata = {
408-
"opsim_config_repository": args.repo,
409-
"opsim_config_script": args.script,
410-
"opsim_config_branch": args.branch,
411-
}
411+
opsim_metadata.update(
412+
{
413+
"opsim_config_repository": args.repo,
414+
"opsim_config_script": args.script,
415+
"opsim_config_branch": args.branch,
416+
}
417+
)
412418
else:
413419
raise ValueError("Either the branch or the version of ts_ocs_config must be specified")
414-
else:
415-
opsim_metadata = None
416420

417421
run_prenights(
418422
day_obs_mjd,

rubin_sim/sim_archive/sim_archive.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ def find_latest_prenight_sim_for_nights(
998998
first_day_obs: str | None = None,
999999
last_day_obs: str | None = None,
10001000
tags: tuple[str] = ("ideal", "nominal"),
1001+
telescope: str = "simonyi",
10011002
max_simulation_age: int = 2,
10021003
archive_uri: str = "s3://rubin:rubin-scheduler-prenight/opsim/",
10031004
compilation_uri: str = "s3://rubin:rubin-scheduler-prenight/opsim/compiled_metadata_cache.h5",
@@ -1015,6 +1016,9 @@ def find_latest_prenight_sim_for_nights(
10151016
tags : `tuple[str]`
10161017
A tuple of tags to filter simulations by.
10171018
Defaults to ``('ideal', 'nominal')``.
1019+
telescope : `str`
1020+
The telescope to search for (simonyi or auxtel).
1021+
Defaults to simonyi.
10181022
max_simulation_age : `int`
10191023
The maximum age of simulations to consider, in days.
10201024
Simulations older than ``max_simulation_age`` will not be considered.
@@ -1053,6 +1057,8 @@ def find_latest_prenight_sim_for_nights(
10531057
continue
10541058
if sim["simulated_dates"]["last"] < last_day_obs:
10551059
continue
1060+
if "telescope" in sim and sim["telescope"].lower() != telescope.lower():
1061+
continue
10561062
if not set(tags).issubset(sim["tags"]):
10571063
continue
10581064
if best_sim is not None:
@@ -1080,6 +1086,7 @@ def fetch_latest_prenight_sim_for_nights(
10801086
first_day_obs: str | None = None,
10811087
last_day_obs: str | None = None,
10821088
tags: tuple[str] = ("ideal", "nominal"),
1089+
telescope: str = "simonyi",
10831090
max_simulation_age: int = 2,
10841091
archive_uri: str = "s3://rubin:rubin-scheduler-prenight/opsim/",
10851092
compilation_uri: str = "s3://rubin:rubin-scheduler-prenight/opsim/compiled_metadata_cache.h5",
@@ -1099,6 +1106,9 @@ def fetch_latest_prenight_sim_for_nights(
10991106
tags : `tuple[str]`
11001107
A tuple of tags to filter simulations by.
11011108
Defaults to ``('ideal', 'nominal')``.
1109+
telescope : `str`
1110+
The telescope to get sims for, "simonyi" or "auxtel".
1111+
Defaults to "simonyi".
11021112
max_simulation_age : `int`
11031113
The maximum age of simulations to consider, in days. Simulations older
11041114
than ``max_simulation_age`` will not be considered. Defaults to 2.
@@ -1119,7 +1129,7 @@ def fetch_latest_prenight_sim_for_nights(
11191129
"""
11201130

11211131
sim_metadata = find_latest_prenight_sim_for_nights(
1122-
first_day_obs, last_day_obs, tags, max_simulation_age, archive_uri, compilation_uri
1132+
first_day_obs, last_day_obs, tags, telescope, max_simulation_age, archive_uri, compilation_uri
11231133
)
11241134
if sim_metadata is None:
11251135
LOGGER.info("No simulations meet requested criteria.")
@@ -1132,7 +1142,9 @@ def fetch_latest_prenight_sim_for_nights(
11321142
return result
11331143

11341144

1135-
def fetch_obsloctap_visits(day_obs: str | None = None, nights: int = 2) -> pd.DataFrame:
1145+
def fetch_obsloctap_visits(
1146+
day_obs: str | None = None, nights: int = 2, telescope: str = "simonyi"
1147+
) -> pd.DataFrame:
11361148
"""Return visits from latest nominal prenight briefing simulation.
11371149
11381150
Parameters
@@ -1143,6 +1155,9 @@ def fetch_obsloctap_visits(day_obs: str | None = None, nights: int = 2) -> pd.Da
11431155
nights : `int`
11441156
The number of nights of observations to return.
11451157
Defaults to 2.
1158+
telescope : `str`
1159+
The telescope to get visits for: "simonyi" or "auxtel".
1160+
Defaults to "simonyi".
11461161
11471162
Returns
11481163
-------
@@ -1182,6 +1197,7 @@ def fetch_obsloctap_visits(day_obs: str | None = None, nights: int = 2) -> pd.Da
11821197
first_day_obs,
11831198
last_day_obs,
11841199
tags=("ideal", "nominal"),
1200+
telescope=telescope,
11851201
max_simulation_age=max_simulation_age,
11861202
sqlconstraint=sqlconstraint,
11871203
dbcols=dbcols,

tests/sim_archive/test_prenight.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ class TestPrenight(unittest.TestCase):
2525
def test_prenight(self):
2626
with TemporaryDirectory() as test_archive_dir:
2727
archive_uri = ResourcePath(test_archive_dir).geturl() # type: ignore
28-
prenight_sim_cli("--archive", archive_uri)
28+
prenight_sim_cli(["--archive", archive_uri, "--telescope", "simonyi"])
29+
pass

tests/sim_archive/test_sim_archive.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,21 @@ def test_cli(self):
142142

143143
@unittest.skipIf(not HAVE_LSST_RESOURCES, "No lsst.resources")
144144
def test_find_latest_prenight_sim_for_night(self):
145-
day_obs = "2025-03-25"
145+
day_obs = "2025-04-25"
146146
max_simulation_age = int(np.ceil(Time.now().mjd - Time(day_obs).mjd)) + 1
147147
sim_metadata = find_latest_prenight_sim_for_nights(day_obs, max_simulation_age=max_simulation_age)
148148
assert sim_metadata["simulated_dates"]["first"] <= day_obs <= sim_metadata["simulated_dates"]["last"]
149149

150150
@unittest.skipIf(not HAVE_LSST_RESOURCES, "No lsst.resources")
151151
def test_fetch_latest_prenight_sim_for_night(self):
152-
day_obs = "2025-03-25"
152+
day_obs = "2025-04-25"
153153
max_simulation_age = int(np.ceil(Time.now().mjd - Time(day_obs).mjd)) + 1
154154
visits = fetch_latest_prenight_sim_for_nights(day_obs, max_simulation_age=max_simulation_age)
155155
assert len(visits) > 0
156156

157157
@unittest.skipIf(not HAVE_LSST_RESOURCES, "No lsst.resources")
158158
def test_fetch_obsloctap_visits(self):
159-
day_obs = "2025-03-25"
159+
day_obs = "2025-04-25"
160160
num_nights = 2
161161
visits = pd.DataFrame(fetch_obsloctap_visits(day_obs, nights=num_nights))
162162
assert np.floor(visits["observationStartMJD"].min() - 0.5) == Time(day_obs).mjd

0 commit comments

Comments
 (0)