{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54aad269-400f-44c2-8438-1b6111ba6a9b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# This cell does not get executed when run with Times Square\n",
    "import os\n",
    "import datetime\n",
    "\n",
    "visit_origin = os.environ.get(\"SCHEDVIEW_VISIT_ORIGIN\", \"baseline\")\n",
    "day_obs = int(\n",
    "    os.environ.get(\n",
    "        \"SCHEDVIEW_DAY_OBS\",\n",
    "        (\n",
    "            (datetime.date.today() - datetime.timedelta(days=1)).isoformat()\n",
    "            if visit_origin in (\"lsstcam\", \"latiss\", \"lsstcomcam\")\n",
    "            else \"2026-12-21\"\n",
    "        ),\n",
    "    ).replace(\"-\", \"\")\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a115ded3-9010-4ce3-8b2a-c0ad75c1aa49",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "# To render this notebook to html, in the current directory with the current python environment\n",
    "\n",
    "export SCHEDVIEW_VISIT_ORIGIN=lsstcam\n",
    "export SCHEDVIEW_DAY_OBS='20250717'\n",
    "jupyter nbconvert \\\n",
    "    --to html \\\n",
    "    --execute \\\n",
    "    --no-input \\\n",
    "    --ExecutePreprocessor.kernel_name=python3 \\\n",
    "    --ExecutePreprocessor.startup_timeout=3600 \\\n",
    "    --ExecutePreprocessor.timeout=3600 \\\n",
    "    nightsum.ipynb\n",
    "\n",
    "# The public USDF page served at\n",
    "#    https://s3df.slac.stanford.edu/data/rubin/sim-data/schedview/reports/nightsum/lsstcam/2025/07/17/nightsum.html\n",
    "# is found at\n",
    "#    /sdf/group/rubin/web_data/sim-data/schedview/reports/nightsum/lsstcam/2025/07/17/nightsum_2025-07-17.html\n",
    "\n",
    "# You can set up the conda environment used to automatically generate these pages with\n",
    "#    conda activate /sdf/data/rubin/shared/scheduler/envs/prenight\n",
    "\"\"\"\n",
    "pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2087487d-5381-4aeb-9f18-73e2c47d0fd3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "\n",
    "#sched_source = 'env'\n",
    "sched_source = 'shared'\n",
    "#sched_source = 'devel'\n",
    "match sched_source:\n",
    "    case 'shared':\n",
    "        if os.path.exists('/sdf/data/rubin/shared/scheduler/packages'):\n",
    "            sys.path.insert(0, \"/sdf/data/rubin/shared/scheduler/packages/uranography-1.2.1\")\n",
    "            sys.path.insert(0, \"/sdf/data/rubin/shared/scheduler/packages/rubin_scheduler-3.11.0\")\n",
    "            sys.path.insert(0, \"/sdf/data/rubin/shared/scheduler/packages/rubin_sim-2.2.4\")\n",
    "            sys.path.insert(0, \"/sdf/data/rubin/shared/scheduler/packages/schedview-0.18.1.dev11+g045227b\")\n",
    "    case 'devel':\n",
    "        if os.path.exists('/sdf/data/rubin/user/neilsen/devel'):\n",
    "            sys.path.insert(0, \"/sdf/data/rubin/user/neilsen/devel/rubin_scheduler\")\n",
    "            sys.path.insert(0, \"/sdf/data/rubin/user/neilsen/devel/rubin_sim\")\n",
    "            sys.path.insert(0, \"/sdf/data/rubin/user/neilsen/devel/schedview\")\n",
    "    case _:\n",
    "        # Use whatever is in the kernel python environment\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd7e09a3-b344-4725-9a42-3cb6d855d686",
   "metadata": {},
   "outputs": [],
   "source": [
    "from schedview.util import config_logging_for_reports\n",
    "import logging\n",
    "config_logging_for_reports(logging.ERROR)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9fa64668-c556-4b2f-8204-d5d68c9b56bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime\n",
    "import os\n",
    "import sqlite3\n",
    "import sys\n",
    "from collections import defaultdict\n",
    "from pathlib import Path\n",
    "\n",
    "import astropy\n",
    "import astropy.units as u\n",
    "import bokeh\n",
    "import bokeh.io\n",
    "import bokeh.layouts\n",
    "import bokeh.models\n",
    "import bokeh.plotting\n",
    "import bokeh.transform\n",
    "import cartopy\n",
    "import colorcet\n",
    "import healpy\n",
    "import healpy as hp\n",
    "import matplotlib as mpl\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "from erfa import ErfaWarning\n",
    "from astropy.coordinates import SkyCoord, get_body\n",
    "from astropy.time import Time\n",
    "from astropy.visualization import ZScaleInterval\n",
    "from IPython.display import HTML, display, Markdown, HTML\n",
    "from lsst.resources import ResourcePath"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d0b8ed4a-6835-4e82-a53d-97bb731c6bc3",
   "metadata": {},
   "outputs": [],
   "source": [
    "usdf_sim_data_dir = \"/sdf/data/rubin/shared/rubin_sim_data\"\n",
    "if os.path.exists(usdf_sim_data_dir):\n",
    "    os.environ[\"RUBIN_SIM_DATA_DIR\"] = \"/sdf/data/rubin/shared/rubin_sim_data\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6ab481d-8e62-4cd8-8735-7178e6a3223e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import schedview.collect.consdb\n",
    "import schedview.collect.nightreport\n",
    "import schedview.collect.timeline\n",
    "import rubin_scheduler\n",
    "import rubin_scheduler.site_models\n",
    "import rubin_scheduler.utils\n",
    "import schedview.compute.astro\n",
    "import schedview.compute.visits\n",
    "import schedview.compute.nightreport\n",
    "import schedview.plot.survey_skyproj\n",
    "import schedview.plot.visitmap\n",
    "import schedview.plot.nightreport\n",
    "import schedview.collect.visits\n",
    "import rubin_sim.sim_archive\n",
    "import uranography\n",
    "from rubin_sim.data import get_baseline\n",
    "from rubin_scheduler.scheduler.model_observatory import ModelObservatory\n",
    "from rubin_sim import maf\n",
    "from schedview.compute.camera import LsstCameraFootprintPerimeter\n",
    "from uranography.api import Planisphere, make_zscale_linear_cmap\n",
    "from schedview import DayObs\n",
    "from rubin_scheduler.utils.consdb import KNOWN_INSTRUMENTS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "373fcdca",
   "metadata": {},
   "outputs": [],
   "source": [
    "if not Path('/sdf/group/rubin/web_data/sim-data').exists():\n",
    "    schedview.collect.visits.OPSIMDB_TEMPLATE = str(\n",
    "        Path.home().joinpath(\"Data/sim-data/sims_featureScheduler_runs{sim_version}/baseline/baseline_v{sim_version}_10yrs.db\")\n",
    "    )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dcd4ecbc-95fe-4548-bf87-24589acecb67",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Validate the input\n",
    "import re\n",
    "\n",
    "assert visit_origin in KNOWN_INSTRUMENTS or visit_origin == 'baseline' or re.match(r\"^\\d+\\.\\d+$\", visit_origin) is not None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7678cee7-491b-4f8d-b73c-79aa8b078700",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Degraded IERS accuracy is never going to be important for these figures.\n",
    "\n",
    "# If IERS degraded accuracy encountered, don't fail, just keep going.\n",
    "astropy.utils.iers.conf.iers_degraded_accuracy = \"ignore\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40f9aca3-fdbe-4247-b860-a35288e328f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "bokeh.io.output_notebook(hide_banner=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3028f9f0-cee9-4f56-9353-5d788ada1c09",
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38816e49-8735-41d6-bee3-01bbfe80c509",
   "metadata": {},
   "outputs": [],
   "source": [
    "ORIGIN_TELESCOPE = defaultdict(\n",
    "    np.array(['Simonyi']).item,\n",
    "    {'latiss': 'AuxTel'}\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75033374-6fc8-44ad-9440-5cdf92904d01",
   "metadata": {},
   "outputs": [],
   "source": [
    "observatory = ModelObservatory(init_load_length=1)\n",
    "timezone = \"Chile/Continental\"\n",
    "telescope = ORIGIN_TELESCOPE[visit_origin]\n",
    "from_opsim = visit_origin not in KNOWN_INSTRUMENTS\n",
    "use_matplotlib = True\n",
    "science_programs_to_include = ['BLOCK-365']\n",
    "telescope = \"AuxTel\" if visit_origin.lower()==\"latiss\" else \"Simonyi\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c7c32cf8-e52d-4e69-aee0-d1fc13601c4a",
   "metadata": {},
   "outputs": [],
   "source": [
    "if from_opsim:\n",
    "    display(Markdown(f\"# Scheduler-oriented night summary of {day_obs} from baseline {visit_origin}\"))\n",
    "else:\n",
    "    display(Markdown(f\"# Scheduler-oriented night summary of {visit_origin} on {day_obs}\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "29c2b3e5-a8db-4676-b24d-b266cf9a55db",
   "metadata": {},
   "source": [
    "This report is a summary of a night of observing designed to understand scheduler behavior during the night, identify scheduler problems, and otherwise monitor scheduler performance."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c7668f23-ee71-47f8-a2d8-970086a022a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "day_obs = DayObs.from_date(day_obs)\n",
    "observatory.mjd = day_obs.mjd + 1 - observatory.location.lon.deg/360 ;# The approximate middle of the night"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d78b1af-7dc7-4665-9fdb-747cf7d30921",
   "metadata": {},
   "outputs": [],
   "source": [
    "visits = schedview.collect.visits.read_visits(day_obs, visit_origin, stackers = schedview.collect.visits.NIGHT_STACKERS)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "089ce7bc-4067-405c-9eea-cbfb2c960043",
   "metadata": {},
   "outputs": [],
   "source": [
    "if not from_opsim and visit_origin == 'lsstcam':\n",
    "    visits = visits.loc[visits['science_program'].isin(science_programs_to_include), :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a635adfa-0242-44d8-a919-0069b51b8cf5",
   "metadata": {},
   "outputs": [],
   "source": [
    "night_events = schedview.compute.astro.night_events(day_obs.date)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5db4e476-1308-4fb7-a5dc-e8e0dfde1127",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Refine the mjd of the middle of the night, unlikely to be important.\n",
    "observatory.mjd = night_events.loc[\"night_middle\", \"MJD\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "016035e9-655f-4e36-89d8-84327d193378",
   "metadata": {},
   "outputs": [],
   "source": [
    "body_positions = schedview.compute.astro.compute_sun_moon_positions(observatory)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5ac8114-2e48-4f05-9296-e7ea0271ae7c",
   "metadata": {},
   "source": [
    "## Visit map"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a54a3c72-5940-4ab2-bcae-4c7bd7e1d6be",
   "metadata": {},
   "outputs": [],
   "source": [
    "if len(visits):\n",
    "    visits = schedview.compute.visits.add_coords_tuple(visits)\n",
    "    vmap, vmap_data = schedview.plot.visitmap.create_visit_skymaps(\n",
    "        visits=visits,\n",
    "        night_date=day_obs.date,\n",
    "        timezone=timezone,\n",
    "        observatory=observatory,\n",
    "        nside=64\n",
    "    )\n",
    "    bokeh.io.show(vmap)\n",
    "else:\n",
    "    print(\"No visits\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0c7559a-6058-4892-823a-ab22429b608d",
   "metadata": {},
   "source": [
    "The above plots show the visits collected during the night in two different representations, modeled after physical observing tools.\n",
    "\n",
    " - The \"Armillary sphere\" shows the sphere in orthographic projection, with the center point of the projection controlled by the \"center alt\" and \"center az\" sliders beneath the plot. A static orthogrophic projection is not an equal-area projection, but playing with the sliders is a helpful way to inform a human's spatial reasoning in three dimensions.\n",
    " - The \"Planisphere\" shows the sky in [Lambert Azimuthal Equal Area Projection](https://en.wikipedia.org/wiki/Lambert_azimuthal_equal-area_projection), centered at the south celestial pole, with R.A. increasing counterclockwise. The projection used is equal area, but highly distorted near the north celestial pole (outside the LSST footprint). This is a particularly helpful representation for planning observing, because changes in time in relevant features are simple rotations, without alterations in distortion, and there are no discontinuities anywhere in the footprint at any time of year.\n",
    "\n",
    "Both plots show the footprints of camera pointing taken up to the time set by the MJD slider, with the most recent three pointings outlined in cyan. The fill colors are set according to the [RTN-45](https://rtn-045.lsst.io/):\n",
    "\n",
    " - <span style='background-color:#0c71ff'>&nbsp;&nbsp;&nbsp;</span><span style='color:#56b4e9'> blue</span>: u band\n",
    " - <span style='background-color:#49be61'>&nbsp;&nbsp;&nbsp;</span><span style='color:#008060'> green</span>: g band\n",
    " - <span style='background-color:#c61c00'>&nbsp;&nbsp;&nbsp;</span><span style='color:#ff4000'> red</span>: r band\n",
    " - <span style='background-color:#ffc200'>&nbsp;&nbsp;&nbsp;</span><span style='color:#850000'> yellow</span>: i band\n",
    " - <span style='background-color:#f341a2'>&nbsp;&nbsp;&nbsp;</span><span style='color:#6600cc'> pink</span>: z band\n",
    " - <span style='background-color:#5d0000'>&nbsp;&nbsp;&nbsp;</span><span style='color:#000000'> brown</span>: y band\n",
    "\n",
    "Both plots have the following additional annotations:\n",
    " - The gray background shows the planned final depth of the LSST survey.\n",
    " - The orange disk shows the coordinates of the moon.\n",
    " - The yellow disk shows the coordinates of the sun.\n",
    " - The green line (oval) shows the ecliptic.\n",
    "   - The sun moves along the ecliptic in the direction of increasing R.A. (counter-clockwise in the planisphere figure) such that it makes a full revolution in one year.\n",
    "   - The moon moves roughly (within 5.14°) along the ecliptic in the direction of increasing R.A. (counter-clockwise in the planisphere figure) , completing a full revolution in one [sidereal month](https://en.wikipedia.org/wiki/Lunar_month#Sidereal_month) (a bit over 27 days), about 14° per day.\n",
    " - The blue line (oval) shows the plane of the Milky Way.\n",
    " - The black line shows the horizon at the time set by the MJD slider.\n",
    " - The red line shows a zenith distince of 70° (airmass=2.9) at the time set by the MJD slider."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1332b0b8-ebab-4003-ae94-cfb828b54102",
   "metadata": {},
   "source": [
    "## Value timelines"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "98e62b05-250a-4a98-80b7-759e41a36f49",
   "metadata": {},
   "source": [
    "Select a value to plot using the dropdown above the plot on the right."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84cb5cc0-6798-4939-adc3-f553656664c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "if len(visits):\n",
    "    fig = schedview.plot.plot_visit_param_vs_time(\n",
    "        visits, \n",
    "        'airmass',\n",
    "        plot=bokeh.plotting.figure(height=512, width=1024),\n",
    "        show_column_selector=True)\n",
    "    bokeh.io.show(fig)\n",
    "else:\n",
    "    print(\"No visits\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43634b30-8c12-4416-86c3-375ee6fbabcd",
   "metadata": {},
   "source": [
    "## Survey Progress"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9340b2fb-7e03-4bfd-830b-e867fb29353f",
   "metadata": {},
   "source": [
    "### Map numbers of visits accumulated so far"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6936d04-ce1d-4020-8878-fba7f928926c",
   "metadata": {},
   "outputs": [],
   "source": [
    "conditions = observatory.return_conditions()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "201a2044-83fa-4b1a-86cd-828e37c2e3a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "previous_day_obs = DayObs.from_date(day_obs.mjd-1, int_format='mjd')\n",
    "previous_visits = schedview.collect.visits.read_visits(previous_day_obs, visit_origin, stackers = schedview.collect.visits.NIGHT_STACKERS, num_nights=10000)\n",
    "if not from_opsim:\n",
    "    previous_visits = previous_visits.loc[previous_visits['science_program'].isin(science_programs_to_include), :]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e8f2e91",
   "metadata": {},
   "outputs": [],
   "source": [
    "if len(visits) and len(previous_visits) \\\n",
    "        and not np.all(np.isnan(visits['fiveSigmaDepth'])) \\\n",
    "        and not np.all(np.isnan(previous_visits['fiveSigmaDepth'])):\n",
    "    fig = schedview.plot.survey.create_metric_visit_map_grid(\n",
    "        maf.CountMetric(col='fiveSigmaDepth', metric_name=\"Numbers of visits\"),\n",
    "        previous_visits.loc[np.isfinite(previous_visits['fiveSigmaDepth']), :],\n",
    "        visits.loc[np.isfinite(visits['fiveSigmaDepth']), :],\n",
    "        observatory,\n",
    "        nside=32,\n",
    "        use_matplotlib=use_matplotlib\n",
    "    )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be7ff398-e1ca-49de-8bc4-b63125a118dc",
   "metadata": {},
   "source": [
    "Each subplot represents the progress in the survey in a different filter, presented in a [Lambert Azimuthal Equal Area Projection](https://en.wikipedia.org/wiki/Lambert_azimuthal_equal-area_projection), centered at the south celestial pole.\n",
    "\n",
    "Annotations are similar to those of the \"Visit Map\" above:\n",
    "\n",
    " - Black outlines show the camera footprint of each exposure taken on this night.\n",
    " - The blue backdrop represents the accumulated effective exposure time, t<sub>eff</sub> (as defined above) at the start of the night.\n",
    " - The orange disk shows the coordinates of the moon.\n",
    " - The yellow disk shows the coordinates of the sun.\n",
    " - The green line (oval) shows the ecliptic.\n",
    " - The blue line (oval) shows the plane of the Milky Way.\n",
    " - Broken red ovals show a zenith distince of 70° (airmass=2.9) at morning and evening 12° twilight.\n",
    "   - The dashed portions of each red oval show the extent of what is observable at all during the night.\n",
    "   - As time progress through the night, the ZD circle maintains its shape, moving counter-clockwise around the pole over the course of the night."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb98630d-4671-44c1-96a6-08684d876bb9",
   "metadata": {},
   "source": [
    "### Map the most recent visit so far"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2c24ba7-b9c0-4cfe-ad43-dc1b411f5dbe",
   "metadata": {},
   "outputs": [],
   "source": [
    "if len(previous_visits):\n",
    "    fig = schedview.plot.survey.create_metric_visit_map_grid(\n",
    "        maf.AgeMetric(night_events.loc['sunset', 'MJD']),\n",
    "        previous_visits,\n",
    "        visits,\n",
    "        observatory,\n",
    "        nside=32,\n",
    "        use_matplotlib=use_matplotlib,\n",
    "        vmin=0,\n",
    "        vmax=10,\n",
    "        cmap=colorcet.cm.blues_r\n",
    "    )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "704059e6-9a15-47ca-9514-336a34fe66ed",
   "metadata": {},
   "source": [
    "Each subplot represents the time since the most recent visits to each point in the sky, by filter, presented in a Lambert Azimuthal Equal Area Projection, centered at the south celestial pole.\n",
    "\n",
    "Parts of the sky visited most recently are dark blue, growing fainter and grayer for areas visited less recently. Regions not visited in the last 10 days are not colored.\n",
    "\n",
    "Other features and annotations are the same as those of the depth map, above."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "53308798-2113-4699-a784-446727d8143e",
   "metadata": {},
   "source": [
    "## DDF Cadence"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5431c52e-f259-44c3-92da-c3fe014e0856",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_window_duration=90"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd07c771-199c-459b-98b9-3b2e3ccaad4f",
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    ddf_visits = schedview.collect.visits.read_ddf_visits(day_obs, visit_origin, num_nights=time_window_duration)\n",
    "    if not from_opsim:\n",
    "        ddf_visits = ddf_visits.loc[ddf_visits['science_program'].isin(science_programs_to_include), :]\n",
    "except:\n",
    "    ddf_visits = []"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ade9e10a-f8f6-4f56-8497-ffba3e62a269",
   "metadata": {},
   "source": [
    "The y-axis (height of the vertical bars) represents the accumulated effective exposure time, teff (as defined above) accumulated over all exposures on the field for the night, colored by filter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b7043d22-d927-43d2-95c2-c7fb1b63a50b",
   "metadata": {},
   "outputs": [],
   "source": [
    "if len(ddf_visits):\n",
    "    nightly_ddf = schedview.compute.visits.accum_stats_by_target_band_night(ddf_visits, target_column='field_name')\n",
    "    cadence_plots = schedview.plot.create_cadence_plot(\n",
    "        nightly_ddf, day_obs.mjd - time_window_duration, day_obs.mjd, target_column='field_name'\n",
    "    )\n",
    "    bokeh.io.show(cadence_plots)\n",
    "else:\n",
    "    print(\"No DDF visits\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7cc70e38-000a-45f3-ac56-ac10cbc8478b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "LSST",
   "language": "python",
   "name": "lsst"
  },
  "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.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
