prysm.coordinates

Coordinate conversions.

prysm.coordinates.optimize_xy_separable(x, y)

Optimize performance for downstream operations.

Parameters
  • x (numpy.ndarray) – 2D or 1D array

  • y (numpy.ndarray) – 2D or 1D array

Returns

optimized arrays (x as 1D row, y as 1D column)

Return type

x, y

Notes

If a calculation is separable in x and y, performing it on a meshgrid of x/y takes 2N^2 operations, for N= the linear dimension (the 2 being x and y). If the calculation is separable, this can be reduced to 2N by using numpy broadcast functionality and two 1D calculations.

prysm.coordinates.broadcast_1d_to_2d(x, y)

Broadcast two (x,y) vectors to 2D.

Parameters
  • x (numpy.ndarray) – ndarray of shape (n,)

  • y (numpy.ndarray) – ndarray of shape (m,)

Returns

  • xx (numpy.ndarray) – ndarray of shape (m, n)

  • yy (numpy.ndarray) – ndarray of shape (m, n)

prysm.coordinates.cart_to_polar(x, y, vec_to_grid=True)

Return the (rho,phi) coordinates of the (x,y) input points.

Parameters
  • x (numpy.ndarray or number) – x coordinate

  • y (numpy.ndarray or number) – y coordinate

  • vec_to_grid (bool, optional) – if True, convert a vector (x,y) input to a grid (r,t) output

Returns

  • rho (numpy.ndarray or number) – radial coordinate

  • phi (numpy.ndarray or number) – azimuthal coordinate

prysm.coordinates.polar_to_cart(rho, phi)

Return the (x,y) coordinates of the (rho,phi) input points.

Parameters
  • rho (numpy.ndarray or number) – radial coordinate

  • phi (numpy.ndarray or number) – azimuthal coordinate

Returns

  • x (numpy.ndarray or number) – x coordinate

  • y (numpy.ndarray or number) – y coordinate

prysm.coordinates.uniform_cart_to_polar(x, y, data)

Interpolate data uniformly sampled in cartesian coordinates to polar coordinates.

Parameters
  • x (numpy.ndarray) – sorted 1D array of x sample pts

  • y (numpy.ndarray) – sorted 1D array of y sample pts

  • data (numpy.ndarray) – data sampled over the (x,y) coordinates

Returns

  • rho (numpy.ndarray) – samples for interpolated values

  • phi (numpy.ndarray) – samples for interpolated values

  • f(rho,phi) (numpy.ndarray) – data uniformly sampled in (rho,phi)

prysm.coordinates.resample_2d(array, sample_pts, query_pts, kind='cubic')

Resample 2D array to be sampled along queried points.

Parameters
  • array (numpy.ndarray) – 2D array

  • sample_pts (tuple) – pair of numpy.ndarray objects that contain the x and y sample locations, each array should be 1D

  • query_pts (tuple) – points to interpolate onto, also 1D for each array

  • kind (str, {‘linear’, ‘cubic’, ‘quintic’}) – kind / order of spline to use

Returns

array resampled onto query_pts

Return type

numpy.ndarray

prysm.coordinates.resample_2d_complex(array, sample_pts, query_pts, kind='linear')

Resample 2D array to be sampled along queried points.

Parameters
  • array (numpy.ndarray) – 2D array

  • sample_pts (tuple) – pair of numpy.ndarray objects that contain the x and y sample locations, each array should be 1D

  • query_pts (tuple) – points to interpolate onto, also 1D for each array

  • kind (str, {‘linear’, ‘cubic’, ‘quintic’}) – kind / order of spline to use

Returns

array resampled onto query_pts

Return type

numpy.ndarray

prysm.coordinates.make_xy_grid(shape, *, dx=0, diameter=0, grid=True)

Create an x, y grid from -1, 1 with n number of samples.

Parameters
  • shape (int or tuple of int) – number of samples per dimension. If a scalar value, broadcast to both dimensions. Order is numpy axis convention, (row, col)

  • dx (float) – inter-sample spacing, ignored if diameter is provided

  • diameter (float) – diameter, clobbers dx if both given

  • grid (bool, optional) – if True, return meshgrid of x,y; else return 1D vectors (x, y)

Returns

  • x (numpy.ndarray) – x grid

  • y (numpy.ndarray) – y grid

prysm.coordinates.make_rotation_matrix(abg, radians=False)

Build a rotation matrix.

The angles are Tait-Bryan angles describing extrinsic rotations about Z, Y, X in that order.

Note that the return is the location of the input points in the output space

For more information, see Wikipedia https://en.wikipedia.org/wiki/Euler_angles#Tait%E2%80%93Bryan_angles The “Tait-Bryan angles” X1Y2Z3 entry is the rotation matrix used in this function.

Parameters
  • abg (tuple of float) – the Tait-Bryan angles (α,β,γ) units of degrees unless radians=True if len < 3, remaining angles are zero

  • radians (bool, optional) – if True, abg are assumed to be radians. If False, abg are assumed to be degrees.

Returns

3x3 rotation matrix

Return type

numpy.ndarray

prysm.coordinates.apply_rotation_matrix(m, x, y, z=None, points=None, return_z=False)

Rotate the coordinates (x,y,[z]) about the origin by angles (α,β,γ).

Parameters
  • m (numpy.ndarray, optional) – rotation matrix; see make_rotation_matrix

  • x (numpy.ndarray) – N dimensional array of x coordinates

  • y (numpy.ndarray) – N dimensional array of x coordinates

  • z (numpy.ndarray) – N dimensional array of z coordinates assumes to be unity if not given

  • points (numpy.ndarray, optional) – array of dimension [x.size, 3] containing [x,y,z] points will be made by stacking x,y,z if not given. passing points directly if this is the native storage of your coordinates can improve performance.

  • return_z (bool, optional) – if True, returns array of shape [3, x.shape] if False, returns an array of shape [2, x.shape] either return unpacks, such that x, y = rotate(…)

Returns

ndarray with rotated coordinates

Return type

numpy.ndarray

prysm.coordinates.xyXY_to_pixels(xy, XY)

Given input points xy and warped points XY, compute pixel indices.

Lists or tuples work for xy and XY, as do 3D arrays.

Parameters
  • xy (numpy.ndarray) – ndarray of shape (2, m, n) with [x, y] on the first dimension represents the input coordinates implicitly rectilinear

  • XY (numpy.ndarray) – ndarray of shape (2, m, n) with [x, y] on the first dimension represents the input coordinates not necessarily rectilinear

Returns

ndarray of shape (2, m, n) with XY linearly projected into pixels

Return type

numpy.ndarray

prysm.coordinates.regularize(xy, XY, z, XY2=None)

Regularize the coordinates XY relative to the frame xy.

This function is used in conjunction with rotate to project surface figure errors onto tilted planes or other geometries.

Parameters
  • xy (numpy.ndarray) – ndarray of shape (2, m, n) with [x, y] on the first dimension represents the input coordinates implicitly rectilinear

  • XY (numpy.ndarray) – ndarray of shape (2, m, n) with [x, y] on the first dimension represents the input coordinates not necessarily rectilinear

  • z (numpy.ndarray) – ndarray of shape (m, n) flat data to warp

  • XY2 (numpy.ndarray, optional) – ndarray of shape (2, m, n) XY, after output from xyXY_to_pixels compute XY2 once and pass many times to optimize models

Returns

Z – z which exists on the grid XY, looked up at the points xy

Return type

numpy.ndarray