Developer Docs

Documentation for all the under-the-hood classes and functions that most users won’t need to interact with.

spherical_coords_transforms

Methods for doing spherical coordinate transformations on vectors.

pyradiosky.spherical_coords_transforms.r_hat(theta, phi)[source]

Get the r hat unit vectors in cartesian coordinates for points on a sphere.

Parameters

theta, phi (float) – The co-latitude and azimuth coordinates, respectively, for a point on the sphere, in radians. Azimuth is defined with respect to the x axis, co-latitude is the angle with the positive z axis.

Returns

array of float – Array of r hat vectors, shape (3, Npoints)

pyradiosky.spherical_coords_transforms.theta_hat(theta, phi)[source]

Get the theta hat unit vectors in cartesian coordinates for points on a sphere.

Parameters

theta, phi (float) – The co-latitude and azimuth coordinates, respectively, for a point on the sphere, in radians. Azimuth is defined with respect to the x axis, co-latitude is the angle with the positive z axis.

Returns

array of float – Array of theta hat vectors, shape (3, Npoints)

pyradiosky.spherical_coords_transforms.phi_hat(theta, phi)[source]

Get the phi hat unit vectors in cartesian coordinates for points on a sphere.

Parameters

theta, phi (float) – The co-latitude and azimuth coordinates, respectively, for a point on the sphere, in radians. Azimuth is defined with respect to the x axis, co-latitude is the angle with the positive z axis.

Returns

array of float – Array of phi hat vectors, shape (3, Npoints)

pyradiosky.spherical_coords_transforms.rotate_points_3d(rot_matrix, theta, phi)[source]

Get the spherical coordinates of the point under a 3d rotation.

Finds the spherical coordinates for point p specified by p = R . q, where q is the 3D position vector of the point specified by (theta,phi) and R is the 3D rotation matrix that relates two coordinate charts.

The accuracy of this method may not be good enough near pols in either coordinate system.

Parameters
  • rot_matrix (array-like of float) – rotation matrix to use

  • theta, phi (float) – The co-latitude and azimuth coordinates, respectively, for a point on the sphere, in radians. Azimuth is defined with respect to the x axis, co-latitude is the angle with the positive z axis.

Returns

beta, alpha (float) – The theta, phi coordinates for the point on the sphere (using normal mathematical conventions) in the rotated frame.

pyradiosky.spherical_coords_transforms.spherical_basis_vector_rotation_matrix(theta, phi, rot_matrix, beta=None, alpha=None)[source]

Get the rotation matrix to take vectors in the theta/phi basis to a new reference frame.

Given a position (theta, phi) in “standard mathematical” coordinates (0 < theta < pi, 0 < phi < 2 pi) which will typically be an ICRS RA/Dec coordinate appropriately converted, and the point to which it is transformed in another standard mathematical coordinate system (beta, alpha), which will typically be local telescope Alt/Az appropriately converted, and a 3 x 3 rotation matrix rot_matrix which connects those two points, calculate the rotation matrix which rotates the basis vectors associated with (theta, phi) to those associated with (beta, alpha).

Parameters
  • theta, phi (float) – The co-latitude and azimuth coordinates, respectively, for a point on the sphere, in radians. Azimuth is defined with respect to the x axis, co-latitude is the angle with the positive z axis.

  • rot_matrix (array-like of float) – Rotation matrix that takes 3-vectors from (theta, phi) to (beta, alpha)

  • beta, alpha (float, optional) – The theta, phi coordinates for the point on the sphere (using normal mathematical conventions) in the rotated frame. If either is not provided, they are calculated using rotate_points_3d. Note these may not be as exact as values calculated from astropy.

Returns

array of float – 2 x 2 rotation matrix that takes vectors in the theta/phi basis to the beta/alpha basis.

pyradiosky.spherical_coords_transforms.axis_angle_rotation_matrix(axis, angle)[source]

Get the rotation matrix using Rodrigues’ rotation matrix formula.

Parameters
  • axis (array-like of float) – 3 element unit vector specifying the axis to rotate around.

  • angle (float) – angle to rotate by in radians

Returns

array – 3x3 rotation matrix to rotate vectors by angle around axis.

pyradiosky.spherical_coords_transforms.is_orthogonal(matrix, tol=1e-15)[source]

Test for matrix orthogonality.

Parameters

matrix (array-like of float) – square matrix to test

Returns

bool – True if matrix is orthogonal, False otherwise.

pyradiosky.spherical_coords_transforms.is_unit_vector(vec, tol=1e-15)[source]

Test for unit vectors.

Parameters

vec (array-like of float) – vector to test

Returns

bool – True if vec is a unit vector, False otherwise.

pyradiosky.spherical_coords_transforms.vecs2rot(r1=None, r2=None, theta1=None, phi1=None, theta2=None, phi2=None)[source]

Get the rotation matrix that connects two points or unit vectors on the sphere.

Parameters
  • r1, r2 (array-like of float, optional) – length 3 unit vectors

  • theta1, phi1, theta2, phi2 (float, optional) – The co-latitude and azimuth coordinates, respectively, for a point on the sphere, in radians. Azimuth is defined with respect to the x axis, co-latitude is the angle with the positive z axis. Ignored if r1 and r2 are supplied.

Returns

array – 3x3 rotation matrix that rotates the first point or vector into the other.