Skip to content

Reference

This page contains a detailed description of all exported methods.

SLM

SLMDisplay

A class to control a Spatial Light Modulator (SLM).

Attributes:

Name Type Description
monitor_id int

The ID of the monitor to use.

slm SLM

The SLM instance.

width int

The width of the SLM.

height int

The height of the SLM.

refreshrate int

The refresh rate of the SLM.

Source code in src/slmcontrol/slm.py
class SLMDisplay:
    """
    A class to control a Spatial Light Modulator (SLM).

    Attributes:
        monitor_id (int): The ID of the monitor to use.
        slm (jl.SLM): The SLM instance.
        width (int): The width of the SLM.
        height (int): The height of the SLM.
        refreshrate (int): The refresh rate of the SLM.
    """

    def __init__(self, monitor_id=jl.lastindex(jl.GetMonitors()) - 1) -> None:
        """
        Initialize the SLM instance.

        Args:
            monitor_id (int): The ID of the monitor to use. Defaults to the last monitor.
        """
        self.monitor_id = monitor_id
        self.slm = jl.SLMDisplay(monitor_id + 1)
        self.width = self.slm.width
        self.height = self.slm.height
        self.refreshrate = self.slm.refreshrate

    def updateArray(self, holo: NDArray[np.uint8], sleep=0.15) -> None:
        """
        Update the hologram displayed on the SLM.

        Args:
            holo: A 2D matrix of UInt8 values representing the hologram. 
        """
        jl.updateArray(self.slm, holo.T, sleep=sleep)

    def close(self) -> None:
        """
        Close the SLM window.
        """
        jl.close(self.slm)

__init__(monitor_id=jl.lastindex(jl.GetMonitors()) - 1)

Initialize the SLM instance.

Parameters:

Name Type Description Default
monitor_id int

The ID of the monitor to use. Defaults to the last monitor.

lastindex(GetMonitors()) - 1
Source code in src/slmcontrol/slm.py
def __init__(self, monitor_id=jl.lastindex(jl.GetMonitors()) - 1) -> None:
    """
    Initialize the SLM instance.

    Args:
        monitor_id (int): The ID of the monitor to use. Defaults to the last monitor.
    """
    self.monitor_id = monitor_id
    self.slm = jl.SLMDisplay(monitor_id + 1)
    self.width = self.slm.width
    self.height = self.slm.height
    self.refreshrate = self.slm.refreshrate

updateArray(holo, sleep=0.15)

Update the hologram displayed on the SLM.

Parameters:

Name Type Description Default
holo NDArray[uint8]

A 2D matrix of UInt8 values representing the hologram.

required
Source code in src/slmcontrol/slm.py
def updateArray(self, holo: NDArray[np.uint8], sleep=0.15) -> None:
    """
    Update the hologram displayed on the SLM.

    Args:
        holo: A 2D matrix of UInt8 values representing the hologram. 
    """
    jl.updateArray(self.slm, holo.T, sleep=sleep)

close()

Close the SLM window.

Source code in src/slmcontrol/slm.py
def close(self) -> None:
    """
    Close the SLM window.
    """
    jl.close(self.slm)

Hologram

generate_hologram(relative, two_pi_modulation, x_period, y_period, method='BesselJ1')

Generate a hologram used to produce the desired output.

Parameters:

Name Type Description Default
relative ArrayLike

The relative field. This is the desired output field divided by the input field. When the input field is a plane wave, this reduces to desired output field.

required
two_pi_modulation int

The greyscale value corresponding to a 2 pi phase shift.

required
x_period Union[int, float]

The period (in pixels) of the diffraction grating in the x direction.

required
y_period Union[int, float]

The period (in pixels) of the diffraction grating in the y direction.

required
method str

Hologram calculation method. Possible values are:

1. 'Simple': Method A of reference [2]

2. 'BesselJ1': Type 3 of reference [1] or method F of reference [2]

Defaults to 'BesselJ1'.
'BesselJ1'

Returns:

Type Description
NDArray[uint8]

NDArray[np.uint8]: The hologram.

References:

[1] Victor Arrizón, Ulises Ruiz, Rosibel Carrada, and Luis A. González, 
    "Pixelated phase computer holograms for the accurate encoding of scalar complex fields," 
    J. Opt. Soc. Am. A 24, 3500-3507 (2007)

[2] Thomas W. Clark, Rachel F. Offer, Sonja Franke-Arnold, Aidan S. Arnold, and Neal Radwell, 
    "Comparison of beam generation techniques using a phase only spatial light modulator," 
    Opt. Express 24, 6249-6264 (2016)
Source code in src/slmcontrol/hologram.py
def generate_hologram(relative: ArrayLike,
                      two_pi_modulation: int, x_period: Union[int, float], y_period: Union[int, float],
                      method: str = 'BesselJ1') -> NDArray[np.uint8]:
    """
    Generate a hologram used to produce the desired output.

    Args:
        relative (ArrayLike): The relative field. This is the desired output field divided by the input field. When the input field is a plane wave, this reduces to desired output field.
        two_pi_modulation (int): The greyscale value corresponding to a 2 pi phase shift.
        x_period (Union[int, float]): The period (in pixels) of the diffraction grating in the x direction.
        y_period (Union[int, float]): The period (in pixels) of the diffraction grating in the y direction.
        method (str, optional): Hologram calculation method. 
            Possible values are:

                1. 'Simple': Method A of reference [2] 

                2. 'BesselJ1': Type 3 of reference [1] or method F of reference [2] 

                Defaults to 'BesselJ1'.

    Returns:
        NDArray[np.uint8]: The hologram.

     References:

        [1] Victor Arrizón, Ulises Ruiz, Rosibel Carrada, and Luis A. González, 
            "Pixelated phase computer holograms for the accurate encoding of scalar complex fields," 
            J. Opt. Soc. Am. A 24, 3500-3507 (2007)

        [2] Thomas W. Clark, Rachel F. Offer, Sonja Franke-Arnold, Aidan S. Arnold, and Neal Radwell, 
            "Comparison of beam generation techniques using a phase only spatial light modulator," 
            Opt. Express 24, 6249-6264 (2016)
    """
    if method == 'BesselJ1':
        _method = jl.BesselJ1()
    elif method == 'Simple':
        _method = jl.Simple()
    else:
        raise ValueError(
            'Invalid method. Must be either "BesselJ1" or "Simple"')
    return np.asarray(jl.generate_hologram(relative.T, two_pi_modulation, x_period, y_period, _method)).T

Structures

lg(x, y, p=0, l=0, w=1)

Compute the Laguerre-Gaussian mode.

Parameters:

Name Type Description Default
x ArrayLike

x argument

required
y ArrayLike

y argument

required
p int

radial index

0
l int

azymutal index

0
w Union[int, float]

waist

1

Returns:

Type Description
ArrayLike

Laguerre-Gaussian mode.

Source code in src/slmcontrol/structures.py
def lg(x: ArrayLike, y: ArrayLike,
       p: int = 0, l: int = 0, w: Union[int, float] = 1) -> ArrayLike:
    """Compute the Laguerre-Gaussian mode.

    Args:
        x (ArrayLike): x argument
        y (ArrayLike): y argument
        p (int): radial index
        l (int): azymutal index
        w (Union[int, float]): waist

    Returns:
        (ArrayLike): Laguerre-Gaussian mode.
    """
    return np.asarray(jl.lg(x, y, w=w, p=p, l=l)).T

hg(x, y, m=0, n=0, w=1)

Compute the Hermite-Gaussian mode.

Parameters:

Name Type Description Default
x ArrayLike

x argument

required
y ArrayLike

y argument

required
m int

vertical index

0
n int

horizontal index

0
w Union[int, float]

waist

1

Returns:

Type Description
ArrayLike

Hermite-Gaussian mode.

Source code in src/slmcontrol/structures.py
def hg(x: ArrayLike, y: ArrayLike, m: int = 0, n: int = 0, w: Union[int, float] = 1) -> ArrayLike:
    """Compute the Hermite-Gaussian mode.

    Args:
        x (ArrayLike): x argument
        y (ArrayLike): y argument
        m (int): vertical index
        n (int): horizontal index
        w (Union[int, float]): waist

    Returns:
        (ArrayLike): Hermite-Gaussian mode.
    """
    return np.asarray(jl.hg(x, y, w=w, m=m, n=n)).T

diagonal_hg(x, y, m=0, n=0, w=1)

Compute the diagonal Hermite-Gaussian mode.

Parameters:

Name Type Description Default
x ArrayLike

x argument

required
y ArrayLike

y argument

required
m int

diagonal index

0
n int

anti-diagonal index

0
w Union[int, float]

waist

1

Returns:

Type Description
ArrayLike

diagonal Hermite-Gaussian mode.

Source code in src/slmcontrol/structures.py
def diagonal_hg(x: ArrayLike, y: ArrayLike, m: int = 0, n: int = 0, w: Union[int, float] = 1) -> ArrayLike:
    """Compute the diagonal Hermite-Gaussian mode.

    Args:
        x (ArrayLike): x argument
        y (ArrayLike): y argument
        m (int): diagonal index
        n (int): anti-diagonal index
        w (Union[int, float]): waist

    Returns:
        (ArrayLike): diagonal Hermite-Gaussian mode.
    """
    return np.asarray(jl.diagonal_hg(x, y, w=w, m=m, n=n)).T

lens(x, y, fx, fy, k=1)

Compute the phase imposed by a lens.

Parameters:

Name Type Description Default
x ArrayLike

x argument

required
y ArrayLike

y argument

required
fx Union[int, float]

focal length in the x direction

required
fy Union[int, float]

focal length in the y direction

required
k Union[int, float]

wavenumber of incoming beam

1

Returns:

Type Description
ArrayLike

phase imposed by the lens.

Source code in src/slmcontrol/structures.py
def lens(x: ArrayLike, y: ArrayLike,
         fx: Union[int, float], fy: Union[int, float], k: Union[int, float] = 1) -> ArrayLike:
    """Compute the phase imposed by a lens.

    Args:
        x (ArrayLike): x argument
        y (ArrayLike): y argument
        fx (Union[int, float]): focal length in the x direction
        fy (Union[int, float]): focal length in the y direction
        k (Union[int, float]): wavenumber of incoming beam

    Returns:
        (ArrayLike): phase imposed by the lens.
    """
    return np.asarray(jl.lens(x, y, fx, fy, k=k)).T

tilted_lens(x, y, f, phi, k=1)

Compute the phase imposed by a tilted spherical lens.

Parameters:

Name Type Description Default
x ArrayLike

x argument

required
y ArrayLike

y argument

required
f Union[int, float]

focal length

required
phi Union[int, float]

tilting angle

required
k Union[int, float]

wavenumber of incoming beam

1

Returns:

Type Description
ArrayLike

phase imposed by the tilted spherical lens

Source code in src/slmcontrol/structures.py
def tilted_lens(x: ArrayLike, y: ArrayLike,
                f: Union[int, float], phi: Union[int, float], k: Union[int, float] = 1) -> ArrayLike:
    """Compute the phase imposed by a tilted spherical lens.

    Args:
        x (ArrayLike): x argument
        y (ArrayLike): y argument
        f (Union[int, float]): focal length
        phi (Union[int, float]): tilting angle
        k (Union[int, float]): wavenumber of incoming beam

    Returns:
        (ArrayLike): phase imposed by the tilted spherical lens
    """

    return np.asarray(jl.tilted_lens(x, y, f, phi, k=k)).T

rectangular_aperture(x, y, a, b)

Rectangular aperture centered at the origin.

Parameters:

Name Type Description Default
x ArrayLike

x argument

required
y ArrayLike

y argument

required
a Union[int, float]

lenght in the horizontal direction

required
b Union[int, float]

lenght in the vertical direction

required

Returns:

Type Description
ArrayLike

True if the point is inside the aperture. False otherwise.

Source code in src/slmcontrol/structures.py
def rectangular_aperture(x: ArrayLike, y: ArrayLike, a: Union[int, float], b: Union[int, float]) -> ArrayLike:
    """Rectangular aperture centered at the origin.

    Args:
        x (ArrayLike): x argument
        y (ArrayLike): y argument
        a (Union[int, float]): lenght in the horizontal direction
        b (Union[int, float]): lenght in the vertical direction

    Returns:
        (ArrayLike): True if the point is inside the aperture. False otherwise.
    """
    return np.asarray(jl.rectangular_aperture(x, y, a, b)).T

square(x, y, l)

Square apperture centered at the origin.

Parameters:

Name Type Description Default
x ArrayLike

x argument

required
y ArrayLike

y argument

required
l Union[int, float]

side length

required

Returns:

Type Description
ArrayLike

True if the point is inside the apperture. False otherwise.

Source code in src/slmcontrol/structures.py
def square(x: ArrayLike, y: ArrayLike, l: Union[int, float]) -> ArrayLike:
    """Square apperture centered at the origin.

    Args:
        x (ArrayLike): x argument
        y (ArrayLike): y argument
        l (Union[int, float]): side length

    Returns:
        (ArrayLike): True if the point is inside the apperture. False otherwise.
    """
    return np.asarray(jl.square(x, y, l)).T

single_slit(x, y, a)

Single vertical slit.

Parameters:

Name Type Description Default
x ArrayLike

x argument

required
y ArrayLike

y argument

required
a Union[int, float]

slit widht

required

Returns:

Type Description
ArrayLike

True if the point is inside the slit. False otherwise.

Source code in src/slmcontrol/structures.py
def single_slit(x: ArrayLike, y: ArrayLike, a: Union[int, float]) -> ArrayLike:
    """Single vertical slit.

    Args:
        x (ArrayLike): x argument
        y (ArrayLike): y argument
        a (Union[int, float]): slit widht

    Returns:
        (ArrayLike): True if the point is inside the slit. False otherwise.
    """
    return np.asarray(jl.single_slit(x, y, a)).T

double_slit(x, y, a, d)

Double vertical slit.

Parameters:

Name Type Description Default
x ArrayLike

x argument

required
y ArrayLike

y argument

required
a Union[int, float]

slit widht

required
d Union[int, float]

slit separation

required

Returns:

Type Description
ArrayLike

True if the point is inside the slits. False otherwise.

Source code in src/slmcontrol/structures.py
def double_slit(x: ArrayLike, y: ArrayLike, a: Union[int, float], d: Union[int, float]) -> ArrayLike:
    """Double vertical slit.

    Args:
        x (ArrayLike): x argument
        y (ArrayLike): y argument
        a (Union[int, float]): slit widht
        d (Union[int, float]): slit separation

    Returns:
        (ArrayLike): True if the point is inside the slits. False otherwise.
    """
    return np.asarray(jl.double_slit(x, y, a, d)).T

pupil(x, y, radius)

Circular pupil centered at the origin.

Parameters:

Name Type Description Default
x ArrayLike

x argument

required
y ArrayLike

y argument

required
radius Union[int, float]

radius of the pupil

required

Returns:

Type Description
ArrayLike

True if the point is inside the pupil. False otherwise.

Source code in src/slmcontrol/structures.py
def pupil(x: ArrayLike, y: ArrayLike, radius: Union[int, float]) -> ArrayLike:
    """Circular pupil centered at the origin.

    Args:
        x (ArrayLike): x argument
        y (ArrayLike): y argument
        radius (Union[int, float]): radius of the pupil

    Returns:
        (ArrayLike): True if the point is inside the pupil. False otherwise.
    """
    return np.asarray(jl.pupil(x, y, radius)).T

triangle(x, y, side_length)

Equilateral triangular apperture centered at the origin.

Parameters:

Name Type Description Default
x ArrayLike

x argument

required
y ArrayLike

y argument

required
side_length Union[int, float]

side length

required

Returns:

Type Description
ArrayLike

True if the point is inside the apperture. False otherwise.

Source code in src/slmcontrol/structures.py
def triangle(x: ArrayLike, y: ArrayLike, side_length: Union[int, float]) -> ArrayLike:
    """Equilateral triangular apperture centered at the origin.

    Args:
        x (ArrayLike): x argument
        y (ArrayLike): y argument
        side_length (Union[int, float]): side length

    Returns:
        (ArrayLike): True if the point is inside the apperture. False otherwise.
    """
    return np.asarray(jl.triangle(x, y, side_length)).T

Wavefront Correction

zernike(x, y, n, m)

Compute the Zernike polynomial of order (n, m) at the points (x, y).

Parameters:

Name Type Description Default
x array_like

x-coordinates.

required
y array_like

y-coordinates.

required
n int

Radial order of the Zernike polynomial.

required
m int

Azimuthal order of the Zernike polynomial.

required

Returns:

Type Description
array_like

The values of the Zernike polynomial at the points (x, y).

Source code in src/slmcontrol/zernike.py
def zernike(x, y, n, m):
    """
    Compute the Zernike polynomial of order (n, m) at the points (x, y).

    Args:
        x (array_like): x-coordinates.
        y (array_like): y-coordinates.
        n (int): Radial order of the Zernike polynomial.
        m (int): Azimuthal order of the Zernike polynomial.

    Returns:
        (array_like): The values of the Zernike polynomial at the points (x, y).
    """
    return np.asarray(jl.zernike_polynomial(x, y, n, m)).T