hnn_core.extracellular.ExtracellularArray

class hnn_core.extracellular.ExtracellularArray(positions, *, conductivity=0.3, method='psa', min_distance=0.5, times=None, voltages=None)[source]

Class for recording extracellular potential fields with electrode array

Note that to add an electrode array to a simulation, you should use the hnn_core.Network.add_electrode_array()-method. After simulation, the network will contain a dictionary of ExtracellularArray-objects in net.rec_arrays (each array must be added with a unique name). An ExtracellularArray contains the voltages at each electrode contact, along with the time points at which the voltages were sampled.

Parameters:
positionstuple | list of tuple

The (x, y, z) coordinates (in um) of the extracellular electrodes.

conductivityfloat

Extracellular conductivity, in S/m, of the assumed infinite, homogeneous volume conductor that the cell and electrode are in.

methodstr

Approximation to use. 'psa' (point source approximation) treats each segment junction as a point extracellular current source. 'lsa' (line source approximation) treats each segment as a line source of current, which extends from the previous to the next segment center point: /—x—/, where x is the current segment flanked by /.

min_distancefloat (default: 0.5; unit: um)

To avoid numerical errors in calculating potentials, apply a minimum distance limit between the electrode contacts and the active neuronal membrane elements that act as sources of current. The default value of 0.5 um corresponds to 1 um diameter dendrites.

timesarray-like, shape (n_times,) | None

Optionally, provide precomputed voltage sampling times for electrodes at positions.

voltagesarray-like, shape (n_trials, n_electrodes, n_times) | None

Optionally, provide precomputed voltages for electrodes at positions.

Notes

The length of an ExtracellularArray is equal to the number of trials of data it contains. Slicing an ExtracellularArray returns a copy of the corresponding trials: array[:5] returns a new array of length 5, etc.

See Table 5 in https://doi.org/10.1152/jn.00122.2010 for measured values of conductivity in rat cortex (note units there are mS/cm)

Attributes:
timesarray, shape (n_times,)

The time points the extracellular voltages are sampled at (ms)

voltagesarray, shape (n_trials, n_electrodes, n_times)

The measured extracellular voltages

sfreqfloat

Return the sampling rate of the extracellular data.

Methods

copy()

Return a copy of the ExtracellularArray instance

plot_csd([vmin, vmax, interpolation, sink, ...])

Plot laminar current source density (CSD) estimation

plot_lfp(*[, trial_no, contact_no, tmin, ...])

Plot laminar local field potential time series.

smooth(window_len)

Smooth extracellular waveforms using Hamming-windowed convolution

to_dict()

Converts an object of ExtracellularArray class to a dictionary.

__repr__()[source]

Return repr(self).

copy()[source]

Return a copy of the ExtracellularArray instance

Returns:
array_copyinstance of ExtracellularArray

A copy of the array instance.

plot_csd(vmin=None, vmax=None, interpolation='spline', sink='b', colorbar=True, ax=None, show=True)[source]

Plot laminar current source density (CSD) estimation

Parameters:
vmin: float, optional

lower bound of the color axis. Will be set automatically of None.

vmax: float, optional

upper bound of the color axis. Will be set automatically of None.

sinkstr

If set to ‘blue’ or ‘b’, plots sinks in blue and sources in red, if set to ‘red’ or ‘r’, sinks plotted in red and sources blue.

interpolationstr | None

If ‘spline’, will smoothen the CSD using spline method, if None, no smoothing will be applied.

colorbarbool

If the colorbar is presented.

axinstance of matplotlib figure | None

The matplotlib axis.

showbool

If True, show the plot.

Returns:
figinstance of matplotlib Figure

The matplotlib figure handle.

plot_lfp(*, trial_no=None, contact_no=None, tmin=None, tmax=None, ax=None, decim=None, color='cividis', voltage_offset=50, voltage_scalebar=200, show=True)[source]

Plot laminar local field potential time series.

One plot is created for each trial. Multiple trials can be overlaid with or without (default) and offset.

Parameters:
trial_noint | list of int | slice

Trial number(s) to plot

contact_noint | list of int | slice

Electrode contact number(s) to plot

axinstance of matplotlib figure | None

The matplotlib axis

decimint | list of int | None (default)

Optional (integer) factor by which to decimate the raw dipole traces. The SciPy function decimate() is used, which recommends values <13. To achieve higher decimation factors, a list of ints can be provided. These are applied successively.

colorstring | array of floats | matplotlib.colors.ListedColormap

The color to use for plotting (optional). The usual Matplotlib standard color strings may be used (e.g., ‘b’ for blue). A color can also be defined as an RGBA-quadruplet, or an array of RGBA-values (one for each electrode contact trace to plot). An instance of ListedColormap may also be provided.

voltage_offsetfloat | None (optional)

Amount to offset traces by on the voltage-axis. Useful for plotting laminar arrays.

voltage_scalebarfloat | None (optional)

Height, in units of uV, of a scale bar to plot in the top-left corner of the plot.

showbool

If True, show the figure

Returns:
figinstance of plt.fig

The matplotlib figure handle into which time series were plotted.

property sfreq

Return the sampling rate of the extracellular data.

smooth(window_len)[source]

Smooth extracellular waveforms using Hamming-windowed convolution

Note that this method operates in-place, i.e., it will alter the data. If you prefer a filtered copy, consider using the copy()-method.

Parameters:
window_lenfloat

The length (in ms) of a hamming window to convolve the data with.

Returns:
extracellular_copyinstance of ExtraCellularArray

The modified ExtraCellularArray instance.

to_dict()[source]

Converts an object of ExtracellularArray class to a dictionary.

Returns:
dictionary form of an object of ExtracellularArray class.