spiketools.spatial.occupancy.compute_bin_edges

spiketools.spatial.occupancy.compute_bin_edges(position, bins, area_range=None)[source]

Compute spatial bin edges.

Parameters:
position1d or 2d array or None

Position values. If None, area_range is required to define bins.

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].

area_rangelist of list, optional

Edges of the area to bin. For 1d defined as [min, max]. For 2d, defined as [[x_min, x_max], [y_min, y_max]]. Any values outside this range will be considered outliers, and not used to compute edges.

Returns:
x_edges1d array

Edge definitions for the spatial binning.

y_edges1d array

Edge definitions for the spatial binning. Only returned in 2d case.

Examples

Compute bin edges for 1d position values:

>>> position = np.array([1, 2, 3, 4, 5])
>>> compute_bin_edges(position, bins=[5])
array([1. , 1.8, 2.6, 3.4, 4.2, 5. ])

Compute bin edges for 2d position values:

>>> position = np.array([[1, 2, 3, 4, 5],
...                      [6, 7, 8, 9, 10]])
>>> compute_bin_edges(position, bins=[5, 4])
(array([1. , 1.8, 2.6, 3.4, 4.2, 5. ]), array([ 6.,  7.,  8.,  9., 10.]))