Skip to content

Commit ff1d1bf

Browse files
committed
refactor to StaticSMLM and Core modules
1 parent 94cb63e commit ff1d1bf

21 files changed

+989
-703
lines changed

CLAUDE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SMLMSim.jl Development Guide
2+
3+
## Build, Test & Run Commands
4+
- Install dependencies: `julia --project -e "using Pkg; Pkg.instantiate()"`
5+
- Run all tests: `julia --project -e "using Pkg; Pkg.test()"`
6+
- Run specific test: `julia --project -e "using Pkg; Pkg.test(\"SMLMSim\", test_args=[\"Patterns\"])"`
7+
- Build docs: `julia --project=docs/ docs/make.jl`
8+
- Run benchmark: `julia --project=dev/ dev/benchmark.jl`
9+
10+
## Code Style Guidelines
11+
- Use physical units consistently (μm for space, seconds for time)
12+
- Follow Julia naming conventions: lowercase for functions, CamelCase for types
13+
- Organize imports: standard library first, then external packages
14+
- Place exports at module level, grouped by functionality
15+
- Type parameters should be explicit for functions with multiple dispatch
16+
- Error handling: use descriptive errors with parameter names and constraints
17+
- Documentation: include docstrings with examples and physical units
18+
- Re-export SMLMData types rather than redefining them
19+
- Follow existing patterns for defining new molecule or pattern types
20+
- Tests should use the `@test` macro with appropriate tolerances for floating-point comparisons
21+
22+
## Module Structure
23+
Functions should be organized in appropriate submodules: core, static, or diffusion.

README.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ Pkg.add("SMLMSim")
2828

2929
## Basic Usage
3030

31-
The high-level interface for simulating SMLM super-resolution coordinate data is the `simulate()` function (or the alias `sim()`).
31+
The high-level interface for simulating SMLM super-resolution coordinate data is the `simulate()` function with a `StaticSMLMParams` object.
3232

3333
```julia
3434
using SMLMSim
3535

3636
# Basic simulation with default parameters
3737
camera = IdealCamera(1:128, 1:128, 0.1) # 128×128 pixels, 100nm pixels
38+
params = StaticSMLMParams() # Default parameters
3839
smld_true, smld_model, smld_noisy = simulate(
40+
params,
3941
camera=camera
4042
)
4143
```
@@ -57,16 +59,20 @@ For more control, you can customize the parameters:
5759

5860
```julia
5961
# More customized simulation
60-
smld_true, smld_model, smld_noisy = simulate(;
62+
params = StaticSMLMParams(
6163
ρ=1.0, # emitters per μm²
6264
σ_psf=0.13, # PSF width in μm (130nm)
6365
minphotons=50, # minimum photons for detection
6466
ndatasets=10, # number of independent datasets
6567
nframes=1000, # frames per dataset
66-
framerate=50.0, # frames per second
68+
framerate=50.0 # frames per second
69+
)
70+
71+
smld_true, smld_model, smld_noisy = simulate(
72+
params,
6773
pattern=Nmer2D(n=6, d=0.2), # hexamer with 200nm diameter
6874
molecule=GenericFluor(; q=[0 50; 1e-2 0]), # rates in 1/s
69-
camera=IdealCamera(; ypixels=256, xpixels=128, pixelsize=0.1) # pixelsize in μm
75+
camera=IdealCamera(1:256, 1:128, 0.1) # 128×256 pixels, 100nm pixels
7076
)
7177
```
7278

@@ -166,10 +172,15 @@ using CairoMakie
166172
# Create camera with physical pixel size
167173
camera = IdealCamera(1:128, 1:256, 0.1) # 128×256 pixels, 100nm pixels
168174

169-
# Simulation parameters in physical units
170-
smld_true, smld_model, smld_noisy = simulate(;
175+
# Create simulation parameters
176+
params = StaticSMLMParams(
171177
ρ=1.0, # emitters per μm²
172-
σ_psf=0.13, # PSF width in μm
178+
σ_psf=0.13 # PSF width in μm
179+
)
180+
181+
# Run simulation
182+
smld_true, smld_model, smld_noisy = simulate(
183+
params,
173184
pattern=Nmer2D(n=6, d=0.2), # hexamer with 200nm diameter
174185
camera=camera
175186
)
@@ -212,13 +223,19 @@ using SMLMSim
212223
# Create camera with physical pixel size
213224
camera = IdealCamera(1:128, 1:256, 0.1) # 128×256 pixels, 100nm pixels
214225

215-
# Simulation parameters in physical units
216-
smld_true, smld_model, smld_noisy = simulate(;
226+
# Create 3D simulation parameters
227+
params = StaticSMLMParams(
217228
ρ=0.5, # emitters per μm²
218-
pattern=Nmer3D(n=8, d=0.3), # 3D pattern
219-
camera=camera,
229+
ndims=3, # 3D simulation
220230
zrange=[-2.0, 2.0] # 4μm axial range
221231
)
232+
233+
# Run simulation
234+
smld_true, smld_model, smld_noisy = simulate(
235+
params,
236+
pattern=Nmer3D(n=8, d=0.3), # 3D pattern
237+
camera=camera
238+
)
222239
```
223240

224241
## Contributors

dev/basic_sim_test.jl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
11
using Revise
22
using SMLMSim
3-
using SMLMData
4-
5-
3+
using SMLMData
64

75
# 2D Example
86
camera = IdealCamera(1:512, 1:512, 0.1)
97
pattern = SMLMSim.Nmer2D(n=6, d=0.2)
10-
smld_true, smld_model, smld_noisy = sim(
11-
ρ=1.0,
8+
params = StaticSMLMParams(ρ=1.0)
9+
smld_true, smld_model, smld_noisy = simulate(
10+
params,
1211
pattern=pattern,
1312
camera=camera
1413
)
1514

1615
# 3D Example
1716
pattern3d = SMLMSim.Nmer3D(n=8, d=0.3)
18-
smld_true, smld_model, smld_noisy = sim(
17+
params3d = StaticSMLMParams(
1918
ρ=1.0,
20-
pattern=pattern3d,
21-
camera=camera,
19+
ndims=3,
2220
zrange=[-2.0, 2.0]
2321
)
22+
smld_true, smld_model, smld_noisy = simulate(
23+
params3d,
24+
pattern=pattern3d,
25+
camera=camera
26+
)
2427

2528
# Complex Pattern Example
2629
line3d = SMLMSim.Line3D(λ=5.0, endpoints=[(-1.0, 0.0, -0.5), (1.0, 0.0, 0.5)])
27-
smld_true, smld_model, smld_noisy = sim(
30+
params_line = StaticSMLMParams(
2831
ρ=0.5,
29-
pattern=line3d,
3032
σ_psf=0.15,
33+
ndims=3
34+
)
35+
smld_true, smld_model, smld_noisy = simulate(
36+
params_line,
37+
pattern=line3d,
3138
camera=camera
3239
)

dev/sim2D.jl

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,24 @@ using GLMakie
66
# Create camera with physical pixel size
77
camera = IdealCamera(1:128, 1:256, 0.1) # 128x256 pixels, 100nm pixels
88

9-
# Simulation parameters in physical units
10-
smld_true, smld_model, smld_noisy = SMLMSim.sim(;
9+
# Create StaticSMLMParams with simulation parameters
10+
params = StaticSMLMParams(
1111
ρ=1.0, # emitters per μm²
1212
σ_psf=0.13, # PSF width in μm
1313
minphotons=50, # minimum photons for detection
1414
ndatasets=10, # number of independent datasets
1515
nframes=1000, # frames per dataset
16-
framerate=50.0, # frames per second
17-
pattern=SMLMSim.Nmer2D(),
18-
molecule=SMLMSim.GenericFluor(; q=[0 50; 1e-2 0]), # rates in 1/s
16+
framerate=50.0 # frames per second
17+
)
18+
19+
# Run simulation with type-based interface
20+
pattern = SMLMSim.Nmer2D()
21+
molecule = SMLMSim.GenericFluor(; q=[0 50; 1e-2 0]) # rates in 1/s
22+
23+
smld_true, smld_model, smld_noisy = simulate(
24+
params,
25+
pattern=pattern,
26+
molecule=molecule,
1927
camera=camera
2028
)
2129

dev/sim3d.jl

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,27 @@ using GLMakie
66
# Create camera with physical pixel size
77
camera = IdealCamera(1:128, 1:256, 0.1) # 128x256 pixels, 100nm pixels
88

9-
# Simulation parameters in physical units
10-
smld_true, smld_model, smld_noisy = SMLMSim.sim(;
11-
ρ=100.0, # emitters per μm²
12-
σ_psf=0.13, # PSF width in μm
13-
minphotons=50, # minimum photons for detection
14-
ndatasets=10, # number of independent datasets
15-
nframes=1000, # frames per dataset
16-
framerate=50.0, # frames per second
17-
pattern=SMLMSim.Nmer3D(), # Using 3D pattern
18-
molecule=SMLMSim.GenericFluor(; q=[0 50; 1e-2 0]),
19-
camera=camera,
20-
zrange=[-1.0, 1.0] # Set z range for 3D patterns
9+
# Create StaticSMLMParams with simulation parameters
10+
params = StaticSMLMParams(
11+
ρ=100.0, # emitters per μm²
12+
σ_psf=0.13, # PSF width in μm
13+
minphotons=50, # minimum photons for detection
14+
ndatasets=10, # number of independent datasets
15+
nframes=1000, # frames per dataset
16+
framerate=50.0, # frames per second
17+
ndims=3, # 3D simulation
18+
zrange=[-1.0, 1.0] # Set z range for 3D patterns
19+
)
20+
21+
# Run simulation with type-based interface
22+
pattern = SMLMSim.Nmer3D() # Using 3D pattern
23+
molecule = SMLMSim.GenericFluor(; q=[0 50; 1e-2 0])
24+
25+
smld_true, smld_model, smld_noisy = simulate(
26+
params,
27+
pattern=pattern,
28+
molecule=molecule,
29+
camera=camera
2130
)
2231

2332
# Extract coordinates from emitters

docs/src/api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ GenericFluor
5858

5959
```@docs
6060
CTMC
61-
getstate
62-
getnext
61+
get_state
62+
get_next
6363
intensitytrace
6464
kineticmodel
6565
```

src/SMLMSim.jl

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ using LinearAlgebra
77
# Re-export critical types from SMLMData to make them available to users
88
export AbstractCamera, IdealCamera, AbstractEmitter, Emitter2D, Emitter3D, Emitter2DFit, Emitter3DFit, BasicSMLD
99

10-
include("molecules.jl")
11-
include("patterns.jl")
12-
include("sim.jl")
10+
# Core module (includes molecules.jl and patterns.jl internally)
11+
include("core/Core.jl")
12+
1313
include("interface.jl")
1414

15-
# Submodules
15+
# Import specific functions from Core
16+
using .Core: CTMC, get_state, get_next, intensity_trace, kinetic_model
17+
using .Core: Molecule, GenericFluor, Pattern, Pattern2D, Pattern3D
18+
using .Core: Nmer2D, Nmer3D, Line2D, Line3D, uniform2D, uniform3D, rotate!
19+
20+
# Include submodules after the Core imports are available
21+
include("static/StaticSMLM.jl")
1622
include("diffusion/InteractionDiffusion.jl")
1723

1824
# Import specific functions from InteractionDiffusion
@@ -21,28 +27,24 @@ using .InteractionDiffusion: DiffusingMolecule, DiffusingMoleculeSystem,
2127
show_frame, visualize_sequence, visualize_simulation,
2228
gen_image, gen_image_sequence
2329

24-
# Add this line to import the simulate method
25-
using .InteractionDiffusion: simulate
30+
# Import from StaticSMLM
31+
using .StaticSMLM: StaticSMLMParams, apply_noise
2632

27-
# Export molecule types
28-
export
29-
# Abstract molecule types
30-
Molecule,
31-
32-
# Concrete molecule types
33-
GenericFluor
33+
# Add this line to import the simulate methods
34+
using .InteractionDiffusion: simulate
35+
using .StaticSMLM: simulate
3436

3537
# Export simulation functions
3638
export
3739
# Kinetic simulation
38-
intensitytrace,
39-
kineticmodel,
40+
intensity_trace, # Renamed from intensitytrace to match function name
41+
kinetic_model, # Renamed from kineticmodel to match function name
4042
noise,
4143

4244
# CTMC type and functions
4345
CTMC,
44-
getstate,
45-
getnext
46+
get_state,
47+
get_next
4648

4749
# Core types and functions for diffusion simulation
4850
export
@@ -57,8 +59,8 @@ export
5759
# Analysis functions
5860
get_dimers,
5961
gen_dimer_images,
60-
gen_image, # Add this
61-
gen_image_sequence # Add this
62+
gen_image,
63+
gen_image_sequence
6264

6365
# Pattern simulation types and functions
6466
export
@@ -81,6 +83,18 @@ export
8183
# Full simulation pipeline
8284
sim
8385

86+
# Export molecule types
87+
export
88+
# Abstract molecule types
89+
Molecule,
90+
91+
# Concrete molecule types
92+
GenericFluor,
93+
94+
# Static SMLM types
95+
StaticSMLMParams,
96+
apply_noise
97+
8498
# Visualization
8599
export
86100
show_frame,

0 commit comments

Comments
 (0)