src.canns.analyzer.spatial¶
Spatial analysis utilities for neural activity data.
This module provides functions for analyzing spatial patterns in neural data, particularly for computing firing fields and spatial smoothing operations.
Functions¶
|
Compute spatial firing fields for neural population activity. |
|
Apply Gaussian smoothing to spatial heatmaps without mixing channels. |
Module Contents¶
- src.canns.analyzer.spatial.compute_firing_field(A, positions, width, height, M, K)[source]¶
Compute spatial firing fields for neural population activity.
This function bins neural activity into a 2D spatial grid based on the animal’s position, creating a heatmap for each neuron showing where it fires most strongly. Uses Numba JIT compilation for high performance.
- Parameters:
A (np.ndarray) – Neural activity array of shape (T, N) where T is the number of time steps and N is the number of neurons.
positions (np.ndarray) – Position data of shape (T, 2) containing (x, y) coordinates at each time step.
width (float) – Width of the spatial environment.
height (float) – Height of the spatial environment.
M (int) – Number of bins along the width dimension.
K (int) – Number of bins along the height dimension.
- Returns:
- Heatmaps array of shape (N, M, K) containing the average
firing rate of each neuron in each spatial bin.
- Return type:
np.ndarray
Example
>>> activity = np.random.rand(1000, 30) # 1000 timesteps, 30 neurons >>> positions = np.random.rand(1000, 2) * 5.0 # Random walk in 5x5 space >>> heatmaps = compute_firing_field(activity, positions, 5.0, 5.0, 50, 50) >>> heatmaps.shape (30, 50, 50)
- src.canns.analyzer.spatial.gaussian_smooth_heatmaps(heatmaps, sigma=1.0)[source]¶
Apply Gaussian smoothing to spatial heatmaps without mixing channels.
This function applies Gaussian filtering to each heatmap independently, preserving zero values (unvisited spatial bins) and only smoothing regions with activity.
- Parameters:
heatmaps (np.ndarray) – Array of shape (N, M, K) where N is the number of neurons/channels and (M, K) is the spatial grid size.
sigma (float, optional) – Standard deviation for Gaussian kernel. Defaults to 1.0.
- Returns:
- Smoothed heatmaps with the same shape as input. Zero values
in the original heatmaps are preserved.
- Return type:
np.ndarray
Example
>>> heatmaps = np.random.rand(30, 50, 50) >>> smoothed = gaussian_smooth_heatmaps(heatmaps, sigma=1.5) >>> smoothed.shape (30, 50, 50)