API Reference
Binning
- binit.bin.bin_array_around_event(arr: ndarray, timestamps_to_bin_around: ndarray, binsize: float) ndarray [source]
Get counts of timestamps of one array occuring around an timestamps specified in another array.
- Parameters:
arr (np.ndarray) – Array of timestamps to be counted
timestamps_to_bin_around (np.ndarray) – Array of timestamps to bin around
binsize (float) – Size of the window around the timestamps to calculate counts over
- Returns:
Array of timestamp counts
- Return type:
np.ndarray
- binit.bin.binarize_array(arr: ndarray) ndarray [source]
Binarize an array
- Parameters:
arr (np.ndarray) – Input array
- Returns:
An array whose non-zero values have been replaced with 1
- Return type:
np.ndarray
- binit.bin.binned_array_bins_provided(arr: ndarray, bins: ndarray) Tuple[ndarray, ndarray] [source]
Bin an array of timestamps into pre-specified time bins
- Parameters:
arr (np.ndarray) – Input array of timestamps
bins (np.ndarray) – Time bins to use for binning
- Returns:
Bin edges, event counts
- Return type:
Tuple[np.ndarray, np.ndarray]
- binit.bin.binned_array_regular_interval(arr: ndarray, binwidth: float, t_start: Optional[float] = None, t_stop: Optional[float] = None) Tuple[ndarray, ndarray] [source]
Bin an array of timestamps into bins at a regular interval
- Parameters:
arr (np.ndarray) – Input array of timestamps
binwidth (float) – Length of bins
t_start (Optional[float], optional) – Sets the first bin to start at this timepoint. Defaults to None.
t_stop (Optional[float], optional) – Sets the last bin to stop before this timepoint. Defaults to None.
- Returns:
Bin edges, event counts
- Return type:
Tuple[np.ndarray, np.ndarray]
- binit.bin.split_by_bin(arr: ndarray, bins: ndarray, max_latency: Optional[float] = None, time_before: float = None) OrderedDict[float, np.ndarray] [source]
Split an array of timestamps by bin and transform their values to be latencies to that bin.
- Parameters:
arr (np.ndarray) – Array of timestamps
bins (np.ndarray) – Array of bins
max_latency (Optional[float], optional) – Exclude timestamps occuring at a latency to the final bin greater than this value. Defaults to None.
time_before (Optional[float], optional) – By default, values are binned into the closest preceding bin but if this value is specified, timestamps falling this value before a following bin are binned to that bin. Defaults to None.
- Returns:
An ordered dict whose keys are the bins and whose values are arrays of vatency to these bins.
- Return type:
OrderedDict[float, np.ndarray]
- binit.bin.which_bin(arr: ndarray, bin_edges: ndarray, time_before: Optional[float] = 0, time_after: Optional[float] = 1) ndarray [source]
For each element of an input array, get the corresponding bin it would be binned into
- Parameters:
arr (np.ndarray) – Input array of timestamps
bin_edges (np.ndarray) – Array of bins
time_before (Optional[float], optional) – By default, values are binned into the closest preceding bin but if this value is specified, timestamps falling this value before a following bin are binned to that bin. Defaults to None.
nan_vals_before_first_bin (bool, optional) – If True, returns np.nan for values of input timestamps occuring before the after the first bin. Defaults to True.
time_after (Optional[float], optional) – If specified, return np.nan for values occuring this latency after the event. Defaults to None.
- Returns:
Bin values
- Return type:
np.ndarray
- binit.bin.which_bin_idx(arr: ndarray, bin_edges: ndarray, time_before: Optional[float] = 0, time_after: Optional[float] = 1) ndarray [source]
For each element of an input array, get the corresponding index of the bin it would be binned into
- Parameters:
arr (np.ndarray) – Input array of timestamps
bin_edges (np.ndarray) – Array of bins
time_before (Optional[float], optional) – By default, values are binned into the closest preceding bin but if this value is specified, timestamps falling this value before a following bin are binned to that bin. Defaults to None.
nan_vals_before_first_bin (bool, optional) – If True, returns np.nan for values of input timestamps occuring before the after the first bin. Defaults to True.
time_after (Optional[float], optional) – If specified, return np.nan for values occuring this latency after the event. Defaults to None.
- Returns:
Bin values
- Return type:
np.ndarray
Alignment
- binit.align.align_around(to_be_aligned: ndarray, to_align_to: ndarray, t_before: Optional[float] = None, max_latency: Optional[float] = None, drop: bool = False) ndarray [source]
Align one array to another.
Useful for aligning data to events. Default behaviour is to align to closest smaller event. If t_before is specified
- Parameters:
to_be_aligned – A numpy array to align
to_align_to – A numpy to align to (events)
t_before – The time window before each aligning event.
max_latency – Maximum aligned latency. Latencies above this threshold will be returned as NaN
drop – Whether to drop NaN elements of the aligned array
- Returns:
A numpy array of aligned data