ibl_alignment_gui.loaders.plot_loader

Functions

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.

img

2D array representing image values.

Type:

np.ndarray

scale

Scaling factors for axes (x and y).

Type:

np.ndarray

levels

Levels for colormap scaling. These can be updated by the user

Type:

list or np.ndarray

default_levels

Default levels for colormap scaling.

Type:

list or np.ndarray

offset

Offset for axes (x and y).

Type:

np.ndarray

xrange

Range of the x-axis.

Type:

np.ndarray

xaxis

Label for the x-axis.

Type:

str

cmap

Colormap name.

Type:

str

title

Plot title.

Type:

str

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.

x

x-coordinates of the line.

Type:

np.ndarray

y

y-coordinates of the line.

Type:

np.ndarray

levels

Levels for colormap scaling. These can be updated by the user

Type:

list or np.ndarray

default_levels

Default levels for colormap scaling.

Type:

list or np.ndarray

xrange

Range of the x-axis.

Type:

np.ndarray

xaxis

Label for the x-axis.

Type:

str

vlines

Positions of vertical lines to be drawn.

Type:

list or None

mask

A boolean array indicating which poitns in the data to highlight with scatter points.

Type:

np.ndarray or None

mask_colour

The colour to use for the mask points.

Type:

str or None

mask_style

The style to use for the mask points.

Type:

str or None

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 ephys atlas feature plots.

Returns:

A dict containing multiple ProbeData objects with keys according to features.

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()[source]

Get all plot data for the different plot types.

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

image_raw_data()[source]

Generate data for image plots of raw 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_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.

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.

# TODO fix docstring
img

2D array containing data arranged according to probe banks.

Type:

np.ndarray

scale

Scaling factor along x and y axes.

Type:

list or np.ndarray

levels

Levels for colormap scaling. These can be updated by the user.

Type:

list or np.ndarray

default_levels

Default levels for colormap scaling.

Type:

list or np.ndarray

offset

Offset along x and y axes.

Type:

list or np.ndarray

xrange

Range of the x-axis.

Type:

np.ndarray

cmap

Colormap name.

Type:

str

title

Plot title.

Type:

str

data

An array of the data along the depth of probe (for 3D view)

Type:

np.ndarray or None

boundaries

Array of boundaries for banks or regions.

Type:

np.ndarray or None

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.

x

x-coordinates of points.

Type:

np.ndarray

y

y-coordinates of points.

Type:

np.ndarray

levels

Levels for colormap scaling. These can be updated by the user

Type:

list or np.ndarray

default_levels

Default levels for colormap scaling.

Type:

list or np.ndarray

colours

Hex colour or data values for each point.

Type:

np.ndarray

pen

Colour for the outline marker of each point

Type:

string or None

size

Size of each point.

Type:

np.ndarray

symbol

Marker symbol(s) for each point.

Type:

str or np.ndarray

xrange

Range of the x-axis.

Type:

np.ndarray

xaxis

Label for the x-axis.

Type:

str

title

Plot title.

Type:

str

cmap

Colormap name for coloring points.

Type:

str

cluster

Whether data is cluster data.

Type:

bool

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.