Skip to content

Commit 103f6a0

Browse files
RouthleckAirs702
andauthored
[analyzer] Refactor CANN1D module and Implement CANN2D module (#20)
* Add CANN2D analysis module and update dependencies Introduces src/canns/analyzer/experimental_data/CANN2D.py for 2D CANN analysis, including spike train embedding and topological data analysis (TDA) functions. Updates pyproject.toml to add ripser as a dependency and moves sphinx-design to docs extras. Refactors CANN1D.py to use internal function naming and improves numba fallback messaging. Updates __init__.py to expose new CANN2D functions. Minor changes to _datasets_utils.py for compatibility. Co-Authored-By: Airs702 <116141471+Airs702@users.noreply.github.com> * Refactor CANN1D and CANN2D modules, update imports Renamed CANN1D.py and CANN2D.py to cann1d.py and cann2d.py for consistency and updated all relevant imports. Refactored CANN1D bump analysis and animation functions to use configuration dataclasses and improved error handling. Updated example script to use new data loading and function signatures. Changed default maxdim in TDAConfig and related usages from 2 to 1 in CANN2D. Co-Authored-By: Airs702 <116141471+Airs702@users.noreply.github.com> * Refactor experimental_data modules for type hints and style Updated type hints to use PEP 604 union syntax, improved code style and consistency, and reordered imports in cann1d and cann2d modules. Enhanced error handling and function signatures, and made minor formatting improvements throughout. No functional changes were made. * Fix TDA 2D analysis implementation to match external TDAvis behavior - Fix active timepoint selection logic to match external TDAvis sorting behavior - Correct omega parameter from 0.2 to 1 in denoising calls for consistency - Fix sampling score calculation indexing in both numpy and numba implementations - Remove epsilon handling in distance matrix to match external behavior - Add numba optimizations while maintaining computational consistency - Enhance API with comprehensive results dictionary format - Add missing standard barcode visualization functionality Ensures CANN 2D topological data analysis produces identical results to reference implementation. --------- Co-authored-by: Airs702 <116141471+Airs702@users.noreply.github.com>
1 parent b322880 commit 103f6a0

File tree

8 files changed

+2688
-954
lines changed

8 files changed

+2688
-954
lines changed

examples/cann1d_bump_analysis.py

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,20 @@
77
"""
88

99
import numpy as np
10-
from canns.analyzer.experimental_data import bump_fits, create_1d_bump_animation
10+
from canns.analyzer.experimental_data import bump_fits, create_1d_bump_animation, load_roi_data
1111

1212

1313
def main():
1414
"""Demonstrate bump analysis and animation creation."""
1515
# Generate sample data for demonstration
1616
# In practice, you would load your experimental data
17-
np.random.seed(42)
18-
n_steps = 1000
19-
n_roi = 16
20-
21-
# Simulate some bump-like activity data
22-
data = np.random.rand(n_steps, n_roi) * 0.1
23-
24-
# Add some bump-like patterns
25-
for i in range(n_steps):
26-
center = (i * 0.01) % n_roi
27-
for j in range(n_roi):
28-
distance = min(abs(j - center), n_roi - abs(j - center))
29-
data[i, j] += 0.5 * np.exp(-distance**2 / 2.0)
30-
31-
print("Running bump fitting analysis...")
17+
data = load_roi_data()
3218

3319
# Run bump fitting analysis
3420
bumps, fits, nbump, centrbump = bump_fits(
3521
data,
36-
n_steps=n_steps,
37-
n_roi=n_roi,
38-
n_bump_max=2,
39-
sigma_diff=0.5,
40-
ampli_min=2.0,
22+
n_steps=5000,
23+
n_roi=16,
4124
random_seed=42
4225
)
4326

@@ -52,8 +35,7 @@ def main():
5235
fits,
5336
show=False,
5437
save_path="examples/bump_analysis_demo.gif",
55-
max_height_value=0.8,
56-
nframes=min(100, len(fits)),
38+
nframes=100,
5739
fps=10,
5840
title="1D CANN Bump Analysis Demo"
5941
)

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies = [
4242
"furo>=2025.7.19",
4343
"notebook>=7.4.4",
4444
"ratinabox>=1.15.3",
45-
"sphinx-design>=0.6.1",
45+
"ripser>=0.6.12",
4646
"tqdm",
4747
]
4848

@@ -65,6 +65,7 @@ docs = [
6565
"sphinx>=8.1.3",
6666
"sphinx-autoapi>=3.6.0",
6767
"sphinx-autodoc-typehints>=3.0.1",
68+
"sphinx-design>=0.6.1",
6869
"sphinx-intl>=2.3.1",
6970
"sphinx-rtd-theme>=3.0.2",
7071
]

0 commit comments

Comments
 (0)