ibl_alignment_gui.loaders.plot_loader

Functions

_get_passive

Import brainbox.task.passive lazily.

compute_bincount

Compute 2D binned spike count and amplitude over time and depth.

compute_spike_average

Compute average spike amplitudes, depths, and firing rates for each cluster.

group_bincount

Average over chunks of group_size along the given axis.

skip_missing

Skip method execution if required data keys are missing or false.

Classes

ImageData

Data structure for 2D image plots.

LineData

Data structure for line plots.

PlotLoader

Class for handling plot data generation.

ProbeData

Data structure for probe plots.

ScatterData

Data structure for 2D scatter plots.

class ibl_alignment_gui.loaders.plot_loader.ImageData(img, scale, levels, default_levels, offset, xrange, xaxis, cmap, title)[source]

Bases: object

Data structure for 2D image plots.

Variables:
  • img (np.ndarray) – 2D array representing image values.

  • scale (np.ndarray) – Scaling factors for axes (x and y).

  • levels (list or np.ndarray) – Levels for colormap scaling. These can be updated by the user

  • default_levels (list or np.ndarray) – Default levels for colormap scaling.

  • offset (np.ndarray) – Offset for axes (x and y).

  • xrange (np.ndarray) – Range of the x-axis.

  • xaxis (str) – Label for the x-axis.

  • cmap (str) – Colormap name.

  • title (str) – Plot title.

cmap: str
default_levels: list | ndarray
img: ndarray
levels: ndarray
offset: ndarray
scale: ndarray
title: str
xaxis: str
xrange: ndarray
class ibl_alignment_gui.loaders.plot_loader.LineData(x, y, levels, default_levels, xrange, xaxis, vlines=None, mask=None, mask_colour=None, mask_style=None)[source]

Bases: object

Data structure for line plots.

Variables:
  • x (np.ndarray) – x-coordinates of the line.

  • y (np.ndarray) – y-coordinates of the line.

  • levels (list or np.ndarray) – Levels for colormap scaling. These can be updated by the user

  • default_levels (list or np.ndarray) – Default levels for colormap scaling.

  • xrange (np.ndarray) – Range of the x-axis.

  • xaxis (str) – Label for the x-axis.

  • vlines (list or None) – Positions of vertical lines to be drawn.

  • mask (np.ndarray or None) – A boolean array indicating which poitns in the data to highlight with scatter points.

  • mask_colour (str or None) – The colour to use for the mask points.

  • mask_style (str or None) – The style to use for the mask points.

default_levels: list | ndarray
levels: ndarray
mask: ndarray | None = None
mask_colour: str | None = None
mask_style: str | None = None
vlines: list | None = None
x: ndarray
xaxis: str
xrange: ndarray
y: ndarray
class ibl_alignment_gui.loaders.plot_loader.PlotLoader[source]

Bases: object

Class for handling plot data generation.

compute_avg_cluster_activity()[source]

Compute average amplitude, depth and firing rate for each cluster.

Return type:

None

Notes

This method sets the following attributes:

self.clust_idnp.ndarray

Cluster identifiers.

self.avg_ampnp.ndarray

Average spike amplitude per cluster.

self.avg_depthnp.ndarray

Average spike depth per cluster.

self.avg_frnp.ndarray

Average firing rate per cluster.

compute_rasters()[source]

Compute binned firing rate, amplitude, spike times, and depths.

Return type:

None

Notes

This method sets the following attributes:

self.chn_min_bcfloat

Minimum depth boundary including spike depths.

self.chn_max_bcfloat

Maximum depth boundary including spike depths.

self.frnp.ndarray

Binned firing rate array.

self.ampnp.ndarray

Binned spike amplitude array.

self.timesnp.ndarray

Binned spike time array.

self.depthsnp.ndarray

Depth values corresponding to bins.

feature_ephys_atlas()[source]

Generate data for the combined ephys atlas feature plot.

Tiles every available feature side by side into a single view.

Returns:

A dict with one key, ‘Ephys Atlas’, containing a Bunch of ProbeData objects keyed by feature.

Return type:

Dict

filter_units(filter_type)[source]

Filter spikes according to cluster metrics.

Parameters:

filter_type (str) – The filter criterion. Options are ‘All’, ‘IBL good’, ‘KS good’, ‘KS mua’.

Return type:

None

Notes

This method sets the following attributes:

self.cluster_idxnp.ndarray

The index of clusters that match the filter criteria

self.spike_idxnp.ndarray

The index of spikes contained in the filtered clusters (cluster_idx)

self.kp_idxnp.ndarray

The index of spikes that do not have NaN values for depth and amplitude

get_data(data, shank_sites)[source]

Get all plot data.

Parameters:
  • data (Bunch) – A bunch containing all the spikes and ephys data required to generate plots

  • shank_sites (Bunch) – A bunch containing electrode geometry information for given shank

get_plots(keep_levels=False)[source]

Get all plot data for the different plot types.

The plots are generated from scratch, so the levels that have been applied to them are replaced by the defaults for the newly generated data. Set keep_levels to reapply them instead, for example when regenerating the plots after changing the unit filter, where the levels chosen by the user should be kept.

Parameters:

keep_levels (bool, default=False) – Whether to reapply the levels that are currently applied to the plots.

Notes

This method sets the following attributes:

self.image_plotsBunch

All plots of type image

self.scatter_plotsBunch

All plots of type scatter

self.line_plotsBunch

All plots of type line

self.probe_plotsBunch

All plots of type probe

image_correlation()[source]

Generate data for an image plot of the correlation of binned firing rates across depth.

Returns:

A dict containing a ImageData object with key ‘Correlation’.

Return type:

Dict

image_firing_rate()[source]

Generate data for an image plot of binned firing rates across time.

Returns:

A dict containing a ImageData object with key ‘Firing Rate’.

Return type:

Dict

image_lfp_spectrum()[source]

Generate data for an image plot of the LFP power spectrum across frequency.

Returns:

A dict containing a ImageData object with key ‘LF spectrum’.

Return type:

Dict

Notes

  • Channels with the same depth are averaged together

  • The power spectrum is limited to the range 0-300 Hz

  • The power is converted to dB scale

image_passive_events()[source]

Generate data for image plots of the passive event aligned PSTHs.

Returns:

A dict containing multiple ImageData objects with keys according to stimulus type.

Return type:

Dict

Notes

  • Will only return data for passive events that are present in the data

  • Requires the optional ibllib dependency; returns an empty dict when it is missing

image_raw_ap_data()[source]

Generate data for image plots of raw AP band ephys data snippets.

Returns:

A dict containing multiple ImageData objects with keys according to the time of the snippet during the recording.

Return type:

Dict

image_raw_lf_data()[source]

Generate data for image plots of raw LFP band ephys data snippets.

Returns:

A dict containing multiple ImageData objects with keys according to the time of the snippet during the recording.

Return type:

Dict

image_rms_ap()[source]

Generate data for an image plot of the RMS of the AP band across time.

Returns:

A dict containing a ImageData object with key ‘rms_AP’.

Return type:

Dict

image_rms_lf()[source]

Generate data for an image plot of the RMS of the LFP band across time.

Returns:

A bunch containing a ImageData object with key ‘rms_LF’.

Return type:

Dict

line_amplitude()[source]

Generate data for a line plot of depth vs amplitude averaged across time.

Returns:

A dict containing a LineData object with key ‘Amplitude’.

Return type:

Dict

line_dead_channels()[source]

Generate data for a line plot of dead channels across depth.

Returns:

A dict containing a LineData object with key ‘Dead Channels’.

Return type:

Dict

line_firing_rate()[source]

Generate data for a line plot of depth vs firing rate averaged across time.

Returns:

A dict containing a LineData object with key ‘Firing Rate’.

Return type:

Dict

line_noisy_channels_coherence()[source]

Generate data for a line plot of noisy channels across depth.

Noisy channels in this plot are identified based on high coherence.

Returns:

A dict containing a LineData object with key ‘Noisy Channels Coherence’.

Return type:

Dict

line_noisy_channels_psd()[source]

Generate data for a line plot of noisy channels across depth.

Noisy channels in this plot are identified based on high PSD.

Returns:

A dict containing a LineData object with key ‘Noisy Channels PSD’.

Return type:

Dict

line_outside_channels()[source]

Generate data for a line plot of outide channels across depth.

Returns:

A dict containing a LineData object with key ‘Outside Channels’.

Return type:

Dict

probe_ephys_atlas()[source]

Generate a standalone probe plot for each available ephys atlas feature.

Unlike feature_ephys_atlas(), which tiles every feature into one combined view, each feature here is registered individually so it can be selected on its own from the probe plot menu, with the usual probe-plot colorbar/level controls.

Returns:

A dict containing one ProbeData object per available ephys atlas feature.

Return type:

Dict

probe_lfp_spectrum()[source]

Generate data for probe plots of the LFP power averaged across different frequency bands.

Returns:

A dict containing multiple ProbeData objects with keys according to frequency bands.

Return type:

Dict

probe_rfmap()[source]

Generate data for probe plots of the Receptive Field map (on and off) across depth.

Returns:

A dict containing ProbeData objects with for keys ‘RF Map - on’ and ‘RF Map - off’.

Return type:

Dict

Notes

  • Although this is a probe plot the data is not split into banks as for the case of other probe plots.

  • Requires the optional ibllib dependency; returns an empty dict when it is missing

probe_rms_ap()[source]

Generate data for a probe plot of the RMS of the AP band averaged across time.

Returns:

A dict containing a ProbeData object with key ‘rms_AP’.

Return type:

Dict

probe_rms_lf()[source]

Generate data for a probe plot of the RMS of the LFP band averaged across time.

Returns:

A dict containing a ProbeData object with key ‘rms_LF’.

Return type:

Dict

scatter_amp_depth_duration()[source]

Generate data for a scatter plot of cluster depth vs. cluster amplitude.

Scatter points are coloured by cluster peak to trough duration.

Returns:

A dict containing a ScatterData object with key ‘Cluster Amp vs Depth vs Duration’.

Return type:

Dict

scatter_amp_depth_fr()[source]

Generate data for a scatter plot of cluster depth vs. cluster amplitude.

Scatter points are coloured by cluster firing rate.

Returns:

A dict containing a ScatterData object with key ‘Cluster Amp vs Depth vs FR’.

Return type:

Dict

scatter_firing_rate()[source]

Generate data for a scatter plot of spike depths vs spike times, coloured by amplitude.

Returns:

A dict containing a ScatterData object with key ‘Amplitude’.

Return type:

Dict

Notes

  • Spikes data is subsampled for performance.

  • Amplitudes are split into a_bin bins and colours set accordingly.

  • Saturated amplitudes, those above the 90th percentile, are coloured dark purple.

scatter_fr_depth_amp()[source]

Generate data for a scatter plot of cluster depth vs. cluster firing rate.

Scatter points are coloured by cluster amplitude.

Returns:

A dict containing a ScatterData object with key ‘Cluster FR vs Depth vs Amp’.

Return type:

Dict

property spike_amps: ndarray

Get spike amplitudes for the selected spikes and non-NaN depths and amplitudes.

property spike_clusters: ndarray

Get spike clusters for the selected spikes and non-NaN depths and amplitudes.

property spike_depths: ndarray

Get spike depths for the selected spikes and non-NaN depths and amplitudes.

property spike_times: ndarray

Get spike times for the selected spikes and non-NaN depths and amplitudes.

class ibl_alignment_gui.loaders.plot_loader.ProbeData(img, scale, levels, default_levels, offset, xrange, cmap, title, data=None, boundaries=None)[source]

Bases: object

Data structure for probe plots.

Variables:
  • docstring (# TODO fix)

  • img (np.ndarray) – 2D array containing data arranged according to probe banks.

  • scale (list or np.ndarray) – Scaling factor along x and y axes.

  • levels (list or np.ndarray) – Levels for colormap scaling. These can be updated by the user.

  • default_levels (list or np.ndarray) – Default levels for colormap scaling.

  • offset (list or np.ndarray) – Offset along x and y axes.

  • xrange (np.ndarray) – Range of the x-axis.

  • cmap (str) – Colormap name.

  • title (str) – Plot title.

  • data (np.ndarray or None) – An array of the data along the depth of probe (for 3D view)

  • boundaries (np.ndarray or None) – Array of boundaries for banks or regions.

boundaries: ndarray | None = None
cmap: str
data: ndarray | None = None
default_levels: list | ndarray
img: ndarray
levels: list | ndarray
offset: ndarray
scale: ndarray
title: str
xrange: ndarray
class ibl_alignment_gui.loaders.plot_loader.ScatterData(x, y, levels, default_levels, colours, pen, size, symbol, xrange, xaxis, title, cmap, cluster)[source]

Bases: object

Data structure for 2D scatter plots.

Variables:
  • x (np.ndarray) – x-coordinates of points.

  • y (np.ndarray) – y-coordinates of points.

  • levels (list or np.ndarray) – Levels for colormap scaling. These can be updated by the user

  • default_levels (list or np.ndarray) – Default levels for colormap scaling.

  • colours (np.ndarray) – Hex colour or data values for each point.

  • pen (string or None) – Colour for the outline marker of each point

  • size (np.ndarray) – Size of each point.

  • symbol (str or np.ndarray) – Marker symbol(s) for each point.

  • xrange (np.ndarray) – Range of the x-axis.

  • xaxis (str) – Label for the x-axis.

  • title (str) – Plot title.

  • cmap (str) – Colormap name for coloring points.

  • cluster (bool) – Whether data is cluster data.

cluster: bool
cmap: str
colours: ndarray
default_levels: list | ndarray
levels: list | ndarray
pen: str | None
size: ndarray
symbol: str | ndarray
title: str
x: ndarray
xaxis: str
xrange: ndarray
y: ndarray
ibl_alignment_gui.loaders.plot_loader.compute_bincount(spike_times, spike_depths, spike_amps, xbin=0.05, ybin=5, **kwargs)[source]

Compute 2D binned spike count and amplitude over time and depth.

Parameters:
  • spike_times (np.ndarray) – Spike times.

  • spike_depths (np.ndarray) – Depths of spikes.

  • spike_amps (np.ndarray) – Amplitudes of spikes.

  • xbin (float) – Bin width along the x-axis (time).

  • ybin (float) – Bin width along the y-axis (depth).

  • **kwargs – Additional arguments for bincount2D.

Return type:

tuple[ndarray, ndarray, ndarray, ndarray]

Returns:

  • count (np.ndarray) – 2D binned spike counts.

  • amp (np.ndarray) – 2D binned spike amplitudes.

  • times (np.ndarray) – Bin edges for x-axis (time).

  • depths (np.ndarray) – Bin edges for y-axis (depth).

ibl_alignment_gui.loaders.plot_loader.compute_spike_average(spikes, clusters)[source]

Compute average spike amplitudes, depths, and firing rates for each cluster.

Parameters:
  • spikes (Bunch) – Spike data containing ‘amps’, ‘depths’, ‘times’, ‘clusters’.

  • clusters (Bunch) – Cluster data containing ‘channels’ and ‘metrics’.

Return type:

tuple[ndarray, ndarray, ndarray, ndarray]

Returns:

  • clust_idx (np.ndarray) – Array of cluster indices.

  • avg_amps (np.ndarray) – Average spike amplitude per cluster (uV).

  • avg_depths (np.ndarray) – Average depth per cluster.

  • avg_fr (np.ndarray) – Average firing rate per cluster (spikes/sec).

Notes

  • Clusters with no spikes are returned as NaN.

ibl_alignment_gui.loaders.plot_loader.group_bincount(arr, group_size, axis=1)[source]

Average over chunks of group_size along the given axis.

If leftover elements exist, sum them and append as the final group.

Parameters:
  • arr (np.ndarray) – 2D array to process.

  • group_size (int) – Number of elements per group to average.

  • axis (int) – Axis to operate on: 0 (rows) or 1 (columns). Default is 1.

Returns:

Array with grouped means and a final summed group if leftovers exist.

Return type:

np.ndarray

ibl_alignment_gui.loaders.plot_loader.skip_missing(required_keys)[source]

Skip method execution if required data keys are missing or false.