slmsuite.hardware.slms.santec.Santec#

class Santec(slm_number=1, display_number=2, bitdepth=10, wav_um=1, pitch_um=(8, 8), **kwargs)[source]#

Bases: SLM

Interfaces with Santec SLMs.

slm_number#

USB port number assigned by Santec SDK.

Type:

int

display_number#

Display number assigned by Santec SDK.

Type:

int

optionboard_id#

ID of the option board

Type:

str

driveboard_id#

ID of the drive board

Type:

str

product_code_id#

Product code of the device

Type:

str

Methods

close

See SLM.close().

fit_aperture

Fits the SLM's aperture to the measured source amplitude distribution in source ["amplitude"].

fit_source_amplitude

Deprecated.

get_error

Read the drive board and option board errors.

get_log

Return this object's log records (only), as a list of plain-text strings.

get_point_spread_function_knm

Fourier transforms the wavefront calibration's measured amplitude to directly compute the expected diffraction-limited performance of the system in "knm" space.

get_realized_phase

The phase the SLM shows for phase: quantized to its bitresolution levels exactly as set_phase() quantizes it (through lut when a gamma is set), in radians wrapped to \([0, 2\pi)\).

get_spot_radius_kxy

Approximates the \(1/e\) amplitude (\(1/e^2\) power) radius of farfield spots in the "kxy" basis: \(1 / (\pi w)\) for a Gaussian source of \(1/e\) amplitude radius \(w =\) source_radius.

get_status

Gets SLM_STATUS return from a Santec SLM and parses the result.

get_temperature

Read the drive board and option board temperatures.

info

Discovers the names of all the displays.

live

Creates and displays a live viewer.

load_csv

Write the phase image contained in a .csv file to the SLM.

load_phase

Loads display from a file and writes to the SLM.

load_vendor_phase_correction

Load phase correction provided by Santec from file, setting "phase" in source.

log_state

Log the current values of all tracked attributes.

pickle

Returns a dictionary containing selected attributes of this class.

plot

Plots the provided phase.

plot_gamma

Plots gamma, the measured phase response as a function of grayscale level.

plot_source

Plots measured or simulated amplitude and phase distribution of the SLM illumination.

save

Saves the dictionary returned from pickle() to a file like "path/name_id.h5".

save_phase

Saves phase and display to a file like "path/name_id.h5".

segment

Splits the area of the SLM into a number of segments.

set_aperture

Sets the SLM's aperture which defines the working coordinate frame (grid centering), the Zernike lateral scaling (zernike_scaling), the in-use mask (aperture_mask), and the effective (masked) source amplitude and phase.

set_gamma

Sets lut, the lookup table mapping a desired phase onto the grayscale level which best realizes it, from a measured phase response gamma.

set_input_trigger

(Not supported by this SLM.) Configures the input trigger of the SLM, where an external electronic signal can synchronize the time at which the SLM updates its display.

set_output_trigger

(Not supported by this SLM.) Configures the output trigger of the SLM, where the SLM can send an electronic signal upon updating its display.

set_phase

Checks, cleans, and adds to data, then sends the data to the SLM and potentially waits for settle_time_s seconds.

set_source_analytic

In the absence of a proper wavefront calibration, sets source amplitude and phase using a fit_function from fitfunctions.

test

Test that the hardware behind this SLM responds to every core method.

write

Backwards-compatibility alias for set_phase().

Attributes

aperture_mask

Boolean mask (of shape) of the pixels inside aperture.

bitresolution

Number of levels, 2**bitdepth.

grid

\((x, y)\) coordinate meshgrids of the SLM's pixels in normalized units (wavelengths), measured from the aperture center.

height

Height in pixels, shape[0].

phase_scaling

Wavelength normalized to the phase range of the SLM, wav_um / wav_design_um.

pitch

Pixel pitch (x, y) normalized to wavelengths, pitch_um / wav_um.

resolution

(width, height) in pixels, the reverse of shape.

source_radius

The \(1/e\) field-amplitude source radius in normalized units, for structured beams such as laguerre_gaussian().

width

Width in pixels, shape[1].

zernike_scaling

The (x_scale, y_scale) lateral scaling mapping grid onto the Zernike unit disk, from aperture.

__init__(slm_number=1, display_number=2, bitdepth=10, wav_um=1, pitch_um=(8, 8), **kwargs)[source]#

Initializes an instance of a Santec SLM.

Parameters:
  • slm_number – See slm_number.

  • display_number – See display_number.

  • bitdepth (int) – Depth of SLM pixel well in bits. Defaults to 10.

  • wav_um (float) – Wavelength of operation in microns. Defaults to 1 μm.

  • pitch_um ((float, float)) – Pixel pitch in microns. Defaults to 8 micron square pixels.

  • **kwargs – See SLM.__init__() for permissible options.

Note

Santec SLMs can reconfigure their phase table: the correspondence between grayscale values and applied voltages. This is configured based upon the wavelength supplied to SLM.wav_design_um. This allows SLM.phase_scaling to be one if desired, and make use of optimized routines (see set_phase()). However, sometimes setting the phase table runs into issues, where the maximum value doesn’t correspond to exactly \(2\pi\) at the target wavelength. This is noted in the initialization, and the user should update SLM.wav_design_um or otherwise to avoid undesired behavior. wav_design_um defaults to wav_um if it is not given.

Caution

Santec defaults to 8 micron square pixel size SLM.pitch_um and 10-bit SLM.bitdepth. This is valid for SLM-200, SLM-210, and SLM-300, but may not be valid for future Santec models.

static info(verbose=True)[source]#

Discovers the names of all the displays. Checks all 8 possible supported by Santec’s SDK.

Parameters:

verbose (bool) – Whether to print the discovered information.

Returns:

The number and name of each potential display.

Return type:

list of (int, str) tuples

load_vendor_phase_correction(file_path, smooth=False, overwrite=True)[source]#

Load phase correction provided by Santec from file, setting "phase" in source.

Parameters:
  • file_path (str) – File path for the vendor-provided phase correction.

  • smooth (bool) – Whether to apply a Gaussian blur to smooth the data.

  • overwrite (bool) – Whether to overwrite the previous phase in source.

Note

This correction is only fully valid at the wavelength at which it was collected.

Returns:

source ["phase"], the Santec-provided phase correction.

Return type:

numpy.ndarray

close()[source]#

See SLM.close().

get_temperature()[source]#

Read the drive board and option board temperatures.

Returns:

Temperature in Celsius of the drive and option board

Return type:

(float, float)

get_error(raise_error=True, return_codes=False)[source]#

Read the drive board and option board errors.

Parameters:
  • raise_error (bool) – Whether to raise an error (if True) or a warning (if False) if error(s) are detected.

  • return_codes (bool) – Whether to return an error string or integer error codes (in (drive_error, option_error) form).

Returns:

List of errors.

Return type:

list of str OR (int, int)

get_status(raise_error=True)[source]#

Gets SLM_STATUS return from a Santec SLM and parses the result.

Parameters:

raise_error (bool) – Whether to raise an error (if True) or a warning (if False) when status is not SLM_OK.

Returns:

Status in (num, name, note) form.

Return type:

(int, str, str)

load_csv(filename)[source]#

Write the phase image contained in a .csv file to the SLM. This image should have the size of the SLM.

Parameters:

filename (str) – Path to the .csv file.

property aperture_mask[source]#

Boolean mask (of shape) of the pixels inside aperture.

property bitresolution[source]#

Number of levels, 2**bitdepth.

fit_aperture(method='moments', edge_level=0.1)[source]#

Fits the SLM’s aperture to the measured source amplitude distribution in source ["amplitude"]. Two radii are fit independently:

  • The circular aperture (pupil), which sets aperture_mask and zernike_scaling, is fit to the rolloff of the measured source power with image_aperture_fit(): its center is that of the circle which best fits the edge where the power falls off, and its radius is where the power has fallen to edge_level. Unlike the power centroid, this is not pulled toward bright regions inside the aperture, and edges which do not belong to the circle (such as a straight clip) are rejected.

  • The source_radius: the \(1/e\) field-amplitude radius (\(1/e^2\) in intensity) of the measured amplitude, analyzed via "moments" or least-squares "fit".

If no rolloff is found (for instance, for an unclipped Gaussian beam), the aperture is instead centered by method, and the pupil is placed where a Gaussian’s power falls to edge_level of its peak (\(\sqrt{\ln(1 / \text{edge\_level}) / 2}\) source radii, \(\approx 1.07\) for the default). A clip where the power has already fallen below about a tenth of its peak (for a Gaussian, beyond about 1.1 source radii) is not found as a rolloff; set such an aperture with set_aperture() instead.

If no source amplitude has been measured, the aperture is set to a circular aperture of source radius equal to a quarter of the smallest SLM extent.

Parameters:
  • method (str {"fit", "moments"}) – Whether to use moment calculations ("moments", faster) or a least-squares "fit" (more accurate) to determine the source radius, and the center when no rolloff is found.

  • edge_level (float) – Where on the rolloff to place the pupil edge, as a fraction in \((0, 1)\) of the way from the background to the power inside the aperture. Smaller values give a larger pupil which includes more of the rolloff; values near \(0.5\) place it near the steepest descent. The center does not depend on edge_level.

Returns:

The fitted aperture.

Return type:

Aperture

fit_source_amplitude(method='moments', extent_threshold=0.1, force=True)[source]#

Deprecated. Forwards to fit_aperture(); extent_threshold and force are ignored.

get_log(verbose=False)[source]#

Return this object’s log records (only), as a list of plain-text strings.

Parameters:

verbose (bool, optional) – If True, also print the records to the console.

get_point_spread_function_knm(padded_shape=None)[source]#

Fourier transforms the wavefront calibration’s measured amplitude to directly compute the expected diffraction-limited performance of the system in "knm" space.

Parameters:

padded_shape ((int, int) OR None) – The point spread function changes in resolution depending on the padding. Use this variable to provide this padding. If None, do not pad.

Returns:

The point spread function of shape padded_shape, on the SLM’s backend.

Return type:

numpy.ndarray OR cupy.ndarray

get_realized_phase(phase=None)[source]#

The phase the SLM shows for phase: quantized to its bitresolution levels exactly as set_phase() quantizes it (through lut when a gamma is set), in radians wrapped to \([0, 2\pi)\).

A 4-bit SLM realizes only 16 phases; this is what it displays, where phase is what was asked of it.

Parameters:

phase (array_like OR None) – Phase in radians, of any shape. Defaults to phase, the last phase written (including any wavefront correction).

Returns:

Float32 phase in radians, on the SLM’s backend.

Return type:

numpy.ndarray OR cupy.ndarray

get_spot_radius_kxy()[source]#

Approximates the \(1/e\) amplitude (\(1/e^2\) power) radius of farfield spots in the "kxy" basis: \(1 / (\pi w)\) for a Gaussian source of \(1/e\) amplitude radius \(w =\) source_radius.

Returns:

Radius of the farfield spot.

Return type:

float

property grid[source]#

\((x, y)\) coordinate meshgrids of the SLM’s pixels in normalized units (wavelengths), measured from the aperture center. This is the working coordinate frame that analytic phase functions (lenses, gratings, Zernike, …) are generated in. Of size shape. Read-only: it is derived from the immutable geometric grid and the aperture center.

Held on xp, so this is a cupy meshgrid for a cupy-backed SLM; pass it through slmsuite.misc.xp.as_numpy() where host memory is required. See the note on xp.

property height[source]#

Height in pixels, shape[0].

live(activate=None, widgets=True, backend='ipython', **kwargs)[source]#

Creates and displays a live viewer.

  • When used with a camera, the viewer displays the last image: the result of get_image() or the last image of get_images() whenever these methods are called. Averaging and HDR are displayed with the same color scaling as without.

  • When used with an SLM, the viewer displays the phase pattern currently on the SLM: the phase pattern passed to set_phase() whenever it is called.

The view itself is drawn either inside the notebook (backend="ipython") or in a resizable window of its own (backend="pyglet"), which also works from a plain script, where no notebook is available to draw into.

If True is passed to the widgets argument, this viewer is accompanied by a series of IPython widgets in the form of sliders and buttons for controlling the color scale, colormap, viewer scale, and live viewing, along with buttons to copy the current view to the clipboard or save it to a file, either as a .png of the view or an .h5 of the raw data. By toggling the Live widget button, a loop is created that continuously polls the camera for new images. This viewer can be used as a realtime camera monitor within the jupyter notebook. However, note that any user-execution will block the monitoring loop. Regardless, any image polling during the blocked period will still update the viewer, which provides useful active feedback for what is happening during the execution. Live mode is ignored for SLMs.

The viewer also supports zooming into a region of interest. With the Zoom widget enabled, scroll the mouse wheel to zoom in/out toward the cursor, click-drag to pan, and double-click to restore the full image; disabling Zoom also restores the full image. Clicking prints the source-image pixel coordinate under the cursor. These mouse interactions require the optional ipyevents package (pip install ipyevents); without it the viewer still functions normally. A pyglet window needs no such package, and zooms by default since it has no page to scroll over. It restores the full image on a right-click and carries keyboard shortcuts (esc close, r reset, c colormap, x crosshairs, l logarithmic, a autorange) so that it is usable without any widgets. The shortcuts that change color scaling take effect on the next frame. The Scale widget sizes the window itself, which keeps the image’s aspect ratio. Closing the window closes the viewer, as toggling live() would.

A viewer leaves its settings on the hardware when it closes, so calling live() again reopens with the same colormap, scaling, and crosshairs, and with the window where and how big it last was. Pass an argument to override any of them.

This limitation is imposed by the Python Global Interpreter Lock (GIL) which restricts operation to a single thread, especially operation connecting to a diverse set of camera and SLM hardware. We use asyncio to allow the realtime monitoring loop to be interrupted by user-execution (e.g. running a cell in jupyter), blocking until the execution is finished.

Parameters:
  • activate (bool OR None) – If True, creates a live viewer in the current cell, destroying any other attached viewer. If False, destroys any other attached viewer. If None, toggles the live viewer, destroying any attached viewer or creating one in the current cell if none is attached. Defaults to None.

  • widgets (bool OR str OR None) – The backend hosting the sliders and controls used to hone the display properties; one of "ipython". True selects the default and False displays no controls. Widgets need a notebook, so a "pyglet" view opened from a script goes without.

  • backend (str) – The backend drawing the view itself: "ipython" or "pyglet". The default is "ipython".

  • **kwargs – Options passed to the _ViewerObject to customize the default settings. These features will be made less hidden in the future. Most things are customizable via these keywords. For instance, the user can pass a custom list of colormaps to appear in the widget dropdown as cmap_options=.

load_phase(file_path=None, settle=False)[source]#

Loads display from a file and writes to the SLM. Logs a warning if the stored phase does not reproduce the stored display.

Parameters:
  • file_path (str OR None) – Full path to the phase file. If None, will search the current directory for a file with a name like name + '_phase'.

  • settle (bool OR float) – Whether to sleep for settle_time_s, or any number (integers included) of seconds to sleep instead.

Returns:

The file path that the phase was loaded from.

Return type:

str

Raises:

FileNotFoundError – If a file is not found.

log_state(level=10)[source]#

Log the current values of all tracked attributes.

Parameters:

level (int, optional) – Logging level. Defaults to logging.DEBUG.

property phase_scaling[source]#

Wavelength normalized to the phase range of the SLM, wav_um / wav_design_um. See wav_design_um.

pickle(attributes=True, metadata=True)[source]#

Returns a dictionary containing selected attributes of this class.

Parameters:
  • attributes (bool OR list of str) – If False, pickles only baseline attributes, usually single floats. If True, also pickles ‘heavy’ attributes such as large images and calibrations. If list of str, pickles the keys in the given list. By default, the chosen attributes should be things that can be written to .h5 files: scalars and lists of scalars.

  • metadata (bool) – If True, package the dictionary as the "__meta__" value of a superdictionary which also contains: "__version__", the current slmsuite version, "__time__", the time formatted as a date string, and "__timestamp__", the time formatted as a floating point timestamp. This information is used as standard metadata for calibrations and saving.

property pitch[source]#

Pixel pitch (x, y) normalized to wavelengths, pitch_um / wav_um. This value is more useful than pitch_um when considering conversions to \(k\)-space.

plot(phase=None, limits=None, title='Phase', ax=None, cbar=True, aperture=True)[source]#

Plots the provided phase.

Parameters:
  • phase (ndarray OR None) – Phase to be plotted. If None, grabs the last written phase from the SLM.

  • limits (None OR float OR [[float, float], [float, float]]) – Scales the limits by a given factor or uses the passed limits directly.

  • title (str) – Title the axis.

  • ax (matplotlib.pyplot.axis OR None) – Axis to plot upon.

  • cbar (bool) – Also plot a colorbar. Does not work if ax is passed.

  • aperture (bool) – If True (default), overlay the current aperture (when it crops the SLM): an outline, with the masked-off region faded.

Returns:

Axis of the plotted phase.

Return type:

matplotlib.pyplot.axis

plot_gamma(gamma=None, ax=None, **kwargs)[source]#

Plots gamma, the measured phase response as a function of grayscale level.

Parameters:
  • gamma (array_like OR None) – Phase response to plot, in units of \(2\pi\). If None, uses gamma.

  • ax (matplotlib.axes.Axes OR None) – Axis to plot onto, if desired.

Returns:

Axis handle for the generated plot.

Return type:

matplotlib.axes.Axes

plot_source(source=None, sim=False, power=False, aperture=True)[source]#

Plots measured or simulated amplitude and phase distribution of the SLM illumination. Also plots the rsquared goodness of fit value if available.

Parameters:
  • source (dict OR None) – The data to plot. If None, uses source.

  • sim (bool) – Plots the simulated source distribution if True or the measured source distribution if False.

  • power (bool) – If True, plot the power (amplitude squared) instead of the amplitude.

  • aperture (bool) – If True (default), overlay the current aperture (when it crops the SLM) on the phase and amplitude panels: an outline, with the masked-off region faded. The data plotted is always the raw source, so that illumination the aperture discards stays visible.

Returns:

Axis handles for the generated plot.

Return type:

matplotlib.axes.Axes

property resolution[source]#

(width, height) in pixels, the reverse of shape.

save(path='.', name=None, **kwargs)[source]#

Saves the dictionary returned from pickle() to a file like "path/name_id.h5".

Parameters:
  • path (str) – Path to directory to save in. Default is current directory.

  • name (str OR None) – Name of the save file. If None, will use the object’s name + '-pickle'.

  • **kwargs – Passed to pickle() to customize how and what data is saved.

Returns:

The file path that the pickled data was saved to.

Return type:

str

save_phase(path='.', name=None)[source]#

Saves phase and display to a file like "path/name_id.h5".

Parameters:
  • path (str) – Path to directory to save in. Default is current directory.

  • name (str OR None) – Name of the save file. If None, will use name + '_phase'.

Returns:

The file path that the phase was saved to.

Return type:

str

segment(shape)[source]#

Splits the area of the SLM into a number of segments.

Parameters:

shape (int OR (int, int)) – Segmentation pattern in (rows, columns). If a single integer is passed, this is assumed to be the number of columns, i.e. (1, shape).

set_aperture(spec=None, *, radius=None, center=None, units='norm')[source]#

Sets the SLM’s aperture which defines the working coordinate frame (grid centering), the Zernike lateral scaling (zernike_scaling), the in-use mask (aperture_mask), and the effective (masked) source amplitude and phase.

Setting an aperture always applies it to the source amplitude and phase: the region outside the aperture is masked off everywhere the source is used (e.g. holography, set_phase()’s wavefront correction). The default aperture ("cropped") circumscribes the whole grid and so masks nothing.

Parameters:
  • spec (Aperture OR spec OR None) – The aperture shape/scaling, as accepted by Aperture ("circular" / "elliptical" / "cropped" / float / (float, float) / an Aperture). Mutually exclusive with radius. If both spec and radius are None, the current aperture’s spec is kept.

  • radius (float OR None) – Shorthand for a circular aperture of the given source (\(1/e\)) radius, interpreted in units and stored as source_radius. The aperture/pupil itself extends to twice this radius (the lateral scaling is \(1 / (2\,r)\)). Passing a new spec instead drops any stored source radius, so source_radius is again derived from the aperture.

  • center ((float, float) OR None) – The (x, y) pixel the aperture is centered on. None (the default) centers the aperture on the geometric center of the SLM.

  • units (str) – Units for radius: "norm" (normalized to wavelengths, the default), "frac" (fraction of the smaller half-extent of the SLM), "pix" (number of pixels), or a physical length ("um", "mm", …). As the pupil extends to twice radius, a "frac" radius puts the pupil at that fraction of the full extent of the shorter axis, as in set_source_analytic().

Returns:

The new aperture.

Return type:

Aperture

set_gamma(gamma=None, levels=None, lut_size=65536)[source]#

Sets lut, the lookup table mapping a desired phase onto the grayscale level which best realizes it, from a measured phase response gamma. Measure gamma with pixel_calibration_process(). Its sweep projects grayscale levels directly, so a previously-set lut does not disturb the measurement.

Note

The lookup table supersedes phase_scaling, as a measured gamma already contains the phase range which the SLM achieves at wav_um. Phases outside this range are mapped to the nearest phase which the SLM can realize.

Parameters:
  • gamma (array_like OR None) – Magnitude of the phase realized by each of the bitresolution grayscale levels, in units of \(2\pi\), increasing with level for the usual SLM. Its sense is set per class, as most SLMs decrease phase delay with increasing level whereas a PLM increases it. Must be unwrapped, as an SLM with more than \(2\pi\) of range spans more than one unit. None clears lut, restoring the ideal linear response.

  • levels (array_like OR None) – The grayscale levels at which gamma was sampled, in any order. gamma is then interpolated onto every level, with levels outside the sampled range closed circularly at the curve’s average slope. If None, gamma must sample every level.

  • lut_size (int) – Number of entries in lut. Must be a power of two.

Returns:

lut.

Return type:

numpy.ndarray OR cupy.ndarray OR None

set_input_trigger(on=False)[source]#

(Not supported by this SLM.) Configures the input trigger of the SLM, where an external electronic signal can synchronize the time at which the SLM updates its display.

Parameters:

on (bool) – Subclasses must support a boolean configuration argument, but can also accept other datatypes or parameters as needed.

set_output_trigger(on=False)[source]#

(Not supported by this SLM.) Configures the output trigger of the SLM, where the SLM can send an electronic signal upon updating its display.

Parameters:

on (bool) – Subclasses must support a boolean configuration argument, but can also accept other datatypes or parameters as needed.

set_phase(phase, phase_correct=None, settle=None, execute=None, block=None, **kwargs)[source]#

Checks, cleans, and adds to data, then sends the data to the SLM and potentially waits for settle_time_s seconds. This method calls the SLM-specific private method _format_phase_hw() (if implemented) to format the phase data before calling _set_phase_hw() which transfers the data to the SLM.

Warning

Subclasses implementing vendor-specific software should not overwrite this method. Subclasses should overwrite _set_phase_hw() (and _format_phase_hw() if required) instead.

Caution

The sign on phase is flipped before converting to integer data. This is to convert between the ‘increasing value ==> increasing voltage (= decreasing phase delay)’ convention in most SLMs and slmsuite’s ‘increasing value ==> increasing phase delay’ convention. As a result, zero phase will appear entirely white (255 for an 8-bit SLM), and increasing phase will darken the displayed pattern. If integer data is passed, this data is displayed directly and the sign is not flipped.

Important

The user does not need to wrap (e.g. numpy.mod(data, 2*numpy.pi)) the passed phase data, unless they are pre-caching data for speed (see below). set_phase() uses optimized routines to wrap the phase (see the private method _phase2gray()). When a measured phase response is loaded with set_gamma(), phase is instead wrapped and converted by lookup into lut. Otherwise, which routine is used depends on phase_scaling:

  • phase_scaling is one.

    Fast bitwise integer modulo is used. Much faster than the other routines which depend on numpy.mod().

  • phase_scaling is less than one.

    In this case, the SLM has more phase tuning range than necessary. If the data is within the SLM range [0, 2*pi/phase_scaling], then the data is passed directly. Otherwise, the data is wrapped by \(2\pi\) using the very slow numpy.mod(). Try to avoid this in applications where speed is important.

  • phase_scaling is more than one.

    In this case, the SLM has less phase tuning range than necessary. Processed the same way as the phase_scaling is less than one case, with the important exception that phases (after wrapping) between 2*pi/phase_scaling and 2*pi are set to zero. For instance, a sawtooth blaze would be truncated at the tips.

Caution

With phase_scaling equal to one, phase is rounded to the nearest level. Otherwise, the scaled data is truncated to integers by np.copyto, and with a lut, phase is floored onto one of its entries. Where this matters, pass integer data to set_phase() directly.

Parameters:
  • phase (numpy.ndarray OR cupy.ndarray OR) –

    slmsuite.holography.algorithms.Hologram OR None Phase data to display, in radians, unless the passed data is of integer type and the data is applied directly.

    • If None is passed to set_phase(), data is zeroed.

    • If a Hologram is passed, the phase is grabbed from get_phase().

    • If the array has a larger shape than the SLM shape, then the data is cropped to size in a centered manner (unpad()).

    • If integer data is passed with the same type as display (np.uint8 for <=8-bit SLMs, np.uint16 otherwise), then this data is directly passed to the SLM, without going through the “phase delay to grayscale” conversion defined in the private method _phase2gray(). In this situation, phase_correct is ignored. This is error-checked such that bits with greater significance than the bitdepth of the SLM are zero (e.g. the final 6 bits of 16 bit data for a 10-bit SLM). Integer data with type different from display leads to a TypeError.

    Usually, an exact stored copy of the data passed by the user under phase is stored in the attribute phase. When phase_scaling is one and no lut is set, this copy is rounded to a whole number of levels. If the data was cropped, then the cropped data is stored, etc. If integer data was passed, the equivalent floating point phase is computed and stored in the attribute phase.

  • phase_correct (bool) – Whether to add wavefront correction to the pattern. This correction is stored in source ["phase"]. If None, defaults to phase_correct (which defaults to True).

  • settle (bool | float) – Whether to sleep for settle_time_s, or any number (integers included) of seconds to sleep instead. If None, defaults to settle (which defaults to False). If block=False, this parameter is ignored.

  • execute (bool) –

    Whether to actually send the image to the SLM. Most SLMs do not support this feature, and will error if execute is not None. Otherwise, None must default to True. Use case: if execute=False and block=True, only the block is enforced and no new data is written.

    Important

    New phase/display data is always calculated regardless of the value of execute.

  • block (bool) – Some SLM subclasses support non-blocking writes that are triggered externally. This parameter will determine whether to block the thread until the image is fully written. Most SLMs do not support this feature, and will error if block is not None. Otherwise, None must default to True. Use case: if execute=True and block=False, the write is non-blocking.

  • **kwargs – Passed to the SLM in case the subclass needs to do something special. For instance, some SLMs support a timeout parameter that determines how long to wait for the SLM commands to execute before raising an error.

Returns:

display, the integer data sent to the SLM.

Return type:

numpy.ndarray OR cupy.ndarray

Raises:

TypeError – If integer data is incompatible with the bitdepth or if the passed phase is otherwise incompatible (not a 2D array or smaller than the SLM shape, etc).

set_source_analytic(fit_function='gaussian2d', units='norm', phase_offset=0, sim=False, **kwargs)[source]#

In the absence of a proper wavefront calibration, sets source amplitude and phase using a fit_function from fitfunctions.

Note

FourierSLM includes capabilities for wavefront calibration via wavefront_calibrate(). This process also measures the amplitude of the source on the SLM and stores this in source. source keywords are also used for better refinement of holograms during numerical optimization. If unable to run wavefront_calibrate(), this method allows the user to set an approximation of the complex source.

Parameters:
  • fit_function (str OR lambda) – Function name from fitfunctions used to set the source profile. The function can also be passed directly. Defaults to "gaussian2d".

  • units (str in {"norm", "frac", "nm", "um", "mm", "m"}) – Units for the \((x,y)\) grid passed to fit_function: "norm" (normalized to wavelengths), "frac" (each axis divided by the full extent of the SLM along it, so the grid spans \([-1/2, 1/2]\)), or a physical length. A "frac" radius here is thus a fraction of the full extent, which is where set_aperture() places the pupil for the same "frac" radius.

  • phase_offset (float OR numpy.ndarray OR cupy.ndarray) – Additional phase (of shape shape) added to source.

  • sim (bool) – Sets the simulated source distribution if True or the approximate experimental source distribution (in absence of wavefront calibration) if False.

  • **kwargs – Arguments passed to fit_function in addition to the SLM grid in the requested units. If the fit_function is "gaussian2d" and no keyword arguments have been passed, the radius defaults to a quarter of the smaller of the two SLM dimensions.

Returns:

source.

Return type:

dict

property source_radius[source]#

The \(1/e\) field-amplitude source radius in normalized units, for structured beams such as laguerre_gaussian(). Set independently of the pupil by fit_aperture() or by set_aperture() (radius=...). Otherwise, it is derived from the aperture scaling as \(1 / (2\,s)\), where \(s\) is the (isotropic) lateral scale, which raises ValueError for an anisotropic (elliptical) aperture that a single radius cannot describe.

test()[source]#

Test that the hardware behind this SLM responds to every core method.

Each step is named, so a failure reports which feature is broken. Correctness of the phase mapping is the business of the test suite, not of a hardware check.

property width[source]#

Width in pixels, shape[1].

write(phase, phase_correct=True, settle=False, **kwargs)[source]#

Backwards-compatibility alias for set_phase().

property zernike_scaling[source]#

The (x_scale, y_scale) lateral scaling mapping grid onto the Zernike unit disk, from aperture. Used by zernike_sum(). This is the SLM-level name for the general scale.