API reference#

fourierslm#

fourierslm.slm_grid(size=None, n=2048, *, pitch=None)#

Coordinates on the SLM, a square of n × n pixels with the axis on pixel n // 2.

Choosing the grid. The size must hold the beam, at least 4 beam radii for a Gaussian. With the size fixed, the number of points sets the field of view at the focus, n·λf/(2·size). A bigger field of view needs more points. With n fixed, the size sets the detail at the focus, λf/(2·size). Finer detail needs a bigger size, and 20 times the beam radius gives about 0.08·w₀. Give pitch instead of size only when the SLM pixels matter, as for stochastic holograms or quantization. Then size = n·pitch. The values at the focus are for the default pad 2 of focus_grid.

Parameters:
sizefloat, optional

Side of the square [m]. Give it or pitch.

nint, default 2048

Number of pixels along each side.

pitchfloat, optional

Pixel pitch [m], instead of size.

Returns:
X, Yndarray

Coordinates (i − n // 2)·pitch of the pixels i = 0 … n − 1 [m], X = Y.

Raises:
ValueError

If both or neither of size and pitch are given.

fourierslm.focus_grid(X, Y, wavelength, f, pad=2, window=None)#

Coordinates at the focus of the lens, on which propagate.focus gives the field.

The pitch is λf/(N·pitch), with N the side of the zero-padded FFT, pad·n rounded up to an even FFT-friendly size. The n samples around the axis are kept, so the window is n·λf/(N·pitch). With pad 2, the pitch is λf/(2·size) and the window is the central half of the plane the SLM reaches, λf/pitch. With pad 1, it is the whole plane at twice the pitch. window keeps a smaller square around the axis, so that propagate.focus computes only that part, as before a scan through the focus by propagate.free.

Parameters:
X, Yndarray

Coordinates on the SLM [m], from slm_grid.

wavelengthfloat

Wavelength [m].

ffloat

Focal length of the lens [m].

padfloat, default 2

Zero padding of the FFT, N over n.

windowfloat, optional

Side of the square kept around the axis [m], the n samples by default.

Returns:
x, yndarray

Coordinates [m], x = y, with the axis on index len(x) // 2.

Raises:
ValueError

If the grid is not square.

fourierslm.slm_field(intensity, phase)#

Field on the SLM, √I·exp(iφ).

Fields are in √(W/m²), so abs(E)**2 is the intensity [W/m²], on the SLM and in every plane after it.

Parameters:
intensityndarray

Intensity of the beam [W/m²], from the intensity module.

phasendarray or float

Phase written by the SLM [rad], from the phase module.

Returns:
ndarray

Complex field [√(W/m²)].

fourierslm.peak_power(energy, duration)#

Peak power of a Gaussian pulse, √(4 ln 2/π)·energy/duration ≈ 0.94·energy/duration.

Give it as the power of the intensity functions to get the peak intensity.

Parameters:
energyfloat

Energy of the pulse [J].

durationfloat

FWHM of the intensity in time [s].

Returns:
float

Peak power [W].

fourierslm.intensity#

Intensity of the beam on the SLM [W/m²].

For a pulse, give the peak power, fourierslm.peak_power, to get the peak intensity, on the SLM and in every plane after it. Coordinates X and Y are 1D, and the arrays have the shape (len(Y), len(X)).

fourierslm.intensity.flattop(X, Y, radius, power=1.0, center=(0.0, 0.0))#

Uniform beam cut by a circular aperture, P/(π radius²) inside the disk and 0 outside.

Parameters:
X, Yndarray

1D coordinates [m].

radiusfloat

Radius of the aperture [m].

powerfloat, default 1

Power P [W] of the continuous disk, the peak power of a pulse for its peak intensity. The pixelated edge changes it slightly.

centertuple of float, default (0, 0)

Center of the beam [m].

Returns:
ndarray

Intensity [W/m²].

fourierslm.intensity.gaussian(X, Y, w, power=1.0, center=(0.0, 0.0))#

Gaussian beam, 2P/(πw²)·exp(−2r²/w²).

Parameters:
X, Yndarray

1D coordinates [m].

wfloat

Radius at 1/e² of the intensity [m].

powerfloat, default 1

Power P [W], the peak power of a pulse for its peak intensity.

centertuple of float, default (0, 0)

Center of the beam [m].

Returns:
ndarray

Intensity [W/m²].

fourierslm.phase#

Phase patterns for the SLM [rad].

The patterns are continuous, not wrapped, so they add. Wrap or quantize the sum only for display. Coordinates X and Y are 1D, the arrays have the shape (len(Y), len(X)), and angles are in radians. The sign convention is the plane wave exp[i(kz − ωt)], so a pattern that grows along +X steers the beam toward +x.

fourierslm.phase.axicon(X, Y, wavelength, angle, center=(0.0, 0.0))#

Axicon, −kR sin(angle), which focuses to a Bessel beam.

Parameters:
X, Yndarray

1D coordinates [m].

wavelengthfloat

Wavelength [m].

anglefloat

Half angle of the cone of rays [rad].

centertuple of float, default (0, 0)

Apex [m].

Returns:
ndarray

Phase [rad].

fourierslm.phase.binary(X, Y, period, depth=3.141592653589793, azimuth=0.0)#

Binary grating, stripes of 0 and depth.

Parameters:
X, Yndarray

1D coordinates [m].

periodfloat

Period, two stripes [m].

depthfloat, default π

Phase of every other stripe [rad].

azimuthfloat, default 0

Direction ψ across the stripes [rad], 0 for stripes along y.

Returns:
ndarray

Phase [rad], 0 on the stripe that starts at the origin.

fourierslm.phase.grating(X, Y, wavelength, angle, azimuth=0.0)#

Blazed grating, k sin(angle)·(X cos ψ + Y sin ψ).

Behind a lens of focal length f, it moves the focus to f sin(angle) along the azimuth ψ.

Parameters:
X, Yndarray

1D coordinates [m].

wavelengthfloat

Wavelength [m].

anglefloat

Deflection angle [rad].

azimuthfloat, default 0

Direction ψ of the deflection [rad], 0 along +x and π/2 along +y.

Returns:
ndarray

Phase [rad].

fourierslm.phase.lens(X, Y, wavelength, f, center=(0.0, 0.0))#

Thin lens, −k(X² + Y²)/(2f).

Parameters:
X, Yndarray

1D coordinates [m].

wavelengthfloat

Wavelength [m].

ffloat

Focal length [m], positive for a converging lens.

centertuple of float, default (0, 0)

Center of the lens [m].

Returns:
ndarray

Phase [rad].

fourierslm.phase.quantize(phase, bits)#

Round a phase to the gray levels of an SLM.

Parameters:
phasendarray

Phase [rad].

bitsint

Bit depth of the SLM, 2^bits levels over 2π.

Returns:
ndarray

Phase on the levels 2πn/2^bits, n = 0 … 2^bits − 1 [rad]. 2π rounds to 0.

fourierslm.phase.radial_step(X, Y, radius, inner=0.0, outer=3.141592653589793, center=(0.0, 0.0))#

Phase step at a radius.

Parameters:
X, Yndarray

1D coordinates [m].

radiusfloat

Radius of the step [m].

inner, outerfloat, default 0 and π

Phase inside and outside the radius [rad].

centertuple of float, default (0, 0)

Center of the step [m].

Returns:
ndarray

Phase [rad].

fourierslm.phase.vortex(X, Y, charge, center=(0.0, 0.0), rotation=0.0)#

Vortex, ℓψ.

Parameters:
X, Yndarray

1D coordinates [m].

chargefloat

Topological charge ℓ, integer or fractional.

centertuple of float, default (0, 0)

Center of the vortex [m].

rotationfloat, default 0

Azimuth of the 2πℓ step is π + rotation [rad]. It only shows for a fractional charge.

Returns:
ndarray

Phase [rad], with the azimuth ψ − rotation taken in (−π, π].

fourierslm.phase.wrap(phase)#

Wrap a phase into [0, 2π).

Parameters:
phasendarray

Phase [rad].

Returns:
ndarray

Phase modulo 2π [rad].

fourierslm.propagate#

Propagation from the SLM to the back focal plane of a lens, and in free space.

The SLM sits at a distance L in front of a lens of focal length f. In the back focal plane the field is the FT of the field on the SLM times a curvature, Goodman (5-19),

E(x, y) = 1/(iλf) · exp[ik(1 − L/f)(x² + y²)/(2f)] ∬ E(X, Y) exp[−ik(xX + yY)/f] dX dY

= k/(if) · exp[ik(1 − L/f)(x² + y²)/(2f)] · E(k_X = kx/f, k_Y = ky/f),

with the unitary FT E(k_X, k_Y) = 1/(2π) ∬ E(X, Y) exp[−i(k_X X + k_Y Y)] dX dY. The other planes follow by free. The plane wave is exp[i(kz − ωt)], fields are in √(W/m²) so that abs(E)**2 is the intensity, and the constant phase exp[ik(L + f)] is left out. Grids are square, and arrays have the shape (n, n). Complex64 fields are propagated in complex64, which is about twice as fast, and FFTs run on every core.

fourierslm.propagate.focus(E, X, Y, x, y, wavelength, f, slm_distance=None)#

Field in the back focal plane of the lens, on the grid of fourierslm.focus_grid.

The FT of the field on the SLM, with the prefactor 1/(iλf) and the curvature exp[ik(1 − L/f)(x² + y²)/(2f)], by one FFT of the SLM field zero-padded to N × N. N is read from the pitch λf/(N·pitch) of x, so the padding is chosen once, in fourierslm.focus_grid.

Parameters:
Endarray

Field on the SLM [√(W/m²)], shape (n, n).

X, Yndarray

Coordinates on the SLM [m], from fourierslm.slm_grid.

x, yndarray

Coordinates at the focus [m], from fourierslm.focus_grid, with or without a window.

wavelengthfloat

Wavelength [m].

ffloat

Focal length of the lens [m].

slm_distancefloat, optional

Distance L from the SLM to the lens [m], f by default.

Returns:
ndarray

Field [√(W/m²)], shape (len(y), len(x)).

Raises:
ValueError

If the grids are not square, or x is not a focal grid of X at this wavelength and focal length.

fourierslm.propagate.free(E, pitch, wavelength, z, bandlimit=True)#

Free-space propagation by z, angular spectrum on a fixed grid.

The transfer function is exp[iz(k_z − k)], exact beyond the paraxial approximation, with the evanescent waves dropped. The grid is periodic, so keep the field away from its edges. A scan reuses the FFT of E, so it costs one inverse FFT per plane.

Parameters:
Endarray

Field [√(W/m²)].

pitchfloat

Pixel pitch [m].

wavelengthfloat

Wavelength [m].

zfloat or ndarray

Distance [m], negative to propagate backward, one value or a 1D scan.

bandlimitbool, default True

Cut the spatial frequencies the grid cannot sample at this distance, above 1/(λ√(1 + (2z/(N·pitch))²)) along each axis, Matsushima and Shimobaba, Opt. Express 17, 19662 (2009).

Returns:
ndarray

Field [√(W/m²)] on the same grid, shape (ny, nx) like E, or (len(z), ny, nx) for a scan.