make_agnostic_optical_element

hcipy.optics.make_agnostic_optical_element(grid_dependent_arguments=None, wavelength_dependent_arguments=None, num_in_cache=50)

Create an optical element that is agnostic to input_grid or wavelength from one that is not.

This decorator is meant to simplify the creation of agnostic optical elements. When you have an optical element that explicitly needs an input grid and/or wavelength on initialization, you can use this decorator to modify it to make it accept all input grids and/or wavelengths.

All parameters pass to the __init__() of the returned class will be attempted to be evaluated on an input grid or wavelength (depending on if the parameter name appears in grid_dependent_arguments or wavelength_dependent_arguments). This evaluation is done by calling the argument with either the input_grid or wavelength, before passing it to the initializer of the optical element provided by the user. When an argument can be both dependent on input grid and wavelength, you can pass a function with double arguments. This will be evaluated as arg(input_grid, wavelength). If the argument only has a single parameter, this function will make a guess on whether it is input_grid or wavelength dependent and try both possibilities.

Parameters:
grid_dependent_argumentslist of strings or None

A list of all names of parameters that could vary with input_grid. These parameters will be evaluated on the grid if they are callable. If this is None, this indicates that no parameters can depend on input_grid, and that the optical element was already input_grid agnostic.

wavelength_dependent_argumentslist of strings or None

A list of all names of parameters that could vary with wavelength. These parameters will be evaluated at the wavelength if they are callable. If this is None, this indicates that no parameters can depend on wavelength, and that the optical element was already wavelength agnostic.

num_in_cacheint

The maximum size of the internal cache for optical elements. Reduce this if the cache is using too much memory, increase if there are a lot of cache misses.

Returns:
class

The new optical element class that is now agnostic to input grid and wavelength.

Raises:
RuntimeError

If one of the argument gave an error during evaluation.