From 312f9b47d4f415c031b76da353c5ebf9a456a13e Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 10:41:33 +0000 Subject: [PATCH 1/4] Implement the ShaperInterface of beam_shaping: pixel count and pixel size from slmsuite Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01CAhZwmbyCSpSgfTyicUxuS --- .../hardware/slm_controller.py | 6 +++++ .../resources/daq_move_SlmsuiteBase.py | 23 +++++++++++++++- tests/test_slmsuite_plugins.py | 26 +++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/pymodaq_plugins_slmsuite/hardware/slm_controller.py b/src/pymodaq_plugins_slmsuite/hardware/slm_controller.py index 1b43b92..45727ac 100644 --- a/src/pymodaq_plugins_slmsuite/hardware/slm_controller.py +++ b/src/pymodaq_plugins_slmsuite/hardware/slm_controller.py @@ -49,6 +49,12 @@ def shape(self) -> tuple[int, int]: """The shape (height, width) of the SLM in pixels""" return tuple(int(s) for s in self.slm.shape) + @property + def pitch_um(self) -> tuple[float, float]: + """The size (x, y) of the pixels in micrometer, as known by slmsuite (the driver when it can tell, else 8 um)""" + pitch = np.broadcast_to(np.asarray(self.slm.pitch_um, dtype=float), (2,)) + return float(pitch[0]), float(pitch[1]) + @property def bitresolution(self) -> int: """The number of grey levels of the SLM""" diff --git a/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py b/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py index 6fd8ee7..e6ef12e 100644 --- a/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py +++ b/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py @@ -1,4 +1,5 @@ import ast +from types import SimpleNamespace from typing import Any import numpy as np @@ -12,10 +13,16 @@ from pymodaq_plugins_slmsuite import config from pymodaq_plugins_slmsuite.hardware.slm_controller import SlmController +try: + from pymodaq_plugins_beam_shaping.utilities.shaper import ShaperInterface, ShaperGeometry +except ImportError: # BeamShaping is optional: the plugin provides the same information without the base class + ShaperInterface = object + ShaperGeometry = None + logger = set_logger(get_module_name(__file__)) -class DAQ_Move_SlmsuiteBase(DAQ_Move_base): +class DAQ_Move_SlmsuiteBase(ShaperInterface, DAQ_Move_base): """Base class of the actuators driving a spatial light modulator (SLM) through slmsuite The target of a move is a 2D array (``DataActuator`` with one 2D array, or one value that is spread over the whole @@ -41,6 +48,8 @@ class DAQ_Move_SlmsuiteBase(DAQ_Move_base): {'title': 'SLM Infos:', 'name': 'info', 'type': 'group', 'children': [ {'title': 'Width:', 'name': 'width', 'type': 'int', 'value': 0, 'readonly': True}, {'title': 'Height:', 'name': 'height', 'type': 'int', 'value': 0, 'readonly': True}, + {'title': 'Pixel size x (um):', 'name': 'pixel_size_x', 'type': 'float', 'value': 0., 'readonly': True}, + {'title': 'Pixel size y (um):', 'name': 'pixel_size_y', 'type': 'float', 'value': 0., 'readonly': True}, {'title': 'Grey levels:', 'name': 'levels', 'type': 'int', 'value': 0, 'readonly': True}, ]}, {'title': 'Wavelength (nm):', 'name': 'wavelength_nm', 'type': 'float', @@ -74,11 +83,23 @@ def ini_stage(self, controller=None): height, width = self.controller.shape self.settings.child('info', 'width').setValue(width) self.settings.child('info', 'height').setValue(height) + pixel_size_x, pixel_size_y = self.controller.pitch_um + self.settings.child('info', 'pixel_size_x').setValue(pixel_size_x) + self.settings.child('info', 'pixel_size_y').setValue(pixel_size_y) self.settings.child('info', 'levels').setValue(self.controller.bitresolution) self.current_value = DataActuator(self._title, data=[np.zeros(self.controller.shape)]) return f'{self.get_slm_type()} SLM {width}x{height} pixels', True + def get_shaper_geometry(self): + """Number of pixels and pixel size (um) from slmsuite, see ShaperInterface of the BeamShaping extension""" + height, width = self.controller.shape + size_x, size_y = self.controller.pitch_um + if ShaperGeometry is None: + return SimpleNamespace(width=width, height=height, shape=(height, width), + pixel_size_x=size_x, pixel_size_y=size_y, pixel_size=(size_x, size_y)) + return ShaperGeometry(width, height, size_x, size_y) + def close(self): if self.is_master and self.controller is not None: self.controller.close() diff --git a/tests/test_slmsuite_plugins.py b/tests/test_slmsuite_plugins.py index be6bce4..ee911e5 100644 --- a/tests/test_slmsuite_plugins.py +++ b/tests/test_slmsuite_plugins.py @@ -65,6 +65,31 @@ def test_not_a_dict(self): parse_kwargs('[1, 2]') +class TestShaperGeometry: + def test_simulated(self, slm): + geometry = slm.get_shaper_geometry() + assert (geometry.width, geometry.height) == (WIDTH, HEIGHT) + assert geometry.shape == (HEIGHT, WIDTH) + assert geometry.pixel_size_x > 0 and geometry.pixel_size_y > 0 + assert slm.settings['info', 'pixel_size_x'] == geometry.pixel_size_x + + def test_pitch_from_slmsuite(self): + controller = SlmController('SimulatedSLM', resolution=(WIDTH, HEIGHT), pitch_um=(5., 6.)) + assert controller.pitch_um == (5., 6.) + controller.close() + + def test_pitch_given_once(self): + controller = SlmController('SimulatedSLM', resolution=(WIDTH, HEIGHT), pitch_um=7.) + assert controller.pitch_um == (7., 7.) + controller.close() + + def test_fake_controller(self, qapp, fake_controller): + plugin = make_actuator(DAQ_Move_SlmsuiteMeadowlark) + geometry = plugin.get_shaper_geometry() + assert (geometry.width, geometry.height, geometry.pixel_size) == (6, 4, (8., 9.)) + plugin.close() + + class TestSimulatedActuator: def test_infos(self, slm): assert slm.settings['info', 'width'] == WIDTH @@ -127,6 +152,7 @@ class FakeController: def __init__(self, slm_type, **kwargs): self.slm_type, self.kwargs = slm_type, kwargs self.shape = (4, 6) + self.pitch_um = (8., 9.) self.bitresolution = 256 FakeController.instances.append(self) From 3e19f04d26de266d59be2e5d0cc4064b6ac26b4e Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 10:48:43 +0000 Subject: [PATCH 2/4] Shaper geometry as a settings group (no dependency on beam_shaping) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01CAhZwmbyCSpSgfTyicUxuS --- .../resources/daq_move_SlmsuiteBase.py | 38 ++++++++----------- tests/test_slmsuite_plugins.py | 16 ++++---- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py b/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py index e6ef12e..4741ca6 100644 --- a/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py +++ b/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py @@ -1,5 +1,4 @@ import ast -from types import SimpleNamespace from typing import Any import numpy as np @@ -13,16 +12,20 @@ from pymodaq_plugins_slmsuite import config from pymodaq_plugins_slmsuite.hardware.slm_controller import SlmController -try: - from pymodaq_plugins_beam_shaping.utilities.shaper import ShaperInterface, ShaperGeometry -except ImportError: # BeamShaping is optional: the plugin provides the same information without the base class - ShaperInterface = object - ShaperGeometry = None - logger = set_logger(get_module_name(__file__)) -class DAQ_Move_SlmsuiteBase(ShaperInterface, DAQ_Move_base): +# Read by the BeamShaping extension (group name and children names are the contract, see +# pymodaq_plugins_beam_shaping.utilities.shaper.shaper_geometry_params), sizes in micrometer +SHAPER_GEOMETRY = {'title': 'Shaper geometry:', 'name': 'shaper_geometry', 'type': 'group', 'children': [ + {'title': 'Width (pixels):', 'name': 'width', 'type': 'int', 'value': 0, 'readonly': True}, + {'title': 'Height (pixels):', 'name': 'height', 'type': 'int', 'value': 0, 'readonly': True}, + {'title': 'Pixel size x (um):', 'name': 'pixel_size_x', 'type': 'float', 'value': 0., 'readonly': True}, + {'title': 'Pixel size y (um):', 'name': 'pixel_size_y', 'type': 'float', 'value': 0., 'readonly': True}, +]} + + +class DAQ_Move_SlmsuiteBase(DAQ_Move_base): """Base class of the actuators driving a spatial light modulator (SLM) through slmsuite The target of a move is a 2D array (``DataActuator`` with one 2D array, or one value that is spread over the whole @@ -48,8 +51,6 @@ class DAQ_Move_SlmsuiteBase(ShaperInterface, DAQ_Move_base): {'title': 'SLM Infos:', 'name': 'info', 'type': 'group', 'children': [ {'title': 'Width:', 'name': 'width', 'type': 'int', 'value': 0, 'readonly': True}, {'title': 'Height:', 'name': 'height', 'type': 'int', 'value': 0, 'readonly': True}, - {'title': 'Pixel size x (um):', 'name': 'pixel_size_x', 'type': 'float', 'value': 0., 'readonly': True}, - {'title': 'Pixel size y (um):', 'name': 'pixel_size_y', 'type': 'float', 'value': 0., 'readonly': True}, {'title': 'Grey levels:', 'name': 'levels', 'type': 'int', 'value': 0, 'readonly': True}, ]}, {'title': 'Wavelength (nm):', 'name': 'wavelength_nm', 'type': 'float', @@ -59,6 +60,7 @@ class DAQ_Move_SlmsuiteBase(ShaperInterface, DAQ_Move_base): 'tip': 'Add the wavefront correction loaded in slmsuite (if any) to the displayed phases'}, {'title': 'Input as grey levels:', 'name': 'input_as_grey_levels', 'type': 'bool', 'value': False, 'tip': 'Interpret the received arrays as grey levels instead of phases in radians'}, + SHAPER_GEOMETRY, ] params = common_slm_params + comon_parameters_fun(is_multiaxes, _axis_names, epsilon=_epsilons) @@ -83,23 +85,15 @@ def ini_stage(self, controller=None): height, width = self.controller.shape self.settings.child('info', 'width').setValue(width) self.settings.child('info', 'height').setValue(height) - pixel_size_x, pixel_size_y = self.controller.pitch_um - self.settings.child('info', 'pixel_size_x').setValue(pixel_size_x) - self.settings.child('info', 'pixel_size_y').setValue(pixel_size_y) + geometry = self.settings.child('shaper_geometry') + for name, value in zip(('width', 'height', 'pixel_size_x', 'pixel_size_y'), (width, height, + *self.controller.pitch_um)): + geometry.child(name).setValue(value) self.settings.child('info', 'levels').setValue(self.controller.bitresolution) self.current_value = DataActuator(self._title, data=[np.zeros(self.controller.shape)]) return f'{self.get_slm_type()} SLM {width}x{height} pixels', True - def get_shaper_geometry(self): - """Number of pixels and pixel size (um) from slmsuite, see ShaperInterface of the BeamShaping extension""" - height, width = self.controller.shape - size_x, size_y = self.controller.pitch_um - if ShaperGeometry is None: - return SimpleNamespace(width=width, height=height, shape=(height, width), - pixel_size_x=size_x, pixel_size_y=size_y, pixel_size=(size_x, size_y)) - return ShaperGeometry(width, height, size_x, size_y) - def close(self): if self.is_master and self.controller is not None: self.controller.close() diff --git a/tests/test_slmsuite_plugins.py b/tests/test_slmsuite_plugins.py index ee911e5..b444348 100644 --- a/tests/test_slmsuite_plugins.py +++ b/tests/test_slmsuite_plugins.py @@ -65,13 +65,16 @@ def test_not_a_dict(self): parse_kwargs('[1, 2]') +def _geometry(plugin): + group = plugin.settings.child('shaper_geometry') + return [group[name] for name in ('width', 'height', 'pixel_size_x', 'pixel_size_y')] + + class TestShaperGeometry: def test_simulated(self, slm): - geometry = slm.get_shaper_geometry() - assert (geometry.width, geometry.height) == (WIDTH, HEIGHT) - assert geometry.shape == (HEIGHT, WIDTH) - assert geometry.pixel_size_x > 0 and geometry.pixel_size_y > 0 - assert slm.settings['info', 'pixel_size_x'] == geometry.pixel_size_x + width, height, size_x, size_y = _geometry(slm) + assert (width, height) == (WIDTH, HEIGHT) + assert size_x > 0 and size_y > 0 def test_pitch_from_slmsuite(self): controller = SlmController('SimulatedSLM', resolution=(WIDTH, HEIGHT), pitch_um=(5., 6.)) @@ -85,8 +88,7 @@ def test_pitch_given_once(self): def test_fake_controller(self, qapp, fake_controller): plugin = make_actuator(DAQ_Move_SlmsuiteMeadowlark) - geometry = plugin.get_shaper_geometry() - assert (geometry.width, geometry.height, geometry.pixel_size) == (6, 4, (8., 9.)) + assert _geometry(plugin) == [6, 4, 8., 9.] plugin.close() From d2cc63deda3e4ebd34b2eb0eae0ca14e76aa85f1 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 14:15:39 +0000 Subject: [PATCH 3/4] Use the shaper contract of pymodaq_plugins_utils and report the internal calibration (slmsuite LUT, Meadowlark) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01CAhZwmbyCSpSgfTyicUxuS --- pyproject.toml | 1 + .../hardware/slm_controller.py | 6 +++++ .../resources/daq_move_SlmsuiteBase.py | 22 +++++-------------- tests/test_slmsuite_plugins.py | 17 ++++++++++++++ 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 57072c0..1f2af43 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ dependencies = [ "pymodaq_utils>=5.3.1", "pymodaq_gui>=5.3.0", "pymodaq_data>=5.3.0", + "pymodaq_plugins_utils>=5.3.9", "slmsuite>=0.5.0", ] diff --git a/src/pymodaq_plugins_slmsuite/hardware/slm_controller.py b/src/pymodaq_plugins_slmsuite/hardware/slm_controller.py index 45727ac..299c44e 100644 --- a/src/pymodaq_plugins_slmsuite/hardware/slm_controller.py +++ b/src/pymodaq_plugins_slmsuite/hardware/slm_controller.py @@ -55,6 +55,12 @@ def pitch_um(self) -> tuple[float, float]: pitch = np.broadcast_to(np.asarray(self.slm.pitch_um, dtype=float), (2,)) return float(pitch[0]), float(pitch[1]) + @property + def has_internal_calibration(self) -> bool: + """True if the SLM converts a phase to grey levels with a calibration of its own: a lookup table known by + slmsuite, or the one the Meadowlark SDK loads from the hardware""" + return self.slm_type == 'Meadowlark' or getattr(self.slm, 'lut', None) is not None + @property def bitresolution(self) -> int: """The number of grey levels of the SLM""" diff --git a/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py b/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py index 4741ca6..9c70b18 100644 --- a/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py +++ b/src/pymodaq_plugins_slmsuite/resources/daq_move_SlmsuiteBase.py @@ -9,22 +9,14 @@ from pymodaq_utils.utils import ThreadCommand from pymodaq_utils.logger import set_logger, get_module_name +from pymodaq_plugins_utils.hardware.shaper import ModulatorType, shaper_params, fill_shaper_settings + from pymodaq_plugins_slmsuite import config from pymodaq_plugins_slmsuite.hardware.slm_controller import SlmController logger = set_logger(get_module_name(__file__)) -# Read by the BeamShaping extension (group name and children names are the contract, see -# pymodaq_plugins_beam_shaping.utilities.shaper.shaper_geometry_params), sizes in micrometer -SHAPER_GEOMETRY = {'title': 'Shaper geometry:', 'name': 'shaper_geometry', 'type': 'group', 'children': [ - {'title': 'Width (pixels):', 'name': 'width', 'type': 'int', 'value': 0, 'readonly': True}, - {'title': 'Height (pixels):', 'name': 'height', 'type': 'int', 'value': 0, 'readonly': True}, - {'title': 'Pixel size x (um):', 'name': 'pixel_size_x', 'type': 'float', 'value': 0., 'readonly': True}, - {'title': 'Pixel size y (um):', 'name': 'pixel_size_y', 'type': 'float', 'value': 0., 'readonly': True}, -]} - - class DAQ_Move_SlmsuiteBase(DAQ_Move_base): """Base class of the actuators driving a spatial light modulator (SLM) through slmsuite @@ -60,8 +52,7 @@ class DAQ_Move_SlmsuiteBase(DAQ_Move_base): 'tip': 'Add the wavefront correction loaded in slmsuite (if any) to the displayed phases'}, {'title': 'Input as grey levels:', 'name': 'input_as_grey_levels', 'type': 'bool', 'value': False, 'tip': 'Interpret the received arrays as grey levels instead of phases in radians'}, - SHAPER_GEOMETRY, - ] + ] + shaper_params() params = common_slm_params + comon_parameters_fun(is_multiaxes, _axis_names, epsilon=_epsilons) def ini_attributes(self): @@ -85,10 +76,9 @@ def ini_stage(self, controller=None): height, width = self.controller.shape self.settings.child('info', 'width').setValue(width) self.settings.child('info', 'height').setValue(height) - geometry = self.settings.child('shaper_geometry') - for name, value in zip(('width', 'height', 'pixel_size_x', 'pixel_size_y'), (width, height, - *self.controller.pitch_um)): - geometry.child(name).setValue(value) + fill_shaper_settings(self.settings, self.get_slm_type(), width, height, *self.controller.pitch_um, + modulator_type=ModulatorType.PHASE, + has_internal_calibration=self.controller.has_internal_calibration) self.settings.child('info', 'levels').setValue(self.controller.bitresolution) self.current_value = DataActuator(self._title, data=[np.zeros(self.controller.shape)]) diff --git a/tests/test_slmsuite_plugins.py b/tests/test_slmsuite_plugins.py index b444348..7676ad9 100644 --- a/tests/test_slmsuite_plugins.py +++ b/tests/test_slmsuite_plugins.py @@ -70,6 +70,11 @@ def _geometry(plugin): return [group[name] for name in ('width', 'height', 'pixel_size_x', 'pixel_size_y')] +def _properties(plugin): + group = plugin.settings.child('shaper_properties') + return [group[name] for name in ('name', 'has_internal_calibration', 'use_internal_calibration')] + + class TestShaperGeometry: def test_simulated(self, slm): width, height, size_x, size_y = _geometry(slm) @@ -89,8 +94,19 @@ def test_pitch_given_once(self): def test_fake_controller(self, qapp, fake_controller): plugin = make_actuator(DAQ_Move_SlmsuiteMeadowlark) assert _geometry(plugin) == [6, 4, 8., 9.] + assert _properties(plugin) == ['Meadowlark', True, True] plugin.close() + def test_no_internal_calibration_by_default(self, slm): + assert _properties(slm) == ['SimulatedSLM', False, False] + + def test_lut_is_an_internal_calibration(self): + controller = SlmController('SimulatedSLM', resolution=(WIDTH, HEIGHT)) + assert not controller.has_internal_calibration + controller.slm.lut = np.arange(256) + assert controller.has_internal_calibration + controller.close() + class TestSimulatedActuator: def test_infos(self, slm): @@ -155,6 +171,7 @@ def __init__(self, slm_type, **kwargs): self.slm_type, self.kwargs = slm_type, kwargs self.shape = (4, 6) self.pitch_um = (8., 9.) + self.has_internal_calibration = slm_type == 'Meadowlark' self.bitresolution = 256 FakeController.instances.append(self) From 11cb00bfd09a00bbd725390fb8c388c4ca1fe3a8 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 14:16:00 +0000 Subject: [PATCH 4/4] Fix the pymodaq_plugins_utils version floor (5.3.4 is the first release with the shaper contract) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01CAhZwmbyCSpSgfTyicUxuS --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1f2af43..a5eefc6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ dependencies = [ "pymodaq_utils>=5.3.1", "pymodaq_gui>=5.3.0", "pymodaq_data>=5.3.0", - "pymodaq_plugins_utils>=5.3.9", + "pymodaq_plugins_utils>=5.3.4", "slmsuite>=0.5.0", ]