Skip to content

Commit b322880

Browse files
RouthleckAirs702
andauthored
[analyzer] Add experimental data utilities and 1D CANN bump fitting (#19)
* Add experimental data utilities and 1D CANN bump fitting Introduces universal data loading utilities in _datasets.py, experimental data processing in analyzer/experimental_data, and 1D CANN bump fitting and animation in CANN1D.py. Updates __init__.py files to expose new modules and functions for streamlined access to datasets and analysis tools. Co-Authored-By: Airs702 <116141471+Airs702@users.noreply.github.com> * Update main block in CANN1D.py for bump fitting Uncommented and updated the main execution block to load ROI data and perform bump fitting with specified parameters. Also refactored the animation creation call for clarity. Fixed boolean value in pyproject.toml for dynamic versioning configuration. * Add CANN1D bump analysis example and refactor analyzer Introduces examples/cann1d_bump_analysis.py to demonstrate bump fitting and animation. Refactors and improves code in analyzer and experimental_data modules for clarity, typing, and robustness. Fixes import paths, updates __init__.py files, and enhances dataset utility functions. Minor formatting and logic improvements throughout for consistency and maintainability. --------- Co-authored-by: Airs702 <116141471+Airs702@users.noreply.github.com>
1 parent 46c9d39 commit b322880

File tree

10 files changed

+1941
-11
lines changed

10 files changed

+1941
-11
lines changed

examples/cann1d_bump_analysis.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
"""
3+
CANN 1D Bump Analysis Example
4+
5+
This example demonstrates how to use the bump_fits and create_1d_bump_animation functions
6+
from the experimental data analyzer to analyze 1D CANN bumps.
7+
"""
8+
9+
import numpy as np
10+
from canns.analyzer.experimental_data import bump_fits, create_1d_bump_animation
11+
12+
13+
def main():
14+
"""Demonstrate bump analysis and animation creation."""
15+
# Generate sample data for demonstration
16+
# 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...")
32+
33+
# Run bump fitting analysis
34+
bumps, fits, nbump, centrbump = bump_fits(
35+
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,
41+
random_seed=42
42+
)
43+
44+
print(f"Analysis complete!")
45+
print(f"Found {len(fits)} time steps with bump data")
46+
print(f"Average number of bumps: {np.mean(nbump):.2f}")
47+
48+
# Create animation of the bump evolution
49+
print("Creating bump animation...")
50+
51+
create_1d_bump_animation(
52+
fits,
53+
show=False,
54+
save_path="examples/bump_analysis_demo.gif",
55+
max_height_value=0.8,
56+
nframes=min(100, len(fits)),
57+
fps=10,
58+
title="1D CANN Bump Analysis Demo"
59+
)
60+
61+
print("Animation saved as 'examples/bump_analysis_demo.gif'")
62+
63+
return bumps, fits, nbump, centrbump
64+
65+
66+
if __name__ == "__main__":
67+
results = main()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ source = "uv-dynamic-versioning"
103103
[tool.uv-dynamic-versioning]
104104
vcs = "git"
105105
style = "pep440"
106-
bump = "true"
106+
bump = true
107107

108108
[tool.hatch.build.targets.wheel]
109109
# The source location for the package.

src/canns/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from . import _datasets as _datasets
12
from . import analyzer as analyzer
23
from . import misc as misc
34
from . import models as models
@@ -14,7 +15,8 @@
1415

1516
__all__ = [
1617
"analyzer",
17-
"misc",
18+
"_datasets",
19+
"misc",
1820
"models",
1921
"pipeline",
2022
"trainer",

0 commit comments

Comments
 (0)