MetadataView¶
class MetadataView(*args, **kwargs)
Bases: MetaView, WalkthroughMixin
Subclass of MetaView for visualizing and interacting with metadata plots.
This view supports a wide variety of statistical visualizations, including: 1D histograms, KDEs, capture rates, scatterplots, heatmaps, and event overlays. Also provides walkthroughs and export options.
- Attributes:
metadata_plots (List[str]): List of supported metadata-based plot types. event_data_plots (List[str]): List of supported event-based plot types. subset_export_count (int): Counter for naming exported subsets. plot_initialized (bool): Indicates whether a plot is currently initialized. no_cached_data (bool): True if data is not cached due to size.
Public Methods¶
- MetadataView.format_axis_label(label: str, unit: str | None) str¶
Ensure the axis label contains the correct unit exactly once. Removes any existing trailing unit in parentheses.
- MetadataView.get_current_view() str¶
Abstract method to get the name of the current view.
Subclasses must override this to return the current view name.
- Returns:
The name of the view currently displayed.
- Return type:
- Raises:
NotImplementedError – Always, unless overridden by a subclass.
- MetadataView.get_save_filename() str¶
Open a file dialog for the user to choose a save location.
- Returns:
Selected filename.
- Return type:
- MetadataView.get_selected_filters() dict¶
Get a dict of the filters that the user has indicated should be active for the current plotting task
- MetadataView.get_walkthrough_steps() List[Tuple[str, str, str, Callable[[], QWidget | List[QWidget]]]]¶
Abstract method to retrieve the walkthrough steps for the current view.
Subclasses must override this to return a list of walkthrough steps, each a (title, description, view name, widget getter) tuple.
- Returns:
The ordered walkthrough steps for this view.
- Return type:
List[WalkthroughStep]
- Raises:
NotImplementedError – Always, unless overridden by a subclass.
- MetadataView.handle_parameter_change(submodel_name: str, action_name: str, args: tuple) None¶
Handle changes triggered by UI controls such as updates to axis selection or filters.
- Parameters:
- Raises:
NotImplementedError – If action_name is “new_axis” (not currently supported).
- MetadataView.is_categorical_type(data_type: str | None) bool¶
Evaluates an SQLite column datatype string. Returns True if categorical/discrete (or blank/None), False if explicitly continuous.
- MetadataView.notify_plugin_state_changed(metaclass: str, plugin_key: str, reason: str) None¶
Called when some other plugin instance’s state changed elsewhere in the app. Refreshes this tab’s column list only when the change concerns a MetaDatabaseLoader’s columns and the loader that changed is the one currently selected here; any other metaclass, reason, or a loader that isn’t currently selected in this tab is ignored.
- MetadataView.on_raw_filter_validated(valid: bool, error_msg: str) None¶
Relay callback from validate_filter_query for raw SQL filter validation.
- MetadataView.relay_experiment_id(exp_id: int | None) None¶
A callback from a global_signal call that stores a resolved experiment id.
- Parameters:
exp_id (Optional[int]) – Integer experiment id.
- MetadataView.relay_query_result(result: DataFrame | None) None¶
A callback from a global_signal call that stores the result of a DB query.
Shared by the
query_database_directlyandload_metadatadispatches, which return the same thing: the rows, an empty frame if none matched, or None if the query could not be built or run.- Parameters:
result (Optional[pd.DataFrame]) – DataFrame returned by the query, or None if it failed.
- MetadataView.replace_filter_item(name: str) None¶
Remove any existing filter item with the same name and add the new one.
- Parameters:
name (str) – The name of the filter to (re)add.
- MetadataView.request_experiment_structure(loader_name: str) None¶
Get a dict of all experiments and channels available in a specified MetaDatabaseLoader object.
- Parameters:
loader_name (str) – the key of the loader
- MetadataView.restore_subset_filters(filters: Dict[str, str]) None¶
Restore subset filters captured in a saved session.
Unlike
_load_filter(), this does not re-validate the filters against a database loader, since they were already valid when the session was saved.
- MetadataView.set_baseline_duration(duration: float | None) None¶
a callback from a global_signal call that sets the baseline_duration variable for further processing
- Parameters:
duration (Optional[float]) – total duration of baseline data in the scoped subset, or None if it could not be resolved.
- MetadataView.set_channel_db_id(channel_db_id: int | None) None¶
a global signal callback that provides the channel_db_id for raw query scoping
- Parameters:
channel_db_id (Optional[int]) – Database id of the scoped channel, or None if unresolved.
- MetadataView.set_column_type(column_type: str | None) None¶
a callback from a global_signal call that sets the column type of a specified variable
- Parameters:
column_type (Optional[str]) – SQL type name of the queried column, or None on failure.
- MetadataView.set_event_data_generator(generator: Iterator[Dict[str, Any]]) None¶
Set the event data generator for event-based plots.
- Parameters:
generator (Iterator[Dict[str, Any]]) – A generator that yields event data.
- MetadataView.set_event_plot_data_generator(generator: Iterator[Dict[str, Any]]) None¶
A callback from a global signal call that sets the generator to be used to construct event plots and overlays.
- Parameters:
generator (Iterator[Dict[str, Any]]) – a generator of event data
- MetadataView.set_event_query(query: str) None¶
A global signal callback that provides a valid SQL query for fetching event data.
- Parameters:
query (str) – SQL query string for fetching event data.
- MetadataView.set_experiment_id(experiment_id: int | None) None¶
A global signal callback that provides an experiment id for a given filter.
- Parameters:
experiment_id (Optional[int]) – the integer id of the experiment in a MetaEventLoader object
- MetadataView.set_exported_event_count(written: int) None¶
A global signal callback that provides the number of events written in a call to export events to csv format.
- Parameters:
written (int) – number of events successfully written
- MetadataView.set_query(query: str, table_name: str) None¶
Set the SQL query and table name used in plotting.
- MetadataView.set_table_by_column(table: str | None) None¶
Get a list of tables affected by an SQL query.
- Parameters:
table (Optional[str]) – the name of a table that is implicated in an SQL query to a MetaDatabaseLoader object
- MetadataView.set_units(units: Any) None¶
Set the units returned from the database for use in axis labels.
- Parameters:
units (Any) – List or string representing units.
- MetadataView.show_edit_filter_dialog(name: str, loader: str) None¶
Displays the dialog to edit an existing filter, and validates the updated SQL filter syntax via construct_metadata_query before saving it.
- MetadataView.show_selection_tree(structure: dict[str, list[str]], loader_name: str, selection: dict[str, list[str]] | None = None) None¶
Displays the selection tree for a given loader using the full structure and current selection.
- MetadataView.update_available_columns(loader: str) None¶
Request available columns from the database loader.
- Parameters:
loader (str) – Name of the active database loader.
- MetadataView.update_available_plugins(available_plugins: Dict[str, List[str]]) None¶
Called whenever a new plugin is instantiated elsewhere in the app, to keep an up-to-date list of possible data sources for use by this plugin.
- MetadataView.update_column_names(column_names: List[str]) None¶
Relay function to update the list of available columns.
- Parameters:
column_names (List[str]) – List of column names.
- MetadataView.update_column_units(column_units: str | None, axis: str) None¶
Relay function to update the column unit label in the UI.
- MetadataView.update_filter_name(old_name: str, new_name: str) None¶
Replace old filter name with new one in the ComboBox, removing any duplicates.
- MetadataView.update_plot(plot_type: str, data: DataFrame, cols: Sequence[str], units: Sequence[str | None], logscales: Sequence[bool], dataset_label: str = '', bins: Any = None, sizes: bool = False) None¶
Update the plot area with the provided data across multiple channels in a grid layout.
- Parameters:
plot_type (str) – The kind of plot to draw (e.g. “Histogram”, “Scatterplot”, “Heatmap”); selects which internal plotting method is dispatched to.
data (pd.DataFrame) – a pandas dataframe with column headers matching x_col, y_col, z_col
cols (Sequence[str]) – a sequence of strings corresponding to column headers in the dataframe
units (Sequence[Optional[str]]) – a sequence of strings corresponding to column units in the dataframe
logscales (Sequence[bool]) – a sequence of bools indicating whether the given axis should be logscaled
dataset_label (str) – string to label the dataset
bins (Any) – Number of bins (if sizes==False) or size of bins (if sizes==True) for use when binning. Arrives as a single-element list from the controls and is rebound to a scalar (or None, to fall back to an automatic estimate) in the body, hence the loose annotation.
sizes (bool) – does the bins parameter refer to bin sizes (True) or widths (False)
- Raises:
NotImplementedError – If plot_type is not one of the supported plot types.
- MetadataView.update_plot_features(vertical: List[float] | None = None, horizontal: List[float] | None = None, points: List[Tuple[float, float]] | None = None, vlabels: List[str] | None = None, hlabels: List[str] | None = None, plabels: List[str] | None = None) None¶
Update feature overlays for the plot, such as vertical/horizontal lines and labeled points.
- Parameters:
vertical (Optional[List[float]]) – List of vertical line positions.
horizontal (Optional[List[float]]) – List of horizontal line positions.
points (Optional[List[Tuple[float, float]]]) – List of (x, y) point coordinates.
vlabels (Optional[List[str]]) – Labels for vertical lines.
hlabels (Optional[List[str]]) – Labels for horizontal lines.
plabels (Optional[List[str]]) – Labels for points.
Private Methods¶
- MetadataView.__init__(*args: Any, **kwargs: Any) None¶
Initialize the MetaTab with a blank plot canvas and a space for controls.
- MetadataView._axes_valid(axis_type: str = '2d') bool¶
Check whether self.axes currently refers to a live axes object that is actually attached to self.figure and has the requested projection. After _update_event_plot() rebuilds the figure into a grid of per-event subplots, self.axes is left pointing at an axes that has been removed from the figure (a stale reference); reusing it would silently draw onto an orphaned, invisible axes.
- MetadataView._calculate_heatmap(xdata: ndarray[tuple[int, ...], dtype[float64]], ydata: ndarray[tuple[int, ...], dtype[float64]], logx: bool = False, logy: bool = False, bins: Any = None, sizes: bool = False) tuple[ndarray, ndarray, ndarray]¶
- Parameters:
xdata (npt.NDArray[np.float64]) – the data on the x axis
ydata (npt.NDArray[np.float64]) – the data on the y axis
logx (bool) – logscale the x data before building the heatmap?
logy (bool) – logscale the y data before building the heatmap?
bins (Any) – number of bins (if sizes==False) or size of bins (if sizes==True) for use when binning. Arrives as a list from the controls and may be rebound to None in the body, hence the loose annotation.
sizes (bool) – does the bins parameter refer to bin sizes (True) or widths (False)
- Returns:
Bin-center x values, bin-center y values, and the log2-scaled 2D histogram counts.
- Return type:
tuple[np.ndarray, np.ndarray, np.ndarray]
- Raises:
ValueError – If bins is an invalid entry when sizes is False.
Build a heatmap of the provided data
- MetadataView._clear_figure_state(axis_type: str = '2d', *, create_default_axes: bool = True) None¶
Canonical figure reset.
- MetadataView._construct_all_points_histogram(event_generator: Iterator[Dict[str, Any]], plot_type: str, bins: Any = None, sizes: bool = False) DataFrame¶
Build a combined histogram across all event current values.
- Parameters:
event_generator (Iterator[Dict[str, Any]]) – Generator yielding individual event data.
plot_type (str) – Type of histogram to create (raw or filtered).
bins (Any) – Number of histogram bins. Arrives as a single-element list from the controls and is rebound to a scalar (or None) in the body, hence the loose annotation.
sizes (bool) – does the bins parameter refer to bin sizes (True) or widths (False)
- Returns:
DataFrame with histogram values and corresponding current levels.
- Return type:
pd.DataFrame
- Raises:
ValueError – If plot_type is not a recognized all-points-histogram variant.
- MetadataView._construct_event_overlay(event_generator: Iterator[Dict[str, Any]], plot_type: str, loader: str) None¶
Overlay multiple event traces in a normalized time plot.
- MetadataView._delete_filter(name: str) None¶
Internal method to remove a filter and update the UI.
- Parameters:
name (str) – The name of the filter to remove.
- MetadataView._delete_filter_by_name(name: str) None¶
Deletes a single filter by name.
- Parameters:
name (str) – The name of the filter to delete.
- MetadataView._export_csv_subset(loader: str, filters: Any, selection: Dict[str, List[str]]) None¶
Open a dialog to export a filtered subset of the dataset.
- Parameters:
loader (str) – Name of the active database loader.
filters (Any) – Dict of named subset filters; only a single filter may be selected for export. Typed loosely because the body rebinds this name to the single selected filter string.
selection (Dict[str, List[str]]) – Selected experiments and channels to scope the export to.
- MetadataView._get_event_id() int | None¶
Get the current event_id from the event_id input field.
- Returns:
Integer event_id, or None if the field is empty.
- Return type:
Optional[int]
- MetadataView._get_n_events() int¶
Get the number of events to plot from the n_events input field.
- Returns:
Number of events, defaulting to 1 if the field is empty.
- Return type:
- MetadataView._handle_other_actions(action_name: str, parameters: Dict[str, Any]) None¶
Raise an error for actions not yet implemented.
- Parameters:
- Raises:
NotImplementedError – Always
- MetadataView._handle_plot_events(parameters: Dict[str, Any]) None¶
Handle loading and plotting of selected events based on provided parameters.
- Parameters:
parameters (Dict[str, Any]) – Dictionary containing eventfinder, filter, channels, and event indices.
- MetadataView._load_filter(parameters: Dict[str, Any]) None¶
Append filters from a JSON file, warn if duplicates are found, and apply all new filters only if none conflict with existing ones.
- Parameters:
parameters (Dict[str, Any]) – Dictionary with ‘db_loader’.
- MetadataView._overlay_plot(parameters: Dict[str, Any]) bool¶
Handle the creation of a new overlay plot based on the selected parameters.
- Parameters:
parameters (Dict[str, Any]) – A dictionary of plotting parameters selected by the user.
- Returns:
True if at least one dataset was plotted, False otherwise - including when every requested dataset was skipped as already plotted, so that the caller can roll the recorded action back rather than leave an undo step that would restore an identical figure.
- Return type:
- MetadataView._plot_1d_density(ax: Axes, data: Any, cols: Sequence[str], units: Sequence[str | None], logscales: Sequence[bool], dataset_label: str = '', bins: Any = None, sizes: bool = False) None¶
- Parameters:
ax (Axes) – the axis object on which to plot
data (Any) – Dataframe of metadata to plot. Typed loosely because the body rebinds this name to the extracted column array.
cols (Sequence[str]) – Sequence of column names, only the first will be used
units (Sequence[Optional[str]]) – Sequence of unit strings for axis labels, only the first entry will be used
logscales (Sequence[bool]) – logscale the data in the given column before building the density plot?
dataset_label (str) – string to label the dataset
bins (Any) – Number of bins (if sizes==False) or size of bins (if sizes==True) for use when binning. Arrives as a single-element list from the controls and is rebound to a scalar (or None, to fall back to an automatic estimate) in the body, hence the loose annotation.
sizes (bool) – does the bins parameter refer to bin sizes (True) or widths (False)
- Raises:
ValueError – If bins is an empty list.
Calculate a plot a 1d kernel density with optional logscaling before binning
- MetadataView._plot_1d_histogram(ax: Axes, data: Any, cols: Sequence[str], units: Sequence[str | None], logscales: Sequence[bool], dataset_label: str = '', bins: Any = None, sizes: bool = False, norm: bool = False) None¶
- Parameters:
ax (Axes) – the axis object on which to plot
data (Any) – Dataframe of metadata to plot. Typed loosely because the body rebinds this name to the extracted column array.
cols (Sequence[str]) – Sequence of column names, only the first will be used
units (Sequence[Optional[str]]) – Sequence of unit strings for axis labels, only the first entry will be used
logscales (Sequence[bool]) – logscale the data in the given column before building the density plot? only the first will be used
dataset_label (str) – string to label the dataset
bins (Any) – Number of bins (if sizes==False) or size of bins (if sizes==True) for use when binning. Arrives as a single-element list from the controls and is rebound to a scalar (or None, to fall back to an automatic estimate) in the body, hence the loose annotation.
sizes (bool) – does the bins parameter refer to bin sizes (True) or widths (False)
norm (bool) – normalize output to [0,1]?
- Raises:
ValueError – If bins is an empty list.
Calculate a plot a 1d histogram with optional logscaling and normalization
- MetadataView._plot_3d_scatterplot(ax: Axes3D, data: DataFrame, cols: Sequence[str], units: Sequence[str | None], logscales: Sequence[bool], dataset_label: str = '') None¶
Create a 3D scatterplot of three metadata columns.
- Parameters:
ax (Axes3D) – A 3D Matplotlib axes object.
data (pd.DataFrame) – DataFrame with the columns to plot.
cols (Sequence[str]) – Sequence with three column names for x, y, and z.
units (Sequence[Optional[str]]) – Corresponding units.
logscales (Sequence[bool]) – Log scale flags for each axis.
dataset_label (str) – Label to apply to the scatter points.
- MetadataView._plot_all_points_histogram(ax: Axes, data: DataFrame, cols: Sequence[str], units: Sequence[str | None], dataset_label: str = '', norm: bool = False) None¶
Plot a histogram of current values across all events (raw or filtered).
- Parameters:
ax (Axes) – Matplotlib axes to draw the histogram on.
data (pd.DataFrame) – DataFrame containing time and current values.
cols (Sequence[str]) – Column names for x and y axes.
units (Sequence[Optional[str]]) – Units corresponding to the axes.
dataset_label (str) – Label for the plotted dataset.
norm (bool) – normalize output to [0,1]?
- MetadataView._plot_capture_rate(ax: Axes, data: Any, cols: Sequence[str], units: Sequence[str | None], logscales: Sequence[bool], dataset_label: str = '', bins: Any = None, sizes: bool = False) None¶
- Parameters:
ax (Axes) – the axis object on which to plot
data (Any) – Dataframe of metadata to plot. Typed loosely because the body rebinds this name to the extracted column array.
cols (Sequence[str]) – Sequence of column names, only the first will be used
units (Sequence[Optional[str]]) – Sequence of unit strings for axis labels, only the first entry will be used
logscales (Sequence[bool]) – logscale the data in the given column before building the density plot? only the first will be used
dataset_label (str) – string to label the dataset
bins (Any) – Number of bins (if sizes==False) or size of bins (if sizes==True) for use when binning. Arrives as a single-element list from the controls and is rebound to a scalar (or None, to fall back to an automatic estimate) in the body, hence the loose annotation.
sizes (bool) – does the bins parameter refer to bin sizes (True) or widths (False)
- Raises:
ValueError – If bins is an empty list, or too little data survives the log filter to estimate a capture rate.
Calculate the capture rate for the given subset
- MetadataView._plot_categorical_histogram(ax: Axes, data: DataFrame, cols: Sequence[str], units: Sequence[str | None], dataset_label: str = '') None¶
Calculate and plot a 1d categorical bar chart showing counts of unique values.
- Parameters:
ax (Axes) – the axis object on which to plot
data (pd.DataFrame) – Dataframe of metadata to plot, only the first named column will be used
cols (Sequence[str]) – Sequence of column names, only the first will be used
units (Sequence[Optional[str]]) – Sequence of unit strings for axis labels, only the first entry will be used
dataset_label (str) – string to label the dataset
- MetadataView._plot_heatmap(ax: Axes, data: DataFrame, cols: Sequence[str], units: Sequence[str | None], logscales: Sequence[bool], dataset_label: str = '', bins: Any = None, sizes: bool = False) None¶
Calculate a 2d heatmap with optional logscaling
- Parameters:
ax (Axes) – the axis object on which to plot
data (pd.DataFrame) – Dataframe of metadata to plot, only the first two named columns will be used
cols (Sequence[str]) – Sequence of column names, only the first two entries will be used
units (Sequence[Optional[str]]) – Sequence of unit strings for axis labels, only the first two entries will be used
logscales (Sequence[bool]) – logscale the data in the given column before building the density plot? only the first two entries will be used
dataset_label (str) – string to label the dataset
bins (Any) – Number of bins (if sizes==False) or size of bins (if sizes==True) for use when binning. Arrives as a single-element list from the controls and is rebound to a scalar (or None, to fall back to an automatic estimate) in the body, hence the loose annotation.
sizes (bool) – does the bins parameter refer to bin sizes (True) or widths (False)
- MetadataView._plot_scatterplot(ax: Axes, data: DataFrame, cols: Sequence[str], units: Sequence[str | None], logscales: Sequence[bool], dataset_label: str = '') None¶
Create a scatterplot of two metadata columns.
- Parameters:
ax (Axes) – Matplotlib axes object.
data (pd.DataFrame) – DataFrame containing the columns to plot.
cols (Sequence[str]) – Sequence containing two column names for x and y axes.
units (Sequence[Optional[str]]) – Corresponding units for x and y axes.
logscales (Sequence[bool]) – Log-scaling flags for x and y axes.
dataset_label (str) – Label for the dataset.
- MetadataView._rebuild_event_id_cache(loader: str, sql_filter: str, exp: str | None, channel: int | None) bool¶
Rebuild the filtered event_id cache when filter or scope changes. Also emits the display panel message (first plot or filter change only).
Goes through
load_metadatarather than querying the events table directly, so that the filter is evaluated against the same joins the subset and scatter paths give it. A filter on a sublevels column -filtered = 5, meaning every event with at least one sublevel that matches - is only meaningful againstevents JOIN sublevels, and the hand-builtSELECT event_id FROM eventsthis replaces made every such filter fail as an unknown column and then report itself as an empty subset.
- MetadataView._reset_actions(axis_type: str = '2d') None¶
Clears the figure and reinitializes axes. This will also add a flag to the tab action history if @register_action is being used to keep track of actions. Only actions applied after the most recent call to this function will be recreated if the related file is loaded.
- Parameters:
axis_type (str) – Either ‘2d’ or ‘3d’ to determine plot projection.
- MetadataView._set_control_area(layout: QBoxLayout) None¶
Set up the control area layout by inserting metadata controls.
- Parameters:
layout (QBoxLayout) – The layout to which the controls will be added.
- MetadataView._shift_range_and_update_plot(parameters: Dict[str, Any], direction: str) None¶
Shift the current event_id forward or backward through the cached filtered set and update the plot.
- MetadataView._show_add_filter_dialog(parameters: dict) None¶
Displays the dialog for adding a new subset filter. Validates filter syntax before actually saving the filter.
- Parameters:
parameters (dict) – Dictionary with ‘db_loader’.
- MetadataView._show_filter_info_dialog(comboBox: MultiSelectComboBox, parameters: Dict[str, Any]) None¶
Called when clicking the edit button for filters with multiple selection.
Validates that exactly one filter is selected and delegates to the edit dialog.
- Parameters:
comboBox (MultiSelectComboBox) – The combo box containing the list of selectable filters.
parameters (Dict[str, Any]) – Dictionary with ‘db_loader’.
- MetadataView._update_event_plot(event_data: Sequence[Dict[str, Any]], horizontal_lines: Sequence[List[float] | None], vertical_lines: Sequence[List[float] | None], points: Sequence[List[Tuple[float, float]] | None], horizontal_labels: Sequence[Sequence[str | None] | None], vertical_labels: Sequence[Sequence[str | None] | None], point_labels: Sequence[Sequence[str | None] | None], use_raw: bool = False) None¶
Update the event plot with raw, filtered, and fitted traces for multiple events.
Each event is plotted in its own subplot with time on the x-axis and current on the y-axis. The method also updates internal cache with data for interactive use (e.g., tooltips or exports).
- Parameters:
event_data (Sequence[Dict[str, Any]]) – List of dictionaries, each containing the data and metadata for one event. Each dictionary should have the keys: ‘experiment_id’, ‘channel_id’, ‘event_id’, ‘raw_data’, ‘filtered_data’, ‘fit_data’, and ‘samplerate’.
horizontal_lines (Sequence[Optional[List[float]]]) – One entry per subplot, each a list of y-values for horizontal line annotations, or None.
vertical_lines (Sequence[Optional[List[float]]]) – One entry per subplot, each a list of x-values for vertical line annotations, or None.
points (Sequence[Optional[List[Tuple[float, float]]]]) – One entry per subplot, each a list of (x, y) coordinate tuples for marker points, or None.
horizontal_labels (Sequence[Optional[Sequence[Optional[str]]]]) – One entry per subplot, each a list of labels for the horizontal lines, or None.
vertical_labels (Sequence[Optional[Sequence[Optional[str]]]]) – One entry per subplot, each a list of labels for the vertical lines, or None.
point_labels (Sequence[Optional[Sequence[Optional[str]]]]) – One entry per subplot, each a list of labels for the points, or None.
use_raw (bool) – Whether to also plot/cache the raw (unfiltered) trace alongside the filtered and fitted ones.
- Returns:
None
- Return type:
None