slmsuite

repository·main·Indexed 41 days ago

https://github.com/holodyne/slmsuite

A high-performance Python library for programmable optics, spatial light modulator (SLM) control, and holography. It features GPU-accelerated beamforming algorithms via cupy, automated wavefront calibration, and a unified hardware interface for SLMs and cameras. The suite includes tools for computational holography, such as iterative phase retrieval (Gerchberg-Saxton), coordinate transformations between Fourier and image space, and Zernike aberration correction.

Tokens
2.8K
Snippets
7
Records
19
Agent score
52%

What's inside slmsuite

  1. Overview of slmsuite capabilities

    main

    slmsuite is a software suite designed for high-precision experimental holography using Spatial Light Modulators (SLMs) and cameras. It aims to simplify the process of projecting computer-generated holograms that are compensated for non-ideal experimental conditions.

    Key features include:

    • Hardware Control: A unified interface for controlling various SLMs and cameras.
    • Coordinate Transformations: Automated transformations between Fourier-domain (SLM) and image-space (camera) coordinates.
    • Wavefront Calibration: Automated calibration to compensate for aberrations in the SLM imaging train.
    • GPU-Accelerated Algorithms: A suite of iterative phase retrieval algorithms (e.g., weighted Gerchberg-Saxton) that support experimental feedback.
    • Performance Monitoring: Automated evaluation metrics for diffraction efficiency and image tolerances.
  2. What is slmsuite?

    main

    slmsuite is a Python package designed for high-precision spatial light modulator (SLM) control and holography. It provides tools for advanced optical manipulation, including:

    • Spot-specific Zernike aberration correction: Optimizing spot imaging across a field of view by correcting for different aberrations experienced along different optical paths.
    • Advanced Holography: Features such as camera feedback and phase flattening to create crisp, accurate holograms.
    • Multi-objective optimization: Capabilities for multi-plane holography (focus, color, or basis) and simultaneous optimization of spot and image objectives.
  3. Overview of slmsuite features

    main

    slmsuite is a high-performance library for Spatial Light Modulator (SLM) control and holography. It combines GPU-accelerated beamforming with optimized hardware control and automated calibration.

    Core Capabilities

    • Computational Holography: GPU-accelerated iterative phase retrieval algorithms (e.g., Gerchberg-Saxton, weighted GS, or phase-stationary WGS).
    • Hardware Control: A unified interface for working with various SLMs and cameras.
    • Automated Calibration:
      • Fourier-to-image-space coordinate transformations.
      • Wavefront calibration to improve flatness maps or compensate for aberrations.
    • Optical Optimization:
      • Optimized optical focus and spot arrays using camera feedback and automated statistics.
      • Mixed region amplitude freedom to optimize hologram performance in high-interest areas while ignoring unused far-field regions.
    • Structured Light Toolboxes: Tools for imprinting sectioned phase masks, SLM unit conversion, and data padding/unpadding.
  4. Explore slmsuite example categories

    main

    The slmsuite package provides several categories of examples ranging from basic usage to advanced applications. Available example modules include:

    • Computational Holography: Focuses on theoretical and mathematical modeling of holographic patterns.
    • Experimental Holography: Demonstrates practical implementation and measurement of holograms.
    • Wavefront Calibration: Techniques for characterizing and correcting wavefront errors.
    • Structured Light: Applications involving the generation and use of structured light patterns.
    • Zernike Holography: Specialized holographic techniques using Zernike polynomials.
    • Multipoint Calibration: Methods for calibrating multiple points or sensors simultaneously.
    • Multiplane Holography: Advanced applications involving multiple planes of light interaction.
  5. Understand the slmsuite module structure

    main

    The slmsuite package is organized into two primary functional domains:

    1. Holography (slmsuite.holography): Contains algorithms for optimizing nearfield phase profiles (applied to SLMs) to achieve desired farfield results (measured by cameras). This module includes:

      • algorithms: Core optimization methods.
      • toolbox: Quality-of-life support methods.
      • analysis: Analysis tools.
    2. Hardware (slmsuite.hardware): Provides interfaces for controlling physical devices used in experimental holography. This module includes:

      • slms: Spatial Light Modulator interfaces.
      • cameras: Camera interfaces.
      • cameraslms: Unification of camera and SLM interfaces.
      • remote: Support for hosting hardware on remote servers.
  6. GPU acceleration with cupy in slmsuite

    main

    slmsuite utilizes cupy to accelerate core holography algorithms, specifically those involving Fast Fourier Transforms (FFTs) on large arrays.

    • Performance: Using cupy can provide approximately two orders of magnitude speedup for standard optimizations compared to CPU-based implementations.
    • Fallback Mechanism: cupy acts as a drop-in replacement for numpy and scipy. If a GPU is not detected or available, the library falls back to using numpy and scipy to ensure functionality, albeit at lower speeds.
  7. Data-Order Conventions in slmsuite

    main

    To maintain compatibility with the numpy ecosystem, slmsuite follows these data-ordering conventions:

    • Images/Arrays: Uses the inverted (h, w) (height, width) form for shape and indexing.
    • Vectors: Uses the standard Cartesian (x, y) form.
    • Vector Lists: A list of $N$ vectors with dimension $D$ is represented with shape (D, N). This allows for direct linear transformations using a (D, D) matrix.
    • Image Stacks: Stacks of $W imes H$ images are stored with the shape (N, H, W) (number of images, height, width).
  8. Install slmsuite for Jupyter notebooks

    main

    It is highly recommended to use Jupyter notebooks for interactive computing with slmsuite. To install the recommended Jupyter-related packages, run:

    pip install -e ".[jupyter]"

    Important Note on Plotting: If you are not using Jupyter, the default matplotlib plots will block further execution. To avoid this, use plot=False flags on functions when calling them in a standard Python script.

  9. Access slmsuite documentation and examples

    main

    Comprehensive resources for using slmsuite are available online:

  10. Install slmsuite

    main

    You can install slmsuite either via the stable version on PyPI or by installing the latest development version directly from GitHub.

    Install stable version

    Use pip to install the stable release from PyPI:

    pip install slmsuite

    Install latest version from GitHub

    To use the most recent development version, install directly from the GitHub repository:

    pip install git+https://github.com/holodyne/slmsuite
    pip install slmsuite
  11. Install optional hardware and feature dependencies for slmsuite

    main

    slmsuite uses optional extras to manage hardware-specific and feature-specific dependencies. You can install them using the following commands from within the package directory:

    GPU Acceleration

    Highly recommended for GPU-accelerated holography. Installs cupy.

    pip install -e ".[gpu]"

    Note: If you have a specific CUDA version, you may need to install a matching cupy version (e.g., pip install cupy-cudaYYx).

    Gradients (PyTorch)

    Required for conjugate gradient hologram optimization. Uses cupy-torch interoperability to pass data without copying overhead.

    pip install -e ".[torch]"

    Cameras

    Installs drivers and libraries for various camera interfaces (e.g., instrumental-lib, pylablib, pymmcore, pypylon, etc.).

    pip install -e ".[cameras]"

    SLMs

    Installs pyglet and other requirements for Spatial Light Modulators.

    pip install -e ".[slms]"

    Image Saving

    Installs imageio, pyav, and pygifsicle for handling various image and video formats.

    pip install -e ".[images]"
    pip install -e ".[gpu]"
    pip install -e ".[torch]"
    pip install -e ".[cameras]"
    pip install -e ".[slms]"
    pip install -e ".[images]"