coord_utils#

This module contains utility functions for dealing with sky coordinates, sky distances, and healpix grids.

Module Contents#

Functions#

uniform_around(centre, area, size)

Uniform distribution of points around location.

upgrade_healpix(pix_id, nested, nside_in, nside_out)

Upgrade (superresolve) a healpix into finer ones

get_distance(ra_i, dec_i, ra_f, dec_f)

Compute the distance between two angular positions given in degrees

get_healpix_centers(pix_id, nside, nest)

Get the ra, dec corresponding to centers of the healpixels with given IDs

get_padded_nside(padding, nside_in)

Get the maximum nside (finest healpix grid) whose centers along

get_corners(n_pix[, counterclockwise])

Get the indices of corners of a set of finer healpixes making up

is_inside(ra, dec, ra_bounds, dec_bounds)

Get the boolean mask for whether points are inside provided bounds

get_skycoord(ra, dec)

Create an astropy.coordinates.SkyCoord object

get_target_nside(n_pix[, nside_in])

Get the NSIDE corresponding to the number of sub-healpixels

match(ra_grid, dec_grid, ra_cat, dec_cat, threshold)

Match gridpoints to a catalog based on distance threshold

sample_in_aperture(N, radius)

Uniformly sample points around a zero coordinate on the celestial sphere

Attributes#

TWO_PI

coord_utils.TWO_PI[source]#
coord_utils.uniform_around(centre, area, size)[source]#

Uniform distribution of points around location. Draws randomly distributed points from a circular region of the given area around the centre point.

Parameters#

centre~astropy.coordinates.SkyCoord

Centre of the sampling region.

area~astropy.units.Quantity

Area of the sampling region as a ~astropy.units.Quantity in units of solid angle.

sizeint

Number of points to draw.

Returns#

coords~astropy.coordinates.SkyCoord

Randomly distributed points around the centre. The coordinates are returned in the same frame as the input.

Examples#

See User Documentation. Modified from the skypy implementation: skypyproject/skypy

coord_utils.upgrade_healpix(pix_id, nested, nside_in, nside_out)[source]#

Upgrade (superresolve) a healpix into finer ones

Parameters#

pix_idint

coarse healpix ID to upgrade

nestedbool

whether pix_id is given in NESTED scheme

nside_inint

NSIDE of pix_id

nside_outint

desired NSIDE of finer healpix

Returns#

np.array

the upgraded healpix IDs in the NESTED scheme

coord_utils.get_distance(ra_i, dec_i, ra_f, dec_f)[source]#

Compute the distance between two angular positions given in degrees

coord_utils.get_healpix_centers(pix_id, nside, nest)[source]#

Get the ra, dec corresponding to centers of the healpixels with given IDs

Parameters#

pix_idint or array-like

IDs of healpixels to evaluate centers. Must be in NESTED scheme

nside_inint

NSIDE of pix_id

coord_utils.get_padded_nside(padding, nside_in)[source]#

Get the maximum nside (finest healpix grid) whose centers along the boundary of the input nside are located sufficiently far away from the boundaries

Parameters#

paddingfloat

Padding in arcmin

nside_inint

NSIDE of the healpix to upgrade

coord_utils.get_corners(n_pix, counterclockwise=False)[source]#

Get the indices of corners of a set of finer healpixes making up a big healpix, e.g. the output of upgrade_healpix

Parameters#

n_pixint

Number of finer healpixes

clockwise: bool

Ordering of the corners are counterclockwise. If False, ordering follows healpix ordering. Default: False

Returns#

list

Indices of four corners that can be used to slice a list of RA, Dec

coord_utils.is_inside(ra, dec, ra_bounds, dec_bounds)[source]#

Get the boolean mask for whether points are inside provided bounds

Parameters#

ranp.ndarray

RA of candidate positions, of shape [N,]

decnp.ndarray

Dec of candidate positions, of shape [N,]

ra_boundsnp.ndarray

RA of bounds, of shape [4,]

dec_boundsnp.ndarray

Dec of bounds, of shape [4,]

Returns#

np.ndarray

Boolean mask over ra, dec, whose elements are true if corresponding points are inside bounds

coord_utils.get_skycoord(ra, dec)[source]#

Create an astropy.coordinates.SkyCoord object

Parameters#

ranp.array

RA in deg

decnp.array

dec in deg

coord_utils.get_target_nside(n_pix, nside_in=2**5)[source]#

Get the NSIDE corresponding to the number of sub-healpixels

Parameters#

n_pixint

desired number of pixels

nside_inint

input NSIDE to subsample

coord_utils.match(ra_grid, dec_grid, ra_cat, dec_cat, threshold)[source]#

Match gridpoints to a catalog based on distance threshold

Parameters#

ra_grid : np.array dec_grid : np.array ra_cat : np.array dec_cat : np.array gridpoints : astropy.SkyCoord instance threshold : float

matching distance threshold in deg

extra_constraintnp.array of type bool

another set of constraints, aside from separation constraint. Ordering must be based on gridpoints

Returns#

sep_constraintnp.array of shape same as ra/dec_grid and type bool

whether each gridpoint was matched to a catalog within sep limit

passing_i_catnp.array of length same as ra_grid[sep_constraint]

catalog idx (value) corresponding to each successfully matched gridpoint (position)

passing_distnp.array of shape same as passing_i_cat

distance (value) corresponding to each successfully matched gridpoint (position)

coord_utils.sample_in_aperture(N, radius)[source]#

Uniformly sample points around a zero coordinate on the celestial sphere and translate to cartesian coordinates

Parameters#

radiusfloat

Aperture radius in deg

Returns#

tuple

(RA, dec) of the angular offsets in deg