hnn_core.CellResponse#

class hnn_core.CellResponse(cell_type_names, cell_type_metadata=None, spike_times=None, spike_gids=None, spike_types=None, times=None)[source]#

The CellResponse class.

Parameters:
cell_type_nameslist

List of unique cell type names that are explicitly modeled in the network.

cell_type_metadatadict, optional

Corresponding metadata of the cell types in the Network that spawned this CellResponse, in the dictionary form of metadata available at the top of network_models.py.

spike_timeslist (n_trials,) of list (n_spikes,) of float | None

Each element of the outer list is a trial. The inner list contains the time stamps of spikes.

spike_gidslist (n_trials,) of list (n_spikes,) of float | None

Each element of the outer list is a trial. The inner list contains the cell IDs of neurons that spiked.

spike_typeslist (n_trials,) of list (n_spikes,) of float | None

Each element of the outer list is a trial. The inner list contains the type of spike (e.g., evprox1 or L2_pyramidal) that occurred at the corresponding time stamp. Each gid corresponds to a type via Network().gid_ranges. Note that the type of spike can be from a cell type or a drive.

timesnumpy array | None

Array of time points for samples in continuous data. This includes vsoma and isoma.

Attributes:
spike_timeslist (n_trials,) of list (n_spikes,) of float

Each element of the outer list is a trial. The inner list contains the time stamps of spikes.

spike_gidslist (n_trials,) of list (n_spikes,) of float

Each element of the outer list is a trial. The inner list contains the cell IDs of neurons that spiked.

spike_typeslist (n_trials,) of list (n_spikes,) of float

Each element of the outer list is a trial. The inner list contains the type of spike (e.g., evprox1 or L2_pyramidal) that occurred at the corresponding time stamp. Each gid corresponds to a type via Network().gid_ranges. Note that the type of spike can be from a cell type or a drive.

vseclist (n_trials,) of dict

Each element of the outer list is a trial. Dictionary indexed by gids containing voltages for cell sections.

iseclist (n_trials,) of dict

Each element of the outer list is a trial. Dictionary indexed by gids containing currents for cell sections.

calist (n_trials,) of dict, shape

Each element of the outer list is a trial. Dictionary indexed by gids containing calcium concentration for cell sections.

timesarray-like, shape (n_times,)

Array of time points for samples in continuous data. This includes vsoma and isoma.

Methods

reset()

Reset all recorded attributes to empty lists.

update_types(gid_ranges)

Update spike types in the current instance of CellResponse.

plot(ax=None, show=True)

Plot and return a matplotlib Figure object showing the aggregate network spiking activity according to cell type.

mean_rates(tstart, tstop, gid_ranges=None, mean_type=’all’)

Calculate mean firing rate for each cell type. Specify averaging method with mean_type argument.

write(fname)

Write spiking activity to a collection of spike trial files.

__repr__()[source]#

Return repr(self).

property cell_types#

Get unique cell types.

mean_rates(tstart, tstop, gid_ranges=None, mean_type='all')[source]#

Mean spike rates (Hz) by cell type.

Parameters:
tstartint | float | None

Value defining the start time of all trials.

tstopint | float | None

Value defining the stop time of all trials.

gid_rangesdict of lists or range objects | None

Dictionary with keys, e.g. net.gid_ranges containing the range of Cell or input GIDs of different cell or input types. If None (default), the number of cells per type is inferred from the recorded spikes.

mean_typestr
‘all’Average over trials and cells

Returns mean firing rate over time, trials, and gids, per cell type. Returns: spike_rates[cell_type] =

‘trial’Average over cell types

Returns mean firing rate over time and gids, per trials and cell type. Returns: spike_rates[cell_type] =

‘cell’Average over individual cells

Returns mean firing rate averaged over time, per gid, trial and cell type. Returns: spike_rates[cell_type] =

Returns:
spike_ratedict

Dictionary with keys ‘L5_pyramidal’, ‘L5_basket’, etc.

plot_firing_rate_time(window_length, trial_idx=None, ax=None, show=True, cell_types=None, colors=None, show_legend=True, sharex=False, sharey=False, xticks=None, yticks=None, xlim=None, ylim=None, xlabel='time (ms)', ylabel='firing rate (Hz)')[source]#

Plot time course of firing rates

Parameters:
window_lengthint | float

Length of the sliding window over which mean rates are calculated, in ms.

trial_idxint | list of int | None

Trial index (or list of indices) to be plotted. If None (the default), mean rate over all trials is plotted, and standard deviation is indicated by shading.

axinstance of matplotlib axis | None

An axis object from matplotlib. If None, a new figure is created.

showbool

If True, show the figure.

cell_typeslist of str | None

List of cell types to plot. If None, all cell types are plotted.

colorslist of str | None

Optional custom colors to plot. Default will use the colors defined in cell metadata.

show_legendbool

If True, show the legend with colors for cell types

sharexbool

If True, subplot x-axes will be shared. Only used when creating a new figure (i.e., when ax is None).

shareybool

If True, subplot y-axes will be shared. Only used when creating a new figure (i.e., when ax is None).

xticksarray-like | None

Custom x-axis tick locations. If None, matplotlib’s default is used.

yticksarray-like | None

Custom y-axis tick locations. If None, matplotlib’s default is used.

xlimtuple of (float, float) | None

Custom x-axis limits. If None, defaults to the full time range.

ylimtuple of (float, float) | None

Custom y-axis limits. If None, matplotlib’s default is used.

xlabelstr

Label for the x-axis.

ylabelstr

Label for the y-axis.

Returns:
figinstance of matplotlib Figure

The matplotlib figure object.

plot_spikes_hist(trial_idx=None, ax=None, spike_types=None, color=None, invert_spike_types=None, show=True, **kwargs_hist)[source]#

Plot the histogram of spiking activity across trials.

Parameters:
trial_idxint | list of int | None

Index of trials to be plotted. If None, all trials plotted.

axinstance of matplotlib axis | None

An axis object from matplotlib. If None, a new figure is created.

spike_types: string | list | dictionary | None

String input of a valid spike type is plotted individually.

Ex: 'poisson', 'evdist', 'evprox', …

List of valid string inputs will plot each spike type individually.

Ex: ['poisson', 'evdist']

Dictionary of valid lists will plot list elements as a group.

Ex: {'Evoked': ['evdist', 'evprox'], 'Tonic': ['poisson']}

If None, all input spike types are plotted individually if any are present. Otherwise spikes from all cells are plotted. Valid strings also include leading characters of spike types

Ex: 'ev' is equivalent to ['evdist', 'evprox']
colorstr | list of str | dict | None

Input defining colors of plotted histograms. If str, all histograms plotted with same color. If list of str provided, histograms for each spike type will be plotted by cycling through colors in the list.

If dict, colors must be specified for all spike_types as a key. If a group of spike types is defined by the spike_types parameter (see dictionary example for spike_types), the name of this group must be used to specify the colors.

Ex: {'evdist': 'g', 'evprox': 'r'}, {'Tonic': 'b'}

If None, default color cycle used.

showbool

If True, show the figure.

**kwargs_histdict

Additional keyword arguments to pass to ax.hist.

Returns:
figinstance of matplotlib Figure

The matplotlib figure handle.

plot_spikes_raster(trial_idx=None, ax=None, show=True, cell_types=None, colors=None, show_legend=True, marker_size=5.0, dpl=None, overlay_dipoles=False, xticks=None, yticks=None, xlabel='Time (ms)', ylabel='Neuron index', title=None)[source]#

Plot the aggregate spiking activity according to cell type.

Parameters:
trial_idxint | list of int | None

Index of trials to be plotted. If None, all trials plotted.

axinstance of matplotlib axis | None

An axis object from matplotlib. If None, a new figure is created.

showbool

If True, show the figure.

cell_typeslist of str

List of cell types to plot

colorslist of str | None

Optional custom colors to plot. Default will use the colors defined in cell metadata.

show_legendbool

If True, show the legend with colors for cell types

marker_sizefloat

Optional marker size to use when plotting spikes. Uses “linelengths” argument of ax.eventplot, which accepts positive numeric values only

dplinstance of Dipole | list

The Dipole object containing layer-specific dipole data to overlay on the raster plot

overlay_dipolesbool

If True, overlay the layer-specific dipole data on the raster plot

xtickslist | np.array | None

Ticks on x-axis. If None, ticks are created by matplotlib.

ytickslist | np.array | None

Ticks on y-axis, If None, ticks are created by matplotlib.

xlabelstr, default: “Time (ms)”

The matplotlib x-axis label

ylabelstr, default: “Neuron index”

The matplotlib y-axis label

titlestr | None

The matplotlib figure title

Returns:
figinstance of matplotlib Figure

The matplotlib figure object.

rate_over_time(window_length, gid_ranges=None, cell_types=None, trial_idx=None)[source]#

Mean spike rates (Hz) by cell type over time.

Parameters:
window_lengthint | float

Length of the sliding window over which firing rates are calculated, in ms. Must be greater than the ‘dt’ of the simulation.

gid_rangesNone | dict of lists or range objects, default=None

Dictionary with keys, e.g. net.gid_ranges containing the range of Cell or input IDs of different cell or input types. If None (default), the number of cells per type is inferred from the recorded spikes.

cell_typesNone| str | list of str, default=None

Cell types for which firing rates are calculated. If None (the default), firing rates are calculated for all cell types in the network.

trial_idxNone | int | list of int, default=None

Trial index (or list of indices) for which firing rate is calculated. If None (the default), firing rates are calculated for all trials.

Returns:
ratesdict

Dictionary one key per cell type (e.g. ‘L5_pyramidal) containing np.array of size <n_trials, timepoints>

property spike_times_by_type#

Get a dictionary of spike times by cell type

to_dict()[source]#

Return cell response as a dict object.

Returns:
dict object containing the cell response
update_types(gid_ranges)[source]#

Update spike types in the current instance of CellResponse.

Parameters:
gid_rangesdict of lists or range objects

Dictionary with keys ‘evprox1’, ‘evdist1’ etc. containing the range of Cell or input IDs of different cell or input types.

write(fname)[source]#

Write spiking activity per trial to a collection of files.

Parameters:
fnamestr

String format (e.g., ‘spk_%d.txt’ or ‘spk_{0}.txt’) of the path to the output spike file(s). If no string format is provided, the trial index will be automatically appended to the file name.