slmsuite.holography.toolbox.convert_vector#

convert_vector(vector, from_units='norm', to_units='norm', hardware=None, shape=None)[source]#

Helper function for vector unit conversions in the \(k\)-space of the SLM.

Currently supported units:

  • "rad", "mrad", "deg"

    Angle at which light is blazed in various units. The small angle approximation is assumed.

  • "norm", "kxy"

    Blaze \(k_x\) normalized to wavenumber \(k = 2\pi/\lambda\), i.e. \(\frac{k_x}{k}\). Equivalent to radians "rad" in the small angle approximation. This is the default slmsuite unit.

  • "knm"

    Computational blaze units for a given Fourier domain shape. This corresponds to integer points on the grid of this (potentially padded) SLM’s Fourier transform. See Hologram. The "knm" basis is centered at shape/2, unlike all of the other units.

  • "freq"

    Pixel frequency of a grating producing the blaze. e.g. 1/16 is a grating with a period of 16 pixels. Under these units, the edge of \(k\)-space is at \(\pm 0.5\), which makes it useful to program in fractions of the SLM’s space.

  • "lpmm"

    Line pairs per mm or lines per mm of a grating producing the blaze. This unit is commonly used to define static diffraction gratings used in spectrometers.

  • "zernike"

    The phase coefficients in radians of the tilt zernike terms \(x = Z_2 = Z_1^1\) and \(y = Z_1 = Z_1^{-1}\) necessary to produce a given blaze. The coefficients of these terms are used as weights multiplied directly with the normalized Zernike functions zernike_sum(). For instance, a weight coefficient of \(\pi\) would produce a wavefront offset of \(\pm\pi\) across the unit disk.

    These functions are defined within the unit disk, and canonically have amplitude of \(\pm 1\) at the edges. The size of the disk when scaled onto the SLM is pulled from the SLM’s aperture (see zernike_scaling and fit_aperture()). Requires a SLM or FourierSLM to be passed to hardware.

  • "ij"

    Camera sensor pixel units, the coordinates of the image array returned by get_image() using numpy img[y, x] convention. When a WOI or binning is applied, the origin is shifted and units are scaled accordingly. Requires a FourierSLM to be passed to hardware, unless converting only between camera units (see "ijraw"), in which case a Camera suffices. See kxyslm_to_ijcam() and ijcam_to_kxyslm().

  • "ijraw"

    Raw camera sensor pixel units: the unbinned, un-WOI’d, untransformed coordinate system of the physical sensor, as opposed to "ij" which lives in the WOI-, binning-, and orientation-applied frame of the returned image. Requires a Camera (or FourierSLM) to be passed to hardware. The mapping to "ij" is the camera’s current window, binning, and orientation.

  • "m", "cm", "mm", "um", "nm"

    Camera position in metric length units, relative to the origin of the camera (potentially with WOI applied). When a WOI or binning is applied, the origin is shifted and units are scaled accordingly. Requires a FourierSLM to be passed to hardware, along with knowledge of the camera pixel size pitch_um.

  • "mag_m", "mag_cm", "mag_mm", "mag_um", "mag_nm"

    Scales the corresponding metric length unit according to the value stored in mag to match the true dimensions of the experiment plane, as opposed to the camera plane. Requires a FourierSLM to be passed to hardware, along with knowledge of the camera pixel size pitch_um.

3D Vectors

If an array of 3D vectors is given, then the depth (\(z\)) direction is handled differently than the field (\(xy\)). Most units use the normalized focal power \(\frac{\lambda}{f}\) on the SLM necessary to produce a spot at the defined depth relative to the focal plane. There are a few units where this differs:

  • "zernike"

    The phase coefficient of the \(2(x^2 + y^2) - 1 = Z_4 = Z_2^0\) zernike focus term necessary to focus at the given depth.

  • "ij"

    True cartesian distance relative to the camera plane in camera pixels. Cameras with rectangular (anisotropic) pixels average the pixel dimensions.

  • "ijraw"

    True cartesian distance relative to the camera plane in raw (unbinned) sensor pixels. This differs from "ij" by the isotropic binning scale.

  • "m", "cm", "mm", "um", "nm"

    True cartesian distance relative to the camera plane in metric units.

  • "mag_m", "mag_cm", "mag_mm", "mag_um", "mag_nm"

    True cartesian distance relative to the experiment plane in metric units. Importantly, \(x\) and \(y\) are divided by mag, while \(z\) is divided by its square, the longitudinal magnification between planes of equal refractive index.

Some of these units will not make sense in a system with anisotropic focusing, for instance due to cylindrical lenses in the optical train.

Warning

The units "freq", "knm", and "lpmm" depend on SLM pixel size, so an SLM should be passed to hardware (otherwise returns an array of nan values). The unit "zernike" also requires an SLM. The unit "knm" additionally requires the shape of the computational space. If not included when hardware is passed, shape=slm.shape is assumed. The units "ij", "um", "mag_um", and related refer to distance on the camera and require calibration data stored in a FourierSLM, so this must be passed to hardware. The exception is conversions only between camera units (e.g. "ij", "ijraw", "um"), which require no Fourier calibration; a bare Camera may be passed to hardware in this case. The "mag_..." units still require a FourierSLM (for its mag).

Parameters:
  • vector (array_like) – Vectors for which we want to convert units, from from_units to to_units. Processed according to format_2vectors(). Can be shape (2, N) or (3, N).

  • from_units (str) – Units which we are converting between. See the listed units above for options. Defaults to "norm".

  • to_units (str) – Units which we are converting between. See the listed units above for options. Defaults to "norm".

  • hardware (SLM OR Camera OR FourierSLM OR None) – Relevant hardware to pull calibration data from in the case of "freq", "knm", "lpmm", or "zernike". If FourierSLM, the unit "ij" and other length units can be processed too. If a bare Camera, conversions only between camera units (e.g. "ij" and "ijraw") are supported.

  • shape ((int, int) OR None) – Shape of the computational SLM space. Needed for "knm". Defaults to slm.shape if hardware is not None.

Returns:

vector_converted – Result of the unit conversion, in the cleaned format of format_2vectors().

Return type:

numpy.ndarray