spiketools.spatial.place.compute_trial_place_bins¶
- spiketools.spatial.place.compute_trial_place_bins(spikes, position, timestamps, bins, start_times, stop_times, area_range=None, speed=None, min_speed=None, max_speed=None, time_threshold=None, trial_occupancy=None, flatten=False, orientation=None)[source]¶
Compute the spatially binned spiking activity, across trials.
- Parameters:
- spikes1d array
Spike times, in seconds.
- position1d or 2d array
Position values.
- timestamps1d array
Timestamps, in seconds, corresponding to the position values.
- binsint or list of [int, int]
The bin definition for dividing up the space. If 1d, can be integer. If 2d should be a list, defined as [number of x_bins, number of y_bins].
- start_times, stop_times1d array
The start and stop times, in seconds, of each trial.
- area_rangelist of list, optional
Edges of the area to bin, defined as [[x_min, x_max], [y_min, y_max]].
- speed1d array, optional
Speed values corresponding to each position. Should be the same length as timestamps.
- min_speed, max_speedfloat, optional
Minimum and/or maximum speed thresholds to apply. Any spikes with an associated speed below the minimum or above maximum are dropped.
- time_thresholdfloat, optional
A maximum time threshold, per bin observation, to apply. If provided, any bin values with an associated time length above this value are dropped.
- trial_occupancy2d or 3d array, optional
Computed occupancy across the space, across trials. If provided, used to normalize bin counts per trial.
- flattenbool, optional, default: False
Whether the flatten the spatial bins per trial. Only used if position data are 2d.
- orientation{‘row’, ‘column’}, optional
The orientation of the position data. If not provided, is inferred from the position data.
- Returns:
- place_bins_trial1d or 2d or 3d array
The spike activity per spatial bin, per trial. If flatten is True, for a 2d position input, the output is 2d, as [n_trial, n_bins]. Otherwise, for a 2d position input, the output is 3d, as [n_trials, n_ybins, n_xbins].
Examples
Compute spike activity, in 1d spatial bins across 2 trials:
>>> spikes = np.array([0.15, 0.22, 0.28, 0.41, 0.50, 0.65, 0.77, 0.81, 0.95]) >>> position = np.array([1.0, 3.5, 2.0, 1.5, 3.0, 3.5, 4.0, 5.0, 3.5, 2.5]) >>> timestamps = np.array([0.10, 0.20, 0.25, 0.35, 0.45, 0.55, 0.6, 0.7, 0.80, 0.95]) >>> bins = 2 >>> start_times, stop_times = np.array([0, 0.6]), np.array([0.4, 1.0]) >>> compute_trial_place_bins(spikes, position, timestamps, bins, start_times, stop_times) array([[2., 1.], [3., 1.]])
Compute spike activity across trials, normalizing by trial-level occupancy:
>>> from spiketools.spatial.occupancy import compute_trial_occupancy >>> trial_occ = compute_trial_occupancy(position, timestamps, bins, start_times, stop_times) >>> compute_trial_place_bins(spikes, position, timestamps, bins, ... start_times, stop_times, trial_occupancy=trial_occ) array([[10., 20.], [20., 5.]])