deepsensor.plot

deepsensor.plot#

acquisition_fn(task, acquisition_fn_ds, X_new_df, data_processor, crs, col_dim='iteration', cmap='Greys_r', figsize=3, add_colorbar=True, max_ncol=5)[source]#
Parameters:
  • task (Task) – Task containing the context set used to compute the acquisition function.

  • acquisition_fn_ds (numpy.ndarray) – Acquisition function dataset.

  • X_new_df (pandas.DataFrame) – Dataframe containing the placement locations.

  • data_processor (DataProcessor) – Data processor used to unnormalise the context set and placement locations.

  • crs (cartopy CRS) – Coordinate reference system for the plots.

  • col_dim (str, optional) – Column dimension to plot over, by default “iteration”.

  • cmap (str | matplotlib.colors.Colormap, optional) – Color map to use for the plots, by default “Greys_r”.

  • figsize (int, optional) – Figure size in inches, by default 3.

  • add_colorbar (bool, optional) – Whether to add a colorbar to the plots, by default True.

  • max_ncol (int, optional) – Maximum number of columns to use for the plots, by default 5.

Returns:

matplotlib.pyplot.Figure

A figure containing the acquisition function plots.

Raises:
  • ValueError – If a column dimension is encountered that is not one of ["time", "sample"].

  • AssertionError – If the number of columns in the acquisition function dataset is greater than max_ncol.

context_encoding(model, task, task_loader, batch_idx=0, context_set_idxs=None, land_idx=None, cbar=True, clim=None, cmap='viridis', verbose_titles=True, titles=None, size=3, return_axes=False)[source]#

Plot the ConvNP SetConv encoding of a context set in a task.

Parameters:
  • model (ConvNP) – ConvNP model.

  • task (Task) – Task containing context set to plot encoding of …

  • task_loader (TaskLoader) – DataLoader used to load the data, containing context set metadata used for plotting.

  • batch_idx (int, optional) – Batch index in encoding to plot, by default 0.

  • context_set_idxs (List[int] | int, optional) – Indices of context sets to plot, by default None (plots all context sets).

  • land_idx (int, optional) – Index of the land mask in the encoding (used to overlay land contour on plots), by default None.

  • cbar (bool, optional) – Whether to add a colorbar to the plots, by default True.

  • clim (tuple, optional) – Colorbar limits, by default None.

  • cmap (str | matplotlib.colors.Colormap, optional) – Color map to use for the plots, by default “viridis”.

  • verbose_titles (bool, optional) – Whether to include verbose titles for the variable IDs in the context set (including the time index), by default True.

  • titles (dict, optional) – Dict of titles to override for each subplot, by default None. If None, titles are generated from context set metadata.

  • size (int, optional) – Size of the figure in inches, by default 3.

  • return_axes (bool, optional) – Whether to return the axes of the figure, by default False.

Returns:

matplotlib.figure.Figure | Tuple[matplotlib.figure.Figure, matplotlib.pyplot.Axes] – Either a figure containing the context set encoding plots, or a tuple containing the figure and the axes of the figure (if return_axes was set to True).

extent_str_to_tuple(extent)[source]#

Convert extent string to (lon_min, lon_max, lat_min, lat_max) tuple.

Parameters:

extent – str String of region name. Options are: “global”, “usa”, “uk”, “europe”.

Returns:

tuple

Tuple of (lon_min, lon_max, lat_min, lat_max).

feature_maps(model, task, n_features_per_layer=1, seed=None, figsize=3, add_colorbar=False, cmap='Greys')[source]#

Plot the feature maps of a ConvNP model’s decoder layers after a forward pass with a Task.

Parameters:
  • model (ConvNP) –

  • task (Task) –

  • n_features_per_layer (int, optional) – …, by default 1.

  • seed (int, optional) – …, by default None.

  • figsize (int, optional) – …, by default 3.

  • add_colorbar (bool, optional) – …, by default False.

  • cmap (str | matplotlib.colors.Colormap, optional) – …, by default “Greys”.

Returns:

matplotlib.figure.Figure – A figure containing the feature maps.

Raises:

ValueError – If the backend is not recognised.

offgrid_context(axes, task, data_processor=None, task_loader=None, plot_target=False, add_legend=True, context_set_idxs=None, markers=None, colors=None, **scatter_kwargs)[source]#

Plot the off-grid context points on axes.

Uses a provided DataProcessor to unnormalise the context coordinates if provided.

Parameters:
  • axes (numpy.ndarray | List[matplotlib.axes.Axes] | Tuple[matplotlib.axes.Axes]) – Axes to plot on.

  • task (Task) – Task containing the context set to plot.

  • data_processor (DataProcessor, optional) – Data processor used to unnormalise the context set, by default None.

  • task_loader (TaskLoader, optional) – Task loader used to load the data, containing context set metadata used for plotting, by default None.

  • plot_target (bool, optional) – Whether to plot the target set, by default False.

  • add_legend (bool, optional) – Whether to add a legend to the plot, by default True.

  • context_set_idxs (List[int] | int, optional) – Indices of context sets to plot, by default None (plots all context sets).

  • markers (str, optional) – Marker styles to use for each context set, by default None.

  • colors (str, optional) – Colors to use for each context set, by default None.

  • scatter_kwargs – Additional keyword arguments to pass to the scatter plot.

Returns:

None

offgrid_context_observations(axes, task, data_processor, task_loader, context_set_idx, format_str=None, extent=None, color='black')[source]#

Plot unnormalised context observation values.

Parameters:
  • axes (numpy.ndarray | List[matplotlib.axes.Axes] | Tuple[matplotlib.axes.Axes]) – Axes to plot on.

  • task (Task) – Task containing the context set to plot.

  • data_processor (DataProcessor) – Data processor used to unnormalise the context set.

  • task_loader (TaskLoader) – Task loader used to load the data, containing context set metadata used for plotting.

  • context_set_idx (int) – Index of the context set to plot.

  • format_str (str, optional) – Format string for the context observation values. By default "{:.2f}".

  • extent (Tuple[int, int, int, int], optional) – Extent of the plot, by default None.

  • color (str, optional) – Color of the text, by default “black”.

Returns:

None.

Raises:
  • AssertionError – If the context set is gridded.

  • AssertionError – If the context set is not 1D.

  • AssertionError – If the task’s “Y_c” value for the context set ID is not 2D.

  • AssertionError – If the task’s “Y_c” value for the context set ID does not have exactly one variable.

placements(task, X_new_df, data_processor, crs, extent=None, figsize=3, **scatter_kwargs)[source]#

Parameters:
  • task (Task) – Task containing the context set used to compute the acquisition function.

  • X_new_df (pandas.DataFrame) – Dataframe containing the placement locations.

  • data_processor (DataProcessor) – Data processor used to unnormalise the context set and placement locations.

  • crs (cartopy CRS) – Coordinate reference system for the plots.

  • extent (Tuple[int, int, int, int] | str, optional) – Extent of the plots, by default None.

  • figsize (int, optional) – Figure size in inches, by default 3.

Returns:

matplotlib.figure.Figure

A figure containing the placement plots.

prediction(pred, date=None, data_processor=None, task_loader=None, task=None, prediction_parameters='all', crs=None, colorbar=True, cmap='viridis', size=5, extent=None)[source]#

Plot the mean and standard deviation of a prediction.

Parameters:
  • pred (Prediction) – Prediction to plot.

  • date (str | pandas.Timestamp) – Date of the prediction.

  • data_processor (DataProcessor) – Data processor used to unnormalise the context set.

  • task_loader (TaskLoader) – Task loader used to load the data, containing context set metadata used for plotting.

  • task (Task, optional) – Task containing the context data to overlay.

  • prediction_parameters (List[str] | str, optional) – Prediction parameters to plot, by default “all”.

  • crs (cartopy CRS, optional) – Coordinate reference system for the plots, by default None.

  • colorbar (bool, optional) – Whether to add a colorbar to the plots, by default True.

  • cmap (str) – Colormap to use for the plots. By default “viridis”.

  • size (int, optional) – Size of the figure in inches per axis, by default 5.

  • extent – (tuple | str, optional): Tuple of (lon_min, lon_max, lat_min, lat_max) or string of region name. Options are: “global”, “usa”, “uk”, “europe”. Defaults to None (no setting of extent).

  • c

receptive_field(receptive_field, data_processor, crs, extent='global')[source]#

Parameters:
  • receptive_field – Receptive field to plot.

  • data_processor (DataProcessor) – Data processor used to unnormalise the context set.

  • crs (cartopy CRS) – Coordinate reference system for the plots.

  • extent (str | Tuple[float, float, float, float], optional) – Extent of the plot, in format (x2_min, x2_max, x1_min, x1_max), e.g. in lat-lon format (lon_min, lon_max, lat_min, lat_max). By default “global”.

Returns:

None.

task(task, task_loader, figsize=3, markersize=None, equal_aspect=False, plot_ticks=False, extent=None)[source]#

Plot the context and target sets of a task.

Parameters:
  • task (Task) – Task to plot.

  • task_loader (TaskLoader) – Task loader used to load task, containing variable IDs used for plotting.

  • figsize (int, optional) – Figure size in inches, by default 3.

  • markersize (int, optional) – Marker size (in units of points squared), by default None. If None, the marker size is set to (2**2) * figsize / 3.

  • equal_aspect (bool, optional) – Whether to set the aspect ratio of the plots to be equal, by default False.

  • plot_ticks (bool, optional) – Whether to plot the coordinate ticks on the axes, by default False.

  • extent (Tuple[int, int, int, int], optional) – Extent of the plot in format (x2_min, x2_max, x1_min, x1_max). Defaults to None (uses the smallest extent that contains all data points across all context and target sets).

Returns:

matplotlib.figure.Figure