Quickstart
The following code gives the minimal working example for this package:
import slmcontrol
import numpy as np
if __name__ == "__main__":
# Initializes the SLM with the default display
slm = slmcontrol.SLMDisplay()
# Queries the SLM for its width and height
width, height = slm.width, slm.height
# Creates a grid of x and y coordinates
# Here, we are taking our units as pixels and the center of the SLM as (0,0)
# One could also use the physical dimensions of the SLM
x = np.linspace(-width / 2, width / 2, width)
y = np.linspace(-height / 2, height / 2, height)
x, y = np.meshgrid(x, y, sparse=True)
# Calculates the field which we want to display
# In this case, we are using a Laguerre-Gaussian mode
desired = slmcontrol.lg(x, y, l=1, w=200)
# The incoming field is assumed to be a larger gaussian beam
incoming = slmcontrol.lg(x, y, w=500)
relative = desired / incoming
# We generate the hologram to be displayed on the SLM
holo = slmcontrol.generate_hologram(relative, 255, 50, 100)
# The hologram is then displayed on the SLM
# We add some sleep time to be able to see the hologram
slm.updateArray(holo, sleep_time=5)
# Finally, the SLM is closed
slm.close()
Breakdown
Let's dissect this example, line by line:
This imports theslmcontrol package and NumPy.
This is necessary when opening the SLM through a script. If running on a notebook, this may be skipped.
This initializes the SLMDisplay object. By default, it uses the last available display for the Spatial Light Modulator (SLM). If you haven't connected your SLM and are just testing the package, this will be your primary display or a second monitor.
This retrieves the width and height of the SLM in pixels. These dimensions will be used to create a coordinate grid.
x = np.linspace(-width/2, width/2, width)
y = np.linspace(-height/2, height/2, height)
x, y = np.meshgrid(x, y, sparse=True)
l=1 and a beam waist of 200 pixels. The lg function generates the complex field amplitude for this specific beam type.
Sets up the incoming beam as a uniform plane wave and the relative field is calculated by dividing the desired field by the incoming field. This relative field represents the phase modulation needed to transform the incoming beam into the desired Laguerre-Gaussian mode.
Generates the hologram that will be displayed on the SLM. This function calculates the phase pattern needed to transform the incoming plane wave into the desired Laguerre-Gaussian beam. The arguments specify:
- The relative field to be modulated.
- Maximum modulation value (255). This is the modulation that imparts a phase shift of 2π and should be set according to the SLM's specifications.
- The last two parameters are the period of the diffraction grating (in units of pixels) in the x (50px) and y (100px) directions.
sleep_time arguments blocks any further execution until 5 seconds have passed. This allows the SLM to settle to a new hologram. The default value is 0.15.
Properly closes the SLM display, releasing any resources.
Next Steps
Now that you have a basic understanding of how to use the slmcontrol package, you can explore more advanced features and functionalities. Here are some suggestions for what to do next:
-
Experiment with Different Beam Profiles: Try generating different types of beams, such as Hermite-Gaussian (
hg) beams or other Laguerre-Gaussian modes, by modifying the parameters in thelgfunction. More spatial structures can be found in here. -
Get a high level view about the capabilities and design of the package in Explanation