simplecochlea.spikes package

Submodules

simplecochlea.spikes.spikelist module

This file is part of simplecochlea.

simplecochlea is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

simplecochlea is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with simplecochlea. If not, see <https://www.gnu.org/licenses/>.

class simplecochlea.spikes.spikelist.SpikeList(time=[], channel=[], pattern_id=[], potential=[], n_channels=0, name='', tmin=0, tmax=[], pattern_names={})[source]

Bases: object

SpikeList Class. A spike is defined by a time and a channel. In addition a pattern ID ad a potential can be assigned to spikes. These characteristics are defined as list.

Attributes:
time : array

Time of each spike (in seconds)

channel : array [int]

Channel of each spike

pattern_id : array [int]

Pattern ID of each spike (Optional). If not defined is nan

potential : array

Spikes potential (Optional). If not defined is 0

n_channels : int

Number of channels in the spikelist

n_spikes : int

Number of spikes in the spikelist

name : str

Spikelist name

tmin : float

Starting time of the spikelist (default: 0)

Note

For spikelist generating by running a signal through the cochlea, the tmin attribute is not the time of the first spike but the starting time of the signal (0 usually).

tmax : float

Ending time of the spikelist. If not given, tmax is set to the maximal spike time

Note

For spikelist generating by running a signal through the cochlea, the tmax attribute should not be the time of the last spike but the ending time of the signal.

pattern_names : dict

Dictionnary giving a label to each pattern defined by pattern_id

Methods

add_time_offset(t_offset) Add a time offset to the spikes time.
convert_to_packet(packet_size[, overlap]) Deprecated.
epoch(t_start, t_end) Epoch the spikelist given the time periods defined by t_start and t_end.
epoch_on_triggers(t_triggers, time_pre, …) Apply the epoch function on each trigger whose time is defined by t_triggers.
export([export_path, export_name]) Export the spikelist as a .mat file
get_channel_selectivity() Compute channel selectivity.
get_mean_isi() Compute and return the mean ISI (Inter-Spike-Interval) for each channel.
get_median_isi() Compute and return the median ISI (Inter-Spike-Interval) for each channel.
get_pattern_results(t_start, t_end, pattern_id) Compute the number of spikes per segment.
plot([bin_duration, potential_thresh, …]) Plot the spikelist.
plot_channel_selectivity([title_str]) Plot channel selectivity.
select_spike([time_min, time_max, …]) Select a subset of the spikelist.
set_pattern_id_from_time_limits(t_start, …) Given time limits given by t_start and t_end, set the pattern_id of spikes in this time interval.
set_pattern_id_from_time_limits_old(t_start, …) Deprecated - Use set_pattern_id_from_time_limits
sort(field) Sort the spikelist by increasing attribute, selected by field
to_dataframe() Convert the spikelist to a dataframe containing 3 fields : ‘time’, ‘channel’ and ‘pattern_id’
add_time_offset(t_offset)[source]

Add a time offset to the spikes time. Used when creating list of spikelists.

convert_to_packet(packet_size, overlap=0)[source]

Deprecated. Used to convert the spikelist to spike packets

epoch(t_start, t_end)[source]

Epoch the spikelist given the time periods defined by t_start and t_end. Returns a SpikeList_list instance.

Parameters:
t_start : array

Start of each time period (s)

t_end : array

End of each time period (s)

Returns:
spikelist_list : SpikeList_list

A SpikeList_list instance.

epoch_on_triggers(t_triggers, time_pre, time_post)[source]

Apply the epoch function on each trigger whose time is defined by t_triggers.

Parameters:
t_triggers : array

Time of each trigger (s)

time_pre : float

Time to keep before triggers

time_post : float

Time to keep after triggers

Returns:
spikelist_list : SpikeList_list

A SpikeList_list instance.

export(export_path='.', export_name='spikelist_0_')[source]

Export the spikelist as a .mat file

Parameters:
export_path : str

Export directory path (default: ‘.’)

export_name : str

Export file name

get_channel_selectivity()[source]

Compute channel selectivity. Definition ?

get_mean_isi()[source]

Compute and return the mean ISI (Inter-Spike-Interval) for each channel.

Returns:
mean_isi : array

Mean ISI for each channel of the spikelist.

get_median_isi()[source]

Compute and return the median ISI (Inter-Spike-Interval) for each channel.

Returns:
median_isi : array

Median ISI for each channel of the spikelist.

get_pattern_results(t_start, t_end, pattern_id, pattern_names=[], min_potential=[], do_plot=True, fig_title='')[source]

Compute the number of spikes per segment. Segments are defined by t_start and t_end. There might be multiples patterns, defined by pattern_id and pattern_names. If min_potential is defined, select only the spikes whose potential is higher than this. If do_plot is true, plot the results.

Parameters:
t_start : array

Starting times of the segments (s)

t_end : array

Ending times of the segments (s)

pattern_id : array

Pattern id of the segments

pattern_names : array | None

Pattern name of the segments

min_potential : float | None

If defined select only spikes whose potential is higher than this

do_plot : bool | None (default: True)

If true, plot the results

fig_title : str | None

Figure’s title

Returns:
n_spikes_mean : array (size n_patterns)

Mean number of spikes across repetition for each pattern

n_spikes_per_chunk : array (size n_segments)

Number of spikes for each segment

n_active_chan_mean : array (size n_pattern)

Mean number of active channel across repetition for each pattern

n_active_chan_per_chunk : array (size n_segments)

Number of active channel for each segment

plot(bin_duration=0.002, potential_thresh=[], ax_list=[], minplot=0, tau_lif=[], pattern_id_sel=[], color=[])[source]

Plot the spikelist. The main central axis plots the spike list, one dot for each spike. Each pattern has a different color. The bottom axis plots the histogram of the spikes for all channels. The right axis sums up the spikes over time for each channel. The left axis plot the median ISI (Inter-Spike Interval), and if the tau_lif parameter is given, the ratio ISI_med / Tau_Lif is also plotted.

Parameters:
bin_duration : float (default: 0.002s)

Bin duration in seconds for the time histogram, in the bottom axis.

potential_thresh : float | none (default)

Potential threshold, only spike whose potential is higher than this value will be plotted. If none, plot all the spikes.

ax_list : list | none (default)

Axis handles to plot on. If none, create new axes.

minplot : bool (default: False)

If True, plot only the central plot.

tau_lif : float | array | none (default)

Tau parameter of the LIF bank of the cochlea. If provided, the ratio ISI_med / Tau_Lif is plotted on the left axis.

pattern_id_sel : int | none (default)

Pattern to select. If provided, the spikes of the selected pattern will appears on a different color in the left and right axes.

color : list | array | none (default)

Color of the patterns. If none, use default color

Returns:
ax_list : list

List of the axes [central, bottom, right, left]

plot_channel_selectivity(title_str='')[source]

Plot channel selectivity. Definition ?

Parameters:
title_str : str

Optional title for the figure

select_spike(time_min=[], time_max=[], channel_sel=[], potential_min=[], potential_max=[], pattern_id_sel=[])[source]

Select a subset of the spikelist. If multiples selection parameters are given, select the spikes meeting all conditions.

Parameters:
time_min : float (s) | None

Select spikes whose time is superior or equal to time_min

time_max : float (s) | None

Select spikes whose time is inferior or equal to time_max

channel_sel : list | array | None

Select spikes whose channel is in channel_sel

potential_min : float | None

Select spikes whose potential is superior or equal to potential_min

potential_max : float | None

Select spikes whose potential is inferior or equal to potential_max

pattern_id_sel : int

Select spikes whose pattern_id is equal to pattern_id_sel

Returns:
sel_ind : array [bool]

Boolean array representing selected spikes

spikelist_sel : SpikeList

Selected SpikeList

n_spikes : int

Number of spikes in the selected spikelist

set_pattern_id_from_time_limits(t_start, t_end, pattern_id, pattern_dict)[source]
Given time limits given by t_start and t_end, set the pattern_id of spikes in this time interval.
Also add entries to the pattern_names dictionnary of the spikelist.
Parameters:
t_start : array

Start of each time period (s)

t_end : array

End of each time period (s)

pattern_id : array [int]

Pattern ID of each time period

pattern_dict :

Dictionnary given the labels associated with each different pattern ID.

set_pattern_id_from_time_limits_old(t_start, t_end, pattern_id, pattern_names=[])[source]

Deprecated - Use set_pattern_id_from_time_limits

sort(field)[source]

Sort the spikelist by increasing attribute, selected by field

Parameters:
field : str

Attribute to sort the spikelist. Must be in [‘time’, ‘channel’, ‘pattern_id’, ‘potential’]

to_dataframe()[source]

Convert the spikelist to a dataframe containing 3 fields : ‘time’, ‘channel’ and ‘pattern_id’

Returns:
df : Pandas DataFrame

The spikelist as a dataframe

class simplecochlea.spikes.spikelist.SpikeList_list(spikelist_list, t_start=[], t_end=[])[source]

Bases: object

SpikeList_list Class. Defines a list of SpikeList instances. Can represents differents epochs of a global spikelist, spikelists corresponding to repetitions of a pattern.

Methods

compute_channel_with_spikes() Get proportion of channel with spikes in all epochs
compute_fano_factor() Compute the Fano Factor (~dispersion) of the number of spikes in each spike list, for each channel.
compute_spike_per_channel_variation() Compute the coefficient of variation of the number of spikes per channel for each spikelist
compute_vanrossum_distance([cos, tau]) Compute the van Rossum distance (see: A Novel Spike Distance - M. C. W. van Rossum).
plot([n_max_cols, plot_vr_dist]) Plot all the spikelist in the same figure
plot_superpose([plot_fano_factor, plot_vr_dist]) Plot all the spikelists of the SpikeList_list superimposed on the same axes.
compute_channel_with_spikes()[source]

Get proportion of channel with spikes in all epochs

Returns:
channel_with_spikes_ratio : array
compute_fano_factor()[source]

Compute the Fano Factor (~dispersion) of the number of spikes in each spike list, for each channel. Fano factor is defined as the variance divided by the mean of a random process The global fano factor returned is the mean across channels

Returns:
fano_factor :
global_fano_factor :
compute_spike_per_channel_variation()[source]

Compute the coefficient of variation of the number of spikes per channel for each spikelist

Returns:
var_coeff, var_coeff_mean
compute_vanrossum_distance(cos=0.1, tau=0.001)[source]

Compute the van Rossum distance (see: A Novel Spike Distance - M. C. W. van Rossum). Also compute the distance normalized by sqrt((M+N)/2) where M and N are the number of spikes in the 2 spike trains. This way the normalized distance between 2 uncorrelated Poisson spike trains in 1. The result is divided by sqrt(2) due to the implementation in pymuvr to get similar results as in the original paper.

The function return the mean of these distance across each comparison of the spikelist_list for each channel.

Parameters:
cos : float

??? - Does not seem to have much influence

tau : float

Time constant for the exponential tail

Returns:
mean_vr_dist
mean_vr_dist_norm :
global_vr_dist:
global_vr_dist_norm
plot(n_max_cols=5, plot_vr_dist=0)[source]

Plot all the spikelist in the same figure

Parameters:
n_max_cols : int

Maximal number of columns.

plot_vr_dist : bool (default: False)
plot_superpose(plot_fano_factor=1, plot_vr_dist=1)[source]

Plot all the spikelists of the SpikeList_list superimposed on the same axes.

Parameters:
plot_fano_factor : bool (default: True)

If True, plot the Fano Factor

plot_vr_dist : bool (default: True)

If True, plot the mean Van-Rossum distance

simplecochlea.spikes.spikelist.dual_spikelist_plot(spikelist_in, spikelist_out, potential_thresh_in=0, potential_thresh_out=0, tau_lif=[], pattern_id_sel_in=[], pattern_id_sel_out=[])[source]
Dual Spikelist Plot.
Plot 2 spikelists in the same figure. Useful when the two spikelist share common parameters. The second spikelist can be obtained from the first one, after running a learning rule for example. First/Top spikelist is defined by spikelist_in and the second/bottom spikelist is defined by spikelist_out
Parameters:
spikelist_in : SpikeList

First spikelist, plot on top

spikelist_out : SpikeList

Second spikelist, plot at the bottom

potential_thresh_in : float

If defined, only spikes of spikelist_in whose threshold is superior to this value will be plot.

potential_thresh_out : float

If defined, only spikes of spikelist_out whose threshold is superior to this value will be plot.

tau_lif : array

Tau value of the LIF neurons of the cochlea (used to generate these spikelists).

pattern_id_sel_in : int

If defined, only spikes of spikelist_in with this ID will be plot

pattern_id_sel_out : int

If defined, only spikes of spikelist_out with this ID will be plot

Returns:
[ax0, ax1, …, ax7] : list

A list of all the axes

simplecochlea.spikes.spikelist.import_spikelist_from_mat(import_path, n_channels)[source]

Import a spikelist (SpikeList instance) from a .mat file.

Parameters:
import_path : str

Spikelist file path

n_channels : int

Number of channels in the spikelist - Now is included in the spikelist.

Returns:
spikelist : SpikeList

The SpikeList instance.

simplecochlea.spikes.spikepacket module

class simplecochlea.spikes.spikepacket.SpikePacket(spike_list, packet_size, overlap=0)[source]

Bases: object

Methods

plot  
plot()[source]

Module contents

Spikes Module