prysm.geometry#
Functions used to generate various geometrical constructs.
- prysm.geometry.gaussian(sigma, x, y, center=(0, 0))#
Generate a gaussian mask with a given sigma.
- Parameters:
sigma (float) – width parameter of the gaussian, expressed in the same units as x and y
x (numpy.ndarray) – x spatial coordinates, 2D or 1D
y (numpy.ndarray) – y spatial coordinates, 2D or 1D
center (tuple of float) – center of the gaussian, (x,y)
- Returns:
mask with gaussian shape
- Return type:
numpy.ndarray
- prysm.geometry.rectangle(width, x, y, height=None, angle=0)#
Generate a rectangular, with the “width” axis aligned to ‘x’.
- Parameters:
width (float) – diameter of the rectangle, relative to the width of the array. width=1 fills the horizontal extent when angle=0
height (float) – diameter of the rectangle, relative to the height of the array. height=1 fills the vertical extent when angle=0. If None, inherited from width to make a square
angle (float) – angle
x (numpy.ndarray) – x spatial coordinates, 2D
y (numpy.ndarray) – y spatial coordinates, 2D
- Returns:
array with the rectangle painted at 1 and the background at 0
- Return type:
numpy.ndarray
- prysm.geometry.rotated_ellipse(width_major, width_minor, x, y, major_axis_angle=0)#
Generate a binary mask for an ellipse, centered at the origin.
- Parameters:
width_major (float) – width of the ellipse in its major axis
width_minor (float) – width of the ellipse in its minor axis
major_axis_angle (float) – angle of the major axis w.r.t. the x axis, degrees
x (numpy.ndarray) – x spatial coordinates, 2D
y (numpy.ndarray) – y spatial coordinates, 2D
- Returns:
An ndarray of shape (samples,samples) of value 0 outside the ellipse and value 1 inside the ellipse
- Return type:
numpy.ndarray
- prysm.geometry.square(x, y)#
Create a square mask.
- Parameters:
samples (int, optional) – number of samples in the square output array
x (numpy.ndarray) – x spatial coordinates, 2D
y (numpy.ndarray) – y spatial coordinates, 2D
- Returns:
binary ndarray representation of the mask
- Return type:
numpy.ndarray
- prysm.geometry.truecircle(radius, r)#
Create a “true” circular mask with anti-aliasing.
- Parameters:
samples (int, optional) – number of samples in the square output array
radius (float, optional) – radius of the shape in the square output array. radius=1 will fill the
r (numpy.ndarray) – radial coordinate, 2D
- Returns:
nonbinary ndarray representation of the mask
- Return type:
numpy.ndarray
Notes
Based on a more general algorithm by Jim Fienup
- prysm.geometry.circle(radius, r)#
Create a circular mask.
- Parameters:
radius (float) – radius of the circle, same units as r. The return is 1 inside the radius and 0 outside
r (numpy.ndarray) – 2D array of radial coordinates
- Returns:
binary ndarray representation of the mask
- Return type:
numpy.ndarray
- prysm.geometry.regular_polygon(sides, radius, x, y, center=(0, 0), rotation=0)#
Generate a regular polygon mask with the given number of sides.
- Parameters:
sides (int) – number of sides to the polygon
radius (float, optional) – radius of the regular polygon. For R=1, will fill the x and y extent
x (numpy.ndarray) – x spatial coordinates, 2D or 1D
y (numpy.ndarray) – y spatial coordinates, 2D or 1D
center (tuple of float) – center of the gaussian, (x,y)
rotation (float) – rotation of the polygon, degrees
- Returns:
mask for regular polygon with radius equal to the array radius
- Return type:
numpy.ndarray
- prysm.geometry.spider(vanes, width, x, y, rotation=0, center=(0, 0), rotation_is_rad=False)#
Generate the mask for a spider.
- Parameters:
vanes (int) – number of spider vanes
width (float) – width of the vanes in array units, i.e. a width=1/128 spider with arydiam=1 and samples=128 will be 1 pixel wide
x (numpy.ndarray) – x spatial coordinates, 2D or 1D
y (numpy.ndarray) – y spatial coordinates, 2D or 1D
rotation (float, optional) – rotational offset of the vanes, clockwise
center (tuple of float) – point from which the vanes emanate, (x,y)
rotation_is_rad (bool, optional) – if True, the rotation parameter is interpreted to be in radians
- Returns:
array, 0 inside the spider and 1 outside
- Return type:
numpy.ndarray
- prysm.geometry.offset_circle(radius, x, y, center)#
Rasterize an offset circle.
- Parameters:
radius (float) – radius of the circle, same units as x and y
x (numpy.ndarray) – array of x coordinates
y (numpy.ndarray) – array of y coordinates
center (tuple) – tuple of (x, y) centers
- Returns:
ndarray containing the boolean mask
- Return type:
numpy.ndarray
- prysm.geometry.rectangle_with_corner_fillets(width, height, cradius, x, y, center=(0, 0), rotation=0)#
Shade a rectangle with filleted (circular arc) corners.
- Parameters:
width (float) – half-width of the rectangle, same units as x and y
height (float) – half-height of the rectangle, same units as x and y
cradius (float) – radius of the corner fillets
x (numpy.ndarray) – x coordinates
y (numpy.ndarray) – y coordinates
center (tuple of float) – (x,y) center of the rectangle
rotation (float) – degrees of rotation about coordinate grid center
- Returns:
1 inside “squircle”, 0 outside
- Return type:
numpy.ndarray
- prysm.geometry.chebygauss_quadrature_xy(rings, radius=1, spokes=-1, center=(0, 0))#
Use Chebyshev-Gauss quadrature to sample a polar coordinate grid.
- Parameters:
rings (int) – number of rings to use; degree of radial sampling
radius (float) – radius of the grid, process units
spokes (int, optional) – number of spokes if -1, use rings*2 + 1
center (tuple) – (x,y) center point of the grid
- Returns:
Chebyshev-Gauss-Lobatto points (x,y)
- Return type:
numpy.ndarray