neoStructures module

class neoStructures.NeoAll(spikesorting_dirpath, spikesorting_filename, probe_filepath, signal_dirpath=[], event_filepath=[], event_csv_sep=';', fig_dirpath=[], save_fig=0, srate=30000, t_max=-1)

Contain spike sorting data from Spyking-Circus results file. Create one Neo Segment per unit.

spikesorting_dirpath : str
Path of the directory containng the spyking circus result file
spikesorting_filename : str
Name of the Spiking Circus result file
probe_filepath : str
Path to the Spiking Circus probe file
signal_dirpath :str | none (default)
Path of the directory containing the LFP signals files (must be in EDF format)
event_filepath : str | none (default)
Path to the event file
event_csv_sep : str (default ‘;’)
Separator used in the event file
fig_dirpath : str | none (default)
Path to the directory where figures will be saved. If none and save_fig is true, then save the figures in the current directory.
save_fig : bool
If True, save the figures
srate : float
Sampling rate (Hz)
t_max : float
Maximum time of spike. If not provided will be computed from the spiketrains.
n_units : int
Number of units
unit_names : array
Name of each unit
unit_shapes : array
Shape/Template of each unit
unit_preferred_chan : array
Preferred channel for each unit
channel_names : array
Name of the channels of the LFP files
electrode_names : array
Name of the electrode for each channel
electrode_names_unique : array
Unique electrode names
fig_dirpath : str
Path where the figure are saved
segments : List of Neo Segments
Neo Segment, 1 per unit
channel_indexes : Neo ChannelIndex
Neo ChannelIndex, 1 per tetrode
signal_provided : bool
True if LFP signal was provided, False otherwise

Methods

channelpos2elec(channel_pos) From the channel (micro-wire) position, return the corresponding electrode’s number and name
channelpos2tetrode(channel_pos) From the channel (micro-wire) position, return the information about the tetrode of this channel
create_epochs_around_events(event_name, …) Create Neo Epochs objects around events specified by event name.
create_event_list(event_times, event_names) Create Neo Event objects for each event specified by event_times and event_names.
elecnum2channelpos(elec_num) From the electrode’s number return the electrode’s channels position and name
get_spikerate_change_ratio_on_epochs(…) Compute the mean spikerate on all target and reference epochs, calcul the ratio of these two, for each unit
getunitpreferredchannelname(unit_name) Get the preferred channel of a unit from the unit’s name
plot_crosscorrelogram(unit_pos_a, unit_pos_b) Plot the cross-correlogram between spiketrains of units specified by unit_pos_a and unit_pos_b
plot_isi([unit_pos, bin_duration_ms, …]) Plot the Inter-Spike Intervals histogram for unit specified by unit_pos
plot_raw_unit_shape(unit_pos, …[, sep, …]) Get the raw signal of each action potential for the unit specified by unit_pos.
plot_spikerate_change_ratio_on_epochs(…[, …]) Plot the mean spikerate ratio between 2 epochs.
plot_spikerate_evolution([unit_pos, …]) Plot the spikerate evolution across all the segment duration for units specified by unit_pos
plot_spikerate_evolution_group(grp_index[, …]) Plot the spike rate evolution across all the length of the segment of all units of the channel index specified by grp_index.
plot_unit_shape([unit_pos, plot_mean, ax]) Plot the shape of unit specified by unit_pos
read_event_file(event_filepath[, event_csv_sep]) Read the event file, specified by event_filepath and add the event to each segments using the neoStructures.NeoAll.create_event_list() method.
reject_spikes_around_events(event_name, …) Reject spikes around events specified by event_name.
save(dirpath[, filename]) Save the instance as a pickle (.p) file The filename is appended with the currendt date and time
subfun_plot_unit_shape(unit_pos[, …]) Sub-routine for plotting shape of the unit
export_spike_file_time  
channelpos2elec(channel_pos)

From the channel (micro-wire) position, return the corresponding electrode’s number and name

Parameters:
channel_pos : int

Channel’s (micro-wire) position

Returns:
el_num : int

Corresponding electrode’s number

el_name : str

Corresponding electrode’s name

channelpos2tetrode(channel_pos)

From the channel (micro-wire) position, return the information about the tetrode of this channel

Parameters:
channel_pos : int

Channel’s (micro-wire) position

Returns:
tetrode_num : int

Corresponding tetrode number

tetrode_channels_pos : array

Position of the 4 channels of the tetrode

wire_num_in_tetrode : int

Position of the input channel in the tetrode (between 0 and 3)

tetrode_channels_pos_glob : array

??? same as tetrode_channels_pos ???

create_epochs_around_events(event_name, time_offset, epoch_duration, epoch_names)

Create Neo Epochs objects around events specified by event name. The epoch times start at the event time plus an possible offset time_offset, the duration is specified by epoch_duration. Epochs are added to all segments

Parameters:
event_name : str

Event name from where to create epochs

time_offset : float

Time offset from the event time

epoch_duration : float

Duration of the epoch

epoch_names : str

Name of the epoch

create_event_list(event_times, event_names, segment_pos=-1)

Create Neo Event objects for each event specified by event_times and event_names. Add these events to all segments specified by segment_pos

Parameters:
event_times : array

Time of each event (s)

event_names : array

Name of each event

segment_pos : int | array

Position of the segments in which events must be added

elecnum2channelpos(elec_num)

From the electrode’s number return the electrode’s channels position and name

Parameters:
elec_num : int

Electrode position

Returns:
channel_pos : array

Position of the input electrode’s channels

channel_names : array

Name of the input electrode’s channels

export_spike_file_time(artefact_free_periods_filepath, output_path, unit_pos=[], sep=';')
get_spikerate_change_ratio_on_epochs(epoch_name_target, epoch_name_ref)

Compute the mean spikerate on all target and reference epochs, calcul the ratio of these two, for each unit

Parameters:
epoch_name_target : str

Name of the target epochs

epoch_name_ref : str

Name of the reference epochs

Returns:
spikerate_ratio : list
spikerate_target : list
spikerate_ref : list
getunitpreferredchannelname(unit_name)

Get the preferred channel of a unit from the unit’s name

Parameters:
unit_name : str

Name of the unit

Returns:
channel_name : str

Name of the preferred channel (micro-wire) of the input unit

plot_crosscorrelogram(unit_pos_a, unit_pos_b, bin_time=array(1.) * ms, max_lag_time=array(80.) * ms, smooth_time=array(10.) * ms, merge_plots=0, same_yscale=0, fill_under_plot=0, do_stat=0, n_surrogates=100, normal_dist_sd=array(10.) * ms, do_plot=1)

Plot the cross-correlogram between spiketrains of units specified by unit_pos_a and unit_pos_b

Parameters:
unit_pos_a : int

Position of first unit

unit_pos_b : int

Position of second unit

bin_time : float | duration quantity (default: 1*ms)

Bin duration (in ms)

max_lag_time : float | duration quantity (default: 80*ms)

Maximal lag time (in ms)

smooth_time : float | duration quantity (default: 10*ms)

Smoothing time (in ms)

merge_plots : bool (default: False)

If True, merge all the cross-correlogram in one figure

same_yscale : bool (default: False)

If True, the y-axis limits are the same

fill_under_plot : bool (default: False)

If True, fill the area under the plot

do_stat : bool (default: False)

If True, do some wrong statistics

n_surrogates : int (default: 100)

Number of jittered spike-trains when doing the wrong stats

normal_dist_sd : float | duration quantity (default: 50*ms)

Parameter for the stats

Returns:
cch : array

Cross-correlation histogram between the spike-trains of input units

bins : array

Contains the IDs of the individual histogram bins

plot_isi(unit_pos=-1, bin_duration_ms=1, tmax_ms=100, logscale=0)

Plot the Inter-Spike Intervals histogram for unit specified by unit_pos

Parameters:
unit_pos : int

Unit position

bin_duration_ms : float (default: 1)

Bin duration for the histogram in ms

tmax_ms : float (default: 100)

Maximal time interval

logscale : bool

If True, the scale of the x-axis is logarithmic

plot_raw_unit_shape(unit_pos, signal_dirpath, artefact_free_periods_filepath, sep=';', fir_order=400, iir_type='bessel', iir_order=2, fn_hz=[300, 3000], half_duration=0.0018, realign=False, plot_mean_shape=True, plot_density_plot=True)

Get the raw signal of each action potential for the unit specified by unit_pos. This allows to investigate the filtering effects on the shape of the unit.

Parameters:
unit_pos : int

Unit’s position

signal_dirpath : str

Path to the directory containing the EEG files

artefact_free_periods_filepath : str

Path to the file containing the periods free of artefacts. Must be a CSV file with 3 columns in the order {‘Filename’, ‘t_start’, ‘t_end’}, with a 1 row header.

sep : str (default: ‘;’)

CSV separator

fir_order : int (default

FIR filter order

iir_type : str (default: ‘bessel’)

IIR filter type - can be ‘bessel’, ‘butter’

iir_order : int (default

IIR filter order

fn_hz : float | array

Cut-off frequency in Hertz. If a scalar, filter will be a high-pass. If contains 2 frequencies, filter will be a band-pass filter. Default : [300, 3000]

half_duration : float (default

Half-duration of the observed spikes

realign : bool (default

If true, tries to realign the spike traces based on the extremum.

plot_mean_shape : bool (default

If true, plot the mean unit shape

plot_density_plot : bool (default

If true, plot the density plot

plot_spikerate_change_ratio_on_epochs(epoch_name_target, epoch_name_ref, plot_ratio_only=0, single_plot=1, merge_plot=0)

Plot the mean spikerate ratio between 2 epochs. Call the method get_spikerate_change_ratio_on_epochs.

Parameters:
epoch_name_target : str

Name of the target epochs

epoch_name_ref : str

Name of the reference epochs

plot_ratio_only : bool (default: False)

If True, plot only the ratio and not the target and reference spiking rate

single_plot : bool (default: True)

If True, plot individual figures

merge_plot : bool (default: False)

If True, merge the figures

Returns:
spikerate_ratio : array
plot_spikerate_evolution(unit_pos=-1, sigma_gauss_kernel=array(30.) * s, merge_plots=0, norm_spikerate=0, plot_events=1)

Plot the spikerate evolution across all the segment duration for units specified by unit_pos

Parameters:
unit_pos : int (default: -1)

Position of the unit. If equal to -1

sigma_gauss_kernel : float | duration quantity (default: 150s)

Duration of the smoothing gaussian kernel

merge_plots : bool (default: False)

If True, merge the plots

norm_spikerate : bool (default: False)

If True, normalize the spiking rate between 0 and 1

plot_events : bool (default: True)

If True, plot a vertical line for each event

plot_spikerate_evolution_group(grp_index, sigma_gauss_kernel=array(30.) * s, merge_plots=0, norm_spikerate=0, mean_plot=0, plot_events=1)

Plot the spike rate evolution across all the length of the segment of all units of the channel index specified by grp_index. The spike rate is computed using the Elephant module

Parameters:
grp_index : int | str

Either the position of the channel index, or its name

sigma_gauss_kernel : float | duration quantity (default: 100*s)

Time of the smoothing gaussian kernel

merge_plots : bool (default: False)

If True, merge the plots

norm_spikerate : bool (default: False)

If True, normalize the spiking rate between 0 and 1

mean_plot : bool (default: False)

If True, only the mean spikerate across all units of the group/channel_index is plot

plot_events : bool (default: True)

If True, plot a vertical line for each event

plot_unit_shape(unit_pos=-1, plot_mean=0, ax=[])

Plot the shape of unit specified by unit_pos

Parameters:
unit_pos : int

Position of the unit

plot_mean : bool

If True, plot the mean of all tetrode templates/shapes

ax : axis | None

Axis to plot on. If none create a new figure and an axis

read_event_file(event_filepath, event_csv_sep=';')

Read the event file, specified by event_filepath and add the event to each segments using the neoStructures.NeoAll.create_event_list() method. This can be done directly when instanciating the NeoAll instance by providin the event_filepath parameter or by calling this function.

Parameters:
event_filepath : str

Path to the event file

event_csv_sep : str

CSV file separator (default: ‘;’)

reject_spikes_around_events(event_name, time_pre, time_post)

Reject spikes around events specified by event_name. All spikes occuring in the window [t_event-time_pre < t < t_event+time_post] will be rejected, for each event. Modify the spiketrains of the segments in which an event is defined.

Parameters:
event_name : str

Name of the events to select

time_pre : float

Beginning of the window, relative to the event time

time_post : float

End of the window, relative to the event time

save(dirpath, filename=[])

Save the instance as a pickle (.p) file The filename is appended with the currendt date and time

Parameters:
dirpath : str

Directory path

filename : str | None

Output filename. If none is ‘neoall_{currentdate}.p’

subfun_plot_unit_shape(unit_pos, plot_mean=0, ax=[], raster_plot_call=0)

Sub-routine for plotting shape of the unit

Parameters:
unit_pos : int

Unit’s position

plot_mean : bool (default: False)

If True, plot the mean of the unit’s shape over the 4 micro-wires of the tetrode

ax : axis handle | None

If provided, plot the figure on this axis

raster_plot_call : bool (default: False)

Should be true, when this method is called from the plot_rasterplot method

class neoStructures.NeoEpoch(neoAll, event_filepath, event_csv_sep=';', time_pre=1, time_post=1)

NeoEpoch instances are created from a NeoAll instance. The spiketrains contained in the NeoAll instance are divided into epochs from an event file. Spikes occuring around each event are kept ([time_pre, ``time_post]). NeoEpoch contains a list of Neo Segments. Each segment represent one epoch. Each segment contains as many Neo SpikeTrain as there are units. Each segment also contain a Neo AnalogSignal instance representing the LFP signal associated with the spiketrains.

Methods

channelpos2elec(channel_pos) From the channel (micro-wire) position, return the corresponding electrode’s number and name
channelpos2tetrode(channel_pos) From the channel (micro-wire) position, return the information about the tetrode of this channel
elecnum2channelpos(elec_num) From the electrode’s number return the electrode’s channels position and name
getunitpreferredchannelname(unit_name) Get the preferred channel of a unit from the unit’s name
plot_crosscorrelogram_around_events(…[, …]) Plot the cross-correlogram around the events of neoEpoch. Compute the shift-predictor to give a significance
plot_rasterplot([unit_pos, bin_duration, …]) Plot the PSTH (peri/post stimulus time histogram) for selected units.
save(dirpath[, filename]) Save the instance as a pickle (.p) file The filename is appended with the currendt date and time
subfun_plot_unit_shape(unit_pos[, …]) Sub-routine for plotting shape of the unit
channelpos2elec(channel_pos)

From the channel (micro-wire) position, return the corresponding electrode’s number and name

Parameters:
channel_pos : int

Channel’s (micro-wire) position

Returns:
el_num : int

Corresponding electrode’s number

el_name : str

Corresponding electrode’s name

channelpos2tetrode(channel_pos)

From the channel (micro-wire) position, return the information about the tetrode of this channel

Parameters:
channel_pos : int

Channel’s (micro-wire) position

Returns:
tetrode_num : int

Corresponding tetrode number

tetrode_channels_pos : array

Position of the 4 channels of the tetrode

wire_num_in_tetrode : int

Position of the input channel in the tetrode (between 0 and 3)

tetrode_channels_pos_glob : array

??? same as tetrode_channels_pos ???

elecnum2channelpos(elec_num)

From the electrode’s number return the electrode’s channels position and name

Parameters:
elec_num : int

Electrode position

Returns:
channel_pos : array

Position of the input electrode’s channels

channel_names : array

Name of the input electrode’s channels

getunitpreferredchannelname(unit_name)

Get the preferred channel of a unit from the unit’s name

Parameters:
unit_name : str

Name of the unit

Returns:
channel_name : str

Name of the preferred channel (micro-wire) of the input unit

plot_crosscorrelogram_around_events(unit_pos_a, unit_pos_b, bin_time=array(1.) * ms, max_lag_time=array(80.) * ms, n_repets=100, plot_superpose=1)
Plot the cross-correlogram around the events of neoEpoch. Compute the shift-predictor to give a significance
level. The shift-predictor is computed by shuffling the trials position n_repets times. The interval plotted is equal to the mean +/- 2 times the standard deviation.
Parameters:
unit_pos_a : int | array | list

Position of first unit(s)

unit_pos_b : int | array | list

Position of second unit(s)

bin_time : time (quantity) (default: 1*ms)

Bin duration

max_lag_time : time (quantity) (default: 80*ms)

Max lagging time when computing the cross-corelogram

n_repets : int (default: 100)

Number of repetitions when computing the sampling distribution

plot_superpose : bool (default: True)

If True, superimpose the plots

plot_rasterplot(unit_pos=-1, bin_duration=0.01, sigma_gauss_kernel=array(20.) * ms, plot_unit_shape=1, plot_event_signal=1)

Plot the PSTH (peri/post stimulus time histogram) for selected units. A gaussian kernel is used for estimating the instantaneous firing rate. Plot the figure if save_fig is True, in fig_dirpath_raster

Parameters:
unit_pos : int | array |list (default: all)

Unit position.

bin_duration : float (default: 0.01 s)

Bin duration when plotting the rasterplot

sigma_gauss_kernel : quantity (default: 20*ms)

Duration of the gaussian kernel used for estimating the instantaneous firing rate. See elephant.statistics.instantaneous_rate

plot_unit_shape : bool (default: True)

If True, plot the shape of the selected units in the bottom-right corner

plot_event_signal : bool (default: True)

If True, plot the mean of the events signals (i.e. mean over the different events)

save(dirpath, filename=[])

Save the instance as a pickle (.p) file The filename is appended with the currendt date and time

Parameters:
dirpath : str

Directory path

filename : str | None

Output filename. If none is ‘neoall_{currentdate}.p’

subfun_plot_unit_shape(unit_pos, plot_mean=0, ax=[], raster_plot_call=0)

Sub-routine for plotting shape of the unit

Parameters:
unit_pos : int

Unit’s position

plot_mean : bool (default: False)

If True, plot the mean of the unit’s shape over the 4 micro-wires of the tetrode

ax : axis handle | None

If provided, plot the figure on this axis

raster_plot_call : bool (default: False)

Should be true, when this method is called from the plot_rasterplot method

class neoStructures.NeoMother

Superclass of NeoAll and NeoEpoch (both NeoAll and NeoEpoch inherits from NeoMother). Used to define methods for both NeoAll and NeoEpochs

Methods

channelpos2elec(channel_pos) From the channel (micro-wire) position, return the corresponding electrode’s number and name
channelpos2tetrode(channel_pos) From the channel (micro-wire) position, return the information about the tetrode of this channel
elecnum2channelpos(elec_num) From the electrode’s number return the electrode’s channels position and name
getunitpreferredchannelname(unit_name) Get the preferred channel of a unit from the unit’s name
subfun_plot_unit_shape(unit_pos[, …]) Sub-routine for plotting shape of the unit
channelpos2elec(channel_pos)

From the channel (micro-wire) position, return the corresponding electrode’s number and name

Parameters:
channel_pos : int

Channel’s (micro-wire) position

Returns:
el_num : int

Corresponding electrode’s number

el_name : str

Corresponding electrode’s name

channelpos2tetrode(channel_pos)

From the channel (micro-wire) position, return the information about the tetrode of this channel

Parameters:
channel_pos : int

Channel’s (micro-wire) position

Returns:
tetrode_num : int

Corresponding tetrode number

tetrode_channels_pos : array

Position of the 4 channels of the tetrode

wire_num_in_tetrode : int

Position of the input channel in the tetrode (between 0 and 3)

tetrode_channels_pos_glob : array

??? same as tetrode_channels_pos ???

elecnum2channelpos(elec_num)

From the electrode’s number return the electrode’s channels position and name

Parameters:
elec_num : int

Electrode position

Returns:
channel_pos : array

Position of the input electrode’s channels

channel_names : array

Name of the input electrode’s channels

getunitpreferredchannelname(unit_name)

Get the preferred channel of a unit from the unit’s name

Parameters:
unit_name : str

Name of the unit

Returns:
channel_name : str

Name of the preferred channel (micro-wire) of the input unit

subfun_plot_unit_shape(unit_pos, plot_mean=0, ax=[], raster_plot_call=0)

Sub-routine for plotting shape of the unit

Parameters:
unit_pos : int

Unit’s position

plot_mean : bool (default: False)

If True, plot the mean of the unit’s shape over the 4 micro-wires of the tetrode

ax : axis handle | None

If provided, plot the figure on this axis

raster_plot_call : bool (default: False)

Should be true, when this method is called from the plot_rasterplot method

neoStructures.realign_spike_trace(spike_trace, spike_trace_filtered=[], resample_factor=5, interp_method='cubic', half_extremum_win=15)

Re-align the spike trace so that the extremum in on the center of the window. The extremum position is computed on the filtered spike trace. Before taking the extremum, the filtered spike trace is upsampled and interpolated. The returned spike trace is the upsampled and interpolated trace, aligned on the center of the window.

Parameters:
spike_trace : array

Spike trace

spike_trace_filtered : array | none (default)

Filtered spike trace. If empty is equal to spike_trace

resample_factor : int (default

Upsampling factor

interp_method : str (default

Interpolation method used

half_extremum_win : int

The extremum will be search only around the center of the window. In a sub-window around the center : [center-half_extremum_win, center+half_extremum_win] Spikes should already be more or less centered.

Returns:
spike_trace_realigned : array

Spike trace aligned and upsampled