torchoptics.profiles#
Functions to generate different types of profiles.
Functions#
|
Generate a truncated 2D Airy beam profile. |
|
Generate an Airy pattern profile. |
|
Generate a zeroth-order Bessel beam. |
|
Generate a binary grating profile. |
|
Generate a blazed grating profile. |
|
Generate a checkerboard pattern. |
|
Generate a circular profile. |
|
Generate a cylindrical lens profile with a quadratic phase in a specified direction. |
|
Generate a Gaussian profile. |
|
Generate a spatial coherence function profile based on the Gaussian Schell-model. |
|
Generate a Hermite-Gaussian profile. |
|
Generate a hexagonal profile. |
|
Generate a Laguerre-Gaussian profile. |
|
Generate a quadratic phase lens profile, which can be used to represent a thin lens. |
|
Generate an octagonal profile. |
|
Compute the phase argument of a plane wave with arbitrary propagation direction. |
|
Generate a rectangle profile. |
|
Generate a regular N-sided polygon profile. |
|
Generate a spatial coherence function profile based on the Schell-model. |
|
Generate a Siemens star pattern. |
|
Generate a sinc profile. |
|
Generate a sinusoidal grating profile. |
|
Compute the phase argument of a spherical wave originating from a point source. |
|
Generate a square profile. |
|
Generate a triangular profile. |
|
Generate a Zernike polynomial profile over a 2D grid. |
Package Contents#
- torchoptics.profiles.airy_beam(shape, scale, truncation, spacing=None, offset=None)#
Generate a truncated 2D Airy beam profile.
The profile is defined as the separable product of two 1D truncated Airy functions:
\[\psi(x, y) = \operatorname{Ai}(x / x_0) e^{a x / x_0} \operatorname{Ai}(y / x_0) e^{a y / x_0}\]where:
\(\operatorname{Ai}\) is the Airy function of the first kind,
\(x_0\) is the transverse scale that sets the lobe spacing, and
\(a\) is the exponential truncation factor that makes the beam finite energy.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
scale (Scalar) – The transverse Airy scale.
truncation (Scalar) – The exponential truncation factor.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the profile. Default: (0, 0).
- Returns:
The generated Airy beam profile.
- Return type:
Tensor
- torchoptics.profiles.airy_pattern(shape, scale, spacing=None, offset=None)#
Generate an Airy pattern profile.
The Airy pattern is defined by the following equation:
\[\psi(r) = \left( \frac{2 J_1(\frac{r}{a})}{\frac{r}{a}} \right)^2\]where:
\(r\) is the radial distance from the center of the diffraction pattern.
\(J_1\) is the Bessel function of the first kind.
\(a\) is the scaling factor that determines the size of the Airy disk.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
scale (Scalar) – A scaling factor that determines the size of the Airy disk.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default.
offset (Vector2 | None) – Center coordinates of the profile. Default: (0, 0).
- Returns:
The generated Airy profile.
- Return type:
Tensor
- torchoptics.profiles.bessel(shape, cone_angle, wavelength=None, spacing=None, offset=None)#
Generate a zeroth-order Bessel beam.
The zeroth-order Bessel beam is defined by the following equation:
\[\psi(r) = J_0(k \, r \sin(\theta)),\]where:
\(J_0\) is the zeroth-order Bessel function of the first kind,
\(\theta\) is the cone angle of the Bessel beam, and
\(k\) is the wave number, \(k = 2\pi / \lambda\).
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
cone_angle (Scalar) – The cone angle in radians.
wavelength (Scalar | None) – The wavelength of the beam. Default: if None, uses a global default (see
torchoptics.set_default_wavelength()).spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the beam. Default: (0, 0).
- Returns:
The generated zeroth-order Bessel beam profile.
- Return type:
Tensor
- torchoptics.profiles.binary_grating(shape, period, spacing=None, offset=None, height=1, theta=0, duty_cycle=0.5)#
Generate a binary grating profile.
The binary grating profile is defined by the following equation:
\[\begin{split}\psi(x, y) = \begin{cases} 0 & \text{if } \mod \left(\frac{x \cos \theta + y \sin \theta}{\Lambda}, 1\right) < d \\ h & \text{otherwise} \end{cases}\end{split}\]where:
\(h\) is the height of the grating,
\(\Lambda\) is the period of the grating,
\(\theta\) is the angle of the grating, and
\(d\) is the duty cycle of the grating.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
period (Scalar) – The grating period (distance between adjacent grooves).
duty_cycle (Scalar) – The duty cycle of the grating. Default: 0.5.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the beam. Default: (0, 0).
height (Scalar) – The height of the grating. Default: 1.
theta (Scalar) – The angle of the grating in radians. Default: 0.
- Returns:
The generated transmission function.
- Return type:
Tensor
- torchoptics.profiles.blazed_grating(shape, period, spacing=None, offset=None, height=1, theta=0)#
Generate a blazed grating profile.
The blazed grating profile is defined by the following equation:
\[\psi(x, y) = h \cdot \mod \left(\frac{x \cos \theta + y \sin \theta}{\Lambda}, 1\right)\]where:
\(h\) is the height of the grating,
\(\Lambda\) is the period of the grating, and
\(\theta\) is the angle of the grating.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
period (Scalar) – The grating period (distance between adjacent grooves).
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the beam. Default: (0, 0).
height (Scalar) – The height of the grating. Default: 1.
theta (Scalar) – The angle of the grating in radians. Default: 0.
- Returns:
The generated transmission function.
- Return type:
Tensor
- torchoptics.profiles.checkerboard(shape, tile_length, num_tiles, spacing=None, offset=None)#
Generate a checkerboard pattern.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
tile_length (Vector2) – The side lengths of the checkerboard tiles.
num_tiles (Vector2) – Number of tiles along the planar dimensions.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Offset coordinates of the pattern. Default: (0, 0).
- Returns:
The generated checkerboard pattern with internal padding.
- Return type:
Tensor
- torchoptics.profiles.circle(shape, radius, spacing=None, offset=None)#
Generate a circular profile.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
radius (Scalar) – The radius of the circle.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the profile. Default: (0, 0).
- Returns:
The generated circular profile.
- Return type:
Tensor
- torchoptics.profiles.cylindrical_lens_phase(shape, focal_length, theta=0.0, wavelength=None, spacing=None, offset=None)#
Generate a cylindrical lens profile with a quadratic phase in a specified direction.
The quadratic phase profile is:
\[\psi(x, y) = -i \frac{\pi}{\lambda f} (x_\theta)^2\]where \(x_\theta = x \cos\theta + y \sin\theta\).
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
focal_length (Scalar) – Focal length along the axis of the lens.
theta (Scalar) – Orientation angle of the cylindrical axis in radians.
wavelength (Scalar | None) – Wavelength used for lens operation.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the beam. Default: (0, 0).
- Return type:
- torchoptics.profiles.gaussian(shape, waist_radius, wavelength=None, waist_z=0, spacing=None, offset=None)#
Generate a Gaussian profile.
The Gaussian profile is defined by the following equation:
\[\psi(r, z) = \frac{w_0}{w(z)} \exp\left(-\frac{r^2}{w(z)^2}\right) \exp\left(i\left[kz + \frac{kr^2}{2R(z)} - \arctan\left(\frac{z}{z_R}\right)\right]\right)\]where the parameters are defined as follows:
\(w_0\): The beam waist radius, representing the minimum beam size at the focal point.
\(w(z)\): The beam radius at a given propagation distance \(z\):
\[w(z) = w_0 \sqrt{1 + \left(\frac{z}{z_R}\right)^2}\]\(R(z)\): The radius of curvature of the beam’s wavefront at a distance \(z\):
\[R(z) = z \left(1 + \left(\frac{z_R}{z}\right)^2\right)\]\(z_R\): The Rayleigh range:
\[z_R = \frac{\pi w_0^2}{\lambda}\]\(k\): The wavenumber:
\[k = \frac{2\pi}{\lambda}\]- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
waist_radius (torchoptics.types.Scalar) – The radius of the beam waist.
wavelength (Scalar | None) – The wavelength of the beam. Default: if None, uses a global default (see
torchoptics.set_default_wavelength()).waist_z (torchoptics.types.Scalar) – Position of beam waist along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the beam. Default: (0, 0).
- Returns:
The generated Gaussian profile.
- Return type:
Tensor
- torchoptics.profiles.gaussian_schell_model(shape, waist_radius, coherence_width, spacing=None, offset=None)#
Generate a spatial coherence function profile based on the Gaussian Schell-model.
The Gaussian Schell-model assumes both the intensity and coherence functions have Gaussian profiles. The mutual coherence function \(\Gamma(x_1, y_1, x_2, y_2)\) is defined as:
\[\Gamma(x_1, y_1, x_2, y_2) = \sqrt{I(x_1, y_1) \cdot I(x_2, y_2)} \cdot \mu(x_1 - x_2, y_1 - y_2)\]- where:
\(I(x, y) = \exp{\left(-\frac{2(x^2 + y^2)}{w_0^2}\right)}\) is the Gaussian intensity distribution with waist radius \(w_0\), and
\(\mu(x_1 - x_2, y_1 - y_2) = \exp{\left(-\frac{(x_1 - x_2)^2 + (y_1 - y_2)^2}{2 \sigma_c^2}\right)}\) is the Gaussian coherence function with coherence width \(\sigma_c\).
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
waist_radius (Scalar) – The beam waist radius.
coherence_width (Scalar) – The coherence width.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Offset coordinates of the pattern. Default: (0, 0).
- Returns:
A 4D tensor representing the mutual coherence function \(\Gamma(x_1, x_2, y_1, y_2)\).
- Return type:
- torchoptics.profiles.hermite_gaussian(shape, m, n, waist_radius, wavelength=None, waist_z=0, spacing=None, offset=None)#
Generate a Hermite-Gaussian profile.
The Hermite-Gaussian profile is defined by the following equation:
\[\begin{split}\begin{align*} \psi_{mn}(x, y, z) &= \frac{w_0}{w(z)} H_m\left(\sqrt{2}\frac{x}{w(z)}\right) H_n\left(\sqrt{2}\frac{y}{w(z)}\right) \\ & \quad \times \exp\left(-\frac{x^2 + y^2}{w(z)^2}\right) \\ & \quad \times \exp\left(i\left[kz + \frac{k(x^2 + y^2)}{2R(z)} - (m+n+1)\arctan\left(\frac{z}{z_R}\right)\right]\right), \end{align*}\end{split}\]where the parameters are defined as follows:
\(w_0\): The beam waist radius, representing the minimum beam size at the focal point.
\(w(z)\): The beam radius at a given propagation distance \(z\):
\[w(z) = w_0 \sqrt{1 + \left(\frac{z}{z_R}\right)^2}\]\(R(z)\): The radius of curvature of the beam’s wavefront at a distance \(z\):
\[R(z) = z \left(1 + \left(\frac{z_R}{z}\right)^2\right)\]\(z_R\): The Rayleigh range:
\[z_R = \frac{\pi w_0^2}{\lambda}\]\(k\): The wavenumber:
\[k = \frac{2\pi}{\lambda}\]\(H_m\) and \(H_n\): The Hermite polynomials of order \(m\) and \(n\).
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
m (int) – The mode number in the first planar dimension.
n (int) – The mode number in the second planar dimension.
waist_radius (torchoptics.types.Scalar) – The radius of the beam waist.
wavelength (Scalar | None) – The wavelength of the beam. Default: if None, uses a global default (see
torchoptics.set_default_wavelength()).waist_z (torchoptics.types.Scalar) – Position of beam waist along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the beam. Default: (0, 0).
- Returns:
The generated Hermite-Gaussian profile.
- Return type:
Tensor
- torchoptics.profiles.hexagon(shape, radius, spacing=None, offset=None)#
Generate a hexagonal profile.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
radius (Scalar) – The circumradius (center-to-vertex distance) of the hexagon.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the profile. Default: (0, 0).
- Returns:
The generated hexagonal profile.
- Return type:
Tensor
- torchoptics.profiles.laguerre_gaussian(shape, p, l, waist_radius, wavelength=None, waist_z=0, spacing=None, offset=None)#
Generate a Laguerre-Gaussian profile.
The Laguerre-Gaussian profile is defined by the following equation:
\[\begin{split}\begin{align*} \psi_{pl}(r, \phi, z) &= \frac{w_0}{w(z)} \left( \frac{\sqrt{2} r}{w(z)} \right)^{|l|} L_p^{|l|} \left(\frac{2 r^2}{w(z)^2} \right) \\ & \quad \times \exp\left(-\frac{r^2}{w(z)^2}\right) \\ & \quad \times \exp\left(i\left[kz + \frac{kr^2}{2R(z)} - (2p+|l|+1)\arctan\left(\frac{z}{z_R}\right) + l\phi \right]\right) \end{align*}\end{split}\]where the parameters are defined as follows:
\(w_0\): The beam waist radius, representing the minimum beam size at the focal point.
\(w(z)\): The beam radius at a given propagation distance \(z\):
\[w(z) = w_0 \sqrt{1 + \left(\frac{z}{z_R}\right)^2}\]\(R(z)\): The radius of curvature of the beam’s wavefront at \(z\):
\[R(z) = z \left(1 + \left(\frac{z_R}{z}\right)^2\right)\]\(z_R\): The Rayleigh range:
\[z_R = \frac{\pi w_0^2}{\lambda}\]\(k\): The wavenumber:
\[k = \frac{2\pi}{\lambda}\]\(L_p^{|l|}\): The Laguerre polynomial of radial order \(p\) and azimuthal index \(l\).
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
p (int) – The radial mode number.
l (int) – The azimuthal mode number.
waist_radius (torchoptics.types.Scalar) – The radius of the beam waist.
wavelength (Scalar | None) – The wavelength of the beam. Default: if None, uses a global default (see
torchoptics.set_default_wavelength()).waist_z (torchoptics.types.Scalar) – Position of beam waist along the z-axis. Default: 0.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the beam. Default: (0, 0).
- Returns:
The generated Laguerre-Gaussian profile.
- Return type:
Tensor
- torchoptics.profiles.lens_phase(shape, focal_length, wavelength=None, spacing=None, offset=None)#
Generate a quadratic phase lens profile, which can be used to represent a thin lens.
The quadratic phase profile is defined by the following equation:
\[\psi(x, y) = -i \frac{\pi}{\lambda f} (x^2 + y^2)\]- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
focal_length (Scalar) – Focal length of the lens.
wavelength (Scalar | None) – Wavelength used for lens operation.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the beam. Default: (0, 0).
- Return type:
- torchoptics.profiles.octagon(shape, radius, spacing=None, offset=None)#
Generate an octagonal profile.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
radius (Scalar) – The circumradius (center-to-vertex distance) of the octagon.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the profile. Default: (0, 0).
- Returns:
The generated octagonal profile.
- Return type:
Tensor
- torchoptics.profiles.plane_wave_phase(shape, theta=0.0, phi=0.0, z=0.0, wavelength=None, spacing=None, offset=None)#
Compute the phase argument of a plane wave with arbitrary propagation direction.
The phase argument is defined as:
\[\psi(x, y, z) = k_x x + k_y y + k_z z\]- where:
\(k_x = \frac{2\pi}{\lambda} \sin\theta \cos\phi\)
\(k_y = \frac{2\pi}{\lambda} \sin\theta \sin\phi\)
\(k_z = \frac{2\pi}{\lambda} \cos\theta\)
- Parameters:
shape (Vector2) – Number of grid points along planar dimensions.
theta (Scalar) – Polar angle from the z-axis, in radians.
phi (Scalar) – Azimuthal angle in the x-y plane, in radians.
z (Scalar) – Axial location at which to evaluate the phase. Default: 0.
wavelength (Scalar | None) – Wavelength of the wave. If None, uses global default.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the wave. Default: (0, 0).
- Returns:
Real-valued 2D phase argument of the plane wave.
- Return type:
- torchoptics.profiles.rectangle(shape, side, spacing=None, offset=None)#
Generate a rectangle profile.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
side (Vector2) – The two side lengths of the rectangle.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the profile. Default: (0, 0).
- Returns:
The generated rectangle profile.
- Return type:
Tensor
- torchoptics.profiles.regular_polygon(shape, num_sides, radius, spacing=None, offset=None, theta=0)#
Generate a regular N-sided polygon profile.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
num_sides (int) – Number of sides (must be >= 3).
radius (Scalar) – The circumradius (center-to-vertex distance).
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the profile. Default: (0, 0).
theta (Scalar) – Rotation angle in radians (angle of the first vertex). Default: 0.
- Returns:
The generated regular polygon profile.
- Return type:
Tensor
- torchoptics.profiles.schell_model(shape, intensity_func, coherence_func, spacing=None, offset=None)#
Generate a spatial coherence function profile based on the Schell-model.
The Schell model describes partially coherent light as a combination of an intensity distribution and a spatial coherence function. The mutual coherence function \(\Gamma(x_1, y_1, x_2, y_2)\) is defined as:
\[\Gamma(x_1, y_1, x_2, y_2) = \sqrt{I(x_1, y_1) \cdot I(x_2, y_2)} \cdot \mu(x_1 - x_2, y_1 - y_2),\]- where:
\(I(x, y)\) is the intensity distribution function, and
\(\mu(x_1 - x_2, y_1 - y_2)\) is the spatial coherence function.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
intensity_func (Callable[[Tensor, Tensor], Tensor]) – Function defining the intensity distribution, which takes the \(x\) and \(y\) coordinates and returns the intensity values.
coherence_func (Callable[[Tensor, Tensor], Tensor]) – Function defining the coherence distribution, which takes the pairwise \(dx\) and \(dy\) coordinate differences and returns the coherence values.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Offset coordinates of the pattern. Default: (0, 0).
- Returns:
A 4D tensor representing the mutual coherence function \(\Gamma(x_1, y_1, x_2, y_2)\).
- Return type:
- torchoptics.profiles.siemens_star(shape, num_spokes, radius, spacing=None, offset=None)#
Generate a Siemens star pattern.
A Siemens star is a radial resolution target with alternating spokes. The number of spokes determines the angular frequency, and the pattern is confined to a circular region defined by
radius.- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
num_spokes (int) – Number of spokes (must be an even integer).
radius (Scalar) – Radius of the circular Siemens star region.
spacing (Vector2 | None) – Distance between grid points along planar dimensions.
offset (Vector2 | None) – Center coordinates of the pattern. Default: (0, 0).
- Returns:
The generated Siemens star pattern with values in [0, 1].
- Return type:
Tensor
- torchoptics.profiles.sinc(shape, scale, spacing=None, offset=None)#
Generate a sinc profile.
The sinc profile is defined by the following equation:
\[\psi(x, y) = \frac{1}{\sqrt{ab}}\text{sinc}\left(\frac{x}{a}\right) \cdot \text{sinc}\left(\frac{y}{b}\right)\]where:
\(\text{sinc}(x) = \frac{\sin(\pi x)}{\pi x}\) is the normalized sinc function.
\(a\) and \(b\) are the scaling factors along the x and y dimensions, respectively.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
scale (Vector2) – The two scaling factors (widths) of the sinc function in the x and y directions.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default.
offset (Vector2 | None) – Center coordinates of the profile. Default: (0, 0).
- Returns:
The generated sinc profile.
- Return type:
Tensor
- torchoptics.profiles.sinusoidal_grating(shape, period, spacing=None, offset=None, height=1, theta=0)#
Generate a sinusoidal grating profile.
The sinusoidal grating profile is defined by the following equation:
\[\psi(x, y) = h \left(\frac{1}{2} + \frac{1}{2} \cos\left(\frac{2 \pi}{\Lambda} (x \cos \theta + y \sin \theta)\right)\right)\]where:
\(h\) is the height of the grating,
\(\Lambda\) is the period of the grating, and
\(\theta\) is the angle of the grating.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
period (Scalar) – The grating period (distance between adjacent grooves).
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the beam. Default: (0, 0).
height (Scalar) – The height of the grating. Default: 1.
theta (Scalar) – The angle of the grating in radians. Default: 0.
- Returns:
The generated transmission function.
- Return type:
Tensor
- torchoptics.profiles.spherical_wave_phase(shape, z, wavelength=None, spacing=None, offset=None)#
Compute the phase argument of a spherical wave originating from a point source.
The phase argument is defined as:
\[\psi(x, y, z) = k \cdot r, \quad r = \sqrt{x^2 + y^2 + z^2}\]- where:
\(z\) is the axial distance from the source to the observation plane,
\(k = \frac{2\pi}{\lambda}\) is the wavenumber.
- Parameters:
shape (Vector2) – Grid shape (height, width).
z (Scalar) – z-location of the observation plane.
wavelength (Scalar | None) – Wavelength of the wave. If None, uses global default.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the wave. Default: (0, 0).
- Returns:
Real-valued 2D phase argument of the spherical wave.
- Return type:
- torchoptics.profiles.square(shape, side, spacing=None, offset=None)#
Generate a square profile.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
side (Scalar) – The side length of the square.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the profile. Default: (0, 0).
- Returns:
The generated square profile.
- Return type:
Tensor
- torchoptics.profiles.triangle(shape, base, height, spacing=None, offset=None, theta=0)#
Generate a triangular profile.
- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
base (Scalar) – The base length of the triangle.
height (Scalar) – The height of the triangle.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default (see
torchoptics.set_default_spacing()).offset (Vector2 | None) – Center coordinates of the profile. Default: (0, 0).
theta (Scalar) – The angle of rotation of the triangle in radians. Default: 0.
- Returns:
The generated triangular profile.
- Return type:
Tensor
- torchoptics.profiles.zernike(shape, n, m, radius, spacing=None, offset=None)#
Generate a Zernike polynomial profile over a 2D grid.
Zernike polynomials are a set of orthogonal polynomials defined on the unit disk, commonly used in optics for wavefront analysis and aberration characterization. They are expressed in polar coordinates \((\rho, \theta)\) as:
\[Z_n^m(\rho, \theta) = R_n^m(\rho) \exp(i m \theta)\]where:
\(n\) is the radial order (non-negative integer),
\(m\) is the azimuthal index (integer satisfying \(|m| \leq n\) and \(n - |m|\) even),
\(R_n^m(\rho)\) is the radial polynomial,
\(\rho\) is the normalized radial coordinate, and
\(\theta\) is the angular coordinate.
The radial polynomial \(R_n^m(\rho)\) is computed using:
\[R_n^m(\rho) = \sum_{k=0}^{(n-|m|)/2} \frac{(-1)^k (n-k)!}{k! \left(\frac{n+|m|}{2}-k\right)! \left(\frac{n-|m|}{2}-k\right)!} \rho^{n-2k}\]- Parameters:
shape (Vector2) – Number of grid points along the planar dimensions.
n (int) – The radial order of the Zernike polynomial.
m (int) – The azimuthal order of the Zernike polynomial.
radius (Scalar) – The radius of the unit disk.
spacing (Vector2 | None) – Distance between grid points along planar dimensions. Default: if None, uses a global default.
offset (Vector2 | None) – Center coordinates of the profile. Default: (0, 0).
- Returns:
The generated Zernike polynomial profile.
- Return type:
Tensor