API Documentation

API reference for the module.

Table of Contents

Measures

Spike related measures and conversions, available in the measures sub-module.

Spikes

Measures for spike data.

compute_firing_rate(spikes[, time_range])

Estimate firing rate from a vector of spike times, in seconds.

compute_isis(spikes)

Compute inter-spike intervals.

compute_cv(isis)

Compute coefficient of variation.

compute_fano_factor(spike_train)

Compute the fano factor of a spike train.

compute_spike_presence(spikes, bins[, ...])

Compute the spike presence across time bins.

compute_presence_ratio(spikes, bins[, ...])

Compute the presence ratio for a set of spike times.

Conversions

Conversions between spike representations.

convert_times_to_train(spikes[, fs, time_range])

Convert spike times into a binary spike train.

convert_train_to_times(spike_train[, fs, ...])

Convert a spike train representation into spike times, in seconds.

convert_isis_to_times(isis[, add_initial, ...])

Convert a sequence of inter-spike intervals to spike times.

convert_times_to_counts(spikes, bins[, ...])

Convert spikes times to counts of spikes per time bin.

convert_times_to_rates(spikes, bins[, ...])

Convert spike times to continuous firing rates.

Circular

Measures for working with circular data.

bin_circular(data[, bin_width])

Bin circular data.

Trials

Measures related to trial-epoched data.

compute_trial_frs(trial_spikes, bins[, ...])

Compute continuous binned firing rates for a set of epoched spike times.

compute_segment_frs(spikes, segments)

Compute firing rate across trial segments.

compute_pre_post_rates(trial_spikes, ...)

Compute the firing rates in pre and post event windows.

compute_pre_post_averages(frs_pre, frs_post)

Compute the average firing rate across pre & post event windows.

compute_pre_post_diffs(frs_pre, frs_post[, ...])

Compute the difference in firing rates between pre & post event windows.

Collections

Measures that can be applied to collections (groups) of neurons.

detect_empty_time_ranges(all_spikes, bins[, ...])

Compute the empty time ranges that are common across a collection of recorded neurons.

find_empty_bins(all_spikes, bins[, time_range])

Find empty time bins across a collection of recorded neurons.

find_empty_ranges(bin_emptiness, bins[, ...])

Find empty time ranges based on time bin emptiness for a collection of recorded neurons.

Objects

Objects for managing spike-related data, available in the objects sub-module.

Unit

Unit([uid, spikes, channel, region, cluster])

A Unit object.

Session

Session([subject, session, task, units])

A Session object.

Spatial

Functionality for processing spatial data, available in the spatial sub-module.

Distance

Measures and methods related to distances.

compute_distance(p1, p2)

Compute the distance between two positions.

compute_distances(position)

Compute distances across a sequence of positions.

compute_cumulative_distances(position[, ...])

Compute cumulative distance across a sequence of positions.

compute_distances_to_location(position, location)

Compute distances between a sequence of positions and a specified location.

get_closest_position(position, location[, ...])

Get the index of the closest position value to a specified location.

Speed

Measures and methods related to speed.

compute_speed(position, timestamps[, ...])

Compute speeds across a sequence of positions.

Occupancy

Measures and methods related to computing spatial occupancy.

compute_bin_edges(position, bins[, area_range])

Compute spatial bin edges.

compute_bin_assignment(position, x_edges[, ...])

Compute spatial bin assignment.

compute_bin_counts_pos(position, bins[, ...])

Compute counts per bin, from position data.

compute_bin_counts_assgn(bins, xbins[, ...])

Compute number of counts per bin, from bin assignments.

normalize_bin_counts(bin_counts, occupancy)

Normalize bin counts by occupancy.

create_position_df(position, timestamps, bins)

Create a dataframe that stores information about position bins.

compute_occupancy_df(bindf, bins[, minimum, ...])

Compute the bin occupancy from bin-position dataframe.

compute_occupancy(position, timestamps, bins)

Compute occupancy across spatial bin positions.

compute_trial_occupancy(position, ...[, ...])

Compute trial-level occupancy across spatial bin positions.

Place

Measures and methods related to place cell analyses.

compute_place_bins(spikes, position, ...[, ...])

Compute the spatially binned spiking activity.

compute_trial_place_bins(spikes, position, ...)

Compute the spatially binned spiking activity, across trials.

Target

Measures and methods related to spatial target cell analyses.

compute_target_bins(target_frs, bins, xbins)

Compute binned firing based on spatial target.

Information

Measures and methods related to computing spatial information.

compute_spatial_information(bin_firing, ...)

Compute spatial information.

Utilities

Utilities related to spatial data.

get_position_xy(position[, orientation])

Get the x & y data vectors from a 2d position data array.

compute_nbins(bins)

Compute the number of bins for a given bin definition.

compute_bin_width(bin_edges)

Compute bin width from a set of bin edges.

compute_pos_ranges(position)

Compute the range of positions.

convert_2dindices(xbins, ybins, bins)

Convert a set of 2d bin indices into the equivalent 1d indices.

convert_1dindices(indices, bins)

Convert a set of 1d bin indices into the equivalent 2d indices.

Checks

Functions to check data and arguments to spatial related processes.

check_position(position)

Check a position array.

check_bin_definition(bins[, position])

Check a bin definition for binning spatial data.

check_bin_widths(bin_widths)

Check computed bin widths for a set of spatial bins.

Statistics

Statistical analyses, available in the stats sub-module.

Generators

Statistical generators.

poisson_generator(rate, duration[, start_time])

Generator function for a Homogeneous Poisson distribution.

Trials

Statistical measures for trial-epoched data.

compute_pre_post_ttest(frs_pre, frs_post)

Compute a related samples t-test between the pre & post event firing rates.

compare_pre_post_activity(trial_spikes, ...)

Compare pre & post activity, computing the average firing rates and a t-test comparison.

compare_trial_frs(trials1, trials2)

Compare binned firing rates between two sets of trials with independent samples t-tests.

Shuffle

Methods for shuffling data.

shuffle_spikes(spikes, approach[, ...])

Shuffle spikes.

shuffle_isis(spikes[, n_shuffles, start_time])

Create shuffled spike times using permuted inter-spike intervals.

shuffle_bins(spikes[, bin_width_range, ...])

Shuffle data with circular shuffles of randomly sized bins of the spike train.

shuffle_poisson(spikes[, n_shuffles, start_time])

Shuffle spikes based on generating new spike trains from a Poisson distribution.

shuffle_circular(spikes[, shuffle_min, ...])

Shuffle spikes based on circularly shifting the spike train.

Permutations

Methods and measures related to permutation statistics.

compute_surrogate_pvalue(value, surrogates)

Compute the empirical p-value from a distribution of surrogates.

compute_surrogate_zscore(value, surrogates)

Compute the z-score of a real data value compared to a distribution of surrogates.

compute_surrogate_stats(data_value, surrogates)

Compute surrogate statistics.

ANOVA

Methods and measures related to computing ANOVAs.

create_dataframe(data[, columns, dropna, dtypes])

Create a dataframe from an array of data.

create_dataframe_bins(bin_data[, ...])

Create a dataframe from an array of binned data.

fit_anova(df, formula[, feature, ...])

Fit an ANOVA.

Simulations

Functionality for simulating spiking data, available in the sim sub-module.

General

General simulation functions.

sim_spiketimes(spike_param, duration, method)

Simulate spike times.

sim_spiketrain(spike_param, n_samples, method)

Simulate a spike train.

sim_trials(n_trials[, method, time_pre, ...])

Simulate a collection of trials.

Spike Times

Simulate spike times.

sim_spiketimes_poisson(rate, duration[, ...])

Simulate spike times based on a Poisson distribution.

Spike Trains

Simulate spike trains.

sim_spiketrain_prob(p_spiking[, n_samples, ...])

Simulate spikes based on a probability of spiking per sample.

sim_spiketrain_binom(p_spiking[, n_samples, ...])

Simulate spike train from a binomial probability distribution.

sim_spiketrain_poisson(rate, n_samples[, ...])

Simulate spike train from a Poisson distribution.

Trials

Simulate trial-structured data.

sim_trials_poisson(n_trials, rate_pre, rate_post)

Simulate a collection of trials, based on a Poisson spike time simulation.

Utilities

Simulation related utilities.

apply_refractory_times(spike_times, ...)

Apply a refractory period to simulated spike times.

apply_refractory_train(spike_train, ...)

Apply a refractory period to a simulated spike train.

Plots

Functions in the plts sub-module for visualizing spiking data and related measures.

Spikes

Plots for spike data.

plot_waveform(waveform[, timestamps, ...])

Plot a spike waveform.

plot_waveforms3d(waveforms[, timestamps])

Plot waveforms on a 3D axis.

plot_waveform_density(waveforms[, ...])

Plot a heatmap of waveform density, created as a 2d histogram of spike waveforms.

plot_isis(isis[, bins, range, density, ax])

Plot a distribution of ISIs.

plot_firing_rates(rates[, ax])

Plot firing rates for a group of neurons.

Spatial

Plots for spatial data.

plot_positions(position[, spike_positions, ...])

Plot positions.

plot_position_1d(position[, events, colors, ...])

Position 1d position data, with annotated events.

plot_position_by_time(timestamps, position)

Plot position across time for a single dimension.

plot_heatmap(data[, smooth, ...])

Plot a spatial heat map.

plot_trial_heatmaps(trial_data, **plt_kwargs)

Plot spatial heat maps for a set of trials.

create_heatmap_title(label, data[, stat, p_val])

Create a standardized title for an heatmap, listing the data range.

Task

Plots for visualizing task structure.

plot_task_structure([task_ranges, ...])

Plot task structure with shaded ranges of event durations and lines for point events.

plot_task_events(events[, ax])

Plot task events.

Trials

Plots for trial-epoched data.

plot_rasters(spikes[, vline, colors, ...])

Plot rasters across multiple trials.

plot_rate_by_time(bin_times, trial_cfrs[, ...])

Plot continuous firing rates across time.

create_raster_title(label, avg_pre, avg_post)

Create a standardized title for an event-related raster plot.

Stats

Plots for statistical measures and methods.

plot_surrogates(surrogates[, data_value, ...])

Plot a distribution of surrogate data.

Data

Basic plot function for different data types.

plot_lines(x_values, y_values[, vline, ax])

Plot data as a line.

plot_scatter(x_values, y_values[, ax])

Plot 2d data as a scatter plot.

plot_points(data[, label, ax])

Plot 1d data as points.

plot_hist(data[, bins, range, density, ...])

Plot data as a histogram.

plot_bar(data[, labels, add_text, ax])

Plot data in a bar graph.

plot_barh(data[, labels, add_text, ax])

Plot a horizontal bar plot.

plot_polar_hist(data[, bin_width, ax])

Plot a polar histogram.

plot_text(text[, xpos, ypos, show_axis, ax])

Plot text.

Annotate

Helper functions to annotate plot axes.

color_pvalue(p_value[, alpha, ...])

Select a color based on the significance of a p-value.

add_vlines(vline[, ax])

Add vertical line(s) to a plot axis.

add_hlines(hline[, ax])

Add horizontal line(s) to a plot axis.

add_gridlines(x_bins, y_bins[, ax])

Add gridlines to a plot axis.

add_vshades(vshades[, ax])

Add vertical shade region(s) to a plot axis.

add_hshades(hshades[, ax])

Add horizontal shade region(s) to a plot axis.

add_box_shade(x1, x2, y_val[, y_range, ax])

Add a shaded box to a plot axis.

add_box_shades(x_values[, y_values, ...])

Add multiple shaded boxes to a plot axis.

add_dots(dots[, ax])

Add dots to a plot axis.

add_significance(stats[, sig_level, x_vals, ax])

Add markers to a plot axis to indicate statistical significance.

add_text_labels(texts[, location, axis, ...])

Add text to the side of a plot.

Style

Helper functions for managing plot style.

drop_spines(sides[, ax])

Drop spines from a plot axis.

invert_axes(invert[, ax])

Invert plot axes.

Utils

Plot related utilities.

check_ax(ax[, figsize, return_current])

Check whether a figure axes object is defined, and define or return current axis if not.

save_figure(file_name[, file_path, close])

Save out a figure.

make_axes(n_axes[, n_cols, figsize, ...])

Make a subplot with multiple axes.

make_grid(nrows, ncols[, title])

Create a plot grid.

get_grid_subplot(grid, row, col, **plt_kwargs)

Get a subplot section from a grid layout.

Utilities

Utility functions, in the utils sub-module.

Base

General utilities for basic data types.

flatten(lst)

Flatten a list of lists into a single list.

lower_list(lst)

Convert all strings in a list to lowercase.

select_from_list(lst, select)

Select elements from a list based on a boolean mask.

count_elements(data[, labels, sort])

Count elements within a collection object.

combine_dicts(dicts)

Combine a list of dictionaries together.

add_key_prefix(indict, prefix)

Update keys of a dictionary by appending a prefix.

drop_key_prefix(indict, prefix)

Update keys of a dictionary by dropping a prefix.

relabel_keys(indict, new_keys)

Relabel keys in a dictionary.

subset_dict(indict, label)

Subset a dictionary based on key labels.

check_keys(indict, lst)

Check a dictionary for a set of keys.

listify(param[, index])

Check and embed a parameter into a list, if is not already in a list.

Data

Utilities for working with arrays of data.

make_orientation(arr, to_orientation[, ...])

Check and make sure a 2d array is in a specified orientation.

compute_range(data)

Compute the range of an array of data.

smooth_data(data, sigma)

Smooth an array of data, using a gaussian kernel.

drop_nans(data)

Drop any NaNs values from an array.

permute_vector(data[, n_permutations])

Create permutations of a vector of data.

assign_data_to_bins(data, edges[, ...])

Assign data values to data bins, based on given edges.

Extract

Utilities for extracting data segments of interest.

create_mask(data[, min_value, max_value])

Create a mask to select data points based on value.

create_nan_mask(data)

Create a mask for non-nan array elements.

select_from_arrays(mask, *arrays)

Select the same set of elements from a collection of arrays.

get_range(data[, min_value, max_value, reset])

Get a specified range from a vector of data.

get_value_range(timestamps, data[, ...])

Extract data and associated timestamps for a desired value range.

get_ind_by_value(values, value[, threshold])

Get the index for a set of values closest to a specified value.

get_inds_by_values(values, select[, ...])

Get indices for a set of specified time points.

get_ind_by_time(timestamps, timepoint[, ...])

Get the index for a set of timepoints closest to a specified timepoint.

get_inds_by_times(timestamps, timepoints[, ...])

Get indices for a set of specified time points.

get_value_by_time(timestamps, values, timepoint)

Get the value from a data array at a specific time point.

get_values_by_times(timestamps, values, ...)

Get values from a data array for a set of specified time points.

get_values_by_time_range(timestamps, values, ...)

Extract data for a requested time range.

threshold_spikes_by_times(spikes, ...)

Threshold spikes by sub-selecting those that are temporally close to a set of time values.

threshold_spikes_by_values(spikes, ...[, ...])

Threshold spikes by sub-selecting based on thresholding values on another data stream.

drop_range(spikes, time_range[, check_empty])

Drop a specified time range from a vector spike times.

reinstate_range(spikes, time_range)

Reinstate a dropped time range into an array of spike times.

Timestamps

Utilities for working with timestamps.

compute_sample_durations(timestamps[, ...])

Compute the time duration of each sample.

infer_time_unit(time_values)

Infer the time unit of given time values.

convert_ms_to_sec(ms)

Convert time value(s) from milliseconds to seconds.

convert_sec_to_min(sec)

Convert time value(s) from seconds to minutes.

convert_min_to_hour(mins)

Convert time value(s) from minutes to hours.

convert_ms_to_min(ms)

Convert time value(s) from milliseconds to minutes.

convert_nsamples_to_time(n_samples, fs)

Convert a number of samples into the corresponding time length.

convert_time_to_nsamples(time, fs)

Convert a time length into the corresponding number of samples.

sum_time_ranges(ranges)

Sum the total amount of time defined by time range(s).

create_bin_times(bins)

Create a timepoints definition for a set of time bins.

split_time_value(sec)

Split a time value from seconds to hours / minutes / seconds.

format_time_string(hours, minutes, seconds)

Format a time value into a string.

Epoch

Utilities for epoching data.

epoch_spikes_by_event(spikes, events, window)

Epoch spiking data into trials, based on events of interest.

epoch_spikes_by_range(spikes, start_times, ...)

Epoch spiking data into trials, based on time ranges of interest.

epoch_spikes_by_segment(spikes, segments)

Epoch spikes by segments.

epoch_data_by_time(timestamps, values, ...)

Epoch data into trials, based on individual timepoints of interest.

epoch_data_by_event(timestamps, values, ...)

Epoch data into trials, based on events of interest.

epoch_data_by_range(timestamps, values, ...)

Epoch data into trials, based on time ranges of interest.

epoch_data_by_segment(timestamps, values, ...)

Epoch data by segments.

Trials

Utilities for working with trial-level data.

split_trials_by_condition(trials, conditions)

Split trial data by condition label.

split_trials_by_condition_list(trials, ...)

Split trial data by condition label, for trial data as a list.

split_trials_by_condition_array(trials, ...)

Split trial data by condition label, for trial data as an array.

recombine_trial_data(times_trials, values_trials)

Recombine data across trials.

Run

Utilities for helping with running analyses.

create_methods_list(methods)

Create a list of all methods.

Checks

Utilities to check for basic properties of data / inputs.

check_param_range(param, label, bounds)

Check a parameter value is within an acceptable range.

check_param_options(param, label, options[, ...])

Check a parameter value is one of the acceptable options.

check_param_lengths(params, labels[, ...])

Check that a set of parameters have the same length.

check_param_type(param, label, types)

Check that a parameter has an acceptable type.

check_list_options(contents, label, options)

Check a list of values that each element is one of a set of acceptable options.

check_array_orientation(arr[, expected])

Check the orientation of an array of data.

check_array_lst_orientation(arr_lst[, expected])

Check the orientation of arrays in a list.

check_axis(axis, arr)

Check axis argument, and infer from array orientation if not defined.

check_bin_range(values, bin_area)

Checks data values against given bin edges, warning if values exceed bin range.

check_time_bins(bins[, time_range, values, ...])

Check a given time bin definition, and define if only given a time resolution.

Random

Utilities for managing random state.

set_random_seed([seed_value])

Set the random seed value.

set_random_state([seed_value])

Set the random state in a RandomState object.