From 1a8b494a4f244356785ebb4a868e6c0bab5ef58c Mon Sep 17 00:00:00 2001 From: "Eric H. Neilsen, Jr." Date: Mon, 30 Mar 2026 12:16:18 -0500 Subject: [PATCH] Remove unused functions to reduce/remove collect dependencies in plot --- .github/workflows/ruff.yaml | 2 +- schedview/plot/__init__.py | 12 +------ schedview/plot/rewards.py | 71 ------------------------------------- schedview/plot/visitmap.py | 7 +++- schedview/plot/visits.py | 44 ----------------------- 5 files changed, 8 insertions(+), 128 deletions(-) diff --git a/.github/workflows/ruff.yaml b/.github/workflows/ruff.yaml index 4558ab7b..626038ce 100644 --- a/.github/workflows/ruff.yaml +++ b/.github/workflows/ruff.yaml @@ -29,4 +29,4 @@ jobs: - uses: psf/black@stable with: options: "--check --verbose" - version: "~= 26.1" \ No newline at end of file + version: "~= 26.1" diff --git a/schedview/plot/__init__.py b/schedview/plot/__init__.py index fc37d39f..c6b280d1 100644 --- a/schedview/plot/__init__.py +++ b/schedview/plot/__init__.py @@ -6,7 +6,6 @@ "plot_obs_vs_sim_time", "plot_polar_alt_az", "plot_survey_rewards", - "create_survey_reward_plot", "reward_timeline_for_tier", "area_timeline_for_tier", "reward_timeline_for_surveys", @@ -23,7 +22,6 @@ "create_hpix_visit_map_grid", "plot_visits", "plot_visit_param_vs_time", - "create_visit_explorer", "create_overhead_summary_table", "create_overhead_histogram", "plot_overhead_vs_slew_distance", @@ -56,21 +54,13 @@ from .progress import make_metric_line_plots from .rewards import ( area_timeline_for_tier, - create_survey_reward_plot, plot_survey_rewards, reward_timeline_for_surveys, reward_timeline_for_tier, ) -from .scheduler import ( - BadConditionsError, - BadSchedulerError, - SchedulerDisplay, - SchedulerNotebookDisplay, - make_logger, -) from .sim_archive import make_html_table_of_sim_archive_metadata from .survey import create_hpix_visit_map_grid, map_survey_healpix, map_visits_over_hpix from .timeline import make_timeline_scatterplots from .util import mpl_fig_to_html from .visitmap import create_visit_skymaps, plot_visit_planisphere, plot_visit_skymaps -from .visits import create_visit_explorer, create_visit_table, plot_visit_param_vs_time, plot_visits +from .visits import create_visit_table, plot_visit_param_vs_time, plot_visits diff --git a/schedview/plot/rewards.py b/schedview/plot/rewards.py index 6098b7a2..29f77e75 100644 --- a/schedview/plot/rewards.py +++ b/schedview/plot/rewards.py @@ -1,4 +1,3 @@ -import warnings from collections.abc import Callable import bokeh @@ -11,18 +10,12 @@ import holoviews as hv import numpy as np import pandas as pd -from astropy.time import Time # Imported to help sphinx make the link from rubin_scheduler.scheduler.model_observatory import ModelObservatory # noqa F401 -import schedview.compute.astro -import schedview.compute.scheduler -from schedview.collect import read_opsim, read_scheduler - __all__ = [ "plot_survey_rewards", - "create_survey_reward_plot", "reward_timeline_for_tier", "area_timeline_for_tier", "reward_timeline_for_surveys", @@ -58,70 +51,6 @@ def plot_survey_rewards(rewards): return reward_plot -def create_survey_reward_plot( - scheduler, - night_date, - additional_visits=None, - observatory=None, - timezone="Chile/Continental", -): - """Build a plot of rewards by survey for a time period. - - Parameters - ---------- - scheduler : `rubin_scheduler.scheduler.schedulers.Core_scheduler` or `str` - The scheduler with the surveys to evaluate, or the name of a file - from which such a scheduler should be loaded. - night_date : `astropy.time.Time` - A time during the night to plot. - additional_visits : `pandas.DataFrame` or `str`, optional - Visits to add to the scheduler before reward evaluation, - by default None - observatory : `ModelObservatory`, optional - Provides the location of the observatory, used to compute - night start and end times. - By default None - timezone : `str`, optional - Timezone for horizontal axis, by default "Chile/Continental" - - Returns - ------- - figure : `bokeh.plotting.figure` - The figure itself. - data : `dict` - The arguments used to produce the figure using - `plot_survey_rewards`. - """ - - site = None if observatory is None else observatory.location - - # Collect - if isinstance(scheduler, str): - scheduler, conditions = read_scheduler(scheduler) - scheduler.update_conditions(conditions) - - if isinstance(additional_visits, str): - night_events = schedview.compute.astro.night_events( - night_date=night_date, site=site, timezone=timezone - ) - start_time = Time(night_events.loc["sunset", "UTC"]) - end_time = Time(night_events.loc["sunrise", "UTC"]) - additional_visits = read_opsim(additional_visits, Time(start_time).iso, Time(end_time).iso) - - # Compute - if additional_visits is not None: - schedview.compute.scheduler.replay_visits(scheduler, additional_visits) - - with warnings.catch_warnings(): - warnings.filterwarnings("ignore", category=FutureWarning) - rewards = schedview.compute.scheduler.compute_basis_function_rewards(scheduler) - - # Plot - data = {"rewards": rewards} - reward_plot = hv.render(plot_survey_rewards(**data)) - return reward_plot, data - - def make_timeline_bars( df, factor_column, diff --git a/schedview/plot/visitmap.py b/schedview/plot/visitmap.py index 298c376e..b95b7fdf 100644 --- a/schedview/plot/visitmap.py +++ b/schedview/plot/visitmap.py @@ -13,7 +13,6 @@ import schedview.compute.astro from schedview import band_column -from schedview.collect import load_bright_stars, read_opsim from schedview.compute.camera import LsstCameraFootprintPerimeter from schedview.compute.footprint import find_healpix_area_polygons from schedview.plot import PLOT_BAND_COLORS @@ -254,6 +253,9 @@ def plot_visit_skymaps( ) if show_stars: + # Import here to avoid schedview.collect dependency unless necessary. + from schedview.collect.stars import load_bright_stars + star_data = load_bright_stars().loc[:, ["name", "ra", "decl", "Vmag"]] star_data["glyph_size"] = 15 - (15.0 / 3.5) * star_data["Vmag"] star_data.query("glyph_size>0", inplace=True) @@ -359,6 +361,9 @@ def create_visit_skymaps( end_time = Time(night_events.loc["sunrise", "UTC"]) if isinstance(visits, str): + # Import here to avoid collect dependency unless necessary + from schedview.collect.opsim import read_opsim + visits = read_opsim(visits) if start_time is not None: diff --git a/schedview/plot/visits.py b/schedview/plot/visits.py index 671aa052..8bb36b85 100644 --- a/schedview/plot/visits.py +++ b/schedview/plot/visits.py @@ -9,14 +9,11 @@ import hvplot import numpy as np import pandas as pd -from astropy.time import Time # Imported to help sphinx make the link from rubin_scheduler.scheduler.model_observatory import ModelObservatory # noqa F401 -import schedview.compute.astro from schedview import band_column -from schedview.collect import read_opsim from .colors import make_band_cmap @@ -122,47 +119,6 @@ def plot_visits(visits): return visit_explorer -def create_visit_explorer(visits, night_date, observatory=None, timezone="Chile/Continental"): - """Create an explorer to interactively examine a set of visits. - - Parameters - ---------- - visits : `str` or `pandas.DataFrame` - One row per visit, as created by `schedview.collect.read_opsim`, - or the name of a file from which such visits should be loaded. - night_date : `datetime.date` - The calendar date in the evening local time. - observatory : `ModelObservatory`, optional - Provides the location of the observatory, used to compute - night start and end times. - By default None. - timezone : `str`, optional - _description_, by default "Chile/Continental" - - Returns - ------- - figure : `hvplot.ui.hvDataFrameExplorer` - The figure itself. - data : `dict` - The arguments used to produce the figure using - `plot_visits`. - """ - site = None if observatory is None else observatory.location - night_events = schedview.compute.astro.night_events(night_date=night_date, site=site, timezone=timezone) - start_time = Time(night_events.loc["sunset", "UTC"]) - end_time = Time(night_events.loc["sunrise", "UTC"]) - - # Collect - if isinstance(visits, str): - visits = read_opsim(visits, Time(start_time).iso, Time(end_time).iso) - - # Plot - data = {"visits": visits} - visit_explorer = plot_visits(visits) - - return visit_explorer, data - - def plot_visit_param_vs_time( visits: pd.DataFrame, column_name: str | Iterable[str],