prysm.coordinates

Coordinate conversions.

prysm.coordinates.cart_to_polar(x, y)

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

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(samples_x, samples_y=None, radius=1)

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

Parameters
  • samples_x (int) – number of samples in x direction

  • samples_y (int) – number of samples in y direction, if None, copied from sample_x

  • radius (float) – radius of the output array, will span -radius, radius

Returns

  • xx (numpy.ndarray) – x meshgrid

  • yy (numpy.ndarray) – y meshgrid

prysm.coordinates.make_rho_phi_grid(samples_x, samples_y=None, aligned='x', radius=1)

Create an rho, phi grid from -1, 1 with n number of samples.

Parameters
  • samples_x (int) – number of samples in x direction

  • samples_y (int) – number of samples in y direction, if None, copied from sample_x

  • radius (float) – radius of the output array

Returns

  • rho (numpy.ndarray) – radial meshgrid

  • phi (numpy.ndarray) – angular meshgrid

prysm.coordinates.v_to_2v_minus_one(v)

Transform v -> 2v-1.

prysm.coordinates.v_to_2v2_minus_one(v)

Transform v -> 2v^2-1.

prysm.coordinates.v_to_v_squared(v)

Transform v -> v^2.

prysm.coordinates.v_to_v_fouth(v)

Transform v -> v^4.

prysm.coordinates.v_to_v2_times_1_minus_v2(v)

Transform v -> v^2(1 - v^2).

prysm.coordinates.v_to_4v2_minus_4v_plus1(v)

Transform v -> (4v)^2 - 4v - 1.

prysm.coordinates.v_to_v_plus90(v)

Transform v -> v+90 deg, v should be in radians.

prysm.coordinates.convert_transformation_to_v(transformation)

Replace any of x,y,r,t with v in a transformation string.

class prysm.coordinates.GridCache

Bases: object

Cache of grid points.

make_basic_grids(samples, radius)

Create basic (unmodified) grids.

Parameters
  • samples (int) – number of samples in the square grid

  • radius (float) – radius of the array in units (not samples)

make_transformation(samples, radius, transformation)

Make a transformed grid.

Parameters
  • samples (int) – number of samples in the square grid

  • radius (float) – radius of the array in units (not samples)

  • transformation (str) – looks like “r => 2r^2 - 1”

get_original_variable(samples, radius, variable)

Retrieve an unmodified variable.

Parameters
  • samples (int) – number of samples in the square grid

  • radius (float) – radius of the array in units (not samples)

  • variable (str, {‘x’, ‘y’, ‘r’, ‘p’}) – which variable on the grid

Returns

array of shape (samples,samples)

Return type

numpy.ndarray

get_transformed_variable(samples, radius, transformation)

Retrieve a modified variable.

Parameters
  • samples (int) – number of samples in the square grid

  • radius (float) – radius of the array in units (not samples)

  • variable (str, {‘x’, ‘y’, ‘r’, ‘t’}) – which variable on the grid

  • transformation (str) – looks like “r => 2r^2 - 1”

Returns

array of shape (samples,samples)

Return type

numpy.ndarray

get_variable_transformed_or_not(samples, radius, variable_or_transformation)

Retrieve a modified variable.

Parameters
  • samples (int) – number of samples in the square grid

  • radius (float) – radius of the array in units (not samples)

  • variable_or_transformation (str or None) – looks like “r => 2r^2 - 1” for a transformation, or “r” for a variable if None, returns None

Returns

array of shape (samples,samples)

Return type

numpy.ndarray

clear()

Empty the cache.