API: pySLM2 package

pySLM2.slm module

class pySLM2.slm.DLP7000(wavelength: float, focal_length: float, periodicity: float, theta: float, negative_order: bool = False)[source]

Bases: DMD

This class implements the DLP7000 model and DLP7000UV model from Texas Instruments.

Parameters:
  • wavelength (float) – Wavelength of the laser.

  • focal_length (float) – Effective focal length of the lens system.

  • periodicity (float) – Periodicity of the grating in unit of pixels

  • theta (float) – Desired grating angle. This affects the direction between first order beam relative to the zeroth order beam.

  • negative_order (bool) – If this parameter is set to True, use negative first order instead of first order diffraction beam.

class pySLM2.slm.DLP9000(wavelength: float, focal_length: float, periodicity: float, theta: float, negative_order: bool = False)[source]

Bases: DMD

This class implements the DLP9000 model, DLP9000X model, and DLP9000XUV model from Texas Instruments.

Parameters:
  • wavelength (float) – Wavelength of the laser.

  • focal_length (float) – Effective focal length of the lens system.

  • periodicity (float) – Periodicity of the grating in unit of pixels

  • theta (float) – Desired grating angle. This affects the direction between first order beam relative to the zeroth order beam.

  • negative_order (bool) – If this parameter is set to True, use negative first order instead of first order diffraction beam.

class pySLM2.slm.DLP9500(wavelength: float, focal_length: float, periodicity: float, theta: float, negative_order: bool = False)[source]

Bases: DMD

This class implements the DLP9500 model and DLP9500UV model from Texas Instruments.

Parameters:
  • wavelength (float) – Wavelength of the laser.

  • focal_length (float) – Effective focal length of the lens system.

  • periodicity (float) – Periodicity of the grating in unit of pixels

  • theta (float) – Desired grating angle. This affects the direction between first order beam relative to the zeroth order beam.

  • negative_order (bool) – If this parameter is set to True, use negative first order instead of first order diffraction beam.

class pySLM2.slm.DMD(wavelength, focal_length, periodicity, theta, Nx, Ny, pixel_size, negative_order=False)[source]

Bases: SLM

Base class for a Digital Micromirror Device (DMD).

Parameters:
  • wavelength (float) – Wavelength of the laser.

  • focal_length (float) – Effective focal length of the lens system.

  • periodicity (float) – Periodicity of the grating in unit of pixels

  • theta (float) – Desired grating angle. This affects the direction between first order beam relative to the zeroth order beam.

  • Nx (int) – Number of pixels in the x direction.

  • Ny (int) – Number of pixels in the y direction.

  • pixel_size (float) – Edge length of a single pixel. In the context of the DMD, a pixel is a micromirror.

  • negative_order (bool) – If this parameter is set to True, use negative first order instead of first order diffraction beam.

calculate_dmd_state(input_profile: FunctionProfile | ndarray | Tensor | float | int | complex, target_profile: FunctionProfile | ndarray | Tensor | float | int | complex, method='random', window=None, **kwargs)[source]

Calculate the DMD grating state based on the input and target profiles.

Parameters:
  • input_profile (FunctionProfile or numpy.ndarray or tensorflow.Tensor or float or int or complex) – The input profile of the beam at Fourier plane.

  • target_profile (FunctionProfile or numpy.ndarray or tensorflow.Tensor or float or int or complex) – The target profile of the beam at image plane.

  • method (str) – Method to calculate the DMD grating. Available methods are “random”, “ideal”, “simple”, “ifta”.

  • window (FunctionProfile or numpy.ndarray or tensorflow.Tensor or float or int or complex) – The window function to be applied to the input_profile.

  • kwargs (dict) – Additional arguments for the method.

Returns:

eta – The efficiency of mode matching.

Return type:

float

See also

profile_to_tensor

circular_patch(i, j, amp, phase_in, phase_out, d, method='random', **kwargs)[source]

Create a circular grating patch.

Parameters:
  • i (int or float) – Coordinate of the center of the patch in the pixel index.

  • j (float) – Coordinate of the center of the patch in the pixel index.

  • amp (float) – Amplitude scaling of the diffracting beam from the grating. The valid range is between 0 and 1.

  • phase_in (float or numpy.ndarray or tensorflow.Tensor) – The input phase map (aberration correction) of the beam.

  • phase_out (float or numpy.ndarray or tensorflow.Tensor) – The output phase map of the beam.

  • d (float) – Diameter of the patch in the unit of pixel.

  • method (str) – (Default: “random”) Available methods are “random”, “ideal”, “simple”, “ifta”.

  • kwargs (dict) – Additional arguments for the method.

property first_order_origin

The origin of the first order beam in images plane.

Type:

(float, float)

pack_dmd_state()[source]

Pack the dmd state to bytes.

Returns:

packed_dmd_state

Return type:

bytes

set_dmd_grating_state(amp=1, phase_in=0, phase_out=0, method='random', **kwargs)[source]
set_dmd_state_off()[source]

Reset dmd_state to be an array (Ny, Nx) of zeros.

set_dmd_state_on()[source]

Reset dmd_state to be an array (Ny, Nx) of ones.

property theta

float

class pySLM2.slm.LCOS_SLM(wavelength, focal_length, Nx, Ny, pixel_size)[source]

Bases: SLM

Base class for a Liquid Crystal on Silicon (LCOS) spatial light modulators.

calculate_hologram(input_profile, target_amp_profile, method='gs', **kwargs)[source]

Calculate the hologram displayed on the LCOS SLM.

Parameters:
  • input_profile (FunctionProfile or numpy.ndarray or tensorflow.Tensor or float or int or complex) – The input profile of the beam at Fourier plane.

  • target_amp_profile (FunctionProfile or numpy.ndarray or tensorflow.Tensor or float or int or complex) – The target profile of the beam at image plane.

  • method (str) – The method to calculate the hologram. ‘gs’: Gerchberg-Saxton algorithm. ‘mraf’: Modified Random Amplitude Fourier Transform Algorithm.

  • kwargs (dict) – Additional arguments for the method.

reset_slm_state()[source]
class pySLM2.slm.PLUTO_2(wavelength, focal_length)[source]

Bases: LCOS_SLM

This class implements the PLUTO-2 families from HOLOEYE Photonics AG.

Parameters:
  • wavelength (float) – Wavelength of the laser.

  • focal_length (float) – Effective focal length of the lens system.

class pySLM2.slm.SLM(wavelength, focal_length, Nx, Ny, pixel_size)[source]

Bases: object

Base class for a spatial light modulators.

Parameters:
  • wavelength (float) – Wavelength of the laser.

  • focal_length (float) – Effective focal length of the lens system.

  • Nx (int) – Number of pixels in the x direction.

  • Ny (int) – Number of pixels in the y direction.

  • pixel_size (float) – Edge length of a single pixel.

Note

Coordinate system:

      +----->  j

+     +------------------+     ^
|     |        y         |     |
|     |        ^         |     |
v     |        |         |     | Ny * pixel_size
      |        0---> x   |     |
i     |                  |     |
      |                  |     |
      +------------------+     v

      <------------------>
         Nx * pixel_size
property Nx
property Ny
property focal_length
property fourier_plane_grid

(numpy.ndarray, numpy.ndarray) The x and y coordinates of all the pixels on the SLM.

property image_plane_grid

(numpy.ndarray, numpy.ndarray) The x and y coordinates of the coorsponding.

property pixel_size
profile_to_tensor(profile: FunctionProfile | Tensor | ndarray | int | float | complex, at_fourier_plane=True, complex=False)[source]

This function covert a profile into into tensor.

Parameters:
  • profile (pySLM2.profile.FunctionProfile, tensorflow.Tensor, numpy.ndarray, int, float or complex) – If profile is a FunctionProfile, it will be sampled with the grid in either the Fourier plane or the images plane. Otherwise, it will be cast into a tensorflow.Tensor.

  • at_fourier_plane (bool) – If the value is True, the profile is sampled with the Fourier plane grid. Otherwise, it will be sampled with the images plane grid. (Default: True)

  • complex (bool) – The dtype of the tensor. If the value is True, the dtype of the tensor will be set to pySLM2.BACKEND.complex_dtype. Otherwise, the dtype will be set to pySLM2.BACKEND.dtype. (Default: False)

Returns:

The tensor has the same dimension as the fourier_plane_grid and the image_plane_grid. The dtyoe of the tensor can be set by complex.

Return type:

tensor

property scaling_factor
property wavelength

pySLM2.simulation module

class pySLM2.simulation.DMDSimulation(dmd, padding_x=0, padding_y=0)[source]

Bases: SLMSimulation

The class implements a Simulation plan for the DMD.

Parameters:
  • dmd (pySLM2.slm.DMD) –

  • padding_x (int) – Number of pixels padded in the x direction. (see pySLM2.simulation.SLMSimulation for details)

  • padding_y (int) – Number of pixels padded in the y direction. (see pySLM2.simulation.SLMSimulation for details)

block_zeroth_order(r=None)[source]

On the DMDSimulation.image_plane array, set the centre values (0th order diffraction) to zero.

property first_order_origin
class pySLM2.simulation.SLMSimulation(slm: SLM, padding_x: int = 0, padding_y: int = 0)[source]

Bases: object

The class implements a Simulation plan for the SLM.

Parameters:
  • slm (pySLM2.slm.SLM) –

  • padding_x (int) – Number of pixels padded in the x direction. (see the note for details)

  • padding_y (int) – Number of pixels padded in the y direction. (see the note for details)

  • Note:: (..) –

    The padded Fourier plane is defined as following:

    +----------------------+ ^
    |                      | | padding_y * pixel_size
    |                      | |
    |    +------------+    | v
    |    |            |    |
    |    |   DMD      |    |
    |    |            |    |
    |    +------------+    |
    |                      |
    |      padded FP       |
    +----------------------+
                      <---->
                       padding_x * pixel_size
    

property Nx: int
property Ny: int
clear()[source]

Clear the simulation result.

property fourier_plane_padded_grid: Tuple[ndarray, ndarray]
property fourier_plane_pixel_area: float

float

get_image_plane_power() float[source]

Calculates and returns the total power at the images plane.

Returns:

power – The total power at images plane.

Return type:

float

get_input_power() float[source]

Calculates and returns the total power incident on the SLM.

Returns:

power – The total power incident on the SLM.

Return type:

float

get_output_power() float[source]

Calculates and returns the total power output from the SLM.

Returns:

power – The total power output from the SLM.

Return type:

float

property image_plane_field: ndarray

np.ndarray

property image_plane_intensity: ndarray

np.ndarray

property image_plane_padded_grid: Tuple[ndarray, ndarray]
property image_plane_pixel_area: float
property input_field: ndarray
property input_intensity: ndarray

np.ndarray

property output_field: ndarray
property output_intensity: ndarray

np.ndarray

property padding_x: int
property padding_y: int
propagate_to_image(input_profile)[source]
Parameters:

input_profile

property scaling_factor: float

pySLM2.profile module

class pySLM2.profile.ConstantProfile(c=0.0)[source]

Bases: FunctionProfile

property c
class pySLM2.profile.FunctionProfile[source]

Bases: object

as_complex_profile()[source]

This function returns the complex form of the profile by applying the exponential function with an imaginary unit to the original profile.

Returns:

complex_profile

Return type:

pySLM2.profile.FunctionProfile

Note

complex_profile(x, y) = exp(1j * original_profile(x, y))

rescale_x(m)[source]
rescale_y(m)[source]
rotate(theta)[source]

This function returns a rotated version of the original profile.

Parameters:

theta (float) – Rotation angle.

Returns:

rotated_profile

Return type:

pySLM2.profile.FunctionProfile

Note

rotated_profile(x, y) = original_profile(cos(theta) * x - sin(theta) * y, sin(theta) * x + cos(theta) * y)

shift(dx, dy)[source]

This function returns a shifted version of the original profile.

Parameters:
  • dx (float) – Shift amount in x direction.

  • dy (float) – Shift amount in y direction.

Returns:

shifted_profile

Return type:

pySLM2.profile.FunctionProfile

Note

shifted_profile(x, y) = original_profile(x-dx, y-dy)

class pySLM2.profile.HermiteGaussian(x0, y0, a, w, n=0, m=0)[source]

Bases: FunctionProfile

Beam profiles of Hermite-Gaussian modes.

\[\begin{split}E(x,y) &= A H_n(\frac{\sqrt{2}(x-x_0)}{w})H_m(\frac{\sqrt{2}(y-y_0)}{w})\mathrm{exp} \left ( - \frac{(x-x_0)^2 + (y-y_0)^2}{w^2} \right ) \\ H_n(x) &= (-1)^n e^{x^2}\frac{d^n}{dx^n}e^{-x^2}.\end{split}\]
Parameters:
  • x0 (float) – The center of the Gaussian in x coordinate \(x_0\).

  • y0 (float) – The center of the Gaussian in y coordinate \(y_0\).

  • a (float) – Amplitude of the Gaussian beam \(A\).

  • w (float) – The Gaussian beam width \(w\). It is the \(1/e\) radius of the fundamental mental (n=0, m=0).

  • n (int) – Order of Hermite polynomials \(H_n\) in x direction . (Default: 0)

  • m (int) – Order of Hermite polynomials \(H_m\) in y direction . (Default: 0)

See also

scipy.special.hermite

Physicist’s Hermite polynomial.

property a
property m
property n
property w
property x0
property y0
class pySLM2.profile.LaguerreGaussian(x0, y0, a, w, l=0, p=0)[source]

Bases: FunctionProfile

class pySLM2.profile.SuperGaussian(x0, y0, a, w, p=1.0)[source]

Bases: FunctionProfile

Beam profiles of super Gaussian function.

\[E(x,y) = A \mathrm{exp} \left ( - \left( \frac{(x-x_0)^2 + (y-y_0)^2}{w^2} \right )^P \right )\]
Parameters:
  • x0 (float) – The center of the Gaussian in x coordinate \(x_0\).

  • y0 (float) – The center of the Gaussian in y coordinate \(y_0\).

  • a (float) – Amplitude of the Gaussian beam \(A\).

  • w (float) – The Gaussian beam width \(w\). It is the \(1/e\) radius of the fundamental mental (n=0, m=0).

  • p (float) – Supper Gaussian power \(P\). (Default: 1.0)

property a
property p
property w
property x0
property y0
class pySLM2.profile.Zernike(a, radius, n=0, m=0, normalize=True, extrapolate=False)[source]

Bases: FunctionProfile

property a
is_normalized()[source]
property m
property n
property normalization
property radius

pySLM2.analysis module

pySLM2.analysis.ansi_j_to_n_m(idx)[source]

Convert ANSI single term to (n,m) two-term index.

See also

The, Copyright

https

//github.com/brandondube/prysm

pySLM2.analysis.remove_trivial_phase(profile, radius, remove_defocus=False, verbose=False)[source]

Remove the trivial phase map from the profile within the aperture.

The trivial phase maps include piston and tilt by default.

Parameters:
  • profile (numpy.ndarray) – The phase map profile

  • radius (int or float) – The aperture radiusa

  • remove_defocus (bool) – If true, remove the defocus from the profile.

  • verbose (bool) – If true, print the coefficient of the removed phase map.

Returns:

profile_nontrivial – Phase map after removing trivial

Return type:

numpy.ndarray

pySLM2.analysis.zernike_decomposition(profile, radius, num_terms, verbose=False, reconstruct=False, extrapolate=False)[source]

Extract Zernike coefficients of a phase profile.

Parameters:
  • profile (numpy.ndarray) – The phase map profile

  • radius (int or float) – The aperture radiusa

  • num_terms (int) – Number of ANSI Zernike coefficients

  • verbose (bool) – If true, print the coefficient of the removed phase map.

Returns:

coefficients – Zernike coefficients. The length is the list is the same as num_terms.

Return type:

list of floats