1+ # Setting the path for XLuminA modules:
2+ import os
3+ import sys
4+ current_path = os .path .abspath (os .path .join ('..' ))
5+ dir_path = os .path .dirname (current_path )
6+ module_path = os .path .join (dir_path )
7+ if module_path not in sys .path :
8+ sys .path .append (module_path )
9+
10+ from xlumina .__init__ import um , nm , cm , mm
11+ from xlumina .vectorized_optics import *
12+ from xlumina .optical_elements import hybrid_setup_fluorophores
13+ from xlumina .loss_functions import vectorized_loss_hybrid
14+ from xlumina .toolbox import space , softmin
15+ import jax .numpy as jnp
16+
17+ """
18+ Large-scale setup for STED microscopy baseline rediscovery:
19+
20+ 3x3 initial setup - light gets detected across 6 detectors.
21+ """
22+
23+ # 1. System specs:
24+ sensor_lateral_size = 824 # Resolution
25+ wavelength1 = 650 * nm
26+ wavelength2 = 532 * nm
27+ x_total = 2500 * um
28+ x , y = space (x_total , sensor_lateral_size )
29+ shape = jnp .shape (x )[0 ]
30+
31+ # 2. Define the optical functions: two orthogonally polarized beams:
32+ w0 = (1200 * um , 1200 * um )
33+ ls1 = PolarizedLightSource (x , y , wavelength1 )
34+ ls1 .gaussian_beam (w0 = w0 , jones_vector = (1 , 1 ))
35+ ls2 = PolarizedLightSource (x , y , wavelength2 )
36+ ls2 .gaussian_beam (w0 = w0 , jones_vector = (1 , 1 ))
37+
38+ # 3. Define the output (High Resolution) detection:
39+ x_out , y_out = jnp .array (space (10 * um , 400 ))
40+
41+ # 4. High NA objective lens specs:
42+ NA = 0.9
43+ radius_lens = 3.6 * mm / 2
44+ f_lens = radius_lens / NA
45+
46+ # 5. Static parameters - don't change during optimization:
47+ fixed_params = [radius_lens , f_lens , x_out , y_out ]
48+
49+ # 6. Define the loss function:
50+ @jit
51+ def loss_hybrid_sted (parameters ):
52+ # Output from hybrid_setup is jnp.array(6, N, N): for 6 detectors
53+ i_effective = hybrid_setup_fluorophores (ls1 , ls2 , ls1 , ls2 , ls1 , ls2 , parameters , fixed_params , distance_offset = 10 )
54+
55+ # Get the minimum value within loss value array of shape (6, 1, 1)
56+ loss_val = softmin (vectorized_loss_hybrid (i_effective ))
57+
58+ return loss_val
0 commit comments