.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/wfs_demonstration_experimental.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_wfs_demonstration_experimental.py: 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. .. GENERATED FROM PYTHON SOURCE LINES 8-45 .. code-block:: Python import astropy.units as u import matplotlib.pyplot as plt import numpy as np from openwfs.algorithms import FourierDualReference from openwfs.devices import Camera, SLM from openwfs.processors import SingleRoi # 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.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)) # we are using a setup with an SLM that produces 2pi phase shift # at a gray value of 142 slm.lookup_table = range(142) alg = FourierDualReference(feedback=roi_detector, slm=slm, slm_shape=[800, 800], k_radius=7) result = alg.execute() print(result) optimised_wf = -np.angle(result.t) before = roi_detector.read() slm.set_phases(optimised_wf) after = roi_detector.read() print(f"actual_optimized_intensity: {after}") print(f"improvement_ratio: {after / before}") while True: slm.set_phases(optimised_wf) plt.pause(1.0) slm.set_phases(0.0) plt.pause(1.0) .. _sphx_glr_download_auto_examples_wfs_demonstration_experimental.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: wfs_demonstration_experimental.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: wfs_demonstration_experimental.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: wfs_demonstration_experimental.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_