Python library

The Python library consists primarily of the “escope” package. Typical use would be something like:

import matplotlib.pyplot as plt
import escope

rec = escope.Recording("/some/path/EScopeData/20241007-123412.escope")
rec.plot()

followed by:

vv1 = rec.data(0, "mV")
tt = rec.time()
plt.plot(tt, vv1)

escope package

class escope.Recording(filename: str)

Object-oriented access to EScope data

The constructor loads data from a “.escope” file. If the name starts with “http://” or “https://”, the file is downloaded from the internet.

info() dict

Information about the recording as a dictionary.

data(channel: int | str, units: str | None = None) ndarray | Tuple[ndarray, str]

Data for a given channel and corresponding units.

Arguments

channel

An integer index specifying the channel number or a string name for the channel (which must exist in the “channels” of the info() dict.

units (optional)

Desired units for returned data

Returns

If units are specified, the raw data are converted into those units and only the result is returned.

If units are not specified, a tuple of data and their units is returned.

For continuous acquisition or a single sweep, data are returned as a length-T vector where T is the number of samples in the recording. For triggered acquisition, data are returned as an NxT array, where N is the number of triggers and T is the number of samples per sweep.

time() ndarray

Timestamp vector in seconds.

plot() None

Quick plot of the entire recording.

rawdata(channel: int | None = None) ndarray

Raw data from the recording.

Arguments

channel (optional)

An integer index specifying the channel number.

Returns

Data for a single channel or all channels

For continuous acquisition or a single sweep, data are returned as a CxT array where C is the number of channels and T is the number of samples. For triggered acquisition, data are returned as a CxNxT array, where N is the number of triggers and T is the number of samples per sweep.

If channel is specified, the result is either a length-T vector or an NxT array.

escope.rmsnoise(dat: ndarray[float], chunksize: int = 300, percentile: int = 25) float

Estimated RMS noise in a data trace

Arguments

dat

The data to be investigated as a length-T vector

chunksize (optional)

The number of samples per chunk. Reasonable values are whatever corresponds to 5 or 10 ms at your sampling rate.

percentile (optional)

The percentile at which to sample the chunks. Usually, the default is reasonable, but if you have extremely high firing rates, a lower number may work better.

Returns

The estimated RMS noise in the data

Description

The data are split into small chunks and the RMS signal power is calculated for each chunk. In some of the chunks, that power will be dominated by the presence of spike or stimulus artifacts. However, in a decent fraction of chunks there are no spikes, so the RMS power in those chunks represents the actual RMS noise.

This function attempts to extract the RMS noise from such chunks by sorting the chunks by their signal power, and finding the 25-th percentile. It corrects the result based on assumption of approximate Gaussianity.

escope.detectspikes(yy: ndarray[float], threshold: float, polarity: int = 0, tkill: int = 50, upperthresh: float | None = None) ndarray[int]

Simple spike detection

Parameters

yy

A NumPy array of floats representing the data

threshold

The threshold for spike detection. Typically, 5× the value from rmsnoise is a reasonable threshold.

polarity (optional)

The polarity of the spikes (0 for both, 1 for positive, -1 for negative)

tkill (optional)

The minimum distance between spikes (in samples)

upperthresh (optional)

The maximum spike amplitude. If given, peaks that exceed it are not returned, so you can use detectspikes iteratively for very basic spike sorting.

Returns

A numpy array of integers indicating the indices of detected spikes within the recording

Description

The algorithm first finds peaks (positive and/or negative depending on the polarity parameter) that exceed the threshold. Then, it drops minor peaks that are within tkill samples of major peaks. Finally, peaks that exceed upperthresh (if given) are discarded.

Submodules

Details on the following submodules are available: