pyimcom.wcsutil
This file contains the PyIMCOM_WCS class, which allows PyIMCOM to take in a WCS either as a FITS header or a GWCS from an ASDF file.
PyIMCOM_WCS supports the all_pix2world and all_world2pix methods, which are like their astropy counterparts. A separate local_partial_pixel_derivatives2 function was written so that we don’t need to rely on astropy’s partial derivative function (which has singular behavior near the poles).
Classes
- ABasis
Base class for basis polynomials.
- SimpleBaiss
Simple polynomials.
- LocWCS
Internal version of gwcs plus approximations.
- PyIMCOM_WCS
Main class for PyIMCOM’s WCS, intended to support functions in PyIMCOM that were originally written with astropy.wcs.WCS but now also have to accept gwcs inputs.
Functions
- local_partial_pixel_derivatives2
Jacobian for WCS (2-sided derivative, designed to also work near poles).
- get_pix_area
Calculate the effective pixel areas in the image.
- _stand_alone_test
Unit test function.
Classes
Base class for 2D basis polynomials. These are defined in the range -1<u<1 and -1<v<1. |
|
Simple polynomials (each coefficient is 1). Base class is pyimcom.wcsutil.ABasis. |
|
WCS built from a gwcs that can be reported in various formats. |
|
Class that has the key methods we depend on from astropy.wcs, |
Functions
|
Alternative form of the local partial derivatives function |
|
Calculate the effective pixel areas in the image. |
|
Simple tests of the above routines. |
Module Contents
- class ABasis(p_order, N)[source]
Base class for 2D basis polynomials. These are defined in the range -1<u<1 and -1<v<1.
Want to use inherited classes that replace the coef_setup method.
- Parameters:
p_order (int) – Max order of the polynomial.
N (int) – Side length of grid the polynomial is evaluated on.
- coefs[source]
Coefficient matrix: coefs[i,j,k] is the coefficient of u^i v^j in the kth polynomial.
- Type:
np.array
- coef_setup()[source]
Build the coefficients.
Shouldn’t get here, always use the methods from the inherited classes.
- eval(u, v)[source]
Takes in an array of positions, and returns an array of the basis polynomials evaluated at those points.
- Parameters:
u (np.array) – Array of horizontal positions. Shape (npts,).
v (np.array) – Array of vertical positions. Shape (npts,).
- Returns:
A 2D array: out[k,l] = kth poly evaluated at lth point. Shape (N_basis, npts).
- Return type:
np.array
Notes
Could be replaced with a more stable version for specific types of polynomials if provided by that basis.
- class SimpleBasis(p_order, N)[source]
Bases:
ABasisSimple polynomials (each coefficient is 1). Base class is pyimcom.wcsutil.ABasis.
- class LocWCS(gwcs, N=4088)[source]
WCS built from a gwcs that can be reported in various formats.
- Parameters:
gwcs (gwcs.WCS) – The generalized WCS.
N (int, optional) – Side length of the array.
- approx_wcs
The best-fit TAN-SIP approximation (if set).
- Type:
astropy.wcs.WCS
- wcs_max_err
The worst error (in pixels) from the approx_wcs (if set).
- Type:
float
- errmap
The error map (in pixels) from the approx_wcs (if set). Shape (2, N, N).
- Type:
np.array
- wcs_approx_sip(p_order=3, nq=100, basis='simple', verbose=False)[source]
Generate approximate TAN-SIP polynomial wcs.
- Parameters:
p_order (int, optional) – Order of polynomial to fit.
nq (int, optional) – Grid size for fitting WCS (nq x nq).
basis (str, optional) – Type of basis to use in fitting the WCS.
verbose (bool) – Print lots of diagnostics to the terminal.
Notes
The following basis sets for the linear algerbra are available:
‘simple’ : simple polynomials (could be unstable for high order)
- _make_errmap()[source]
Builds the error map.
Notes
The shape of the error map is (2, N, N).
The format is:
errmap[0,j,i] is the x-offset of pixel (i,j)
errmap[1,j,i] is the y-offset.
The offset is in the sense of if there is a barred coordinate system that is the TAN-SIP approximation and unbarred is the true system, then:
# xbar == x + errmap[0,y,x] # ybar == y + errmap[1,y,x]
- err_interp(a=4, n_pad=2048)[source]
Makes interpolators for the delta x = xbar-x and delta y = ybar-y directions.
The functions returned are of the form dX(arr), where arr is an array of shape (K,2) indicating K points. arr[:,0] are the y-values, and arr[:,1] are the x-values.
- Parameters:
a (int) – Number of pixels from edge to use for linear extrapolation..
n_pad (int) – Distance to extrapolate the error map.
- Returns:
function – An interpolator function for the delta x error.
function – An interpolator function for the delta y error.
- class PyIMCOM_WCS(inwcs, noconvert=False)[source]
Class that has the key methods we depend on from astropy.wcs, but can be constructed from other types of WCS information (including gwcs).
- Parameters:
inwcs (fits.Header or astropy.wcs.WCS or gwcs.wcs.WCS) – The input WCS.
noconvert (bool, optional) – Do not internally convert WCS type.
- constructortype
What type of input was used to make this object.
- Type:
str
- type
What type of method to use in computation (currently ASTROPY or GWCS).
- Type:
str
- obj
The WCS object being wrapped.
- Type:
variable
- err
For ‘ASTROPY+’, contains an interpolator for the error. Not used for other types.
- Type:
(function,function), optional
- _all_pix2world(pos, origin)[source]
An astropy-like function to go from pixel to world coordinates.
- Parameters:
pos (np.array) – Pixel coordinates, shape (N,2).
origin (int) – Offset of lower-left pixel, should be 0 or 1.
- Returns:
World coordinates. Shape (N,2).
- Return type:
np.array
- all_pix2world(*args)[source]
An astropy-like function to go from pixel to world coordinates.
This has both a 2-argument
(pos, origin)or a 3-argument(pos, pos2, origin)format.In 2-argument format, pos is a shape (N, 2) array and the return is also a shape (N, 2) array.
In 3-argument format, pos is a shape (N,) array of pixel x, pos2 is a shape (N,) array of pixel y, and the return valus is ra, dec, both shape (N,) arrays. For N=1, you may use scalars.
In both cases, origin is an integer indicating the index of the lower-left pixel (0 or 1).
- Parameters:
*args (variable) – See description.
- Returns:
World coordinates.
- Return type:
np.array or np.array, np.array
See also
_all_pix2world2-argument format.
- _all_world2pix(pos, origin)[source]
An astropy-like function to go from world to pixel coordinates.
- Parameters:
pos (np.array) – World coordinates, shape (N,2).
origin (int) – Offset of lower-left pixel, should be 0 or 1.
- Returns:
Pixel coordinates. Shape (N,2).
- Return type:
np.array
- all_world2pix(*args)[source]
An astropy-like function to go from pixel to world coordinates.
This has both a 2-argument
(pos,origin)or a 3-argument(pos,pos2,origin)format.In 2-argument format, pos is a shape (N, 2) array and the return is also a shape (N, 2) array.
In 3-argument format, pos is a shape (N,) array of ra, pos2 is a shape (N,) array of dec, and the return valus is x, y, both shape (N,) arrays. For N=1, you may use scalars.
In both cases, origin is an integer indicating the index of the lower-left pixel (0 or 1).
- Parameters:
*args (variable) – See description.
- Returns:
Pixel coordinates.
- Return type:
np.array or np.array, np.array
See also
_all_world2pix2-argument format.
- local_partial_pixel_derivatives2(inwcs, x, y)[source]
Alternative form of the local partial derivatives function that is well-behaved near the poles and uses 2-sided derivatives.
- Parameters:
inwcs (pyimcom.wcsutil.PyIMCOM_WCS) – The WCS that we are using.
x (float) – x position in pixels (0 offset)
y (float) – y position in pixels (0 offset)
- Returns:
jac – 2x2 Jacobian matrix, with output 0->West and 1->North
- Return type:
np.array
Notes
This is relative to unit vectors, so jac[0,:] is -cos(declination) * d(ra)/d(pix x or y). So note this is different from astropy local_partial_pixel_derivatives, which doesn’t have the factor of -cos(declination).
- get_pix_area(inwcs, region=[0, Settings.sca_nside, 0, Settings.sca_nside], pad=1, ovsamp=1)[source]
Calculate the effective pixel areas in the image.
- Parameters:
inwcs (pyimcom.wcsutil.PyIMCOM_WCS) – The WCS that we are using.
region (list) – A list of [x0,x1,y0,y1] to indicate a subregion of the image to calculate the pixel area for. Default: Full active region of SCA
pad (int, optional) – Number of native pixels to pad on each side of the image for derivative calculation.
ovsamp (int, optional) – Oversampling factor to use in calculating the pixel area.
- Returns:
pix_area – Matrix of effecitive pixel areas in square degrees; shape (ovsamp*(y1-y0), ovsamp*(x1-x0)).
- Return type:
np.array of float
Notes