Power Spectral Density Plots of CBGTC spike times

class analyseur.cbgtc.visual.powspec.VizPSD[source]

Bases: object

View Power Spectral Density (PSD) Class.

Plot (display)

Plot in axis

plot()

plot_in_ax()

plot_aggstat()

plot_aggstat_in_ax()

plot_PSD_of_rate()

plot_PSD_of_rate_in_ax()

plot_heatmap()

plot_heatmap_in_ax()

plot_cluster()

plot_cluster_in_ax()

plot_with_spiketrains()

plot_spiketrain_in_ax()

Use Case:

  1. Setup

from  analyseur.cbgtc.loader import LoadSpikeTimes
from analyseur.cbgtc.visual.powspec import VizPSD

loadST = LoadSpikeTimes("/full/path/to/spikes_GPi.csv")
spiketimes_superset = loadST.get_spiketrains()
  1. Power Spectral Density for the whole simulation window

VizPSD.plot_pool(spiketimes_superset)
  1. PSD for desired window and bin size

VizPSD.plot_pool(spiketimes_superset, window=(0,5), binsz=1)  # time unit in seconds
VizPSD.plot_pool(spiketimes_superset, window=(0,5), binsz=0.05)

classmethod plot(spiketimes_set, neurons=None, nucleus=None, window=None, sampling_rate=None, resolution=None, mode=None)[source]

Plots each neuron’s PSD individually by calling plot_in_ax()

\[P_i(f) = \frac{1}{K}\sum_{m=1}^K\frac{1}{L}\left|\sum_{n=0}^{L-1}s_i^{(m)}(n)\cdot w(n)\cdot e^{-i2\pi f n/f_s}\right|^2\]

In addition to the arguments for plot_in_ax()

Parameters:

mode“portrait” or “landscape” [default]

NOTE: Unlike plot_in_ax() this will display the plot and also return the plotted matplotlib.pyplot.axis objects.


classmethod plot_PSD_of_rate(spiketimes_set, binsz=None, window=None, nucleus=None, resolution=None, method=None)[source]

Visualize the Power Spectral Density of the population rate using plot_PSD_of_rate_in_ax().

\[P_r(f) = PSD\{r(t)\}\]

where \(r(t) = \frac{1}{N}\sum_{i=1}^N s_i(t)\) is the rate for the spike train \(s_i(n)\) of the \(i\)-th neuron for total neurons \(N\).

NOTE: Unlike plot_PSD_of_rate_in_ax() this will display the plot and also return the plotted matplotlib.pyplot.axis objects.


static plot_PSD_of_rate_in_ax(ax, spiketimes_set, binsz=None, window=None, nucleus=None, resolution=None, method=None)[source]

Given a matplotlib.pyplot.axis and the firing rates of a given neuron population–\(r(t) = \frac{1}{N}\sum_{i=1}^N s_i(t)`where :math:`s_i(n)\) is the spike train of \(i\)-th neuron for total neurons \(N\)–this method draws the PSD of population rate.

\[P_r(f) = \left|\mathcal{F}\{r(t)\}\right|^2\]

\(\mathcal{F}\) is the Fourier transform operator. Other operators are Welch’s method and the Magnitude spectrum of the FFT.

Parameters:

or using get_spiketimes_subset()

[OPTIONAL]

Parameters:
  • nucleus – string; name of the nucleus

  • binsz – integer or float; 0.01 [default]

  • window – Tuple in the form (start_time, end_time); (0, 10) [default]

  • resolution~ 9.76 Hz = sampling_rate/1024 [default]

  • method“welch” or “fft” or “fft-mag”

Returns:

axis incorporating the plot


classmethod plot_aggstat(spiketimes_set, neurons=None, nucleus=None, window=None, sampling_rate=None, resolution=None)[source]

Visualize the Aggregate Statistic of the Power Spectral Density of the given neuron population using plot_aggstat_in_ax().

\[P_\text{pop}(f) = \frac{1}{N}\sum_{i=1}^N P_i(f)\]

NOTE: Unlike plot_aggstat_in_ax() this will display the plot and also return the plotted matplotlib.pyplot.axis objects.


classmethod plot_aggstat_in_ax(ax_mean_std, ax_percentile, ax_confidence_intervals, spiketimes_set, neurons=None, nucleus=None, window=None, sampling_rate=None, resolution=None)[source]

Given a matplotlib.pyplot.axis and the spike times of a given neuron population this method draws the Aggregate Statistic of the Power Spectral Density of the population

\[P_\text{pop}(f) = \frac{1}{N}\sum_{i=1}^N P_i(f)\]
Parameters:

or using get_spiketimes_subset()

[OPTIONAL]

Parameters:
  • neurons

    “all” [default] or scalar or range(a, b) or list of neuron ids like [2, 3, 6, 7]

    • ”all” means subset = superset

    • N (a scalar) means subset of first N neurons in the superset

    • range(a, b) or [2, 3, 6, 7] means subset of selected neurons

  • nucleus – string; name of the nucleus

  • window – Tuple in the form (start_time, end_time); (0, 10) [default]

  • sampling_rate1000/dt = 10000 Hz [default]; sampling_rate ∊ (0, 10000)

  • resolution~ 9.76 Hz = sampling_rate/1024 [default]

Returns:

three axes with respective plotting


classmethod plot_cluster(spiketimes_set, neurons=None, nucleus=None, window=None, sampling_rate=None, resolution=None)[source]

Visualize the Power Spectral Density by Cluster of the given neuron population using plot_cluster_in_ax().

NOTE: Unlike plot_cluster_in_ax() this will display the plot and also return the plotted matplotlib.pyplot.axis objects.


classmethod plot_cluster_in_ax(axes, spiketimes_set, neurons=None, nucleus=None, window=None, sampling_rate=None, resolution=None)[source]

Draws the Power Spectral Density by Cluster of the given neuron population on the given matplotlib.pyplot.axis

Parameters:
  • axes – 2-objects of the type matplotlib.pyplot.axis`

  • spiketimes_set – Dictionary returned using get_spiketimes_superset()

or using get_spiketimes_subset()

[OPTIONAL]

Parameters:
  • neurons

    “all” [default] or scalar or range(a, b) or list of neuron ids like [2, 3, 6, 7]

    • ”all” means subset = superset

    • N (a scalar) means subset of first N neurons in the superset

    • range(a, b) or [2, 3, 6, 7] means subset of selected neurons

  • nucleus – string; name of the nucleus

  • window – Tuple in the form (start_time, end_time); (0, 10) [default]

  • sampling_rate1000/dt = 10000 Hz [default]; sampling_rate ∊ (0, 10000)

  • resolution~ 9.76 Hz = sampling_rate/1024 [default]

Returns:

two axes with respective plotting


classmethod plot_heatmap(spiketimes_set, neurons=None, nucleus=None, window=None, sampling_rate=None, resolution=None)[source]

Visualize the Heatmap of the Power Spectral Density of the given neuron population using plot_heatmap_in_ax().

NOTE: Unlike plot_heatmap_in_ax() this will display the plot and also return the plotted matplotlib.pyplot.axis objects.


classmethod plot_heatmap_in_ax(fig, axes, spiketimes_set, neurons=None, nucleus=None, window=None, sampling_rate=None, resolution=None)[source]

Draws the Heatmap of the Power Spectral Density of the given neuron population on the given matplotlib.pyplot.axis

Parameters:

or using get_spiketimes_subset()

[OPTIONAL]

Parameters:
  • neurons

    “all” [default] or scalar or range(a, b) or list of neuron ids like [2, 3, 6, 7]

    • ”all” means subset = superset

    • N (a scalar) means subset of first N neurons in the superset

    • range(a, b) or [2, 3, 6, 7] means subset of selected neurons

  • nucleus – string; name of the nucleus

  • window – Tuple in the form (start_time, end_time); (0, 10) [default]

  • sampling_rate1000/dt = 10000 Hz [default]; sampling_rate ∊ (0, 10000)

  • resolution~ 9.76 Hz = sampling_rate/1024 [default]

Returns:

fig object and the two axes with respective plotting


classmethod plot_in_ax(ax, spiketimes_set, neurons=None, nucleus=None, window=None, sampling_rate=None, resolution=None)[source]

Given a matplotlib.pyplot.axis and the spike times of a given neuron population this method draws the PSD for each neuron.

\[P_i(f) = \frac{1}{K}\sum_{m=1}^K\frac{1}{L}\left|\sum_{n=0}^{L-1}s_i^{(m)}(n)\cdot w(n)\cdot e^{-i2\pi f n/f_s}\right|^2\]

where \(s_i(n)\) is the spike train of \(i\)-th neuron, \(L\) segment length and \(K\) is the number of Welch’s segments.

Parameters:

or using get_spiketimes_subset()

[OPTIONAL]

Parameters:
  • neurons

    “all” [default] or scalar or range(a, b) or list of neuron ids like [2, 3, 6, 7]

    • ”all” means subset = superset

    • N (a scalar) means subset of first N neurons in the superset

    • range(a, b) or [2, 3, 6, 7] means subset of selected neurons

  • nucleus – string; name of the nucleus

  • window – Tuple in the form (start_time, end_time); (0, 10) [default]

  • sampling_rate1000/dt = 10000 Hz [default]; sampling_rate ∊ (0, 10000)

  • resolution~ 9.76 Hz = sampling_rate/1024 [default]

Returns:

three axes with respective plotting

NOTE: Because the raw PSD can vary widely and to avoid division by zero the plot employs normalization

\[\widetilde{P}_i(f) = \frac{P_i(f)}{\text{max}_f P_i(f)}\]

which ensures \(\max_{f} \tilde{P}_i(f) = 1\). After normalization you compare spectral shape, not magnitude.


classmethod plot_spiketrain_in_ax(ax, spiketrains, yticks, time_axis)[source]

Given a matplotlib.pyplot.axis this draws the spike trains for each neuron of a given neuron population.


classmethod plot_with_spiketrains(spiketimes_set, neurons=None, nucleus=None, window=None, sampling_rate=None, resolution=None)[source]

Plots each neuron’s PSD individually by calling plot_in_ax() and their respective spike train by calling plot_spiketrain_in_ax().

Parameters:

spiketimes_set – Dictionary returned using get_spiketimes_superset()

or using get_spiketimes_subset()

[OPTIONAL]

Parameters:
  • neurons

    “all” [default] or scalar or range(a, b) or list of neuron ids like [2, 3, 6, 7]

    • ”all” means subset = superset

    • N (a scalar) means subset of first N neurons in the superset

    • range(a, b) or [2, 3, 6, 7] means subset of selected neurons

  • nucleus – string; name of the nucleus

  • window – Tuple in the form (start_time, end_time); (0, 10) [default]

  • sampling_rate1000/dt = 10000 Hz [default]; sampling_rate ∊ (0, 10000)

  • resolution~ 9.76 Hz = sampling_rate/1024 [default]

Returns:

four axes with respective plotting