hswfs.shifts
This module provides functions to generate shift grids to be used with the HSWFS class.
- hswfs.shifts.generate_random_shifts(grid_size: int = 16, smooth_std: Optional[float] = None, random_seed: int = 42) ndarray[source]
Create a 2D grid of random shifts (or offsets, or delta) for the subapertures of the Hartmann-Shack wavefront sensor.
By default, these shifts will independently of each other follow a uniform distribution for both \(\Delta x\) and \(\Delta y\). This is almost certainly an oversimplification; however, I do not know the “true” distribution that these shifts should follow for real atmospheric perturbations.
To make the results slightly more realistic, there is the option to smooth (i.e., convolve) the vector field of shifts with an 2D Gaussian kernel, which will introduce some local correlations between neighboring apertures.
- Parameters
grid_size – An integer specifying the size of the (quadratic) grid of subapertures in the HSWFS sensor. Default: 16.
smooth_std – The standard deviation of the 2D Gaussian kernel that is used to smooth the results. If None, no smoothing is applied (default).
random_seed – Seed to be used for the random number generator.
- Returns
A numpy array of shape (grid_size, grid_size, 2) which, for each subaperture in the wavefront sensor, contains the a 2D shift vector (delta_x, delta_y) specifying the relative offsets. “Relative” means that the values are in [-1, 1] and may still need to be multiplied with the (pixel) size of the subapertures.
- hswfs.shifts.generate_test_shifts(test_case: str, grid_size: int = 16) ndarray[source]
Create a special 2D grid of shifts (or offsets, or delta) for the subapertures of the Hartmann-Shack wavefront sensor, for which the the shape of the corresponding wavefront is known. This is useful for testing.
Currently, there are three such special cases:
x_shift: The shifts in all subapertures are equal and only in x-direction. In this case, the resulting wavefront can be described using only the Zernike polynomial \(Z^{-1}_{1}\); that is, if we try to fit the wavefront corresponding to this case, the coefficients of all Zernike polynomials should be 0, except for \(j=1\).
y_shift: The shifts in all subapertures are equal and only in y-direction. In this case, the resulting wavefront can be described using only the Zernike polynomial \(Z^{1}_{1}\); that is, if we try to fit the wavefront corresponding to this case, the coefficients of all Zernike polynomials should be 0, except for \(j=2\).
defocus: The shifts in all subapertures point in the direction that is given by the vector from the center of the sensor to the respective aperture, and the value of the shift is proportional to the square of the distance of the subaperture from the center of the sensor. In this case, the resulting wavefront can be described using only the Zernike polynomial \(Z^{0}_{2}\); that is, if we try to fit the wavefront corresponding to this case, the coefficients of all Zernike polynomials should be 0, except for \(j=4\).
- Parameters
test_case – A string containing the name of one of the three cases described above, that is, one of the following: “x_shift”, “y_shift” or “defocus”.
grid_size – An integer specifying the size of the (quadratic) grid of subapertures in the HSWFS sensor. Default: 16.
- Returns
A numpy array of shape (grid_size, grid_size, 2) which, for each subaperture in the wavefront sensor, contains the a 2D shift vector (delta_x, delta_y) specifying the relative offsets for the chosen test case.