From 64667d9f701eb4783a00441db29b7eaf1c8ac157 Mon Sep 17 00:00:00 2001 From: Ivo Vellekoop Date: Thu, 12 Dec 2024 14:12:34 +0100 Subject: [PATCH] updated example to include centering and better description --- examples/wfs_demonstration_experimental.py | 33 ++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/examples/wfs_demonstration_experimental.py b/examples/wfs_demonstration_experimental.py index 2002326..3a7e0e4 100644 --- a/examples/wfs_demonstration_experimental.py +++ b/examples/wfs_demonstration_experimental.py @@ -2,8 +2,14 @@ WFS demo experiment ===================== This script demonstrates how to perform a wavefront shaping experiment using the openwfs library. -It assumes that you have a genicam camera and an SLM connected to your computer. -Please adjust the path to the camera driver and (when needed) the monitor id in the Camera and SLM objects. +It performs wavefront shaping with a FourierDualReference algorithm, maximizing feedback from a +single region of interest (ROI) on a camera. +It assumes that you have a genicam-compatible camera and an SLM connected to the video output of your computer. + +Adjustments to make for your specific setup: +* the path to the camera driver. +* The code assumes the SLM is connected as a secondary monitor. If not, adjust the monitor_id below. +* The gray value that corresponds to a 2pi phase shift on the SLM. This is used to set the lookup table of the SLM. """ import astropy.units as u @@ -13,19 +19,30 @@ from openwfs.algorithms import FourierDualReference from openwfs.devices import Camera, SLM from openwfs.processors import SingleRoi +from openwfs.utilities import Transform + +# Adjust these parameters to your setup +# The camera driver file path +camera_driver_path = R"C:\Program Files\Basler\pylon 7\Runtime\x64\ProducerU3V.cti" +monitor_id = 2 +# time to stabilize the SLM, in frames +settle_time = 2 +# we are using a setup with an SLM that produces 2pi phase shift +# at a gray value of 142. With proper calibration, this is usually 256. +two_pi_gray_value = 142 +centering = Transform(source_origin=(0, 0), destination_origin=(0.0, 0.15)) + # This script shows how a wavefront shaping experiment can be performed from Python -cam = Camera(R"C:\Program Files\Basler\pylon 7\Runtime\x64\ProducerU3V.cti") +cam = Camera(camera_driver_path) cam.exposure_time = 16.666 * u.ms roi_detector = SingleRoi(cam, radius=2) # constructs the actual slm for wavefront shaping, and a monitor window to display the current phase pattern -slm = SLM(monitor_id=2, duration=2) -monitor = slm.clone(monitor_id=0, pos=(0, 0), shape=(slm.shape[0] // 4, slm.shape[1] // 4)) +slm = SLM(monitor_id=monitor_id, duration=settle_time, transform=centering) +monitor = slm.clone(monitor_id=0, pos=(0, 0), shape=(slm.shape[0] // 3, slm.shape[1] // 3)) -# we are using a setup with an SLM that produces 2pi phase shift -# at a gray value of 142 -slm.lookup_table = range(142) +slm.lookup_table = range(two_pi_gray_value) alg = FourierDualReference(feedback=roi_detector, slm=slm, slm_shape=[800, 800], k_radius=7) result = alg.execute()