wavelength (float) – Wavelength of light in meters.
cone_angle (float) – Cone half-angle in radians. Determines the transverse wave
vector component: k_r = k * sin(cone_angle).
dx (float) – Spatial sampling interval (pixel size) in meters.
grid_size (Union[Int[Array, "2"], Tuple[ScalarInteger, ScalarInteger]]) – Size of the computational grid. If int, creates square grid.
If tuple, specifies (height, width).
amplitude (float, optional) – Peak amplitude at beam center, by default 1.0.
z_position (float, optional) – Initial z position of the wavefront in meters, by default 0.0.
Returns:
wavefront – Bessel beam OpticalWavefront PyTree.
Return type:
OpticalWavefront
Notes
An ideal Bessel beam has a transverse profile given by the
zeroth-order Bessel function:
\[E(r) = A J_0(k_r r)\]
where \(k_r = k \\sin(\\theta)\) is the transverse wave vector
and \(\\theta\) is the cone half-angle.
Bessel beams are “non-diffracting” - their transverse profile
remains constant upon propagation (in the ideal infinite case).
In practice, physical Bessel beams have finite extent and
eventually diffract.
The central lobe radius (first zero) is approximately
\(r_0 \\approx 2.405 / k_r\).
Create a Gaussian beam at arbitrary position from waist.
This is the most general Gaussian beam generator, using the full
Gaussian beam propagation formulas including Gouy phase.
Parameters:
wavelength (float) – Wavelength of light in meters.
waist_0 (float) – Beam waist at the waist position (minimum spot size) in meters.
z_from_waist (float) – Distance from the beam waist in meters.
Positive = downstream from waist (diverging).
Negative = upstream from waist (converging toward waist).
dx (float) – Spatial sampling interval (pixel size) in meters.
grid_size (Union[Int[Array, "2"], Tuple[ScalarInteger, ScalarInteger]]) – Size of the computational grid. If int, creates square grid.
If tuple, specifies (height, width).
center (Tuple[ScalarFloat, ScalarFloat], optional) – Center position (x0, y0) in meters, by default (0.0, 0.0).
amplitude (float, optional) – Peak amplitude at beam waist, by default 1.0.
z_position (float, optional) – Initial z position of the wavefront in meters, by default 0.0.
include_gouy_phase (bool, optional) – Whether to include the Gouy phase shift, by default True.
\[\begin{split}E_{p,l}(r, \\phi) = A \\left(\\frac{r\\sqrt{2}}{w}\\right)^{|l|}
L_p^{|l|}\\left(\\frac{2r^2}{w^2}\\right)
\\exp\\left(-\\frac{r^2}{w^2}\\right)
\\exp(i l \\phi)\end{split}\]
where \(L_p^{|l|}\) is the generalized Laguerre polynomial.
Special cases:
(p=0, l=0): Fundamental Gaussian mode
(p=0, l≠0): Optical vortex beams with topological charge l
wavelength (float) – Wavelength of light in meters.
dx (float) – Spatial sampling interval (pixel size) in meters.
grid_size (Union[Int[Array, "2"], Tuple[ScalarInteger, ScalarInteger]]) – Size of the computational grid. If int, creates square grid.
If tuple, specifies (height, width).
amplitude (float, optional) – Amplitude of the plane wave, by default 1.0.
tilt_x (float, optional) – Tilt angle along x-axis in radians (small angle), by default 0.0.
tilt_y (float, optional) – Tilt angle along y-axis in radians (small angle), by default 0.0.
z_position (float, optional) – Initial z position of the wavefront in meters, by default 0.0.
Returns:
wavefront – Plane wave OpticalWavefront PyTree.
Return type:
OpticalWavefront
Notes
A plane wave has uniform amplitude and linear phase (flat if no tilt).
The tilt angles introduce a linear phase ramp corresponding to
propagation at an angle to the optical axis:
\[\begin{split}E(x, y) = A \\exp(i k (x \\sin\\theta_x + y \\sin\\theta_y))\end{split}\]
For small angles, \(\\sin\\theta \\approx \\theta\).
Generate a beam at multiple z positions as a PropagatingWavefront.
Parameters:
beam_type (str) – Type of beam to generate. One of:
- “plane_wave”: Uniform plane wave with optional tilt
- “sinusoidal_wave”: Sinusoidal interference pattern
- “collimated_gaussian”: Collimated Gaussian beam with flat phase
- “converging_gaussian”: Gaussian beam converging to a focus
- “diverging_gaussian”: Gaussian beam diverging from a source
- “gaussian_beam”: General Gaussian beam at arbitrary z from waist
- “bessel_beam”: Bessel beam with specified cone angle
- “laguerre_gaussian”: Laguerre-Gaussian modes
- “hermite_gaussian”: Hermite-Gaussian modes
z_positions (Float[Array, "zz"]) – Array of z positions at which to evaluate the beam (meters).
For “gaussian_beam”, these are distances from the waist.
For other beam types, these set the z_position attribute.
wavelength (float) – Wavelength of light in meters.
dx (float) – Spatial sampling interval (pixel size) in meters.
grid_size (Union[Int[Array, "2"], Tuple[ScalarInteger, ScalarInteger]]) – Size of the computational grid as (height, width).
waist (float) – Beam waist (1/e² intensity radius) in meters. Used by
collimated_gaussian, converging_gaussian, diverging_gaussian,
laguerre_gaussian, hermite_gaussian. Default is 1e-3.
amplitude (float) – Peak amplitude, by default 1.0.
center (Tuple[ScalarFloat, ScalarFloat]) – Center position (x0, y0) in meters, by default (0.0, 0.0).
tilt_x (float) – Tilt angle along x-axis in radians for plane_wave, by default 0.0.
tilt_y (float) – Tilt angle along y-axis in radians for plane_wave, by default 0.0.
focus_distance (float) – Distance to focus for converging_gaussian (meters). Default is 1.0.
source_distance (float) – Distance from source for diverging_gaussian (meters). Default is 1.0.
waist_0 (float) – Beam waist at the waist position for gaussian_beam (meters).
Default is 1e-3.
include_gouy_phase (bool) – Whether to include Gouy phase for gaussian_beam, by default True.
cone_angle (float) – Cone half-angle in radians for bessel_beam. Default is 0.01.
period (float) – Spatial period for sinusoidal_wave (meters). Default is 1e-4.
direction (float) – Direction angle for sinusoidal_wave (radians). Default is 0.0.
p (int) – Radial mode index for laguerre_gaussian, by default 0.
l (int) – Azimuthal mode index for laguerre_gaussian, by default 0.
n (int) – Mode index in x direction for hermite_gaussian, by default 0.
m (int) – Mode index in y direction for hermite_gaussian, by default 0.
Returns:
propagating_wavefront – A PropagatingWavefront containing the beam at all specified z
positions.
This function uses jax.vmap to efficiently generate the beam at all
z positions in parallel. The resulting PropagatingWavefront can be
used to visualize beam evolution or as input to propagation algorithms.
For “gaussian_beam”, the z_positions represent distances from the beam
waist, allowing visualization of beam evolution through focus.
For other beam types, z_positions sets the z_position attribute but
the field profile remains constant (as these are evaluated at a
single plane).
A sinusoidal wave has an intensity profile that varies as:
\[E(x, y) = A \cos\left(\frac{2\pi}{T}(x \cos\theta + y \sin\theta)
\right)\]
where \(T\) is the spatial period and \(\theta\) is the
direction angle.
This pattern represents the interference of two plane waves and is
useful for testing optical systems, creating gratings, and studying
diffraction phenomena.
tz (float) – Slice spacing in z direction in meters
center (Tuple[ScalarFloat, float, ScalarFloat], optional) – Center position (y, x, z) in meters. If None, centered in volume.
Returns:
material – Biological cell material PyTree
Return type:
SlicedMaterialFunction
Notes
Algorithm:
- Create coordinate grids for x, y, z
- Compute radial distance from center
- Use nested jnp.where to assign refractive index:
If r < nucleus_radius: n_nucleus
Elif r < cell_radius: n_cytoplasm
Else: n_medium
Convert to SlicedMaterialFunction PyTree
Implementation Details:
- Nested jnp.where for three regions
- Inner to outer: nucleus, cytoplasm, medium
- All operations use JAX arrays
- Typical values:
tz (float) – Slice spacing in z direction in meters
n_min (float, optional) – Minimum refractive index (for clipping), default is 1.0
Returns:
material – GRIN material PyTree
Return type:
SlicedMaterialFunction
Notes
Algorithm:
- Create coordinate grids for x, y
- Compute radial distance in x-y plane: r_xy = sqrt(x² + y²)
- Apply GRIN formula: n(r) = n_center × (1 - A × r_xy² / 2)
- Clip to ensure n >= n_min
- Broadcast to all z slices (z-invariant)
- Convert to SlicedMaterialFunction PyTree
Implementation Details:
- GRIN profile: n(r) = n₀(1 - Ar²/2)
- Only depends on x-y position (constant along z)
- Uses jnp.clip to enforce physical bounds
- Typical A values: 1e8 to 1e12 m^-2
- All operations are differentiable
- Real refractive index only (no absorption)
tz (float) – Slice spacing in z direction in meters
slices_per_layer (int, optional) – Number of slices per layer, by default 1
Returns:
material – Layered material PyTree
Return type:
SlicedMaterialFunction
Notes
Algorithm:
- Create array to hold material
- Use vmap over z slices to assign refractive index
- Layer index = z_idx // slices_per_layer
- Use modulo to alternate between n1 and n2
- Convert to SlicedMaterialFunction PyTree
Implementation Details:
- Uses jax.lax.cond for layer selection (JAX-compatible)
- Layer pattern: n1, n2, n1, n2, …
- Each layer is slices_per_layer thick
- All operations are differentiable
- Uses vmap for efficient parallel processing
tz (float) – Slice spacing in z direction in meters
center (Tuple[ScalarFloat, float, ScalarFloat], optional) – Center position (y, x, z) in meters. If None, centered in volume.
Returns:
material – Material with spherical inclusion
Return type:
SlicedMaterialFunction
Notes
Algorithm:
- Create coordinate grids for x, y, z
- Compute radial distance from center
- Use jnp.where to assign refractive index based on distance
- Convert to SlicedMaterialFunction PyTree
Implementation Details:
- Uses meshgrid with indexing=’ij’ for consistent ordering
- If center is None, defaults to volume center
- Radial distance: r = sqrt((x-x0)^2 + (y-y0)^2 + (z-z0)^2)
- Refractive index: n = n_sphere if r < radius else n_background
- All operations use JAX arrays for automatic differentiation
tz (float) – Slice spacing in z direction in meters
Returns:
material – Uniform material PyTree
Return type:
SlicedMaterialFunction
Notes
Algorithm:
- Create array filled with constant refractive index
- Convert to SlicedMaterialFunction PyTree
- Return material
Implementation Details:
- Uses jnp.ones for efficient array creation
- Multiplies by complex scalar to set refractive index
- All operations are JAX-compatible and differentiable
Creates a cylindrical vector beam where the electric field points
in the azimuthal direction (tangent to circles centered on the axis).
The polarization direction is:
Azimuthally polarized beam as OpticalWavefront PyTree.
Field shape is (H, W, 2) with [Ex, Ey] components.
Return type:
OpticalWavefront
Notes
Azimuthally polarized beams have complementary properties to radial
polarization:
Donut focus: When focused by a high-NA lens, azimuthally
polarized beams produce NO longitudinal (Ez) field component.
The focal spot has a dark center (“donut” shape).
Singular at center: Like radial polarization, the polarization
is undefined at r=0, and the amplitude naturally goes to zero.
Orthogonal to radial: At every point, the azimuthal polarization
is perpendicular to the radial polarization.
\[\begin{split}\vec{E}_{LCP} = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ i
\end{pmatrix}\end{split}\]
Note: Sign conventions vary in the literature. We use the physics
convention where RCP has E_y = -i*E_x (clockwise rotation for an
observer looking into the beam).
Generate a generalized cylindrical vector beam of arbitrary order.
Creates a cylindrical vector beam with polarization pattern
determined by the topological order m. Standard radial (m=1, φ₀=0)
and azimuthal (m=1, φ₀=π/2) polarizations are special cases.
Parameters:
wavelength (float) – Wavelength of light in meters.
dx (float) – Spatial sampling interval (pixel size) in meters.
grid_size (Union[Int[Array, "2"], Tuple[ScalarInteger, ScalarInteger]]) – Size of the computational grid as (height, width).
order (int, optional) – Topological order m of the polarization pattern, by default 1.
- m=1 : Standard radial/azimuthal (1 polarization singularity)
- m=2 : Higher-order with 2 singularities
- etc.
phase_offset (float, optional) – Phase offset φ₀ in radians, by default 0.0.
- φ₀=0 : Radial-like
- φ₀=π/2 : Azimuthal-like
beam_radius (float, optional) – Beam waist in meters.
amplitude (float, optional) – Peak amplitude, by default 1.0.
z_position (float, optional) – Initial z position in meters, by default 0.0.
Returns:
Generalized cylindrical vector beam with field shape (H, W, 2).
Return type:
OpticalWavefront
Notes
The generalized cylindrical vector beam has polarization:
Creates a cylindrical vector beam where the electric field points
radially outward from the optical axis at every point. The polarization
direction is:
wavelength (float) – Wavelength of light in meters.
dx (float) – Spatial sampling interval (pixel size) in meters.
grid_size (Union[Int[Array, "2"], Tuple[ScalarInteger, ScalarInteger]]) – Size of the computational grid as (height, width) or (ny, nx).
beam_radius (float, optional) – Characteristic beam radius in meters. If None, defaults to
1/4 of the grid extent. For Gaussian apodization, this is the
1/e² intensity radius.
amplitude (float, optional) – Peak amplitude at beam edge, by default 1.0.
z_position (float, optional) – Initial z position of the wavefront in meters, by default 0.0.
Radially polarized beam as OpticalWavefront PyTree.
Field shape is (H, W, 2) with [Ex, Ey] components.
Return type:
OpticalWavefront
Notes
Radially polarized beams have several unique properties:
Tight focusing: When focused by a high-NA lens, radially
polarized beams produce a strong longitudinal (Ez) field component
at the focus, resulting in a tighter focal spot than linearly
polarized beams.
Singular at center: The polarization is undefined at r=0
(the optical axis), creating a phase singularity. The amplitude
naturally goes to zero at the center.
Zero orbital angular momentum: Unlike Laguerre-Gaussian vortex
beams, radially polarized beams carry no orbital angular momentum.
min_bar_pixels (int, optional) – Minimum bar width in pixels for visibility, by default 2
grid_fill_fraction (float, optional) – Scale factor for fitting largest group, by default 0.95
Returns:
result – Dictionary containing:
- max_group: finest group where bars are still >= min_bar_pixels
- min_group: coarsest group that fits in image
- recommended_range: suggested range() for generate_usaf_pattern
- num_groups: how many groups in recommended range
- pixels_per_mm: calculated pixel density
- group_info: dict with bar width info for each group
Both horizontal and vertical patterns are computed, then selected
based on the horizontal flag. This is JAX-safe since the flag is
a static Python bool that doesn’t change during tracing.
Create a single USAF element (horizontal + vertical bar triplets).
Parameters:
bar_width_px (int) – Width of each bar in pixels (minimum 1)
gap_factor (float, optional) – Gap between triplets as fraction of bar_width, by default 0.5
Returns:
element – The complete element pattern with both triplets
Return type:
Float[Array, "..."]
Notes
Each USAF element consists of:
- 3 horizontal bars (triplet) on the left
- 3 vertical bars (triplet) on the right
Bar length is 5× the bar width per USAF specification.
The element is composed as:
[horizontal triplet] [gap] [vertical triplet]
Triplets are centered vertically within the element canvas.
max_phase (float, optional) – Maximum phase shift in radians applied to the bars, by default 0.0.
The phase pattern follows the same structure as the amplitude,
scaling from 0 (at background) to max_phase (at foreground).
auto (bool, optional) – If True, automatically calculate the optimal group range to
fill the image based on image_size and pixel_size. Overrides
the groups parameter. By default False.
min_bar_pixels (int, optional) – Minimum bar width in pixels for visibility when auto=True,
by default 2. Ignored if auto=False.
Returns:
pattern – SampleFunction PyTree containing the USAF test pattern as a
complex array with both amplitude and phase information.
Return type:
SampleFunction
Notes
The USAF 1951 test pattern consists of groups arranged in a grid.
Each group contains 6 elements of progressively higher resolution.
Resolution formula per MIL-STD-150A:
Resolution = 2^(group + (element-1)/6) line pairs per mm
Standard groups range from -2 (coarsest) to 7 (finest).
Each element consists of:
- 3 horizontal bars (bar triplet)
- 3 vertical bars (bar triplet)
with bar length = 5 × bar width.
The output is a complex field: amplitude * exp(i * phase), where
the phase follows the same spatial pattern as the amplitude.
The loop over groups is unrolled at Python trace time since
groups_list is known before tracing. Python-level conditionals
for bounds checking, scaling, and phase normalization are evaluated
at trace time since all controlling values are Python scalars.
A global scale factor is computed from the largest (coarsest) group
to ensure all groups fit within their grid cells while preserving
the correct relative size ratios between groups.