WCS objects perform standard WCS transformations, and correct for SIP and Paper IV table-lookup distortions, based on the WCS keywords and supplementary data read from a FITS file.
header: A string containing the header content, or a PyFITS header object. If header is not provided or None, the object will be initialized to default values.
fobj: A PyFITS file (hdulist) object. It is needed when header keywords point to a Paper IV Lookup table distortion stored in a different extension.
key: A string. The name of a particular WCS transform to use. This may be either ' ' or 'A'-'Z' and corresponds to the "a" part of the CTYPEia cards. key may only be provided if header is also provided.
minerr: A floating-point value. The minimum value a distortion correction must have in order to be applied. If the value of CQERRja is smaller than minerr, the corresponding distortion is not applied.
relax: Degree of permissiveness:
- False: Recognize only FITS keywords defined by the published WCS standard.
- True: Admit all recognized informal extensions of the WCS standard.
- int: a bit field selecting specific extensions to accept. See Header-reading relaxation constants for details.
naxis: int or sequence. Extracts specific coordinate axes using sub(). If a header is provided, and naxis is not None, naxis will be passed to sub() in order to select specific axes from the header. See sub() for more details about this parameter.
keysel: A list of flags used to select the keyword types considered by wcslib. When None, only the standard image header keywords are considered (and the underlying wcspih() C function is called). To use binary table image array or pixel list keywords, keysel must be set.
Each element in the list should be one of the following strings:
- ‘image’: Image header keywords
- ‘binary’: Binary table image array keywords
- ‘pixel’: Pixel list keywords
Keywords such as EQUIna or RFRQna that are common to binary table image arrays and pixel lists (including WCSNna and TWCSna) are selected by both ‘binary’ and ‘pixel’.
colsel: A sequence of table column numbers used to restrict the WCS transformations considered to only those pertaining to the specified columns. If None, there is no restriction.
fix : When True (default), call fix on the resulting object to fix any non-standard uses in the header.
Warning
pywcs supports arbitrary n dimensions for the core WCS (the transformations handled by WCSLIB). However, the Paper IV lookup table and SIP distortions must be two dimensional. Therefore, if you try to create a WCS object where the core WCS has a different number of dimensions than 2 and that object also contains a Paper IV lookup table or SIP distortion, a ValueError exception will be raised. To avoid this, consider using the naxis kwarg to select two dimensions from the core WCS.
Exceptions:
Transforms pixel coordinates to sky coordinates by doing all of the following in order:
Either two or three arguments may be provided.
- 2 arguments: An N x naxis array of x- and y-coordinates, and an origin.
- 3 arguments: 2 one-dimensional arrays of x and y coordinates, and an origin.
Here, origin is the coordinate in the upper left corner of the image. In FITS and Fortran standards, this is 1. In Numpy and C standards this is 0.
Returns the sky coordinates, in degrees. If the input was a single array and origin, a single array is returned, otherwise a tuple of arrays is returned.
An optional keyword argument, ra_dec_order, may be provided, that when True will ensure that sky coordinates are always given and returned in as (ra, dec) pairs, regardless of the order of the axes specified by the in the CTYPE keywords.
For a transformation that is not two-dimensional, the two-argument form must be used.
Note
The order of the axes for the result is determined by the CTYPEia keywords in the FITS header, therefore it may not always be of the form (ra, dec). The lat, lng, lattyp and lngtyp members can be used to determine the order of the axes.
Exceptions:
Calculates the footprint of the image on the sky.
A footprint is defined as the positions of the corners of the image on the sky after all available distortions have been applied.
Returns a (4, 2) array of (x, y) coordinates.
Return a shallow copy of the object.
Convenience method so user doesn’t have to import the copy stdlib module.
Return a deep copy of the object.
Convenience method so user doesn’t have to import the copy stdlib module.
Convert detector coordinates to image plane coordinates using Paper IV table-lookup distortion correction.
Either two or three arguments may be provided.
- 2 arguments: An N x 2 array of x- and y-coordinates, and an origin.
- 3 arguments: 2 one-dimensional arrays of x and y coordinates, and an origin.
Here, origin is the coordinate in the upper left corner of the image. In FITS and Fortran standards, this is 1. In Numpy and C standards this is 0.
Returns the pixel coordinates. If the input was a single array and origin, a single array is returned, otherwise a tuple of arrays is returned.
Exceptions:
Writes out a ds9 style regions file. It can be loaded directly by ds9.
list of dicts
Similar to self.wcsprm.axis_types but provides the information in a more Python-friendly format.
Returns a list of dictionaries, one for each axis, each containing attributes about the type of that axis.
Each dictionary has the following keys:
CTYPEia in "4-3" form with unrecognized algorithm code will generate an error.
Convert pixel coordinates to focal plane coordinates using Paper IV table-lookup distortion correction.
Either two or three arguments may be provided.
- 2 arguments: An N x 2 array of x- and y-coordinates, and an origin.
- 3 arguments: 2 one-dimensional arrays of x and y coordinates, and an origin.
Here, origin is the coordinate in the upper left corner of the image. In FITS and Fortran standards, this is 1. In Numpy and C standards this is 0.
Returns the focal coordinates. If the input was a single array and origin, a single array is returned, otherwise a tuple of arrays is returned.
Exceptions:
Convert pixel coordinates to focal plane coordinates using the SIP polynomial distortion convention and Paper IV table-lookup distortion correction.
Either two or three arguments may be provided.
- 2 arguments: An N x 2 array of x- and y-coordinates, and an origin.
- 3 arguments: 2 one-dimensional arrays of x and y coordinates, and an origin.
Here, origin is the coordinate in the upper left corner of the image. In FITS and Fortran standards, this is 1. In Numpy and C standards this is 0.
Returns the focal coordinates. If the input was a single array and origin, a single array is returned, otherwise a tuple of arrays is returned.
Exceptions:
Temporary function for internal use.
Convert focal plane coordinates to pixel coordinates using the SIP polynomial distortion convention.
Paper IV table lookup distortion correction is not applied, even if that information existed in the FITS file that initialized this WCS object.
Either two or three arguments may be provided.
- 2 arguments: An N x 2 array of x- and y-coordinates, and an origin.
- 3 arguments: 2 one-dimensional arrays of x and y coordinates, and an origin.
Here, origin is the coordinate in the upper left corner of the image. In FITS and Fortran standards, this is 1. In Numpy and C standards this is 0.
Returns the pixel coordinates. If the input was a single array and origin, a single array is returned, otherwise a tuple of arrays is returned.
Exceptions:
Convert pixel coordinates to focal plane coordinates using the SIP polynomial distortion convention.
Paper IV table lookup distortion correction is not applied, even if that information existed in the FITS file that initialized this WCS object. To correct for that, use pix2foc or p4_pix2foc.
Either two or three arguments may be provided.
- 2 arguments: An N x 2 array of x- and y-coordinates, and an origin.
- 3 arguments: 2 one-dimensional arrays of x and y coordinates, and an origin.
Here, origin is the coordinate in the upper left corner of the image. In FITS and Fortran standards, this is 1. In Numpy and C standards this is 0.
Returns the focal coordinates. If the input was a single array and origin, a single array is returned, otherwise a tuple of arrays is returned.
Exceptions:
Extracts the coordinate description for a subimage from a WCS object.
The world coordinate system of the subimage must be separable in the sense that the world coordinates at any point in the subimage must depend only on the pixel coordinates of the axes extracted. In practice, this means that the PCi_ja matrix of the original image must not contain non-zero off-diagonal terms that associate any of the subimage axes with any of the non-subimage axes.
sub can also add axes to a wcsprm struct. The new axes will be created using the defaults set by the Wcsprm constructor which produce a simple, unnamed, linear axis with world coordinates equal to the pixel coordinate. These default values can be changed before invoking set.
No checks are performed to verify that the coordinate axes are consistent, that is done by set.
Coordinate axes types may be specified using either strings or special integer constants. The available types are:
- 'longitude' / WCSSUB_LONGITUDE: Celestial longitude
- 'latitude' / WCSSUB_LATITUDE: Celestial latitude
- 'cubeface' / WCSSUB_CUBEFACE: Quadcube CUBEFACE axis
- 'spectral' / WCSSUB_SPECTRAL: Spectral axis
- 'stokes' / WCSSUB_STOKES: Stokes axis
- 'celestial' / WCSSUB_CELESTIAL: An alias for the combination of 'longitude', 'latitude' and 'cubeface'.
Returns a WCS object, which is a deep copy of the original object.
Exceptions:
Note
Combinations of subimage axes of particular types may be extracted in the same order as they occur in the input image by combining the integer constants with the ‘binary or’ (|) operator. For example:
wcs.sub([WCSSUB_LONGITUDE | WCSSUB_LATITUDE | WCSSUB_SPECTRAL])
would extract the longitude, latitude, and spectral axes in the same order as the input image. If one of each were present, the resulting object would have three dimensions.
For convenience, WCSSUB_CELESTIAL is defined as the combination WCSSUB_LONGITUDE | WCSSUB_LATITUDE | WCSSUB_CUBEFACE.
The codes may also be negated to extract all but the types specified, for example:
wcs.sub([
WCSSUB_LONGITUDE,
WCSSUB_LATITUDE,
WCSSUB_CUBEFACE,
-(WCSSUB_SPECTRAL | WCSSUB_STOKES)])
The last of these specifies all axis types other than spectral or Stokes. Extraction is done in the order specified by axes, i.e. a longitude axis (if present) would be extracted first (via axes[0]) and not subsequently (via axes[3]). Likewise for the latitude and cubeface axes in this example.
The number of dimensions in the returned object may be less than or greater than the length of axes. However, it will never exceed the number of axes in the input image.
Generate a pyfits.HDUList object with all of the information stored in this object. This should be logically identical to the input FITS file, but it will be normalized in a number of ways.
See WCS.to_header for some warnings about the output produced.
Returns a pyfits.HDUList object.
Generate a pyfits.Header object with the basic WCS and SIP information stored in this object. This should be logically identical to the input FITS file, but it will be normalized in a number of ways.
Warning
This function does not write out Paper IV distortion information, since that requires multiple FITS header data units. To get a full representation of everything in this object, use to_fits.
The output header will almost certainly differ from the input in a number of respects:
- The output header only contains WCS-related keywords. In particular, it does not contain syntactically-required keywords such as SIMPLE, NAXIS, BITPIX, or END.
- Deprecated (e.g. CROTAn) or non-standard usage will be translated to standard (this is partially dependent on whether fix was applied).
- Quantities will be converted to the units used internally, basically SI with the addition of degrees.
- Floating-point quantities may be given to a different decimal precision.
- Elements of the PCi_j matrix will be written if and only if they differ from the unit matrix. Thus, if the matrix is unity then no elements will be written.
- Additional keywords such as WCSAXES, CUNITia, LONPOLEa and LATPOLEa may appear.
- The original keycomments will be lost, although to_header tries hard to write meaningful comments.
- Keyword order may be changed.
Returns a pyfits.Header object.
Identical to to_header, but returns a string containing the header cards.
Transforms pixel coordinates to sky coordinates by doing only the basic wcslib transformation. No SIP or Paper IV table lookup distortion correction is applied. To perform distortion correction, see all_pix2sky, sip_pix2foc, p4_pix2foc, or pix2foc.
Either two or three arguments may be provided.
- 2 arguments: An N x naxis array of x- and y-coordinates, and an origin.
- 3 arguments: 2 one-dimensional arrays of x and y coordinates, and an origin.
Here, origin is the coordinate in the upper left corner of the image. In FITS and Fortran standards, this is 1. In Numpy and C standards this is 0.
Returns the sky coordinates, in degrees.. If the input was a single array and origin, a single array is returned, otherwise a tuple of arrays is returned.
An optional keyword argument, ra_dec_order, may be provided, that when True will ensure that sky coordinates are always given and returned in as (ra, dec) pairs, regardless of the order of the axes specified by the in the CTYPE keywords.
For a transformation that is not two-dimensional, the two-argument form must be used.
Note
The order of the axes for the result is determined by the CTYPEia keywords in the FITS header, therefore it may not always be of the form (ra, dec). The lat, lng, lattyp and lngtyp members can be used to determine the order of the axes.
Exceptions:
Transforms sky coordinates to pixel coordinates, using only the basic wcslib WCS transformation. No SIP or Paper IV table lookup distortion is applied.
Either two or three arguments may be provided.
- 2 arguments: An N x naxis array of x- and y-coordinates, and an origin.
- 3 arguments: 2 one-dimensional arrays of x and y coordinates, and an origin.
Here, origin is the coordinate in the upper left corner of the image. In FITS and Fortran standards, this is 1. In Numpy and C standards this is 0.
Returns the pixel coordinates. If the input was a single array and origin, a single array is returned, otherwise a tuple of arrays is returned.
An optional keyword argument, ra_dec_order, may be provided, that when True will ensure that sky coordinates are always given and returned in as (ra, dec) pairs, regardless of the order of the axes specified by the in the CTYPE keywords.
For a transformation that is not two-dimensional, the two-argument form must be used.
Note
The order of the axes for the input sky array is determined by the CTYPEia keywords in the FITS header, therefore it may not always be of the form (ra, dec). The lat, lng, lattyp and lngtyp members can be used to determine the order of the axes.
Exceptions:
The pre-linear transformation distortion lookup table, CPDIS1.
The pre-linear transformation distortion lookup table, CPDIS2.
A DistortionLookupTable object for detector to image plane correction in the x-axis. double
The native latitude of the celestial pole, LATPOLEa (deg).
A DistortionLookupTable object for detector to image plane correction in the y-axis. The name of the unit being converted to.
This value always uses standard unit names, even if the UnitConverter was initialized with a non-standard unit name.
Find all the WCS transformations in the given header.
header: A string or PyFITS header object.
relax: Degree of permissiveness:
- False: Recognize only FITS keywords defined by the published WCS standard.
- True: Admit all recognized informal extensions of the WCS standard.
- int: a bit field selecting specific extensions to accept. See Header-reading relaxation constants for details.
keysel: A list of flags used to select the keyword types considered by wcslib. When None, only the standard image header keywords are considered (and the underlying wcspih() C function is called). To use binary table image array or pixel list keywords, keysel must be set.
Each element in the list should be one of the following strings:
- ‘image’: Image header keywords
- ‘binary’: Binary table image array keywords
- ‘pixel’: Pixel list keywords
Keywords such as EQUIna or RFRQna that are common to binary table image arrays and pixel lists (including WCSNna and TWCSna) are selected by both ‘binary’ and ‘pixel’.
Returns a list of WCS objects.