neurochat.nc_spike module

This module implements NSpike Class for NeuroChaT software.

@author: Md Nurul Islam; islammn at tcd dot ie

class neurochat.nc_spike.NSpike(**kwargs)[source]

Bases: neurochat.nc_base.NBase

This data class contains information about the neural spikes.

It decodes data from different formats and analyses single units in the recording.

_unit_no

The current unit number being considered.

Type:int
_unit_stamp

The timestamps of the current unit.

Type:np.ndarray
_timestamp

The timestamps of all units.

Type:np.ndarray
_unit_list

The list of all units available.

Type:list of int
_unit_Tags

The tag of each timestamp, denoting which unit it represents. It must match the length of _timestamp.

Type:list of int
_waveform

Spike waveforms where each key represents one channel The data in a channel is a numpy array.

Type:OrderedDict
__str__()[source]

Return a friendly string representation of this object.

add_lfp(lfp=None, **kwargs)[source]

Add new LFP node to current NSpike() object.

Parameters:lfp (NLfp) – NLfp object. If None, new object is created
Returns:` (obj:Nlfp`) – A new NLfp() object
add_spike(spike=None, **kwargs)[source]

Add new spike node to current NSpike() object.

Parameters:spike (NSpike) – NSPike object. If None, new object is created
Returns:` (obj:NSpike`) – A new NSpike() object
burst(burst_thresh=5, ibi_thresh=50)[source]

Analysis of bursting properties of the spiking train.

Parameters:
  • burst_thresh (int) – Minimum ISI between consecutive spikes in a burst
  • ibi_thresh (int) – Minimum inter-burst interval between two bursting groups of spikes
Returns:

None

get_bytes_per_sample()[source]

Return the number of bytes to represent each spike waveform sample.

Parameters:None
Returns:int – Number of bytes to represent each sample of the spike waveforms
get_channel_ids()[source]

Return the identities of individual channels.

Parameters:None
Returns:list – Identities of individual channels
get_fullscale_mv()[source]

Return the fullscale value of the ADC in mV.

Parameters:None
Returns:int – Fullscale ADC value in mV
get_samples_per_spike()[source]

Return number of bytes to represent each timestamp in the binary file.

Parameters:None
Returns:int – Number of bytes to represent timestamps
get_sampling_rate()[source]

Return the sampling rate of spike waveforms.

Parameters:None
Returns:int – Sampling rate for spike waveforms
get_timebase()[source]

Return the timebase for spike event timestamps.

Parameters:None
Returns:int – Timebase for spike event timestamps
get_timestamp(unit_no=None)[source]

Return the timestamps of the spike-waveforms of specified unit.

Parameters:None
Returns:ndarray – Timestamps of the spiking waveforms
get_timestamp_bytes()[source]

Return the number of bytes to represent a timestamp in the binary file.

Parameters:None
Returns:int – Number of bytes to represent timestamps
get_total_channels()[source]

Return total number of electrode channels in the spike data file.

Parameters:None
Returns:int – Total number of electrode channels
get_total_spikes()[source]

Return total number of spikes in the recording.

Parameters:None
Returns:int – Total number of spikes
get_type()[source]

Return the type of object. For NSpike, this is always spike type.

Parameters:None
Returns:str
get_unit_list()[source]

Get the list of the units.

Parameters:None
Returns:list – List of the unique tags of spiking-waveforms from clustering
get_unit_no(spike_name=None)[source]

Get currently set unit number of the spike dataset to analyse.

Parameters:None
Returns:int – Unit or cell number set to analyse
get_unit_spikes_count(unit_no=None)[source]

Return the number of spikes in a unit.

Parameters:unit_no (int) – Units whose spike count is returned
Returns:int – Number of units spikes of a unit in a recording session
get_unit_stamp()[source]

Get the timestamps for currently set unit to analyse.

Parameters:None
Returns:list or ndarray – Timestamps for currently set unit
get_unit_stamps_in_ranges(ranges)[source]

Return the unit timestamps in a list of ranges.

Parameters:ranges (list) – A list of tuples indicating time ranges to get stamps in. Should be specified in the same unit as the timestamps. This is usually in seconds.
Returns:list – The timestamps
get_unit_tags()[source]

Return the unit number or tags of the clustered units.

Parameters:None
Returns:list or ndarray
get_unit_waves(unit_no=None)[source]

Return spike waveform of a specified unit.

Parameters:unit_no (int) – Unit whose waveforms are to be returned
Returns:OrderedDict – Waveforms of the specified unit. If None, waveforms of currently set unit are returned
get_waveform()[source]

Return spike-waveforms.

Parameters:None
Returns:OrderedDict – Dictionary of spiking waveforms where keys represent the channel number
isi(bins='auto', bound=None, density=False, refractory_threshold=2)[source]

Calculate the ISI histogram of the spike train.

Parameters:
  • bins (str or int) – Number of ISI histogram bins. If ‘auto’, NumPy default is used
  • bound (int) – Length of the ISI histogram in msec
  • density (bool) – If true, normalized histogram is calculated
  • refractory_threshold (int) – Length of the refractory period in msec
Returns:

dict – Graphical data of the analysis

isi_corr(spike=None, **kwargs)[source]

Calculate the correlation of ISI histogram.

Parameters:
  • spike (NSpike()) – If specified, it calulates cross-correlation.
  • **kwargs – Keyword arguments
Returns:

dict – Graphical data of the analysis

load(filename=None, system=None)[source]

Load spike datasets.

Parameters:
  • filename (str) – Name of the spike datafile
  • system (str) – Recording system or format of the spike data file
Returns:

None

See also

load_spike_axona(), load_spike_NLX(), load_spike_NWB()

load_lfp(names='all')[source]

Load datasets of the LFP nodes.

The name of each node is used for obtaining the filenames.

Parameters:names (list of str) – Names of the nodes to load. If all, all LFP nodes are loaded
Returns:None
load_spike(names=None)[source]

Load datasets of the spike nodes.

The name of each node is used for obtaining the filenames.

Parameters:names (list of str) – Names of the nodes to load. If None, current NSpike() object is loaded
Returns:None
load_spike_Axona(file_name, return_raw=False)[source]

Decode spike data from Axona file format.

Parameters:file_name (str) – Full file directory for the spike data
Returns:None
load_spike_NWB(file_name)[source]

Decode spike data from NWB (HDF5) file format.

Parameters:file_name (str) – Full file directory for the spike data
Returns:None
load_spike_Neuralynx(file_name)[source]

Decode spike data from Neuralynx file format.

Parameters:file_name (str) – Full file directory for the spike data
Returns:None
load_spike_spikeinterface(sorting, channel_scaling=None, group=None)[source]

Load spike information from any Sorting Extractor object.

This extracts timestamps, tags, and waveforms from a sorting object. Then stores them into NeuroChaT NSpike attributes.

Parameters:
  • sorting (spikeinterface.extractors.SortingExtractor) – The sorting extractor object to load from.
  • channel_scaling (list | np.ndarray) – This is used to apply gains. There should be one entry for each channel if provided. Applied as waveform_channel_i * channel_scaling[i]. Defaults to unit gain for each channel.
  • group (int | str) – The group in the sorting extractor to consider. This can be used to split the data into tetrodes or probes.
Returns:

None

Note

NC assumes that unit 0 is not present in the sorting. However, other sorters don’t assume this. As such, if your sorter contains 0 as a unit, ALL unit numbers will be incremented by 1.

Example

# This would convert from Phy to NeuroChaT native NWB
import spikeinterface.extractors as se
to_exclude = ["mua", "noise"]
sorting = se.PhySortingExtractor(
    "phy_folder", exclude_cluster_groups=to_exclude,
    load_waveforms=True, verbose=False)
spike = NSpike()
hdf_path = "test.hdf5"
nhdf = Nhdf(filename=hdf_path)

groups = []
unit_ids = sorting.get_unit_ids()
for unit in unit_ids:
    try:
        tetrode = sorting.get_unit_property(unit, "group")
    except BaseException:
        try:
            tetrode = sorting.get_unit_property(unit, "ch_group")
        except BaseException:
            tetrode = None
    if tetrode is not None:
        if tetrode not in groups:
            groups.append(tetrode)

for g in groups:
spike.load_spike_spikeinterface(sorting, group=g)
    spike.set_unit_no(spike.get_unit_list()[0])
    print(spike)
    nhdf.save_spike(spike=spike)
phase_dist(lfp=None, **kwargs)[source]

Analysis of spike to LFP phase distribution.

Delegates to NLfp().phase_dist()

Parameters:
  • lfp (NLfp) – LFP object which contains the LFP data
  • **kwargs – Keyword arguments
Returns:

dict – Graphical data of the analysis

See also

nc_lfp.NLfp()

plv(lfp=None, **kwargs)[source]

Calculate phase-locking value of spike train to underlying LFP signal.

Delegates to NLfp().plv()

Parameters:
  • lfp (NLfp) – LFP object which contains the LFP data
  • **kwargs – Keyword arguments
Returns:

dict – Graphical data of the analysis

See also

nc_lfp.NLfp()

psth(event_stamp, **kwargs)[source]

Calculate peri-stimulus time histogram (PSTH).

Parameters:
  • event_stamp (ndarray) – Event timestamps
  • **kwargs – Keyword arguments
Returns:

dict – Graphical data of the analysis

save_to_hdf5(file_name=None, system=None)[source]

Store NSpike() object to HDF5 file.

Parameters:
  • file_name (str) – Full file directory for the spike data
  • system (str) – Recoring system or data format
Returns:

  • None
  • Also see
  • ——–
  • nc_hdf.Nhdf().save_spike()

set_unit_no(unit_no=None, spike_name=None)[source]

Set the unit number of the spike dataset to analyse.

Parameters:
  • unit_no (int) – Unit or cell number to analyse
  • spike_name (str) – The spike to set the unit on. Default is None.
Returns:

None

set_unit_tags(new_tags)[source]

Set the number or tags of the clustered units.

Parameters:new_tags (list or ndarray) – Tags for each spiking wave
Returns:None
shift_spike_times(n_shuffles, limit=None)[source]

Randomly shift the spike times for the currently set unit.

Parameters:
  • n_shuffles (int) – The number of times to shuffle.
  • limit (int) – How much to shuffle by in seconds. limit = None implies enirely random shuffle limit = ‘x’ implies shuffles in the range [-x x]
Returns:

np.ndarray – The shifted spike times, shape (n_shuffles, n_spikes)

shuffle_spike_times(n_shuffles, limit=None)[source]

Randomly shuffle the spike times for the currently set unit.

Parameters:
  • n_shuffles (int) – The number of times to shuffle.
  • limit (int) – How much to shuffle by in seconds. limit = None implies enirely random shuffle limit = ‘x’ implies shuffles in the range [-x x]
Returns:

np.ndarray – The shuffled spike times, shape (n_shuffles, n_spikes)

spike_lfp_causality(lfp=None, **kwargs)[source]

Analyse spike to underlying LFP causality.

Delegates to NLfp().spike_lfp_causality()

Parameters:**kwargs – Keyword arguments
Returns:dict – Graphical data of the analysis

See also

nc_lfp.NLfp()

subsample(sample_range=None)[source]

Extract a time range from the spikes.

Parameters:sample_range (tuple) – the time in seconds to extract from the spikes
Returns:NSpike – subsampled version of initial spike object
theta_index(**kwargs)[source]

Analysis of theta-modulation of a unit.

Parameters:**kwargs – Keyword arguments
Returns:dict – Graphical data of the analysis
theta_skip_index(**kwargs)[source]

Analysis of theta-skipping of a unit.

Parameters:**kwargs – Keyword arguments
Returns:dict – Graphical data of the analysis
wave_property()[source]

Calculate different waveform properties for currently set unit.

Parameters:None
Returns:dict – Graphical data of the analysis