Coordinates (coordinates)

Handle the survey coordinate systems.

cartesian_to_spherical(cartesian_coords)

Convert 3-d Cartesian coordinate arrays to spherical coordinate arrays.

spherical_to_cartesian(spherical_coords)

Convert 3-d spherical coordinate arrays to Cartesian coordinate arrays.

sky_to_spherical(sky_coords[, z_to_r])

Convert 3-d (or 2-d) sky coordinate arrays (Z, DEC, RA) (or (DEC, RA)) to spherical coordinate arrays.

spherical_to_sky(spherical_coords[, z_from_r])

Convert 3-d spherical coordinate arrays to sky coordinate arrays.

to_box_coords(native_coord_system[, ...])

Convert a function defined for a native 3-d curvilinear coordinate system to an equivalent function defined for a box in Cartesian coordinates.


harmonia.surveyor.coordinates.cartesian_to_spherical(cartesian_coords)[source]

Convert 3-d Cartesian coordinate arrays to spherical coordinate arrays.

The coordinate transformation is given by

\[r = \sqrt{x^2 + y^2 + z^2} \,, \quad \theta = \arccos(z/r) \,, \quad \phi = \arctan(y/x) \,,\]

where the image of \(\arccos\) is \([0, \pi]\), and \(\arctan\) has an extended image set \([0, 2\pi]\).

Parameters:

cartesian_coords (float, array_like) – Cartesian coordinates.

Returns:

spherical_coords – Spherical coordinates.

Return type:

float numpy.ndarray

harmonia.surveyor.coordinates.spherical_to_cartesian(spherical_coords)[source]

Convert 3-d spherical coordinate arrays to Cartesian coordinate arrays.

The coordinate transformation is given by

\[x = r \sin\theta \cos\phi \,, \quad y = r \sin\theta \sin\phi \,, \quad z = r \cos\theta \,.\]
Parameters:

spherical_coords (float, array_like) – Spherical coordinates.

Returns:

cartesian_coords – Cartesian coordinates.

Return type:

float numpy.ndarray

harmonia.surveyor.coordinates.sky_to_spherical(sky_coords, z_to_r=None)[source]

Convert 3-d (or 2-d) sky coordinate arrays (Z, DEC, RA) (or (DEC, RA)) to spherical coordinate arrays.

The spherical surface coordinate transformation is given by

\[\theta = \frac{\pi}{180} (90 - \delta) \,, \quad \phi = \frac{\pi}{180} \alpha \,.\]

where \(\delta\) is the declination (DEC) and \(\alpha\) the right ascension (RA) both given in degrees.

The radial coordinate transformation from redshifts is given by cosmo.comoving_distance() if the input coordinates are 3-d and a redshift-to-distance conversion function is provided.

Parameters:
  • sky_coords (float, array_like) – Sky coordinates (2-d or 3-d).

  • z_to_r (callable or None, optional) – Redshift-to-distance conversion (default is None).

Returns:

spherical_coords – Spherical surface coordinates.

Return type:

float numpy.ndarray

harmonia.surveyor.coordinates.spherical_to_sky(spherical_coords, z_from_r=None)[source]

Convert 3-d spherical coordinate arrays to sky coordinate arrays.

The spherical surface coordinate transformation is given by

\[\delta = 90 - \frac{180}{\pi} \theta \,, \quad \alpha = \frac{180}{\pi} \phi \,.\]

where \(\delta\) is the declination (DEC) and \(\alpha\) the right ascension (RA) both given in degrees.

The radial coordinate transformation is given by a distance-to-redshift conversion if it provided.

Parameters:
  • sky_coords (float, array_like) – Sky coordinates.

  • z_from_r (callable or None, optional) – Distance-to-redshift conversion (default is None).

Returns:

sky_coords – Sky coordinates.

Return type:

float numpy.ndarray

harmonia.surveyor.coordinates.to_box_coords(native_coord_system, box_centre=None, conversion_kwargs=None)[source]

Convert a function defined for a native 3-d curvilinear coordinate system to an equivalent function defined for a box in Cartesian coordinates.

Parameters:
  • native_coord_system ({‘null’, ‘spherical’, ‘sky’}, optional) – Native coordinate system of the function. If ‘cartesian’ (with the implicit assumption that the origin is at the box centre), the function is unconverted unless box_shift is also provided.

  • box_centre (float, array_like or Nonw) – If provided, translate the box coordinates so that the (positive) box_centre is moved to(0, 0, 0). This is needed to when the wrapped function needs to accept box coordinates with the origin placed at its corner whilst the native_coord_system has the origin at the centre of the box (e.g. ‘spherical’).

  • conversion_kwargs (dict or None, optional) – Additional parameters to use in conversion, e.g. z_from_r if native_coords is ‘sky’ (default is None).

Returns:

The original function now accepting Cartesian coordinates.

Return type:

callable