Spike Input/Output¶
-
slayerSNN.spikeFileIO.
animTD
(TD, fig=None, frameRate=24, preComputeFrames=True, repeat=True)[source]¶ Reutrn animation object for TD event.
- Arguments:
TD
: spike event to visualize.fig
: figure to plot animation. Default isNone
, in which case a figure is created.frameRate
: framerate of visualization.preComputeFrames
: flag to enable precomputation of frames for faster visualization. Default isTrue
.repeat
: flag to enable repeat of animation. Default isTrue
.
Usage:
>>> anim = animTD(TD)
-
slayerSNN.spikeFileIO.
encode1DnumSpikes
(filename, nID, tSt, tEn, nSp)[source]¶ Writes binary spike file given a tuple specifying neuron, start of spike region, end of spike region and number of spikes.
- The binary file is encoded as follows:
Number of spikes data is represented by an 80 bit number
First 16 bits (bits 79-64) represent the neuronID
Next 24 bits (bits 63-40) represents the start time in microseconds
Next 24 bits (bits 39-16) represents the end time in microseconds
Last 16 bits (bits 15-0) represents the number of spikes
- Arguments:
filename
(string
): path to the binary filenID
(numpy array
): neuron IDtSt
(numpy array
): region start time (in milliseconds)tEn
(numpy array
): region end time (in milliseconds)nSp
(numpy array
): number of spikes in the region
Usage:
>>> spikeFileIO.encode1DnumSpikes(file_path, nID, tSt, tEn, nSp)
-
slayerSNN.spikeFileIO.
encode1Dspikes
(filename, TD)[source]¶ Writes one dimensional binary spike file from a TD event.
- The binary file is encoded as follows:
Each spike event is represented by a 40 bit number.
First 16 bits (bits 39-24) represent the neuronID.
Bit 23 represents the sign of spike event: 0=>OFF event, 1=>ON event.
the last 23 bits (bits 22-0) represent the spike event timestamp in microseconds.
- Arguments:
filename
(string
): path to the binary file.TD
(anspikeFileIO.event
): TD event.
Usage:
>>> spikeFileIO.write1Dspikes(file_path, TD)
-
slayerSNN.spikeFileIO.
encode2Dspikes
(filename, TD)[source]¶ Writes two dimensional binary spike file from a TD event. It is the same format used in neuromorphic datasets NMNIST & NCALTECH101.
- The binary file is encoded as follows:
Each spike event is represented by a 40 bit number.
First 8 bits (bits 39-32) represent the xID of the neuron.
Next 8 bits (bits 31-24) represent the yID of the neuron.
Bit 23 represents the sign of spike event: 0=>OFF event, 1=>ON event.
The last 23 bits (bits 22-0) represent the spike event timestamp in microseconds.
- Arguments:
filename
(string
): path to the binary file.TD
(anspikeFileIO.event
): TD event.
Usage:
>>> spikeFileIO.write2Dspikes(file_path, TD)
-
slayerSNN.spikeFileIO.
encode3Dspikes
(filename, TD)[source]¶ Writes binary spike file for TD event in height, width and channel dimension.
- The binary file is encoded as follows:
Each spike event is represented by a 56 bit number.
First 12 bits (bits 56-44) represent the xID of the neuron.
Next 12 bits (bits 43-32) represent the yID of the neuron.
Next 8 bits (bits 31-24) represents the channel ID of the neuron.
The last 24 bits (bits 23-0) represent the spike event timestamp in microseconds.
- Arguments:
filename
(string
): path to the binary file.TD
(anspikeFileIO.event
): TD event.
Usage:
>>> spikeFileIO.write3Dspikes(file_path, TD)
-
slayerSNN.spikeFileIO.
encodeNpSpikes
(filename, TD, fmt='xypt', timeUnit=0.001)[source]¶ Writes TD event into numpy file.
- Arguments:
filename
(string
): path to the binary file.TD
(anspikeFileIO.event
): TD event.
Usage:
>>> spikeFileIO.write1Dspikes(file_path, TD) >>> spikeFileIO.write1Dspikes(file_path, TD, fmt='xypt')
-
class
slayerSNN.spikeFileIO.
event
(xEvent, yEvent, pEvent, tEvent)[source]¶ This class provides a way to store, read, write and visualize spike event.
- Members:
x
(numpyint
array): x index of spike event.y
(numpyint
array): y index of spike event (not used if the spatial dimension is 1).p
(numpyint
array): polarity or channel index of spike event.t
(numpydouble
array): timestamp of spike event. Time is assumend to be in ms.
Usage:
>>> TD = spikeFileIO.event(xEvent, yEvent, pEvent, tEvent)
-
toSpikeArray
(samplingTime=1, dim=None)[source]¶ Returns a numpy tensor that contains the spike events sampled in bins of samplingTime. The array is of dimension (channels, height, time) or``CHT`` for 1D data. The array is of dimension (channels, height, width, time) or``CHWT`` for 2D data.
- Arguments:
samplingTime
: the width of time bin to use.dim
: the dimension of the desired tensor. Assignes dimension itself if not provided.
Usage:
>>> spike = TD.toSpikeArray()
-
toSpikeTensor
(emptyTensor, samplingTime=1, randomShift=False, binningMode='OR')[source]¶ Returns a numpy tensor that contains the spike events sampled in bins of samplingTime. The tensor is of dimension (channels, height, width, time) or``CHWT``.
- Arguments:
emptyTensor
(numpy or torch tensor
): an empty tensor to hold spike datasamplingTime
: the width of time bin to use.randomShift
: flag to shift the sample in time or not. Default: False.binningMode
: the way spikes are binned. ‘SUM’ or ‘OR’ are supported. Default: ‘OR’
Usage:
>>> spike = TD.toSpikeTensor( torch.zeros((2, 240, 180, 5000)) )
-
slayerSNN.spikeFileIO.
read1DnumSpikes
(filename)[source]¶ Reads a tuple specifying neuron, start of spike region, end of spike region and number of spikes from binary spike file.
- The binary file is encoded as follows:
Number of spikes data is represented by an 80 bit number.
First 16 bits (bits 79-64) represent the neuronID.
Next 24 bits (bits 63-40) represents the start time in microseconds.
Next 24 bits (bits 39-16) represents the end time in microseconds.
Last 16 bits (bits 15-0) represents the number of spikes.
- Arguments:
filename
(string
): path to the binary file
Usage:
>>> nID, tSt, tEn, nSp = spikeFileIO.read1DnumSpikes(file_path) ``tSt`` and ``tEn`` are returned in milliseconds
-
slayerSNN.spikeFileIO.
read1Dspikes
(filename)[source]¶ Reads one dimensional binary spike file and returns a TD event.
- The binary file is encoded as follows:
Each spike event is represented by a 40 bit number.
First 16 bits (bits 39-24) represent the neuronID.
Bit 23 represents the sign of spike event: 0=>OFF event, 1=>ON event.
the last 23 bits (bits 22-0) represent the spike event timestamp in microseconds.
- Arguments:
filename
(string
): path to the binary file.
Usage:
>>> TD = spikeFileIO.read1Dspikes(file_path)
-
slayerSNN.spikeFileIO.
read2Dspikes
(filename)[source]¶ Reads two dimensional binary spike file and returns a TD event. It is the same format used in neuromorphic datasets NMNIST & NCALTECH101.
- The binary file is encoded as follows:
Each spike event is represented by a 40 bit number.
First 8 bits (bits 39-32) represent the xID of the neuron.
Next 8 bits (bits 31-24) represent the yID of the neuron.
Bit 23 represents the sign of spike event: 0=>OFF event, 1=>ON event.
The last 23 bits (bits 22-0) represent the spike event timestamp in microseconds.
- Arguments:
filename
(string
): path to the binary file.
Usage:
>>> TD = spikeFileIO.read2Dspikes(file_path)
-
slayerSNN.spikeFileIO.
read3Dspikes
(filename)[source]¶ Reads binary spike file for spike event in height, width and channel dimension and returns a TD event.
- The binary file is encoded as follows:
Each spike event is represented by a 56 bit number.
First 12 bits (bits 56-44) represent the xID of the neuron.
Next 12 bits (bits 43-32) represent the yID of the neuron.
Next 8 bits (bits 31-24) represents the channel ID of the neuron.
The last 24 bits (bits 23-0) represent the spike event timestamp in microseconds.
- Arguments:
filename
(string
): path to the binary file.
Usage:
>>> TD = spikeFileIO.read3Dspikes(file_path)
-
slayerSNN.spikeFileIO.
readNpSpikes
(filename, fmt='xypt', timeUnit=0.001)[source]¶ Reads numpy spike event and returns a TD event. The numpy array is assumed to be of nEvent x event diension.
- Arguments:
filename
(string
): path to the file.fmt
(string
): format of event. For e.g.’xypt’ means the event data is arrange in x data, y data, p data and time data.timeUnit
(double
): factor to scale the time data to convert it into seconds. Default: 1e-3 (ms).
Usage:
>>> TD = spikeFileIO.readNpSpikes(file_path) >>> TD = spikeFileIO.readNpSpikes(file_path, fmt='xypt') >>> TD = spikeFileIO.readNpSpikes(file_path, timeUnit=1e-6)
-
slayerSNN.spikeFileIO.
showTD
(TD, fig=None, frameRate=24, preComputeFrames=True, repeat=False)[source]¶ Visualizes TD event.
- Arguments:
TD
: spike event to visualize.fig
: figure to plot animation. Default isNone
, in which case a figure is created.frameRate
: framerate of visualization.preComputeFrames
: flag to enable precomputation of frames for faster visualization. Default isTrue
.repeat
: flag to enable repeat of animation. Default isFalse
.
Usage:
>>> showTD(TD)
-
slayerSNN.spikeFileIO.
spikeArrayToEvent
(spikeMat, samplingTime=1)[source]¶ Returns TD event from a numpy array (of dimension 3 or 4). The numpy array must be of dimension (channels, height, time) or``CHT`` for 1D data. The numpy array must be of dimension (channels, height, width, time) or``CHWT`` for 2D data.
- Arguments:
spikeMat
: numpy array with spike information.samplingTime
: time width of each time bin.
Usage:
>>> TD = spikeFileIO.spikeArrayToEvent(spike)