visualization.py#

Functions to support data visualization.

class seabirdscientific.visualization.Axes(x: list[seabirdscientific.visualization.AxisSettings], y: list[seabirdscientific.visualization.AxisSettings], z: list[seabirdscientific.visualization.AxisSettings])#
class seabirdscientific.visualization.AxisSettings(name: str, title: str, units: str, range: list[float], marker: str, color: str, color_scale: list[list[float | str]], transform: seabirdscientific.visualization.Transform)#
class seabirdscientific.visualization.ChartConfig(title: str, x_names: list[str], y_names: list[str], z_names: list[str], chart_type: Literal['overlay', 'subplots'], bounds: dict[Literal['x', 'y', 'z'], dict[int, list[int]]] | None = None, x_titles: list[str] | None = None, y_titles: list[str] | None = None, z_titles: list[str] | None = None, plot_loop_edit_flags=False, lift_pen_over_bad_data=False, flag_value=-9.99e-29)#

Dataclass to contain chart information and plotly settings

class seabirdscientific.visualization.PlotSettings(axes: seabirdscientific.visualization.Axes, title: str, layout_type: Literal['multiple-x', 'multiple-y', 'contour'], show_loop_edit_flags: bool, connect_gaps: bool, flag_value: float, invert_y_axis: bool, title_font_size: float, label_font_size: float, marker_size: float, series_names: list[str], annotate: bool, background_color: str, height: int, width: int, disabled: bool, plot_previous_casts: str, plot_all_scans: bool, previous_scans_to_plot: int, previous_interval_to_plot: datetime.timedelta)#
class seabirdscientific.visualization.Transform(slope: float, offset: float)#
seabirdscientific.visualization.apply_overlay_config(figure: Figure, config: ChartConfig)#

Updates various chart settings for charts with multiple y axes.

Config parameters may contain upto 4 arguments per axis, and must be in the same order as the data. Hence all of the magic number indexing below

Parameters:
  • figure – The figure being updated

  • config – The user defined config being applied to the figure

seabirdscientific.visualization.apply_single_config(figure: Figure, config: ChartConfig)#

Updates various chart settings for single plots.

Parameters:
  • figure – The figure being updated

  • config – The user defined config being applied to the figure

seabirdscientific.visualization.apply_subplots_x_config(figure: Figure, config: ChartConfig)#

Updates various chart settings for charts with multiple x axes.

Config parameters may contain upto 4 arguments per axis, and must be in the same order as the data. Hence all of the magic number indexing below

Parameters:
  • figure – The figure being updated

  • config – The user defined config being applied to the figure

seabirdscientific.visualization.apply_subplots_y_config(figure: Figure, config: ChartConfig)#

Updates various chart settings for charts with multiple y axes.

Config parameters may contain upto 4 arguments per axis, and must be in the same order as the data. Hence all of the magic number indexing below

Parameters:
  • figure – The figure being updated

  • config – The user defined config being applied to the figure

seabirdscientific.visualization.create_overlay(x: Dataset, y: Dataset, config: ChartConfig) → Figure#

Creates a chart with multiple datasets overlayed on one axis.

Parameters:
  • x – xarray dataset of data for the x axis

  • y – xarray dataset of data for the y axis

  • config – Dataclass with settings for the plotly chart

Returns:

A plotly.graph_objects.Figure

seabirdscientific.visualization.create_single_plot(x: Dataset, y: Dataset, config: ChartConfig) → Figure#

Creates a single XY plot, with one or more data sets.

If there are multiple datasets for the x or y axis, an overlay plot will be generated

Parameters:
  • x – xarray dataset of data for the x axis

  • y – xarray dataset of data for the y axis

  • config – Dataclass with settings for the plotly chart

Returns:

A plotly.graph_objects.Figure displaying the provided x y data

seabirdscientific.visualization.create_subplots(x: Dataset, y: Dataset, config: ChartConfig) → Figure#

Creates a chart with multiple subplots.

Parameters:
  • x – xarray dataset of data for the x axis

  • y – xarray dataset of data for the y axis

  • config – Dataclass with settings for the plotly chart

Returns:

A plotly.graph_objects.Figure with multiple subplots

seabirdscientific.visualization.parse_instrument_data(source: str | Path | DataFrame | Dataset) → Dataset#

Top level function for converting instrument data to numpy array.

Currently supports pandas dataframes, json strings, or a Path to the following file types: .csv, .asc (comma separated only), .json.

Parameters:

source – A JSON string, file path (.csv, .asc, .json), or pandas DataFrame

Returns:

xarray dataset containing field names and data

seabirdscientific.visualization.plot_ts_chart(x: ndarray, y: ndarray, z: ndarray, x_vec: ndarray, y_vec: ndarray, z_mat: ndarray, config: ChartConfig) → Figure#

Overlays a scatter plot onto a contour plot to create a TS plot. Takes as args the xyz properties on a Contour object. In a future version these will be replaced with a single contour object

Parameters:
  • x – absolute salinity

  • y – conservative temperature

  • z – potential density

  • x_vec – absolute salinity vector

  • y_vec – conservative temperature vector

  • z_mat – potential density matrix

  • config – Config object with key/values required by conversion function

Returns:

A plotly.graph_objects.Figure

seabirdscientific.visualization.plot_xy_chart(data: Dataset, config: ChartConfig) → Figure#

Takes instrument data and a config and plots an XY chart with one or more data sets.

Parameters:
  • data – xarray dataset, such as that returned by read_cnv_file or read_hex_file

  • config – Config object with various plotly settings

Returns:

A plotly.graph_objects.Figure

seabirdscientific.visualization.select_subset(axis_names: list[str], data: Dataset) → Dataset#

Takes a list of axis names and returns a data set for each name in the list.

If axis_names is empty the function will return a Dataset of integers representing the scan count of the data. This could be used in a single series chart for example.

Otherwise, the function will return a Dataset for each name in the list. This would be for a single xy chart or an overlay/subplot chart.

Example:

data = read_data(“./example.csv”)

subset = select_subset([“T090C”, “C0Sm”], data)

Parameters:
  • axis_names – List of axis names corresponding to the data

  • data – xarray dataset containing one-dimensional instrument variables

Returns:

A tuple with the axis name and data