hswfs.utils

This module provides various utility functions.

hswfs.utils.crop_center(array: ndarray, size: Tuple[int, ...]) ndarray[source]

Crop an n-dimensional array to the given size around its center.

Parameters
  • array – The numpy array to be cropped.

  • size – A tuple containing the size of the cropped array. To not crop along a specific axis, you can specify the size of that axis as -1.

Returns

The input array, cropped to the desired size around its center.

hswfs.utils.get_subaperture_centers(grid_size: int) Tuple[ndarray, ndarray][source]

Compute the positions of the centers of the subapertures of the sensor. This assumes a simple geometry, where the sensor is taken to be the largest square that can fit inside the unit circle, and consists of a grid of grid_size x grid_size subapertures.

Parameters

grid_size – An integer specifying the size of the (quadratic) grid of subapertures in the HSWFS sensor.

Returns

A mesh grid, consisting of two numpy arrays which specify the x and y positions of the centers of the subapertures.

hswfs.utils.get_unit_disk_meshgrid(resolution: int) Tuple[ndarray, ndarray][source]

Get a (Cartesian) mesh grid of positions on the unit disk, that is, all positions with with a Euclidean distance <= 1 from (0, 0).

Parameters

resolution – An integer specifying the size of the mesh grid, that is, the number of points in each dimensions.

Returns

A mesh grid consisting of the tuple x_0, y_0, which are each numpy arrays of shape (resolution, resolution). For positions that are on the unit disk, they contain the coordinates of the position; otherwise, they contain np.nan.