pyimcom.utils.compareutils

This is a helper module with functions for comparing different SCAs. The SCAs are assumed to be square.

Fuctions

getfootprint

Extracts from the SCA a Mangle cap (Cartesian coordinates of the center and a bounding circle).

map_sca2sca

Gets the (x,y) in one SCA for each pixel in another SCA.

overlap_matrix

Computes the Boolean overlap matrix of a list of SCAs.

str2dirstem

Utility to separate the directory and file name from a stem.

Functions

getfootprint(mywcs, pad)

Gets the Cartesian coordinates of the corners.

map_sca2sca(target_wcs, ref_wcs[, pad, dtype, subsamp])

Finds the pixel mappings from a 'reference' WCS to a 'target' WCS.

get_overlap_matrix(list_of_wcs[, pad, verbose, subsamp])

Computes the fractional overlap matrix of a list of WCSs.

str2dirstem(st)

Utility to split a string st into a directory and a file stem:

Module Contents

getfootprint(mywcs, pad)[source]

Gets the Cartesian coordinates of the corners.

Parameters:
  • mywcs (astropy.wcs.WCS) – The WCS of the SCA.

  • pad (int or float) – How many native pixels to pad the sides of the SCA.

Returns:

This is a numpy array of the form [x,y,z,p], where (x,y,z) are the Cartesian coordinates of center; and p = 1 - cos(theta_max), where theta_max is the maximum distance from the center.

Return type:

np.array

Notes

The corners are padded by the indicated number of native pixels on each axis. The SCA is assumed square.

map_sca2sca(target_wcs, ref_wcs, pad=0, dtype=np.float64, subsamp=1)[source]

Finds the pixel mappings from a ‘reference’ WCS to a ‘target’ WCS.

Parameters:
  • target_wcs (astropy.wcs.WCS) – WCS that we want to ‘map to’ (we will make a map of the full nside x nside region).

  • ref_wcs (astropy.wcs.WCS) – WCS of the reference exposure that we want to ‘map from’

  • pad (int, optional) – Number of pixels by which to pad the input and output exposures.

  • dtype (type, optional) – Ouput data type for xf and yf (note is_in_ref is always Boolean).

  • subsamp (int, optional) – Samples every subsamp-th pixel (allows overlap to be computed faster). Starts with pixel [subsamp//2, subsamp//2].

Returns:

  • xpix (np.array) – Array of the x-positions in the “reference” WCS corresponding to a meshgrid in the “target” WCS. Shape (nside+2*pad, nside+2*pad). Data type dtype.

  • ypix (np.array) – Array of the x-positions in the “reference” WCS corresponding to a meshgrid in the “target” WCS. Shape (nside+2*pad, nside+2*pad). Data type dtype.

  • is_in_ref (np.array of bool) – Whether that pixel is in the reference exposure (including padding).

get_overlap_matrix(list_of_wcs, pad=0, verbose=False, subsamp=1)[source]

Computes the fractional overlap matrix of a list of WCSs.

We extend the boundaries by pad pixels on each side.

Parameters:
  • list_of_wcs (list of astropy.wcs.WCS) – The list of WCSs for each exposure; length N.

  • pad (int, optional) – Number of pixels to pad around each side.

  • verbose (bool, optional) – Whether to print details to the terminal.

  • subsamp (int, optional) – Samples every subsamp-th pixel (allows overlap to be computed faster).

Returns:

For N WCSs, this is a shape (N,N) symmetric matrix of fractional overlap. Here 0 represents no overlap and 1 represents full overlap.

Return type:

np.array of float

Notes

Because of distortions, fractional overlaps depend somewhat on which WCS is first in the list (fraction of exposure i in j is not the same as fraction of exposure j in i). Not recommended to use this function in cases where that matters.

str2dirstem(st)[source]

Utility to split a string st into a directory and a file stem: e.g. if input is 'A/c24/B_' then output is ('A/c24', 'B_').

Parameters:

st (str) – File stem.

Returns:

The first entry is the directory, and the second is the local stem.

Return type:

(str, str)