diff --git a/notebooks/make_test_schedulers.ipynb b/notebooks/make_test_schedulers.ipynb new file mode 100644 index 00000000..9ce2255d --- /dev/null +++ b/notebooks/make_test_schedulers.ipynb @@ -0,0 +1,2117 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "5bd48342-698f-4fa6-bf5a-951034d41f3f", + "metadata": { + "execution": { + "iopub.execute_input": "2023-10-18T17:42:18.128209Z", + "iopub.status.busy": "2023-10-18T17:42:18.127911Z", + "iopub.status.idle": "2023-10-18T17:42:18.130573Z", + "shell.execute_reply": "2023-10-18T17:42:18.130150Z", + "shell.execute_reply.started": "2023-10-18T17:42:18.128195Z" + }, + "tags": [] + }, + "source": [ + "# Create scheduler pickles for testing `schedview`" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "20b7a7e4-a1dd-4703-8830-d64e6c9a7341", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:16.626941Z", + "iopub.status.busy": "2023-11-03T18:16:16.626805Z", + "iopub.status.idle": "2023-11-03T18:16:16.629105Z", + "shell.execute_reply": "2023-11-03T18:16:16.628773Z", + "shell.execute_reply.started": "2023-11-03T18:16:16.626926Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "from collections import namedtuple\n", + "import lzma\n", + "import pickle\n", + "from pathlib import Path\n", + "import warnings" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b89b4ab2-8751-4518-a7dc-db9cb732ac2a", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:16.673620Z", + "iopub.status.busy": "2023-11-03T18:16:16.673478Z", + "iopub.status.idle": "2023-11-03T18:16:18.260824Z", + "shell.execute_reply": "2023-11-03T18:16:18.260372Z", + "shell.execute_reply.started": "2023-11-03T18:16:16.673606Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import pandas as pd\n", + "import healpy as hp\n", + "import rubin_sim\n", + "from astropy.time import Time\n", + "import astropy.units as u\n", + "import astropy.coordinates\n", + "from rubin_sim.scheduler.model_observatory import ModelObservatory\n", + "from rubin_sim.scheduler.surveys.field_survey import FieldSurvey\n", + "from rubin_sim.scheduler.schedulers import CoreScheduler\n", + "import rubin_sim.scheduler.basis_functions as bf\n", + "from rubin_sim.scheduler import sim_runner\n", + "import schedview.collect\n", + "import schedview.compute\n", + "from rubin_sim.utils import survey_start_mjd" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "96800bac-3d6f-4325-ad09-20780c704096", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:18.261917Z", + "iopub.status.busy": "2023-11-03T18:16:18.261723Z", + "iopub.status.idle": "2023-11-03T18:16:18.264418Z", + "shell.execute_reply": "2023-11-03T18:16:18.264003Z", + "shell.execute_reply.started": "2023-11-03T18:16:18.261902Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "SchedulerPickleContent = namedtuple('SchedulerPickleContent', ['scheduler', 'conditions'])" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "1681d2ba-4d80-416b-8dc3-2fdc88ce5fe7", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:18.264988Z", + "iopub.status.busy": "2023-11-03T18:16:18.264869Z", + "iopub.status.idle": "2023-11-03T18:16:21.314544Z", + "shell.execute_reply": "2023-11-03T18:16:21.314044Z", + "shell.execute_reply.started": "2023-11-03T18:16:18.264977Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "mjd_start = survey_start_mjd()\n", + "model_observatory = ModelObservatory(mjd_start=mjd_start)\n", + "nside = model_observatory.nside\n", + "survey_length = (4*u.hour).to(u.day).value" + ] + }, + { + "cell_type": "markdown", + "id": "2713726d-4343-4062-8df1-d904df9f77a8", + "metadata": {}, + "source": [ + "# Create a near-baseline sample scheduler" + ] + }, + { + "cell_type": "markdown", + "id": "d6e32f02-db64-4d1a-b7f2-4ac6aa98bdf2", + "metadata": {}, + "source": [ + "Use the `make_sample_test_data.py` script in `schedview`, found in `util/sample_data`:" + ] + }, + { + "cell_type": "raw", + "id": "01f53ab6-4b7e-4062-974c-89317d47e6ba", + "metadata": {}, + "source": [ + "python ../util/sample_data/make_sample_test_data.py --duration 4 " + ] + }, + { + "cell_type": "markdown", + "id": "c946d51c-8582-4082-81e2-606efaef30a0", + "metadata": {}, + "source": [ + "# Get a production auxtel scheduler" + ] + }, + { + "cell_type": "markdown", + "id": "958df168-c723-4b03-a0cd-29e9f9b108d0", + "metadata": {}, + "source": [ + "Use python `efd_sched.py` script in `schedview`, found in `util`. For example:" + ] + }, + { + "cell_type": "raw", + "id": "6b4f3571-e725-4ae3-8652-cb462515a6be", + "metadata": {}, + "source": [ + "python util/efd_sched.py get '2023-10-11 04:30:16'" + ] + }, + { + "cell_type": "markdown", + "id": "8cbe8c9c-90d3-4fcf-a801-517d4e274e39", + "metadata": {}, + "source": [ + "Note that the date specified is the date the entry was added to the EFD, rather than the date of the pickle itself, so there is some offset. For example, the above command returns the file\n", + "`auxtel_scheduler_2023-10-11T043052.526.p`.\n", + "\n", + "You can use `efd_sched.py` in this command to query for which EFD date corresponds to a given file:\n", + "```\n", + "bash$ python util/efd_sched.py query '2023-10-10' | grep '2023-10-11T04.30.52'\n", + "55\t2023-10-11 04:30:16.625007+00:00\thttps://s3.cp.lsst.org/rubinobs-lfa-cp/Scheduler:2/Scheduler:2/2023/10/10/Scheduler:2_Scheduler:2_2023-10-11T04:30:52.526.p\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "0783496d-c1ad-4d5d-b04d-b6d9b84a8e08", + "metadata": {}, + "source": [ + "# Create schedulers with problems" + ] + }, + { + "cell_type": "markdown", + "id": "83bb41d6-6ad5-4f38-b8e0-acd83c4f8ce0", + "metadata": {}, + "source": [ + "## Introduction\n", + "\n", + "I start by making an example scheduler with two tiers. The first tier is an equatorial survey in with fields every hour, such that there should be fields visible at all times.\n", + "The second tier is a single greed survey (in g) covering the whole sky." + ] + }, + { + "cell_type": "markdown", + "id": "62c36cd9-7b32-48f8-aeea-bf4951555cca", + "metadata": {}, + "source": [ + "## Make some basis functions" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "c4439c24-ba6a-4ca0-9406-df668cf1c507", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:21.315248Z", + "iopub.status.busy": "2023-11-03T18:16:21.315115Z", + "iopub.status.idle": "2023-11-03T18:16:21.318518Z", + "shell.execute_reply": "2023-11-03T18:16:21.318166Z", + "shell.execute_reply.started": "2023-11-03T18:16:21.315235Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "def make_sky_bf_list(band='g', nside=32):\n", + " not_twilight = bf.feasibility_funcs.NotTwilightBasisFunction()\n", + " moon_limit = bf.mask_basis_funcs.MoonAvoidanceBasisFunction(nside=nside, moon_distance=30.0)\n", + " zenith_limit = bf.mask_basis_funcs.ZenithShadowMaskBasisFunction(nside=nside, min_alt=20.0, max_alt=82.0)\n", + " sky_brightness_limit = bf.basis_functions.SkybrightnessLimitBasisFunction(nside=nside, filtername=band, sbmin=18.5, sbmax=30)\n", + " wind_limit = bf.basis_functions.AvoidDirectWind(5)\n", + " m5diff = bf.basis_functions.M5DiffBasisFunction(filtername=band, nside=nside)\n", + " basis_functions = [\n", + " not_twilight,\n", + " moon_limit,\n", + " zenith_limit,\n", + " sky_brightness_limit,\n", + " wind_limit,\n", + " m5diff\n", + " ]\n", + " return basis_functions" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "2bb70e9d-925a-477f-b304-f5195986f124", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:21.319755Z", + "iopub.status.busy": "2023-11-03T18:16:21.319517Z", + "iopub.status.idle": "2023-11-03T18:16:21.322952Z", + "shell.execute_reply": "2023-11-03T18:16:21.322614Z", + "shell.execute_reply.started": "2023-11-03T18:16:21.319741Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "def make_field_bf_list(ra, decl, band='g', nside=32):\n", + " basis_functions = make_sky_bf_list(band=band, nside=nside)\n", + " basis_functions.append(bf.feasibility_funcs.HourAngleLimitBasisFunction(RA=ra, ha_limits=[[22,24], [0,2]]))\n", + " return basis_functions" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "62f9d5d0-4dc8-4c4f-b2f5-524458268250", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:21.323497Z", + "iopub.status.busy": "2023-11-03T18:16:21.323378Z", + "iopub.status.idle": "2023-11-03T18:16:21.328240Z", + "shell.execute_reply": "2023-11-03T18:16:21.327911Z", + "shell.execute_reply.started": "2023-11-03T18:16:21.323485Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "def make_field_survey(ra, decl, band='g', nside=32):\n", + " basis_functions = make_field_bf_list(ra, decl, band=band, nside=nside)\n", + " sequence = band\n", + " nvis = [1]*len(band)\n", + " survey_name = f\"field_{ra}_{'n' if decl<0 else 'p'}{np.abs(decl)}_{band}\"\n", + " survey = FieldSurvey(basis_functions, np.array([ra]), np.array([decl]), sequence=sequence, nvis=nvis, nside=nside, survey_name=survey_name, reward_value=1.0)\n", + " return survey" + ] + }, + { + "cell_type": "markdown", + "id": "c9930fb1-3e1e-4739-b086-ba7f5d8ad805", + "metadata": {}, + "source": [ + "## Make an equatorial survey in g" + ] + }, + { + "cell_type": "markdown", + "id": "dcee9fd3-d10c-4461-82ef-215519700d71", + "metadata": {}, + "source": [ + "Start by making a list of field surveys in g on the equator, with fields spaced every hour (15 degrees):" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "a24c465e-719c-498e-942f-190dc604946d", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:21.328819Z", + "iopub.status.busy": "2023-11-03T18:16:21.328703Z", + "iopub.status.idle": "2023-11-03T18:16:21.414672Z", + "shell.execute_reply": "2023-11-03T18:16:21.414184Z", + "shell.execute_reply.started": "2023-11-03T18:16:21.328807Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "decl = 0\n", + "band = 'g'\n", + "field_surveys = [make_field_survey(ra, decl, band, nside) for ra in range(0, 360, 15)]" + ] + }, + { + "cell_type": "markdown", + "id": "3cb0b075-c16f-46c0-b17d-5f3e8cb9c9da", + "metadata": {}, + "source": [ + "As a fallback, greate a greedy survey in g that covers the whole sky:" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "cf7a6c39-a974-472f-92bd-c26f6e48facf", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:21.415425Z", + "iopub.status.busy": "2023-11-03T18:16:21.415276Z", + "iopub.status.idle": "2023-11-03T18:16:21.658354Z", + "shell.execute_reply": "2023-11-03T18:16:21.657835Z", + "shell.execute_reply.started": "2023-11-03T18:16:21.415411Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "sky_basis_functions = make_sky_bf_list(band=band, nside=nside)\n", + "weights = [1] * len(sky_basis_functions)\n", + "greedy_surveys = [rubin_sim.scheduler.surveys.surveys.GreedySurvey(sky_basis_functions, weights, filtername=band, survey_name=f\"greedy_{band}\")]" + ] + }, + { + "cell_type": "markdown", + "id": "524082a6-885e-4c29-a80e-301bf7a1e2c0", + "metadata": {}, + "source": [ + "Actually create the scheduler:" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "dce7eaf9-dc00-4a27-8810-5dfc2984b1df", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:21.659063Z", + "iopub.status.busy": "2023-11-03T18:16:21.658937Z", + "iopub.status.idle": "2023-11-03T18:16:21.673953Z", + "shell.execute_reply": "2023-11-03T18:16:21.673607Z", + "shell.execute_reply.started": "2023-11-03T18:16:21.659050Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "scheduler = CoreScheduler([field_surveys, greedy_surveys], nside=nside)" + ] + }, + { + "cell_type": "markdown", + "id": "c80e31a6-8372-4617-b21a-16457aab0716", + "metadata": {}, + "source": [ + "Configure the scheduler to keep reward values:" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "a9351e92-5106-4209-b3dc-be8312fe4c9b", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:21.674538Z", + "iopub.status.busy": "2023-11-03T18:16:21.674424Z", + "iopub.status.idle": "2023-11-03T18:16:21.676346Z", + "shell.execute_reply": "2023-11-03T18:16:21.676018Z", + "shell.execute_reply.started": "2023-11-03T18:16:21.674527Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "scheduler.keep_rewards = True" + ] + }, + { + "cell_type": "markdown", + "id": "de8c1752-464d-41c0-b81d-ff18f7c1beb5", + "metadata": {}, + "source": [ + "Actually run the survey for a little bit:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "a74d2196-eaf5-4177-ae91-3db2a30504b1", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:16:21.676937Z", + "iopub.status.busy": "2023-11-03T18:16:21.676801Z", + "iopub.status.idle": "2023-11-03T18:17:07.197342Z", + "shell.execute_reply": "2023-11-03T18:17:07.196876Z", + "shell.execute_reply.started": "2023-11-03T18:16:21.676926Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "progress = 75.46%Skipped 0 observations\n", + "Flushed 0 observations from queue for being stale\n", + "Completed 397 observations\n", + "ran in 0 min = 0.0 hours\n" + ] + } + ], + "source": [ + "observatory, scheduler, observations, reward_df, obs_rewards = sim_runner(\n", + " model_observatory,\n", + " scheduler,\n", + " mjd_start=mjd_start,\n", + " survey_length=survey_length,\n", + " record_rewards=True,\n", + ")\n", + "conditions = scheduler.conditions" + ] + }, + { + "cell_type": "markdown", + "id": "ff53fd9a-cc46-4fd9-ac90-7b1ff7f120d6", + "metadata": {}, + "source": [ + "Save the survey:" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "78a9f360-0aea-4964-8e32-a95d1b56a8ba", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:07.198055Z", + "iopub.status.busy": "2023-11-03T18:17:07.197925Z", + "iopub.status.idle": "2023-11-03T18:17:08.218313Z", + "shell.execute_reply": "2023-11-03T18:17:08.217845Z", + "shell.execute_reply.started": "2023-11-03T18:17:07.198042Z" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "PosixPath('/sdf/data/rubin/user/neilsen/devel/schedview/tmp/eq_field_survey_v0.p.xz')" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "output_tuple = (scheduler, conditions)\n", + "fname = Path('../tmp/eq_field_survey_v0.p.xz').resolve()\n", + "with lzma.open(fname, 'wb') as sched_out:\n", + " pickle.dump(output_tuple, sched_out)\n", + "\n", + "fname" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "657d3bc7-f77f-4911-b0b8-705437fd5f0c", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:08.219030Z", + "iopub.status.busy": "2023-11-03T18:17:08.218902Z", + "iopub.status.idle": "2023-11-03T18:17:08.222049Z", + "shell.execute_reply": "2023-11-03T18:17:08.221699Z", + "shell.execute_reply.started": "2023-11-03T18:17:08.219018Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Conditions calculated for 2025-05-01 03:59:35.041 (mjd 60796.16637779371)\n" + ] + } + ], + "source": [ + "print(f\"Conditions calculated for {Time(conditions.mjd[0], format='mjd').iso} (mjd {conditions.mjd[0]})\")" + ] + }, + { + "cell_type": "markdown", + "id": "e919e900-edcd-4c44-948a-3a9b8e9d9458", + "metadata": {}, + "source": [ + "Take a look at one survey:" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "2b17dabd-fb8c-41e5-8306-e5a1314c62a6", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:08.223858Z", + "iopub.status.busy": "2023-11-03T18:17:08.223739Z", + "iopub.status.idle": "2023-11-03T18:17:08.610341Z", + "shell.execute_reply": "2023-11-03T18:17:08.609937Z", + "shell.execute_reply.started": "2023-11-03T18:17:08.223847Z" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
basis_functionbasis_function_classfeasiblemax_basis_rewardbasis_areabasis_weightmax_accum_rewardaccum_areatier_labelsurvey_labelsurvey_classsurvey_reward
list_indexsurvey_index
01NotTwilightNotTwilightBasisFunctionTrue0.03.3571750.1428570.00000041252.961249tier 0field_15_p0_gFieldSurvey-inf
1MoonAvoidanceMoonAvoidanceBasisFunctionTrue1.03.3571750.1428570.14285741252.961249tier 0field_15_p0_gFieldSurvey-inf
1ZenithShadowMaskZenithShadowMaskBasisFunctionFalse-inf0.0000000.142857-inf0.000000tier 0field_15_p0_gFieldSurvey-inf
1SkybrightnessLimit gSkybrightnessLimitBasisFunctionFalse-inf0.0000000.142857-inf0.000000tier 0field_15_p0_gFieldSurvey-inf
1AvoidDirectWindAvoidDirectWindTrue0.03.3571750.142857-inf0.000000tier 0field_15_p0_gFieldSurvey-inf
1M5Diff gM5DiffBasisFunctionFalse-inf0.0000000.142857-inf0.000000tier 0field_15_p0_gFieldSurvey-inf
1HourAngleLimitHourAngleLimitBasisFunctionFalse-inf3.3571750.142857-inf0.000000tier 0field_15_p0_gFieldSurvey-inf
\n", + "
" + ], + "text/plain": [ + " basis_function \\\n", + "list_index survey_index \n", + "0 1 NotTwilight \n", + " 1 MoonAvoidance \n", + " 1 ZenithShadowMask \n", + " 1 SkybrightnessLimit g \n", + " 1 AvoidDirectWind \n", + " 1 M5Diff g \n", + " 1 HourAngleLimit \n", + "\n", + " basis_function_class feasible \\\n", + "list_index survey_index \n", + "0 1 NotTwilightBasisFunction True \n", + " 1 MoonAvoidanceBasisFunction True \n", + " 1 ZenithShadowMaskBasisFunction False \n", + " 1 SkybrightnessLimitBasisFunction False \n", + " 1 AvoidDirectWind True \n", + " 1 M5DiffBasisFunction False \n", + " 1 HourAngleLimitBasisFunction False \n", + "\n", + " max_basis_reward basis_area basis_weight \\\n", + "list_index survey_index \n", + "0 1 0.0 3.357175 0.142857 \n", + " 1 1.0 3.357175 0.142857 \n", + " 1 -inf 0.000000 0.142857 \n", + " 1 -inf 0.000000 0.142857 \n", + " 1 0.0 3.357175 0.142857 \n", + " 1 -inf 0.000000 0.142857 \n", + " 1 -inf 3.357175 0.142857 \n", + "\n", + " max_accum_reward accum_area tier_label \\\n", + "list_index survey_index \n", + "0 1 0.000000 41252.961249 tier 0 \n", + " 1 0.142857 41252.961249 tier 0 \n", + " 1 -inf 0.000000 tier 0 \n", + " 1 -inf 0.000000 tier 0 \n", + " 1 -inf 0.000000 tier 0 \n", + " 1 -inf 0.000000 tier 0 \n", + " 1 -inf 0.000000 tier 0 \n", + "\n", + " survey_label survey_class survey_reward \n", + "list_index survey_index \n", + "0 1 field_15_p0_g FieldSurvey -inf \n", + " 1 field_15_p0_g FieldSurvey -inf \n", + " 1 field_15_p0_g FieldSurvey -inf \n", + " 1 field_15_p0_g FieldSurvey -inf \n", + " 1 field_15_p0_g FieldSurvey -inf \n", + " 1 field_15_p0_g FieldSurvey -inf \n", + " 1 field_15_p0_g FieldSurvey -inf " + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scheduler_reward_df = scheduler.make_reward_df(conditions, accum=True)\n", + "scheduler_reward_df.loc[(0,1),:]" + ] + }, + { + "cell_type": "markdown", + "id": "37e0c383-74f5-4148-9afa-eeff4b28f22d", + "metadata": {}, + "source": [ + "Take a look at the rewards for all surveys." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "bc30a69b-7800-40a9-b18c-4e6ae1657f52", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:08.611015Z", + "iopub.status.busy": "2023-11-03T18:17:08.610884Z", + "iopub.status.idle": "2023-11-03T18:17:08.644065Z", + "shell.execute_reply": "2023-11-03T18:17:08.643716Z", + "shell.execute_reply.started": "2023-11-03T18:17:08.611003Z" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
list_indexsurvey_indexsurvey_name_with_idsurvey_urltierreward
0000: field_0_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
1011: field_15_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
2022: field_30_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
3033: field_45_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
4044: field_60_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
5055: field_75_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
6066: field_90_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0MoonAvoidance, ZenithShadowMask, Skybrightness...
7077: field_105_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
8088: field_120_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
9099: field_135_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
1001010: field_150_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0HourAngleLimit
1101111: field_165_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0HourAngleLimit
1201212: field_180_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 00.467255
1301313: field_195_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 00.480597
1401414: field_210_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 00.482711
1501515: field_225_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 00.474278
1601616: field_240_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0HourAngleLimit
1701717: field_255_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0HourAngleLimit
1801818: field_270_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0SkybrightnessLimit g, M5Diff g, HourAngleLimit
1901919: field_285_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
2002020: field_300_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
2102121: field_315_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
2202222: field_330_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
2302323: field_345_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
\n", + "
" + ], + "text/plain": [ + " list_index survey_index survey_name_with_id \\\n", + "0 0 0 0: field_0_p0_g \n", + "1 0 1 1: field_15_p0_g \n", + "2 0 2 2: field_30_p0_g \n", + "3 0 3 3: field_45_p0_g \n", + "4 0 4 4: field_60_p0_g \n", + "5 0 5 5: field_75_p0_g \n", + "6 0 6 6: field_90_p0_g \n", + "7 0 7 7: field_105_p0_g \n", + "8 0 8 8: field_120_p0_g \n", + "9 0 9 9: field_135_p0_g \n", + "10 0 10 10: field_150_p0_g \n", + "11 0 11 11: field_165_p0_g \n", + "12 0 12 12: field_180_p0_g \n", + "13 0 13 13: field_195_p0_g \n", + "14 0 14 14: field_210_p0_g \n", + "15 0 15 15: field_225_p0_g \n", + "16 0 16 16: field_240_p0_g \n", + "17 0 17 17: field_255_p0_g \n", + "18 0 18 18: field_270_p0_g \n", + "19 0 19 19: field_285_p0_g \n", + "20 0 20 20: field_300_p0_g \n", + "21 0 21 21: field_315_p0_g \n", + "22 0 22 22: field_330_p0_g \n", + "23 0 23 23: field_345_p0_g \n", + "\n", + " survey_url tier \\\n", + "0 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "1 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "2 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "3 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "4 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "5 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "6 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "7 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "8 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "9 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "10 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "11 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "12 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "13 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "14 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "15 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "16 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "17 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "18 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "19 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "20 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "21 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "22 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "23 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "\n", + " reward \n", + "0 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "1 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "2 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "3 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "4 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "5 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "6 MoonAvoidance, ZenithShadowMask, Skybrightness... \n", + "7 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "8 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "9 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "10 HourAngleLimit \n", + "11 HourAngleLimit \n", + "12 0.467255 \n", + "13 0.480597 \n", + "14 0.482711 \n", + "15 0.474278 \n", + "16 HourAngleLimit \n", + "17 HourAngleLimit \n", + "18 SkybrightnessLimit g, M5Diff g, HourAngleLimit \n", + "19 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "20 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "21 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "22 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "23 ZenithShadowMask, SkybrightnessLimit g, M5Diff... " + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scheduler_summary_df = schedview.compute.make_scheduler_summary_df(scheduler, conditions, scheduler_reward_df)\n", + "scheduler_summary_df.query('tier==\"tier 0\"')" + ] + }, + { + "cell_type": "markdown", + "id": "f06b17b2-6f1f-4cca-95ac-220dbb22e945", + "metadata": {}, + "source": [ + "# Make a survey where everything is infeasible" + ] + }, + { + "cell_type": "markdown", + "id": "78145a0a-7990-45bc-afe7-527b492d5b76", + "metadata": {}, + "source": [ + "Create a combination of survey and conditions where everything is infeasible, blocked either by wind or by sky brightess, but where there are observations not blocked by both.\n", + "\n", + "The first full moon after the nominal survey start is 2025-05-12. This should be in the default limited sky brightness data set." + ] + }, + { + "cell_type": "markdown", + "id": "856f1e9b-8a81-410b-b7da-cd348f912cba", + "metadata": {}, + "source": [ + "Find the next full moon after the start of the survey:" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "81baec26-7670-4992-8db6-0408d49a2004", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:08.644718Z", + "iopub.status.busy": "2023-11-03T18:17:08.644596Z", + "iopub.status.idle": "2023-11-03T18:17:08.661006Z", + "shell.execute_reply": "2023-11-03T18:17:08.660658Z", + "shell.execute_reply.started": "2023-11-03T18:17:08.644706Z" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "'2025-05-13 00:00:00.000'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "month_mjds = np.arange(int(mjd_start), int(mjd_start)+30)\n", + "month_phases = np.array([model_observatory.almanac.get_sun_moon_positions(mjd)['moon_phase'] for mjd in month_mjds])\n", + "mjd = month_mjds[np.argmax(month_phases)]\n", + "Time(mjd, format='mjd').iso" + ] + }, + { + "cell_type": "markdown", + "id": "d3b3763c-45ca-4064-a09c-2105793772b6", + "metadata": {}, + "source": [ + "Find a time during the night where the moon is at a zd of about 55 degrees." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "4e38e507-c9b5-4672-a98d-77ec46666140", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:08.661771Z", + "iopub.status.busy": "2023-11-03T18:17:08.661531Z", + "iopub.status.idle": "2023-11-03T18:17:08.671460Z", + "shell.execute_reply": "2023-11-03T18:17:08.671086Z", + "shell.execute_reply.started": "2023-11-03T18:17:08.661758Z" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/plain": [ + "('2025-05-13 02:06:31.806', 60808.08786812174)" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sunset_info = model_observatory.almanac.get_sunset_info(mjd)\n", + "sunset, sunrise = sunset_info[3], sunset_info[4]\n", + "for mjd in np.arange(sunset, sunrise, 1.0/(24*4)):\n", + " moon_alt = model_observatory.almanac.get_sun_moon_positions(mjd)['moon_alt']\n", + " if np.abs(np.degrees(moon_alt)-55) < 5:\n", + " break\n", + "\n", + "time_to_sched = Time(mjd, format='mjd')\n", + "time_to_sched.iso, mjd" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "6e222897-5a42-4cbd-a58b-e28c93cf04c5", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:08.672006Z", + "iopub.status.busy": "2023-11-03T18:17:08.671891Z", + "iopub.status.idle": "2023-11-03T18:17:08.673956Z", + "shell.execute_reply": "2023-11-03T18:17:08.673632Z", + "shell.execute_reply.started": "2023-11-03T18:17:08.671996Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "model_observatory.mjd = time_to_sched.mjd" + ] + }, + { + "cell_type": "markdown", + "id": "7d069d75-3b17-4fc5-9dc9-c61fa6322ca3", + "metadata": {}, + "source": [ + "Set the wind so it comes from the opposite direction." + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "f842487e-c53d-4c43-a4f3-1a160c682496", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:08.674564Z", + "iopub.status.busy": "2023-11-03T18:17:08.674452Z", + "iopub.status.idle": "2023-11-03T18:17:08.677747Z", + "shell.execute_reply": "2023-11-03T18:17:08.677408Z", + "shell.execute_reply.started": "2023-11-03T18:17:08.674553Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "moon_az = model_observatory.almanac.get_sun_moon_positions(time_to_sched.mjd)['moon_az']\n", + "wind_az = moon_az - np.pi ;# opposite moon\n", + "wind_data = rubin_sim.site_models.ConstantWindData(wind_speed=18.0, wind_direction=wind_az)\n", + "model_observatory.wind_data = wind_data" + ] + }, + { + "cell_type": "markdown", + "id": "7e8dd32f-e7f2-47e6-b463-0b0cc4909a54", + "metadata": {}, + "source": [ + "Actually build our instance of Conditions:" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "b3b3707d-1b43-4213-98d6-6f86b01a64d6", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:08.678309Z", + "iopub.status.busy": "2023-11-03T18:17:08.678189Z", + "iopub.status.idle": "2023-11-03T18:17:12.477163Z", + "shell.execute_reply": "2023-11-03T18:17:12.476679Z", + "shell.execute_reply.started": "2023-11-03T18:17:08.678298Z" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "conditions = model_observatory.return_conditions()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "775f7e96-2a26-46d0-8284-47867ed7feea", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:12.477893Z", + "iopub.status.busy": "2023-11-03T18:17:12.477772Z", + "iopub.status.idle": "2023-11-03T18:17:12.927662Z", + "shell.execute_reply": "2023-11-03T18:17:12.927231Z", + "shell.execute_reply.started": "2023-11-03T18:17:12.477881Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/sdf/data/rubin/user/neilsen/devel/rubin_sim/rubin_sim/scheduler/schedulers/core_scheduler.py:547: RuntimeWarning: All-NaN axis encountered\n", + " survey_df[\"survey_reward\"] = np.nanmax(survey.calc_reward_function(conditions))\n", + "/sdf/data/rubin/user/neilsen/devel/rubin_sim/rubin_sim/scheduler/schedulers/core_scheduler.py:547: RuntimeWarning: All-NaN axis encountered\n", + " survey_df[\"survey_reward\"] = np.nanmax(survey.calc_reward_function(conditions))\n", + "/sdf/data/rubin/user/neilsen/devel/rubin_sim/rubin_sim/scheduler/schedulers/core_scheduler.py:547: RuntimeWarning: All-NaN axis encountered\n", + " survey_df[\"survey_reward\"] = np.nanmax(survey.calc_reward_function(conditions))\n", + "/sdf/data/rubin/user/neilsen/devel/rubin_sim/rubin_sim/scheduler/schedulers/core_scheduler.py:547: RuntimeWarning: All-NaN axis encountered\n", + " survey_df[\"survey_reward\"] = np.nanmax(survey.calc_reward_function(conditions))\n", + "/sdf/data/rubin/user/neilsen/devel/rubin_sim/rubin_sim/scheduler/schedulers/core_scheduler.py:547: RuntimeWarning: All-NaN slice encountered\n", + " survey_df[\"survey_reward\"] = np.nanmax(survey.calc_reward_function(conditions))\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
basis_functionbasis_function_classfeasiblemax_basis_rewardbasis_areabasis_weightmax_accum_rewardaccum_areatier_labelsurvey_labelsurvey_classsurvey_reward
list_indexsurvey_index
00NotTwilightNotTwilightBasisFunctionTrue0.0000003.3571750.1428570.00000041252.961249tier 0field_0_p0_gFieldSurvey-inf
0MoonAvoidanceMoonAvoidanceBasisFunctionTrue1.0000003.3571750.1428570.14285741252.961249tier 0field_0_p0_gFieldSurvey-inf
0ZenithShadowMaskZenithShadowMaskBasisFunctionFalse-inf0.0000000.142857-inf0.000000tier 0field_0_p0_gFieldSurvey-inf
0SkybrightnessLimit gSkybrightnessLimitBasisFunctionFalse-inf0.0000000.142857-inf0.000000tier 0field_0_p0_gFieldSurvey-inf
0AvoidDirectWindAvoidDirectWindTrue-52.6448173.3571750.142857-inf0.000000tier 0field_0_p0_gFieldSurvey-inf
..........................................
10MoonAvoidanceMoonAvoidanceBasisFunctionTrue1.00000038483.2922201.0000001.00000038483.292220tier 1greedy_gGreedySurveyNaN
0ZenithShadowMaskZenithShadowMaskBasisFunctionTrue1.00000013334.6974351.0000002.00000010601.957326tier 1greedy_gGreedySurveyNaN
0SkybrightnessLimit gSkybrightnessLimitBasisFunctionTrue1.0000002141.8773831.0000003.0000002141.877383tier 1greedy_gGreedySurveyNaN
0AvoidDirectWindAvoidDirectWindTrue-0.00020124329.4441871.000000-inf0.000000tier 1greedy_gGreedySurveyNaN
0M5Diff gM5DiffBasisFunctionTrue-1.63477312045.5423961.000000-inf0.000000tier 1greedy_gGreedySurveyNaN
\n", + "

174 rows × 12 columns

\n", + "
" + ], + "text/plain": [ + " basis_function \\\n", + "list_index survey_index \n", + "0 0 NotTwilight \n", + " 0 MoonAvoidance \n", + " 0 ZenithShadowMask \n", + " 0 SkybrightnessLimit g \n", + " 0 AvoidDirectWind \n", + "... ... \n", + "1 0 MoonAvoidance \n", + " 0 ZenithShadowMask \n", + " 0 SkybrightnessLimit g \n", + " 0 AvoidDirectWind \n", + " 0 M5Diff g \n", + "\n", + " basis_function_class feasible \\\n", + "list_index survey_index \n", + "0 0 NotTwilightBasisFunction True \n", + " 0 MoonAvoidanceBasisFunction True \n", + " 0 ZenithShadowMaskBasisFunction False \n", + " 0 SkybrightnessLimitBasisFunction False \n", + " 0 AvoidDirectWind True \n", + "... ... ... \n", + "1 0 MoonAvoidanceBasisFunction True \n", + " 0 ZenithShadowMaskBasisFunction True \n", + " 0 SkybrightnessLimitBasisFunction True \n", + " 0 AvoidDirectWind True \n", + " 0 M5DiffBasisFunction True \n", + "\n", + " max_basis_reward basis_area basis_weight \\\n", + "list_index survey_index \n", + "0 0 0.000000 3.357175 0.142857 \n", + " 0 1.000000 3.357175 0.142857 \n", + " 0 -inf 0.000000 0.142857 \n", + " 0 -inf 0.000000 0.142857 \n", + " 0 -52.644817 3.357175 0.142857 \n", + "... ... ... ... \n", + "1 0 1.000000 38483.292220 1.000000 \n", + " 0 1.000000 13334.697435 1.000000 \n", + " 0 1.000000 2141.877383 1.000000 \n", + " 0 -0.000201 24329.444187 1.000000 \n", + " 0 -1.634773 12045.542396 1.000000 \n", + "\n", + " max_accum_reward accum_area tier_label \\\n", + "list_index survey_index \n", + "0 0 0.000000 41252.961249 tier 0 \n", + " 0 0.142857 41252.961249 tier 0 \n", + " 0 -inf 0.000000 tier 0 \n", + " 0 -inf 0.000000 tier 0 \n", + " 0 -inf 0.000000 tier 0 \n", + "... ... ... ... \n", + "1 0 1.000000 38483.292220 tier 1 \n", + " 0 2.000000 10601.957326 tier 1 \n", + " 0 3.000000 2141.877383 tier 1 \n", + " 0 -inf 0.000000 tier 1 \n", + " 0 -inf 0.000000 tier 1 \n", + "\n", + " survey_label survey_class survey_reward \n", + "list_index survey_index \n", + "0 0 field_0_p0_g FieldSurvey -inf \n", + " 0 field_0_p0_g FieldSurvey -inf \n", + " 0 field_0_p0_g FieldSurvey -inf \n", + " 0 field_0_p0_g FieldSurvey -inf \n", + " 0 field_0_p0_g FieldSurvey -inf \n", + "... ... ... ... \n", + "1 0 greedy_g GreedySurvey NaN \n", + " 0 greedy_g GreedySurvey NaN \n", + " 0 greedy_g GreedySurvey NaN \n", + " 0 greedy_g GreedySurvey NaN \n", + " 0 greedy_g GreedySurvey NaN \n", + "\n", + "[174 rows x 12 columns]" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scheduler.make_reward_df(conditions, accum=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "76205852-dfba-4061-a1f0-d167255ffe3f", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:12.928383Z", + "iopub.status.busy": "2023-11-03T18:17:12.928241Z", + "iopub.status.idle": "2023-11-03T18:17:13.382555Z", + "shell.execute_reply": "2023-11-03T18:17:13.382136Z", + "shell.execute_reply.started": "2023-11-03T18:17:12.928370Z" + }, + "tags": [] + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/sdf/data/rubin/user/neilsen/devel/rubin_sim/rubin_sim/scheduler/schedulers/core_scheduler.py:547: RuntimeWarning: All-NaN axis encountered\n", + " survey_df[\"survey_reward\"] = np.nanmax(survey.calc_reward_function(conditions))\n", + "/sdf/data/rubin/user/neilsen/devel/rubin_sim/rubin_sim/scheduler/schedulers/core_scheduler.py:547: RuntimeWarning: All-NaN axis encountered\n", + " survey_df[\"survey_reward\"] = np.nanmax(survey.calc_reward_function(conditions))\n", + "/sdf/data/rubin/user/neilsen/devel/rubin_sim/rubin_sim/scheduler/schedulers/core_scheduler.py:547: RuntimeWarning: All-NaN axis encountered\n", + " survey_df[\"survey_reward\"] = np.nanmax(survey.calc_reward_function(conditions))\n", + "/sdf/data/rubin/user/neilsen/devel/rubin_sim/rubin_sim/scheduler/schedulers/core_scheduler.py:547: RuntimeWarning: All-NaN axis encountered\n", + " survey_df[\"survey_reward\"] = np.nanmax(survey.calc_reward_function(conditions))\n", + "/sdf/data/rubin/user/neilsen/devel/rubin_sim/rubin_sim/scheduler/schedulers/core_scheduler.py:547: RuntimeWarning: All-NaN slice encountered\n", + " survey_df[\"survey_reward\"] = np.nanmax(survey.calc_reward_function(conditions))\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
list_indexsurvey_indexsurvey_name_with_idsurvey_urltierreward
0000: field_0_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
1011: field_15_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
2022: field_30_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, AvoidD...
3033: field_45_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, AvoidD...
4044: field_60_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, AvoidD...
5055: field_75_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, AvoidD...
6066: field_90_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, AvoidD...
7077: field_105_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, AvoidD...
8088: field_120_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, AvoidD...
9099: field_135_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0SkybrightnessLimit g, AvoidDirectWind, HourAng...
1001010: field_150_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0AvoidDirectWind, HourAngleLimit
1101111: field_165_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0AvoidDirectWind
1201212: field_180_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0SkybrightnessLimit g, AvoidDirectWind
1301313: field_195_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0SkybrightnessLimit g
1401414: field_210_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0SkybrightnessLimit g
1501515: field_225_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0MoonAvoidance, SkybrightnessLimit g, HourAngle...
1601616: field_240_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0MoonAvoidance, SkybrightnessLimit g, HourAngle...
1701717: field_255_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0SkybrightnessLimit g, M5Diff g, HourAngleLimit
1801818: field_270_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
1901919: field_285_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
2002020: field_300_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
2102121: field_315_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
2202222: field_330_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
2302323: field_345_p0_ghttps://rubin-sim.lsst.io/api/FieldSurvey.html...tier 0ZenithShadowMask, SkybrightnessLimit g, M5Diff...
24100: greedy_ghttps://rubin-sim.lsst.io/api/GreedySurvey.htm...tier 1-inf
\n", + "
" + ], + "text/plain": [ + " list_index survey_index survey_name_with_id \\\n", + "0 0 0 0: field_0_p0_g \n", + "1 0 1 1: field_15_p0_g \n", + "2 0 2 2: field_30_p0_g \n", + "3 0 3 3: field_45_p0_g \n", + "4 0 4 4: field_60_p0_g \n", + "5 0 5 5: field_75_p0_g \n", + "6 0 6 6: field_90_p0_g \n", + "7 0 7 7: field_105_p0_g \n", + "8 0 8 8: field_120_p0_g \n", + "9 0 9 9: field_135_p0_g \n", + "10 0 10 10: field_150_p0_g \n", + "11 0 11 11: field_165_p0_g \n", + "12 0 12 12: field_180_p0_g \n", + "13 0 13 13: field_195_p0_g \n", + "14 0 14 14: field_210_p0_g \n", + "15 0 15 15: field_225_p0_g \n", + "16 0 16 16: field_240_p0_g \n", + "17 0 17 17: field_255_p0_g \n", + "18 0 18 18: field_270_p0_g \n", + "19 0 19 19: field_285_p0_g \n", + "20 0 20 20: field_300_p0_g \n", + "21 0 21 21: field_315_p0_g \n", + "22 0 22 22: field_330_p0_g \n", + "23 0 23 23: field_345_p0_g \n", + "24 1 0 0: greedy_g \n", + "\n", + " survey_url tier \\\n", + "0 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "1 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "2 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "3 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "4 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "5 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "6 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "7 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "8 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "9 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "10 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "11 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "12 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "13 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "14 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "15 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "16 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "17 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "18 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "19 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "20 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "21 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "22 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "23 https://rubin-sim.lsst.io/api/FieldSurvey.html... tier 0 \n", + "24 https://rubin-sim.lsst.io/api/GreedySurvey.htm... tier 1 \n", + "\n", + " reward \n", + "0 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "1 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "2 ZenithShadowMask, SkybrightnessLimit g, AvoidD... \n", + "3 ZenithShadowMask, SkybrightnessLimit g, AvoidD... \n", + "4 ZenithShadowMask, SkybrightnessLimit g, AvoidD... \n", + "5 ZenithShadowMask, SkybrightnessLimit g, AvoidD... \n", + "6 ZenithShadowMask, SkybrightnessLimit g, AvoidD... \n", + "7 ZenithShadowMask, SkybrightnessLimit g, AvoidD... \n", + "8 ZenithShadowMask, SkybrightnessLimit g, AvoidD... \n", + "9 SkybrightnessLimit g, AvoidDirectWind, HourAng... \n", + "10 AvoidDirectWind, HourAngleLimit \n", + "11 AvoidDirectWind \n", + "12 SkybrightnessLimit g, AvoidDirectWind \n", + "13 SkybrightnessLimit g \n", + "14 SkybrightnessLimit g \n", + "15 MoonAvoidance, SkybrightnessLimit g, HourAngle... \n", + "16 MoonAvoidance, SkybrightnessLimit g, HourAngle... \n", + "17 SkybrightnessLimit g, M5Diff g, HourAngleLimit \n", + "18 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "19 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "20 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "21 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "22 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "23 ZenithShadowMask, SkybrightnessLimit g, M5Diff... \n", + "24 -inf " + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "schedview.compute.make_scheduler_summary_df(scheduler, conditions)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "8896369f-8935-4839-aeec-1153cda52712", + "metadata": { + "execution": { + "iopub.execute_input": "2023-11-03T18:17:13.383284Z", + "iopub.status.busy": "2023-11-03T18:17:13.383155Z", + "iopub.status.idle": "2023-11-03T18:17:14.704012Z", + "shell.execute_reply": "2023-11-03T18:17:14.703588Z", + "shell.execute_reply.started": "2023-11-03T18:17:13.383272Z" + } + }, + "outputs": [ + { + "data": { + "text/plain": [ + "PosixPath('/sdf/data/rubin/user/neilsen/devel/schedview/tmp/eq_field_survey_v0_infeasible1.p.xz')" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "output_tuple = (scheduler, conditions)\n", + "fname = Path('../tmp/eq_field_survey_v0_infeasible1.p.xz').resolve()\n", + "with lzma.open(fname, 'wb') as sched_out:\n", + " pickle.dump(output_tuple, sched_out)\n", + "\n", + "fname" + ] + }, + { + "cell_type": "markdown", + "id": "22e7c644-493d-4e3b-be0f-69eda97b243f", + "metadata": {}, + "source": [ + "# Making pickles available" + ] + }, + { + "cell_type": "markdown", + "id": "46e78665-64db-42ca-a26f-aae401dad7d7", + "metadata": {}, + "source": [ + "Copy them to `/sdf/group/rubin/web_data/sim-data/sched_pickles` at the USDF for them to be visible at https://s3df.slac.stanford.edu/data/rubin/sim-data/sched_pickles" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0993d5ce-3f0a-4827-841d-c90b223ada1b", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "ehn311", + "language": "python", + "name": "ehn311" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/util/sample_data/make_sample_test_data.py b/util/sample_data/make_sample_test_data.py index 589543c9..b8eff481 100644 --- a/util/sample_data/make_sample_test_data.py +++ b/util/sample_data/make_sample_test_data.py @@ -74,6 +74,12 @@ def make_sample_test_data(): default=DEFAULT_DATE, help="Date of the night to simulate (YYYY-MM-DD).", ) + parser.add_argument( + "--duration", + type=int, + default=None, + help="The number of hours to simulate (defaults to one night).", + ) args = parser.parse_args() opsim_output_fname = args.opsim_output_fname @@ -104,7 +110,10 @@ def make_sample_test_data(): mjd_start = observatory.almanac.sunsets[this_night]["sun_n12_setting"][0] mjd_end = observatory.almanac.sunsets[this_night]["sunrise"][0] - night_duration = mjd_end - mjd_start + if args.duration is not None: + duration = args.duration / 24.0 + else: + duration = mjd_end - mjd_start observatory = ModelObservatory(mjd_start=mjd_start) @@ -115,7 +124,7 @@ def make_sample_test_data(): observatory, scheduler, mjd_start=mjd_start, - survey_length=night_duration, + survey_length=duration, record_rewards=True, )