autowisp.browser_interface.diagnostics.image_diagnostics_views module

Class Inheritance Diagram

Inheritance diagram of BytesIO, Figure, HttpResponse

Views for displaying per-image diagnostics.

One quantity may be plotted against another, where a quantity is a DiagnosticType name, the pixel_quantiles pseudo-name expanding to one series per pixel_q*, or jd. Plotting against time is not a separate mode: it is x="jd", which resolves through the same path as everything else because the canonical image list already carries the Julian dates.

The figure half of the page: reading the values a row asks for, drawing them, and the Django views that serve it. What the table above the plot offers, and what a row binds, is series_table – which never evaluates anything, where everything here does.

autowisp.browser_interface.diagnostics.image_diagnostics_views.collect_series_data(series_list, x_diagnostic, y_diagnostic, expressions, db_session)[source]

Read the selected series, dropping those with nothing to draw.

Every row of the table is posted rather than only the drawn ones, so that the server can see what the whole table binds. Three of them are skipped here: one the user has not selected, one whose marker is blank, and one still missing a channel, which names no data to read.

Parameters:
  • series_list (list) – Every row as the client posted it back.

  • x_diagnostic (str) – Quantity on the X axis.

  • y_diagnostic (str) – Quantity on the Y axis.

  • expressions (dict) – The library, {name: expression}.

  • db_session – An active SQLAlchemy database session.

Returns:

(series, x_values, y_values, image_ids) tuples for the

series having at least one point where both axes are finite.

Return type:

list

autowisp.browser_interface.diagnostics.image_diagnostics_views.create_diagnostics_figure(series_list, *, x_diagnostic, y_diagnostic, expressions, db_session, figure_config=None)[source]

Create the figure for the selected series of an axis pair.

Parameters:
  • series_list (list) – Entries from get_available_series(). Only those with a non-empty marker are plotted.

  • x_diagnostic (str) – Quantity on the X axis.

  • y_diagnostic (str) – Quantity on the Y axis.

  • expressions (dict) – The library, {name: expression}.

  • db_session – An active SQLAlchemy database session.

  • figure_config (dict) – Layout of the figure, defining plot_height_frac, num_columns and aspect_ratio.

Returns:

The completed figure.

Return type:

matplotlib.figure.Figure

autowisp.browser_interface.diagnostics.image_diagnostics_views.create_figure(num_plots, plot_height_frac, aspect_ratio, num_columns)[source]

Create the figure for the diagnostics plot per given configuration.

autowisp.browser_interface.diagnostics.image_diagnostics_views.display_diagnostics(request, x_diagnostic, y_diagnostic, expressions)[source]

View displaying the table of available series for an axis pair.

The library arrives as an argument rather than being fetched here: it is the one thing on this page that comes from the browser-interface database, and keeping it out means everything in this module can be tested against a project database alone. views.py supplies it.

autowisp.browser_interface.diagnostics.image_diagnostics_views.display_image_diagnostics(_request, diagnostic_name)[source]

Redirect the pre-merge time-series URL onto the merged view.

Kept so that links built before the merge keep working, including the six {% url %} tags in processing/progress.html.

autowisp.browser_interface.diagnostics.image_diagnostics_views.download_plot_view(request, figure_factory, session_key, **url_kwargs)[source]

Return the last-plotted figure as a PDF download.

Reads the plot configuration stored in the session by a previous call to update_plot_view() and regenerates the figure in PDF format.

Parameters:
  • request – Django HTTP request.

  • figure_factory – Same factory used by the corresponding update view.

  • session_key – Session key where update_plot_view() stored the last POST data.

Returns:

HttpResponse with PDF content.

autowisp.browser_interface.diagnostics.image_diagnostics_views.draw_series_group(axes, group, x_offset)[source]

Plot every series sharing one set of axes.

Parameters:
  • axes – The matplotlib Axes the group was assigned.

  • group (list) – (series, x_values, y_values, image_ids) tuples, as grouped by group_series_by_x_overlap().

  • x_offset (float) – Subtracted from every x value. Shared by the whole figure so the series keep their spacing relative to each other.

Returns:

None

autowisp.browser_interface.diagnostics.image_diagnostics_views.get_series_data(series, x_diagnostic, y_diagnostic, expressions, db_session)[source]

Query the paired x/y values for a single series.

Both axes are resolved in one call, which is what makes them share a query for the diagnostics they need and one symbol table, so a subexpression common to the two is evaluated once. They are returned unmasked; the single finite mask lives in plot_image_diagnostic_series().

Parameters:
  • series (dict) – One row as the client posted it back, holding the id it was rendered with and the channels its dropdowns say.

  • x_diagnostic (str) – Quantity on the X axis.

  • y_diagnostic (str) – Quantity on the Y axis.

  • expressions (dict) – The library, {name: expression}, passed in rather than fetched so that nothing below the view has to know it came from the browser-interface database.

  • db_session – An active SQLAlchemy database session.

Returns:

(x_values, y_values, image_ids), all of equal length.

Return type:

tuple

autowisp.browser_interface.diagnostics.image_diagnostics_views.group_series_by_x_overlap(series_data)[source]

Group series into sets whose x ranges overlap.

Series whose x ranges overlap share axes; disjoint ones get their own. For a time axis this separates observing nights, which is what it was written for. For any other quantity the ranges normally overlap, so everything collapses onto a single set of axes.

Parameters:

series_data (list) – (series, x_values, y_values, image_ids) tuples.

Returns:

Lists of the entries that should share one set of axes.

Return type:

list

autowisp.browser_interface.diagnostics.image_diagnostics_views.plot_image_diagnostic_series(axes, x_values, y_values, image_ids, config)[source]

Plot a single series on the given axes.

Parameters:
  • axes – A matplotlib Axes to plot on.

  • x_values – Sequence of x coordinates.

  • y_values – Sequence of y coordinates.

  • image_ids – The image each point belongs to, used for the click-through URLs.

  • config (dict) – Configuration for the plotting, usually produced by get_available_series(). Should contain keys channel, color, marker, scale, and label.

autowisp.browser_interface.diagnostics.image_diagnostics_views.plot_session_key = 'diagnostics_last'

Where the last posted plot configuration is kept, so that the download view can regenerate exactly what was on screen.

autowisp.browser_interface.diagnostics.image_diagnostics_views.update_plot_view(request, figure_factory, session_key=None, extra=None, **url_kwargs)[source]

Common handler for diagnostics AJAX plot-update views.

Parses the JSON POST body, calls figure_factory to produce the figure, and returns an SVG JsonResponse.

Parameters:
  • request – Django HTTP request whose body is a JSON object with a datasets dict (keyed by series id) and an optional figure_config dict.

  • figure_factory – Callable accepting series_list, db_session, figure_config, plus any URL kwargs as keyword arguments.

  • session_key – If given, the raw POST data is stored in the session under this key so a download view can retrieve it.

  • extra – Optional callable given the whole POST, the database session and the URL kwargs, returning a dict merged into the response. What a redraw answers besides the figure – a newly bound row’s count and its spare – rides along here, so that one action costs one round trip.

Returns:

JsonResponse with plot_data containing the SVG string.