Skip to content

Commit cd61d37

Browse files
committed
Check and fix example codes from the README. They are in test_README.jl, which now works.
1 parent 80a8728 commit cd61d37

File tree

5 files changed

+42
-21
lines changed

5 files changed

+42
-21
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ params = SmoluchowskiParams(
136136
systems = simulate(params)
137137

138138
# Visualize the simulation
139-
visualize_sequence(systems, filename="diffusion.mp4", framerate=30)
139+
visualize_sequence(systems, filename="diffusion.mp4", framerate=round(Int64,1/params.dt))
140140

141141
# Generate microscope images
142142
psf = Gaussian2D(0.15) # 150nm PSF width
@@ -185,7 +185,8 @@ ax = Axis(fig[1, 1],
185185
title="Simulated SMLM Localizations",
186186
xlabel="x (μm)",
187187
ylabel="y (μm)",
188-
aspect=DataAspect()
188+
aspect=DataAspect(),
189+
yreversed=true # This makes (0,0) at top-left
189190
)
190191

191192
# Scatter plot with photon counts as color
@@ -199,7 +200,7 @@ scatter!(ax, x_noisy, y_noisy,
199200
Colorbar(fig[1, 2], colormap=:viridis, label="Photons")
200201

201202
# Show or save the figure
202-
# display(fig)
203+
display(fig)
203204
# save("smlm_simulation.png", fig)
204205
```
205206

dev/test_README.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# using Pkg
22
# Pkg.activate("dev")
33

4-
# using Revise
5-
using SMLMSim # must be 'dev'ed in the current environment
4+
using Revise
5+
using SMLMSim
66
using CairoMakie
7-
7+
using MicroscopePSFs
88
#==========================================================================
99
Basic Usage
1010
==========================================================================#
@@ -25,7 +25,7 @@ smld_true, smld_model, smld_noisy = simulate(;
2525
framerate=50.0, # frames per second
2626
pattern=Nmer2D(n=6, d=0.2), # hexamer with 200nm diameter
2727
molecule=GenericFluor(; q=[0 50; 1e-2 0]), # rates in 1/s
28-
camera=IdealCamera(; ypixels=256, xpixels=128, pixelsize=0.1) # pixelsize in μm
28+
camera=IdealCamera(1:256, 1:128, 0.1) # pixelsize in μm
2929
)
3030

3131
#==========================================================================
@@ -77,7 +77,7 @@ params = SmoluchowskiParams(
7777
systems = simulate(params)
7878

7979
# Visualize the simulation
80-
visualize_sequence(systems, filename="diffusion.mp4", framerate=30)
80+
visualize_sequence(systems, filename="diffusion.mp4", framerate=round(Int64,1/params.dt))
8181

8282
# Generate microscope images
8383
psf = Gaussian2D(0.15) # 150nm PSF width
@@ -121,7 +121,8 @@ ax = Axis(fig[1, 1],
121121
title="Simulated SMLM Localizations",
122122
xlabel="x (μm)",
123123
ylabel="y (μm)",
124-
aspect=DataAspect()
124+
aspect=DataAspect(),
125+
yreversed=true # This makes (0,0) at top-left
125126
)
126127

127128
# Scatter plot with photon counts as color

src/SMLMSim.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ using SMLMData
44
using Distributions
55
using LinearAlgebra
66

7+
# Re-export critical types from SMLMData to make them available to users
8+
export AbstractCamera, IdealCamera, AbstractEmitter, Emitter2D, Emitter3D, Emitter2DFit, Emitter3DFit, BasicSMLD
79

810
include("molecules.jl")
911
include("patterns.jl")
@@ -13,7 +15,14 @@ include("interface.jl")
1315
# Submodules
1416
include("diffusion/InteractionDiffusion.jl")
1517

16-
using .InteractionDiffusion
18+
# Import specific functions from InteractionDiffusion
19+
using .InteractionDiffusion: DiffusingMolecule, DiffusingMoleculeSystem,
20+
SmoluchowskiParams, get_dimers,
21+
show_frame, visualize_sequence, visualize_simulation,
22+
gen_image, gen_image_sequence
23+
24+
# Add this line to import the simulate method
25+
using .InteractionDiffusion: simulate
1726

1827
# Export molecule types
1928
export
@@ -43,12 +52,13 @@ export
4352
SmoluchowskiParams,
4453

4554
# Core simulation functions
46-
simulate,
47-
simulate_and_image,
48-
55+
simulate, # Will dispatch to appropriate method based on argument types
56+
4957
# Analysis functions
5058
get_dimers,
51-
gen_dimer_images
59+
gen_dimer_images,
60+
gen_image, # Add this
61+
gen_image_sequence # Add this
5262

5363
# Pattern simulation types and functions
5464
export
@@ -77,5 +87,4 @@ export
7787
visualize_sequence,
7888
visualize_simulation
7989

80-
8190
end

src/diffusion/InteractionDiffusion.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,20 @@ module InteractionDiffusion
4242
using SMLMData
4343
using Distributions
4444
using MicroscopePSFs
45-
using SMLMSim
4645

4746
using Printf
4847
using CairoMakie
4948

49+
# Import the main simulate function to add our method
50+
import ..simulate
51+
5052
include("types.jl")
5153
include("smoluchowski.jl")
5254
include("visualize.jl")
5355
include("microscope.jl")
5456
include("dimer.jl")
5557

58+
5659
# Core types and functions for diffusion simulation
5760
export
5861
# Core types
@@ -61,7 +64,7 @@ export
6164
SmoluchowskiParams,
6265

6366
# Core simulation functions
64-
simulate,
67+
simulate, # Export the function, but the implementation is a method
6568
simulate_and_image,
6669

6770
# Analysis functions

src/diffusion/visualize.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,16 @@ function visualize_sequence(systems::Vector{<:DiffusingMoleculeSystem};
164164
xlims!(ax, (0, box_size))
165165
ylims!(ax, (box_size, 0))
166166

167-
# Add legend if showing dimers
167+
# Store legend position for updates
168+
legend_pos = (1, 2)
169+
170+
# Create Observables for legend labels
168171
if show_dimers
169-
leg = Legend(fig[1, 2], ["Monomers", "Dimers"], [:blue, :red])
172+
legend_labels = Observable(["Monomers (0)", "Dimers (0)"])
173+
leg = Legend(fig[legend_pos...],
174+
[MarkerElement(color=:blue, marker=:circle),
175+
MarkerElement(color=:red, marker=:circle)],
176+
legend_labels[])
170177
end
171178

172179
# Information display
@@ -185,10 +192,10 @@ function visualize_sequence(systems::Vector{<:DiffusingMoleculeSystem};
185192
if show_dimers
186193
sc.color = [mol.state == 2 ? :red : :blue for mol in systems[i].molecules]
187194

188-
# Update legend with counts
195+
# Update legend labels
189196
n_monomers = count(mol -> mol.state == 1, systems[i].molecules)
190197
n_dimers = count(mol -> mol.state == 2, systems[i].molecules)
191-
leg.labels = ["Monomers ($n_monomers)", "Dimers ($n_dimers)"]
198+
legend_labels[] = ["Monomers ($n_monomers)", "Dimers ($n_dimers)"]
192199
end
193200

194201
# Update info text

0 commit comments

Comments
 (0)