Source code for schedview.plot.cadence

import bokeh
import numpy as np
from astropy.time import Time

from .colors import PLOT_FILTER_CMAP


[docs] def create_cadence_plot( nightly_totals, start_dayobs_mjd, end_dayobs_mjd, targets=None, cmap=PLOT_FILTER_CMAP, user_plot_kwargs={} ): """ "Create a cadence plot for a set of targets. Parameters ---------- nightly_totals : `pandas.DataFrame` A DataFrame indexed by ``"target"`` (`str`) and ``"day_obs_iso8601"`` (`str` in YYYY-MM-DD format), filter names as column names (`float`), with total effective exposure times. start_dayobs_mjd : `float` The dayobs MJD of the first night in the plot. end_dayobs_mjd : `float` The dayobs MJD of the last night in the plot. targets : `list` (`str`), optional The list of targets for which to make plots. Defaults to the targets included in the ``nightly_totals`` DataFrame. cmap : `bokeh.core.property.vectorization.Field` (optional) The ``bokeh`` color map as generated by ``bokeh.transform.factor_cmap``. Defaults to `schedview.plot.PLOT_FILTER_CMAP`. user_plot_kwargs : `dict` Extra arguments to pass to `bokeh.plotting.figure.vbar_stack`. Defaults to ``{}``. Returns ------- full_cadence_figure : `bokeh.models.layouts.LayoutDOM` The bokeh plot with cadence plots for all targets. """ if targets is None: targets = tuple(nightly_totals.index.get_level_values("target").unique()) date_factors = [Time(mjd, format="mjd").iso[:10] for mjd in np.arange(start_dayobs_mjd, end_dayobs_mjd)] band_factors = cmap.transform.factors cadence_plots = [] plot_kwargs = { "x_range": bokeh.models.FactorRange(factors=date_factors), "frame_height": 150, "frame_width": 1024, "title_location": "left", } plot_kwargs.update(user_plot_kwargs) for target in targets: last_plot = len(cadence_plots) == len(targets) - 1 plot_kwargs["title"] = target plot_kwargs["x_axis_location"] = "below" if last_plot else None this_plot = bokeh.plotting.figure(**plot_kwargs) this_plot.xaxis.major_label_orientation = "vertical" kwargs = {"legend_label": band_factors} if last_plot else {} this_plot.vbar_stack( stackers=band_factors, x="day_obs_iso8601", width=0.9, source=nightly_totals.loc[target, :].reset_index(), color=cmap.transform.palette, fill_alpha=0.3, **kwargs, ) if last_plot: legend = this_plot.legend[0] legend.orientation = "horizontal" this_plot.add_layout(legend, "below") cadence_plots.append(this_plot) full_cadence_figure = bokeh.layouts.column(cadence_plots) return full_cadence_figure