Title: Draft abc.SLM feedback wanted · Issue #302 · python-microscope/microscope · GitHub
Open Graph Title: Draft abc.SLM feedback wanted · Issue #302 · python-microscope/microscope
X Title: Draft abc.SLM feedback wanted · Issue #302 · python-microscope/microscope
Description: I implemented a draft of an abc.SLM in here. Very much like abc.DM Code below. Any comments or feedback? class SpatialLightModulator(TriggerTargetMixin, Device, metaclass=abc.ABCMeta): """Base class for Spatial Light Modulators (SLM). Th...
Open Graph Description: I implemented a draft of an abc.SLM in here. Very much like abc.DM Code below. Any comments or feedback? class SpatialLightModulator(TriggerTargetMixin, Device, metaclass=abc.ABCMeta): """Base clas...
X Description: I implemented a draft of an abc.SLM in here. Very much like abc.DM Code below. Any comments or feedback? class SpatialLightModulator(TriggerTargetMixin, Device, metaclass=abc.ABCMeta): ""...
Opengraph URL: https://github.com/python-microscope/microscope/issues/302
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Draft abc.SLM feedback wanted","articleBody":"I implemented a draft of an abc.SLM in [here](https://github.com/juliomateoslangerak/microscope/tree/implement_SLM). Very much like abc.DM\r\n\r\nCode below. Any comments or feedback?\r\n\r\n```python\r\nclass SpatialLightModulator(TriggerTargetMixin, Device, metaclass=abc.ABCMeta):\r\n \"\"\"Base class for Spatial Light Modulators (SLM).\r\n\r\n This class is very similar to the Deformable Mirrors abc. We are trying\r\n to keep nomenclature consistent. The main differences are that the shape\r\n of the patterns are different and that we need to provide wavelengths\r\n along the patterns.\r\n\r\n Similarly to deformable mirrors, there is no method to reset\r\n or clear a deformable mirror. For the sake of uniformity, it is better for\r\n python-microscope users to pass the pattern they want, probably a\r\n pattern that flattens the SLM.\r\n\r\n The private properties `_patterns` and `_pattern_idx` are\r\n initialized to `None` to support the queueing of patterns and\r\n software triggering.\r\n \"\"\"\r\n\r\n @abc.abstractmethod\r\n def __init__(self, **kwargs) -\u003e None:\r\n super().__init__(**kwargs)\r\n self._patterns: typing.Optional[numpy.ndarray] = None\r\n self._pattern_idx: int = -1\r\n self._wavelengths: typing.Optional[typing.List[int]] = None\r\n\r\n @abc.abstractmethod\r\n def _get_shape(self) -\u003e typing.Tuple[int, int]:\r\n \"\"\"Get the shape of the SLM in pixels as a (width, height) tuple.\"\"\"\r\n raise NotImplementedError\r\n\r\n def get_shape(self) -\u003e typing.Tuple[int, int]:\r\n \"\"\"Return a tuple of `(width, height)` corresponding to the shape of the SLM\"\"\"\r\n return self._get_shape()\r\n\r\n def _validate_patterns(self, patterns: numpy.ndarray, wavelengths: typing.Union[list[int], int]) -\u003e None:\r\n \"\"\"Validate the shape of a series of patterns.\r\n\r\n Only validates the shape of the patterns, not if the values\r\n are actually in the [0 1] range. If some hardware is unable\r\n to handle values outside their defined range (most will simply\r\n clip them), then it's the responsibility of the subclass to do\r\n the clipping before sending the values.\r\n\r\n \"\"\"\r\n if 2 \u003e patterns.ndim \u003e 3:\r\n raise ValueError(\r\n \"PATTERNS has %d dimensions (must be 2 or 3)\" % patterns.ndim\r\n )\r\n\r\n if patterns.ndim == 3:\r\n if not isinstance(wavelengths, list) or len(wavelengths) != patterns.shape[0]:\r\n raise ValueError(\r\n \"The length of the wavelengths list %d does not match the number of patterns to load %d\"\r\n % (len(wavelengths), patterns.shape[0],)\r\n )\r\n elif not isinstance(wavelengths, int):\r\n raise ValueError(\r\n \"The wavelength should be an integer when loading a single pattern\"\r\n )\r\n\r\n if (patterns.shape[-2], patterns.shape[-1]) != self.get_shape():\r\n raise ValueError(\r\n \"PATTERNS shape %s does not match the SLM's shape %s\"\r\n % ((patterns.shape[-2], patterns.shape[-1],), self.get_shape(),)\r\n )\r\n\r\n @abc.abstractmethod\r\n def _do_apply_pattern(self, pattern: numpy.ndarray, wavelength: int) -\u003e None:\r\n raise NotImplementedError()\r\n\r\n def apply_pattern(self, pattern: numpy.ndarray, wavelength: int) -\u003e None:\r\n \"\"\"Apply this pattern.\r\n\r\n Args:\r\n pattern: A 'XY' ndarray with the phases to be loaded into the SLM. The phases have to be\r\n in the range [0, 1]. 0=0pi and 1=2pi\r\n wavelength: The wavelength to which the SLM has to be calibrated for that pattern\r\n\r\n Raises:\r\n microscope.IncompatibleStateError: if device trigger type is\r\n not set to software.\r\n\r\n \"\"\"\r\n if self.trigger_type is not microscope.TriggerType.SOFTWARE:\r\n # An alternative to error is to change the trigger type,\r\n # apply the pattern, then restore the trigger type, but\r\n # that would clear the queue on the device. It's better\r\n # to have the user specifically do it. See issue #61.\r\n raise microscope.IncompatibleStateError(\r\n \"apply_pattern requires software trigger type\"\r\n )\r\n self._validate_patterns(pattern, [wavelength])\r\n self._do_apply_pattern(pattern, wavelength)\r\n\r\n def queue_patterns(self, patterns: numpy.ndarray, wavelengths: typing.List[int]) -\u003e None:\r\n \"\"\"Send a set of patterns to the SLM.\r\n\r\n Args:\r\n patterns: An `NXY` elements array of phase values in the range\r\n [0, 1]. 0=0pi and 1=2pi. N is the number of phases to add the queue\r\n wavelengths: A list of wavelengths (in nm) of length N\r\n\r\n A convenience fallback is provided for software triggering is provided.\r\n\r\n \"\"\"\r\n self._validate_patterns(patterns, wavelengths)\r\n self._patterns = patterns\r\n self._wavelengths = wavelengths\r\n self._pattern_idx = -1 # none is applied yet\r\n # TODO: What is the function to run the patterns in the queue? enable?\r\n\r\n def _do_trigger(self) -\u003e None:\r\n \"\"\"Convenience fallback.\r\n\r\n This only provides a convenience fallback for devices that\r\n don't support queuing multiple patterns and software trigger,\r\n i.e., devices that take only one pattern at a time. This is\r\n not the case of most devices.\r\n\r\n Devices that support queuing patterns, should override this\r\n method.\r\n\r\n .. todo::\r\n\r\n Instead of a convenience fallback, we should have a\r\n separate mixin for this.\r\n\r\n \"\"\"\r\n if self._patterns is None:\r\n raise microscope.DeviceError(\"no pattern queued to apply\")\r\n self._pattern_idx += 1\r\n self.apply_pattern(self._patterns[self._pattern_idx, :], self._wavelengths[self._pattern_idx])\r\n\r\n def trigger(self) -\u003e None:\r\n \"\"\"Apply the next pattern in the queue.\"\"\"\r\n # This is just a passthrough to the TriggerTargetMixin class\r\n # and only exists for the docstring.\r\n return super().trigger()\r\n```","author":{"url":"https://github.com/juliomateoslangerak","@type":"Person","name":"juliomateoslangerak"},"datePublished":"2024-06-11T15:36:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/302/microscope/issues/302"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7031415c-ff42-ad0b-845e-b2a52d6ea545 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AB92:25DF2:C809AD:10371F3:699200A0 |
| html-safe-nonce | 6c73b1d965b124e0475d2a989ffad12e06ecc18079aa2731cb58d4500eb3e66a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQjkyOjI1REYyOkM4MDlBRDoxMDM3MUYzOjY5OTIwMEEwIiwidmlzaXRvcl9pZCI6IjczMDYyMjIxNjUyNDU5NTIxNjAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a6f0d1bbe7cf8cb29791b8a9a1c433328efc127f61756a682f65b7f4ab7f3abf |
| hovercard-subject-tag | issue:2346738959 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-microscope/microscope/302/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5249e6362751a51e38fa35768d42743cda3499d7f39b4a42193c5d6ba53ad9a1/python-microscope/microscope/issues/302 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5249e6362751a51e38fa35768d42743cda3499d7f39b4a42193c5d6ba53ad9a1/python-microscope/microscope/issues/302 |
| og:image:alt | I implemented a draft of an abc.SLM in here. Very much like abc.DM Code below. Any comments or feedback? class SpatialLightModulator(TriggerTargetMixin, Device, metaclass=abc.ABCMeta): """Base clas... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | juliomateoslangerak |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| go-import | github.com/python-microscope/microscope git https://github.com/python-microscope/microscope.git |
| octolytics-dimension-user_id | 58992974 |
| octolytics-dimension-user_login | python-microscope |
| octolytics-dimension-repository_id | 68124661 |
| octolytics-dimension-repository_nwo | python-microscope/microscope |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 68124661 |
| octolytics-dimension-repository_network_root_nwo | python-microscope/microscope |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 848bc6032dcc93a9a7301dcc3f379a72ba13b96e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width