src.canns.analyzer.experimental_data¶
Submodules¶
Classes¶
Specialized PlotConfig for CANN1D visualizations. |
|
Specialized PlotConfig for CANN2D visualizations. |
|
Unified configuration class for all plotting helpers in |
|
Configuration for spike train embedding. |
|
Configuration for Topological Data Analysis. |
Functions¶
|
Fit CANN1D bumps to data using MCMC optimization. |
|
Create 1D CANN bump animation using vectorized operations. |
|
Decode circular coordinates (bump positions) from cohomology. |
|
Load and preprocess spike train data from npz file. |
|
Load grid cell data for 2D CANN analysis. |
|
Load ROI data for 1D CANN analysis. |
|
Visualize the movement of the neural activity bump on a torus using matplotlib animation. |
|
Plot a 3D projection of the embedded data. |
|
Topological Data Analysis visualization with optional shuffle testing. |
|
Validate grid data format for 2D CANN analysis. |
|
Validate ROI data format for 1D CANN analysis. |
Package Contents¶
- class src.canns.analyzer.experimental_data.CANN1DPlotConfig[source]¶
Bases:
src.canns.analyzer.plotting.PlotConfigSpecialized PlotConfig for CANN1D visualizations.
- class src.canns.analyzer.experimental_data.CANN2DPlotConfig[source]¶
Bases:
src.canns.analyzer.plotting.PlotConfigSpecialized PlotConfig for CANN2D visualizations.
- class src.canns.analyzer.experimental_data.PlotConfig[source]¶
Unified configuration class for all plotting helpers in
canns.analyzer.This mirrors the behaviour of the previous
visualizemodule so that reorganising the files does not affect the public API. The attributes map directly to keyword arguments exposed by the high-level plotting functions, allowing users to keep existing configuration objects unchanged after the reorganisation.
- class src.canns.analyzer.experimental_data.SpikeEmbeddingConfig[source]¶
Configuration for spike train embedding.
- class src.canns.analyzer.experimental_data.TDAConfig[source]¶
Configuration for Topological Data Analysis.
- src.canns.analyzer.experimental_data.bump_fits(data, config=None, save_path=None, **kwargs)[source]¶
Fit CANN1D bumps to data using MCMC optimization.
- Parameters:
data – numpy.ndarray Input data for bump fitting
config (BumpFitsConfig | None) – BumpFitsConfig, optional Configuration object with all fitting parameters
save_path – str, optional Path to save the results
**kwargs – backward compatibility parameters
- Returns:
- list
List of fitted bump objects
- fits_arraynumpy.ndarray
Array of fitted bump parameters
- nbump_arraynumpy.ndarray
Array of bump counts and reconstructed signals
- centrbump_arraynumpy.ndarray
Array of centered bump data
- Return type:
bumps
- src.canns.analyzer.experimental_data.create_1d_bump_animation(fits_data, config=None, save_path=None, **kwargs)[source]¶
Create 1D CANN bump animation using vectorized operations.
- Parameters:
fits_data – numpy.ndarray Shape (n_fits, 4) array with columns [time, position, amplitude, kappa]
config (CANN1DPlotConfig | None) – AnimationConfig, optional Configuration object with all animation parameters
save_path – str, optional Output path for the generated GIF
**kwargs – backward compatibility parameters
- Returns:
- matplotlib.animation.FuncAnimation
The animation object
- src.canns.analyzer.experimental_data.decode_circular_coordinates(persistence_result, spike_data, real_ground=True, real_of=True, save_path=None)[source]¶
Decode circular coordinates (bump positions) from cohomology.
- Parameters:
persistence_result (dict[str, Any]) – dict containing persistence analysis results with keys: - ‘persistence’: persistent homology result - ‘indstemp’: indices of sampled points - ‘movetimes’: selected time points - ‘n_points’: number of sampled points
spike_data (dict[str, Any]) – dict, optional Spike data dictionary containing ‘spike’, ‘t’, and optionally ‘x’, ‘y’
real_ground (bool) – bool Whether x, y, t ground truth exists
real_of (bool) – bool Whether experiment was performed in open field
save_path (str | None) – str, optional Path to save decoding results. If None, saves to ‘Results/spikes_decoding.npz’
- Returns:
- Dictionary containing decoding results with keys:
’coords’: decoded coordinates for all timepoints
’coordsbox’: decoded coordinates for box timepoints
’times’: time indices for coords
’times_box’: time indices for coordsbox
’centcosall’: cosine centroids
’centsinall’: sine centroids
- Return type:
- src.canns.analyzer.experimental_data.embed_spike_trains(spike_trains, config=None, **kwargs)[source]¶
Load and preprocess spike train data from npz file.
This function converts raw spike times into a time-binned spike matrix, optionally applying Gaussian smoothing and filtering based on animal movement speed.
- Parameters:
spike_trains – dict containing ‘spike’, ‘t’, and optionally ‘x’, ‘y’.
config (SpikeEmbeddingConfig | None) – SpikeEmbeddingConfig, optional configuration object
**kwargs – backward compatibility parameters
- Returns:
Binned and optionally smoothed spike matrix of shape (T, N). xx (ndarray, optional): X coordinates (if speed_filter=True). yy (ndarray, optional): Y coordinates (if speed_filter=True). tt (ndarray, optional): Time points (if speed_filter=True).
- Return type:
spikes_bin (ndarray)
- src.canns.analyzer.experimental_data.load_grid_data(source=None, dataset_key='grid_1')[source]¶
Load grid cell data for 2D CANN analysis.
- Parameters:
- Returns:
Dictionary containing spike data and metadata if successful, None otherwise. Expected keys: ‘spike’, ‘t’, and optionally ‘x’, ‘y’ for position data.
- Return type:
dict or None
Examples
>>> # Load default dataset >>> grid_data = load_grid_data() >>> >>> # Load from URL >>> grid_data = load_grid_data('https://example.com/grid_data.npz') >>> >>> # Load specific default dataset >>> grid_data = load_grid_data(dataset_key='grid_2')
- src.canns.analyzer.experimental_data.load_roi_data(source=None)[source]¶
Load ROI data for 1D CANN analysis.
- Parameters:
source (str, Path, or None) – Data source. Can be: - URL string: downloads and loads from URL - Path: loads from local file - None: uses default CANNs dataset
- Returns:
ROI data array if successful, None otherwise.
- Return type:
ndarray or None
Examples
>>> # Load default dataset >>> roi_data = load_roi_data() >>> >>> # Load from URL >>> roi_data = load_roi_data('https://example.com/roi_data.txt') >>> >>> # Load from local file >>> roi_data = load_roi_data('./my_roi_data.txt')
- src.canns.analyzer.experimental_data.plot_3d_bump_on_torus(decoding_result, spike_data, config=None, save_path=None, numangsint=51, r1=1.5, r2=1.0, window_size=300, frame_step=5, n_frames=20, fps=5, show_progress=True, show=True, figsize=(8, 8), **kwargs)[source]¶
Visualize the movement of the neural activity bump on a torus using matplotlib animation.
This function follows the canns.analyzer.plotting patterns for animation generation with progress tracking and proper resource cleanup.
- Parameters:
decoding_result (dict[str, Any] | str) – dict or str Dictionary containing decoding results with ‘coordsbox’ and ‘times_box’ keys, or path to .npz file containing these results
spike_data (dict[str, Any]) – dict, optional Spike data dictionary containing spike information
config (CANN2DPlotConfig | None) – PlotConfig, optional Configuration object for unified plotting parameters
**kwargs – backward compatibility parameters
save_path (str | None) – str, optional Path to save the animation (e.g., ‘animation.gif’ or ‘animation.mp4’)
numangsint (int) – int Grid resolution for the torus surface
r1 (float) – float Major radius of the torus
r2 (float) – float Minor radius of the torus
window_size (int) – int Time window (in number of time points) for each frame
frame_step (int) – int Step size to slide the time window between frames
n_frames (int) – int Total number of frames in the animation
fps (int) – int Frames per second for the output animation
show_progress (bool) – bool Whether to show progress bar during generation
show (bool) – bool Whether to display the animation
figsize (tuple[int, int]) – tuple[int, int] Figure size for the animation
- Returns:
The animation object
- Return type:
matplotlib.animation.FuncAnimation
- src.canns.analyzer.experimental_data.plot_projection(reduce_func, embed_data, config=None, title='Projection (3D)', xlabel='Component 1', ylabel='Component 2', zlabel='Component 3', save_path=None, show=True, dpi=300, figsize=(10, 8), **kwargs)[source]¶
Plot a 3D projection of the embedded data.
- Parameters:
reduce_func (callable) – Function to reduce the dimensionality of the data.
embed_data (ndarray) – Data to be projected.
config (PlotConfig, optional) – Configuration object for unified plotting parameters
**kwargs – backward compatibility parameters
title (str) – Title of the plot.
xlabel (str) – Label for the x-axis.
ylabel (str) – Label for the y-axis.
zlabel (str) – Label for the z-axis.
save_path (str, optional) – Path to save the plot. If None, plot will not be saved.
show (bool) – Whether to display the plot.
dpi (int) – Dots per inch for saving the figure.
figsize (tuple) – Size of the figure.
- Returns:
The created figure object.
- Return type:
fig
- src.canns.analyzer.experimental_data.tda_vis(embed_data, config=None, **kwargs)[source]¶
Topological Data Analysis visualization with optional shuffle testing.
- Parameters:
embed_data (numpy.ndarray) – ndarray Embedded spike train data.
config (TDAConfig | None) – TDAConfig, optional Configuration object with all TDA parameters
**kwargs – backward compatibility parameters
- Returns:
- Dictionary containing:
persistence: persistence diagrams from real data
indstemp: indices of sampled points
movetimes: selected time points
n_points: number of sampled points
shuffle_max: shuffle analysis results (if do_shuffle=True, otherwise None)
- Return type: