Reference
This page contains a detailed description of all exported methods.
SLM
SLMDisplay
A class to control a Spatial Light Modulator (SLM).
This class uses multiprocessing to manage the display in a separate process.
When using this class in Python scripts (not imported modules), you must protect
the instantiation with an if __name__ == '__main__': guard to prevent errors
on macOS and Windows:
Example
This guard is NOT required when:
- Using in Jupyter notebooks or IPython
- Importing and using in modules (not the main script)
- Running via test frameworks (pytest, unittest)
Attributes:
| Name | Type | Description |
|---|---|---|
monitor_id |
int
|
The ID of the monitor to use. |
width |
int
|
The width of the SLM. |
height |
int
|
The height of the SLM. |
Source code in src/slmcontrol/slm.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
__init__(monitor_id=-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. |
-1
|
Source code in src/slmcontrol/slm.py
updateArray(holo, sleep_time=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 |
sleep_time
|
float | int
|
Time to sleep after updating (in seconds) to allow display to refresh. Set to 0 for maximum throughput (no waiting). |
0.15
|
Source code in src/slmcontrol/slm.py
close()
Close the SLM window.
Source code in src/slmcontrol/slm.py
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
|
NDArray
|
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
|
int
|
The period (in pixels) of the diffraction grating in the x direction. |
required |
y_period
|
int
|
The period (in pixels) of the diffraction grating in the y direction. |
required |
method
|
str
|
Hologram calculation method. Possible values are: 1. 'BesselJ1': Type 3 of reference [1] or method F of reference [2] |
'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
Structures
lg(x, y, p=0, l=0, w=1)
Compute the Laguerre-Gaussian mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
x argument |
required |
y
|
NDArray
|
y argument |
required |
p
|
int
|
radial index |
0
|
l
|
int
|
azymutal index |
0
|
w
|
int | float
|
waist |
1
|
Returns:
| Type | Description |
|---|---|
NDArray
|
Laguerre-Gaussian mode. |
Source code in src/slmcontrol/structures.py
hg(x, y, m=0, n=0, w=1)
Compute the Hermite-Gaussian mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
x argument |
required |
y
|
NDArray
|
y argument |
required |
m
|
int
|
vertical index |
0
|
n
|
int
|
horizontal index |
0
|
w
|
int | float
|
waist |
1
|
Returns:
| Type | Description |
|---|---|
NDArray
|
Hermite-Gaussian mode. |
Source code in src/slmcontrol/structures.py
diagonal_hg(x, y, m=0, n=0, w=1)
Compute the diagonal Hermite-Gaussian mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
x argument |
required |
y
|
NDArray
|
y argument |
required |
m
|
int
|
diagonal index |
0
|
n
|
int
|
anti-diagonal index |
0
|
w
|
int | float
|
waist |
1
|
Returns:
| Type | Description |
|---|---|
NDArray
|
diagonal Hermite-Gaussian mode. |
Source code in src/slmcontrol/structures.py
lens(x, y, fx, fy, k=1)
Compute the phase imposed by a lens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
x argument |
required |
y
|
NDArray
|
y argument |
required |
fx
|
int | float
|
focal length in the x direction |
required |
fy
|
int | float
|
focal length in the y direction |
required |
k
|
int | float
|
wavenumber of incoming beam |
1
|
Returns:
| Type | Description |
|---|---|
NDArray
|
phase imposed by the lens. |
Source code in src/slmcontrol/structures.py
Masks
rectangular_aperture(x, y, a, b)
Rectangular aperture centered at the origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
x argument |
required |
y
|
NDArray
|
y argument |
required |
a
|
int | float
|
lenght in the horizontal direction |
required |
b
|
int | float
|
lenght in the vertical direction |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
True if the point is inside the aperture. False otherwise. |
Source code in src/slmcontrol/masks.py
square(x, y, L)
Square apperture centered at the origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
x argument |
required |
y
|
NDArray
|
y argument |
required |
L
|
int | float
|
side length |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
True if the point is inside the apperture. False otherwise. |
Source code in src/slmcontrol/masks.py
single_slit(x, y, a)
Single vertical slit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
x argument |
required |
y
|
NDArray
|
y argument |
required |
a
|
int | float
|
slit width |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
True if the point is inside the slit. False otherwise. |
Source code in src/slmcontrol/masks.py
double_slit(x, y, a, d)
Double vertical slit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
x argument |
required |
y
|
NDArray
|
y argument |
required |
a
|
int | float
|
slit width |
required |
d
|
int | float
|
slit separation |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
True if the point is inside the slits. False otherwise. |
Source code in src/slmcontrol/masks.py
pupil(x, y, radius)
Circular pupil centered at the origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
x argument |
required |
y
|
NDArray
|
y argument |
required |
radius
|
int | float
|
radius of the pupil |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
True if the point is inside the pupil. False otherwise. |
Source code in src/slmcontrol/masks.py
triangle(x, y, side_length)
Equilateral triangular apperture centered at the origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NDArray
|
x argument |
required |
y
|
NDArray
|
y argument |
required |
side_length
|
int | float
|
side length |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
True if the point is inside the apperture. False otherwise. |