Wcsprm#
- class astropy.wcs.Wcsprm(header=None, key=' ', relax=False, naxis=2, keysel=0, colsel=None)#
Bases:
objectWcsprmperforms the core WCS transformations.Note
The members of this object correspond roughly to the key/value pairs in the FITS header. However, they are adjusted and normalized in a number of ways that make performing the WCS transformation easier. Therefore, they can not be relied upon to get the original values in the header. For that, use
astropy.io.fits.Headerdirectly.The FITS header parsing enforces correct FITS “keyword = value” syntax with regard to the equals sign occurring in columns 9 and 10. However, it does recognize free-format character (NOST 100-2.0, Sect. 5.2.1), integer (Sect. 5.2.3), and floating-point values (Sect. 5.2.4) for all keywords.
Warning
Many of the attributes of this class require additional processing when modifying underlying C structure. When needed, this additional processing is implemented in attribute setters. Therefore, for mutable attributes, one should always set the attribute rather than a slice of its current value (or its individual elements) since the latter may lead the class instance to be in an invalid state. For example, attribute
crpixof a 2D WCS’Wcsprmobjectwcsshould be set aswcs.crpix = [crpix1, crpix2]instead ofwcs.crpix[0] = crpix1; wcs.crpix[1] = crpix2].- Parameters:
- header
Header,python:str, or None. If
None, the object will be initialized to default values.- key
python:str, optional The key referring to a particular WCS transform in the header. This may be either
' 'or'A'-'Z'and corresponds to the"a"part of"CTYPEia". (key may only be provided if header is also provided.)- relaxbool or
python:int, optional 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
python:int, optional The number of world coordinates axes for the object. (naxis may only be provided if header is
None.)- keyselpython:sequence of flag bits, optional
Vector of flag bits that may be used to restrict the keyword types considered:
WCSHDR_IMGHEAD: Image header keywords.WCSHDR_BIMGARR: Binary table image array.WCSHDR_PIXLIST: Pixel list keywords.
If zero, there is no restriction. If -1, the underlying wcslib function
wcspih()is called, rather thanwcstbh().- colselpython:sequence of
python:int A sequence of table column numbers used to restrict the keywords considered.
Noneindicates no restriction.
- header
- Raises:
MemoryErrorMemory allocation failed.
ValueErrorInvalid key.
KeyErrorKey not found in FITS header.
Attributes Summary
strCharacter code for alternate coordinate descriptions.AuxprmAuxiliary coordinate system information of a specialist nature.int array[naxis]An array of four-digit type codes for each axis.doubleEquivalent toDATE-OBS.double array[naxis][naxis]TheCDi_jalinear transformation matrix.double array[naxis]Coordinate increments (CDELTia) for each coord axis.CelprmInformation required to transform celestial coordinates.booleanIs there an offset?list of stringsA list of the coordinate axis names, fromCNAMEia.int array[naxis]An array recording the column numbers for each axis in a pixel list.intColumn of FITS binary table associated with this WCS.double array[naxis]period of a phase axis, CPERIia.double array[naxis]The random error in each coordinate axis,CRDERia.double array[naxis]CROTAiakeyvalues for each coordinate axis.double array[naxis]Coordinate reference pixels (CRPIXja) for each pixel axis.double array[naxis]Coordinate reference values (CRVALia) for each coordinate axis.double array[naxis]The systematic error in the coordinate value axes,CSYERia.list of strings[naxis]List ofCTYPEiakeyvalues.intIndex into thepixcrd(pixel coordinate) array for theCUBEFACEaxis.list of astropy.UnitBase[naxis]List ofCUNITiakeyvalues asastropy.units.UnitBaseinstances.double array[naxis]The time at the zero point of a phase axis,CSPHSia.stringRepresentative mid-point of the date of observation.stringDate at the start of the observation.stringDate at the end of the observation.stringStart of the date of observation.stringDate of a reference epoch relative to which other time measurements refer.doubleThe equinox associated with dynamical equatorial or ecliptic coordinate systems.double array[2][2](read-only) Inverse of theCDELTorPCmatrix.doubleEquivalent toDATE-OBS.int(read-only) The index into the world coord array containing latitude values.doubleThe native latitude of the celestial pole,LATPOLEa(deg).string(read-only) Celestial axis type for latitude.int(read-only) The index into the world coord array containing longitude values.string(read-only) Celestial axis type for longitude.doubleThe native longitude of the celestial pole.doubleModified Julian Date corresponding toDATE-AVG.doubleModified Julian Date corresponding toDATE-BEG.doubleModified Julian Date corresponding toDATE-END.doubleModified Julian Date corresponding toDATE-OBS.doubleModified Julian Date corresponding toDATE-REF.stringThe name given to the coordinate representationWCSNAMEa.int(read-only) The number of axes (pixel and coordinate).double array[3]Location of the observer in a standard terrestrial reference frame.stringURI, URL, or name of an orbit ephemeris file giving spacecraft coordinates relating to TREFPOS.double array[naxis][naxis]ThePCi_ja(pixel coordinate) transformation matrix.doubleThe native latitude of the fiducial point.double array[2][2](read-only) Matrix containing the product of theCDELTiadiagonal matrix and thePCi_jamatrix.stringThe Solar System ephemeris used for calculating a pathlength delay.stringThe equatorial or ecliptic coordinate system type,RADESYSa.doubleRest frequency (Hz) fromRESTFRQa.doubleRest wavelength (m) fromRESTWAVa.int(read-only) The index containing the spectral axis values.stringSpectral reference frame (standard of rest),SPECSYSa.stringSpectral reference frame.stringSpectral reference frame for redshift.list of TabprmTabular coordinate objects.doubleequivalent to the elapsed time between DATE-BEG and DATE-END, in units of TIMEUNIT.doubleThe native longitude of the fiducial point.doublethe resolution of the time stamps.doubleTime offset, which may be used, for example, to provide a uniform clock correctiondoublerelative position of the time stamps in binned time intervals, a value between 0.0 and 1.0.stringTime scale (UTC, TAI, etc.) in which all other time-related auxiliary header values are recorded.stringTime units in which the following header values are expressed:TSTART,TSTOP,TIMEOFFS,TIMSYER,TIMRDER,TIMEDEL.doublethe accuracy of time stamps relative to each other, in units of TIMEUNIT.doublethe absolute error of the time values, in units of TIMEUNIT.stringReference direction used in calculating a pathlength delay.stringLocation in space where the recorded time is valid.doubleequivalent to DATE-BEG expressed as a time in units of TIMEUNIT relative to DATEREF+TIMEOFFS.doubleequivalent to DATE-END expressed as a time in units of TIMEUNIT relative to DATEREF+TIMEOFFS.doubleVelocity angle.doubleRelative radial velocity.intAIPS velocity code.list of Wtbarrobjects to construct coordinate lookup tables from BINTABLE.doubleeffective exposure time in units of TIMEUNIT.doubleThe redshift,ZSOURCEa, of the source.Methods Summary
bounds_check(pix2world, world2pix)Enable/disable bounds checking.
cdfix()Fix erroneously omitted
CDi_jakeywords.celfix(/)Translates AIPS-convention celestial projection types,
-NCPand-GLS.compare(other[, cmp, tolerance])Compare two Wcsprm objects for equality.
cylfix()Fixes WCS keyvalues for malformed cylindrical projections.
datfix()Translates the old
DATE-OBSdate format to year-2000 standard form(yyyy-mm-ddThh:mm:ss)and derivesMJD-OBSfrom it if not already set.fix([translate_units, naxis])Applies all of the corrections handled separately by
datfix,unitfix,celfix,spcfix,cylfixandcdfix.get_cdelt(/)Coordinate increments (
CDELTia) for each coord axis asdouble array[naxis].get_pc(/)Returns the
PCmatrix in read-only form asdouble array[naxis][naxis].get_ps(/)Returns
PSi_makeywords for each i and m as list of tuples.get_pv(/)Returns
PVi_makeywords for each i and m as list of tuples.has_cd(/)Returns
TrueifCDi_jais present.has_cdi_ja(/)Alias for
has_cd.has_crota(/)Returns
TrueifCROTAiais present.has_crotaia(/)Alias for
has_crota.has_pc(/)Returns
TrueifPCi_jais present.has_pci_ja(/)Alias for
has_pc.is_unity(/)Returns
Trueif the linear transformation matrix (cd) is unity.mix(mixpix, mixcel, vspan, vstep, viter, ...)Given either the celestial longitude or latitude plus an element of the pixel coordinate, solves for the remaining elements by iterating on the unknown celestial coordinate element using
s2p.p2s(pixcrd, origin)Converts pixel to world coordinates.
Print the contents of the
Wcsprmobject to stdout.s2p(world, origin)Transforms world coordinates to pixel coordinates.
set()Sets up a WCS object for use according to information supplied within it.
set_ps(ps)Sets
PSi_makeywords for each i and m.set_pv(pv)Sets
PVi_makeywords for each i and m.spcfix(/)Translates AIPS-convention spectral coordinate types.
sptr(ctype[, i])Translates the spectral axis in a WCS object.
sub(axes)Extracts the coordinate description for a subimage from a
WCSobject.to_header([relax])to_headertranslates a WCS object into a FITS header.unitfix([translate_units])Translates non-standard
CUNITiakeyvalues.Attributes Documentation
- alt#
strCharacter code for alternate coordinate descriptions.For example, the
"a"in keyword names such asCTYPEia. This is a space character for the primary coordinate description, or one of the 26 upper-case letters, A-Z.
- axis_types#
int array[naxis]An array of four-digit type codes for each axis.First digit (i.e. 1000s):
0: Non-specific coordinate type.
1: Stokes coordinate.
2: Celestial coordinate (including
CUBEFACE).3: Spectral coordinate.
Second digit (i.e. 100s):
0: Linear axis.
1: Quantized axis (
STOKES,CUBEFACE).2: Non-linear celestial axis.
3: Non-linear spectral axis.
4: Logarithmic axis.
5: Tabular axis.
Third digit (i.e. 10s):
0: Group number, e.g. lookup table number
The fourth digit is used as a qualifier depending on the axis type.
For celestial axes:
0: Longitude coordinate.
1: Latitude coordinate.
2:
CUBEFACEnumber.
For lookup tables: the axis number in a multidimensional table.
CTYPEiain"4-3"form with unrecognized algorithm code will have its type set to -1 and generate an error.
- bepoch#
doubleEquivalent toDATE-OBS.Expressed as a Besselian epoch.
See also
- cd#
double array[naxis][naxis]TheCDi_jalinear transformation matrix.For historical compatibility, three alternate specifications of the linear transformations are available in wcslib. The canonical
PCi_jawithCDELTia,CDi_ja, and the deprecatedCROTAiakeywords. Although the latter may not formally co-exist withPCi_ja, the approach here is simply to ignore them if given in conjunction withPCi_ja.has_pc,has_cdandhas_crotacan be used to determine which of these alternatives are present in the header.These alternate specifications of the linear transformation matrix are translated immediately to
PCi_jabysetand are nowhere visible to the lower-level routines. In particular,setresetscdeltto unity ifCDi_jais present (and noPCi_ja). If noCROTAiais associated with the latitude axis,setreverts to a unityPCi_jamatrix.
- cdelt#
double array[naxis]Coordinate increments (CDELTia) for each coord axis.If a
CDi_jalinear transformation matrix is present, a warning is raised andcdeltis ignored. TheCDi_jamatrix may be deleted by:del wcs.wcs.cd
An undefined value is represented by NaN.
- cel_offset#
booleanIs there an offset?If
True, an offset will be applied to(x, y)to force(x, y) = (0, 0)at the fiducial point, (phi_0, theta_0). Default isFalse.
- cname#
list of stringsA list of the coordinate axis names, fromCNAMEia.
- colax#
int array[naxis]An array recording the column numbers for each axis in a pixel list.
- colnum#
intColumn of FITS binary table associated with this WCS.Where the coordinate representation is associated with an image-array column in a FITS binary table, this property may be used to record the relevant column number.
It should be set to zero for an image header or pixel list.
- cperi#
double array[naxis]period of a phase axis, CPERIia.An undefined value is represented by NaN.
- crder#
double array[naxis]The random error in each coordinate axis,CRDERia.An undefined value is represented by NaN.
- crota#
double array[naxis]CROTAiakeyvalues for each coordinate axis.For historical compatibility, three alternate specifications of the linear transformations are available in wcslib. The canonical
PCi_jawithCDELTia,CDi_ja, and the deprecatedCROTAiakeywords. Although the latter may not formally co-exist withPCi_ja, the approach here is simply to ignore them if given in conjunction withPCi_ja.has_pc,has_cdandhas_crotacan be used to determine which of these alternatives are present in the header.These alternate specifications of the linear transformation matrix are translated immediately to
PCi_jabysetand are nowhere visible to the lower-level routines. In particular,setresetscdeltto unity ifCDi_jais present (and noPCi_ja). If noCROTAiais associated with the latitude axis,setreverts to a unityPCi_jamatrix.
- crpix#
double array[naxis]Coordinate reference pixels (CRPIXja) for each pixel axis.
- crval#
double array[naxis]Coordinate reference values (CRVALia) for each coordinate axis.
- csyer#
double array[naxis]The systematic error in the coordinate value axes,CSYERia.An undefined value is represented by NaN.
- ctype#
list of strings[naxis]List ofCTYPEiakeyvalues.The
ctypekeyword values must be in upper case and there must be zero or one pair of matched celestial axis types, and zero or one spectral axis.
- cubeface#
intIndex into thepixcrd(pixel coordinate) array for theCUBEFACEaxis.This is used for quadcube projections where the cube faces are stored on a separate axis.
The quadcube projections (
TSC,CSC,QSC) may be represented in FITS in either of two ways:The six faces may be laid out in one plane and numbered as follows:
0 4 3 2 1 4 3 2 5
Faces 2, 3 and 4 may appear on one side or the other (or both). The world-to-pixel routines map faces 2, 3 and 4 to the left but the pixel-to-world routines accept them on either side.
The
COBEconvention in which the six faces are stored in a three-dimensional structure using aCUBEFACEaxis indexed from 0 to 5 as above.
These routines support both methods;
setdetermines which is being used by the presence or absence of aCUBEFACEaxis inctype.p2sands2ptranslate theCUBEFACEaxis representation to the single plane representation understood by the lower-level projection routines.
- cunit#
list of astropy.UnitBase[naxis]List ofCUNITiakeyvalues asastropy.units.UnitBaseinstances.These define the units of measurement of the
CRVALia,CDELTiaandCDi_jakeywords.As
CUNITiais an optional header keyword,cunitmay be left blank but otherwise is expected to contain a standard units specification as defined by WCS Paper I.unitfixis available to translate commonly used non-standard units specifications but this must be done as a separate step before invokingset.For celestial axes, if
cunitis not blank,setuseswcsunitsto parse it and scalecdelt,crval, andcdto decimal degrees. It then resetscunitto"deg".For spectral axes, if
cunitis not blank,setuseswcsunitsto parse it and scalecdelt,crval, andcdto SI units. It then resetscunitaccordingly.setignorescunitfor other coordinate types;cunitmay be used to label coordinate values.
- czphs#
double array[naxis]The time at the zero point of a phase axis,CSPHSia.An undefined value is represented by NaN.
- dateavg#
stringRepresentative mid-point of the date of observation.In ISO format,
yyyy-mm-ddThh:mm:ss.See also
- datebeg#
stringDate at the start of the observation.In ISO format,
yyyy-mm-ddThh:mm:ss.See also
- dateend#
stringDate at the end of the observation.In ISO format,
yyyy-mm-ddThh:mm:ss.See also
- dateobs#
stringStart of the date of observation.In ISO format,
yyyy-mm-ddThh:mm:ss.See also
- dateref#
stringDate of a reference epoch relative to which other time measurements refer.See also
- equinox#
doubleThe equinox associated with dynamical equatorial or ecliptic coordinate systems.EQUINOXa(orEPOCHin older headers). Not applicable to ICRS equatorial or ecliptic coordinates.An undefined value is represented by NaN.
- imgpix_matrix#
double array[2][2](read-only) Inverse of theCDELTorPCmatrix.Inverse containing the product of the
CDELTiadiagonal matrix and thePCi_jamatrix.
- jepoch#
doubleEquivalent toDATE-OBS.Expressed as a Julian epoch.
See also
- lat#
int(read-only) The index into the world coord array containing latitude values.
- latpole#
doubleThe native latitude of the celestial pole,LATPOLEa(deg).
- lattyp#
string(read-only) Celestial axis type for latitude.For example, “RA”, “DEC”, “GLON”, “GLAT”, etc. extracted from “RA–“, “DEC-”, “GLON”, “GLAT”, etc. in the first four characters of
CTYPEiabut with trailing dashes removed.
- lng#
int(read-only) The index into the world coord array containing longitude values.
- lngtyp#
string(read-only) Celestial axis type for longitude.For example, “RA”, “DEC”, “GLON”, “GLAT”, etc. extracted from “RA–“, “DEC-”, “GLON”, “GLAT”, etc. in the first four characters of
CTYPEiabut with trailing dashes removed.
- lonpole#
doubleThe native longitude of the celestial pole.LONPOLEa(deg).
- mjdavg#
doubleModified Julian Date corresponding toDATE-AVG.(MJD = JD - 2400000.5).An undefined value is represented by NaN.
See also
- mjdbeg#
doubleModified Julian Date corresponding toDATE-BEG.(MJD = JD - 2400000.5).An undefined value is represented by NaN.
See also
- mjdend#
doubleModified Julian Date corresponding toDATE-END.(MJD = JD - 2400000.5).An undefined value is represented by NaN.
See also
- mjdobs#
doubleModified Julian Date corresponding toDATE-OBS.(MJD = JD - 2400000.5).An undefined value is represented by NaN.
See also
- mjdref#
doubleModified Julian Date corresponding toDATE-REF.(MJD = JD - 2400000.5).An undefined value is represented by NaN.
See also
- name#
stringThe name given to the coordinate representationWCSNAMEa.
- naxis#
int(read-only) The number of axes (pixel and coordinate).Given by the
NAXISorWCSAXESakeyvalues.The number of coordinate axes is determined at parsing time, and can not be subsequently changed.
It is determined from the highest of the following:
NAXISWCSAXESaThe highest axis number in any parameterized WCS keyword. The keyvalue, as well as the keyword, must be syntactically valid otherwise it will not be considered.
If none of these keyword types is present, i.e. if the header only contains auxiliary WCS keywords for a particular coordinate representation, then no coordinate description is constructed for it.
This value may differ for different coordinate representations of the same image.
- obsgeo#
double array[3]Location of the observer in a standard terrestrial reference frame.OBSGEO-X,OBSGEO-Y,OBSGEO-Z(in meters).An undefined value is represented by NaN.
- obsorbit#
stringURI, URL, or name of an orbit ephemeris file giving spacecraft coordinates relating to TREFPOS.See also
- pc#
double array[naxis][naxis]ThePCi_ja(pixel coordinate) transformation matrix.The order is:
[[PC1_1, PC1_2], [PC2_1, PC2_2]]
For historical compatibility, three alternate specifications of the linear transformations are available in wcslib. The canonical
PCi_jawithCDELTia,CDi_ja, and the deprecatedCROTAiakeywords. Although the latter may not formally co-exist withPCi_ja, the approach here is simply to ignore them if given in conjunction withPCi_ja.has_pc,has_cdandhas_crotacan be used to determine which of these alternatives are present in the header.These alternate specifications of the linear transformation matrix are translated immediately to
PCi_jabysetand are nowhere visible to the lower-level routines. In particular,setresetscdeltto unity ifCDi_jais present (and noPCi_ja). If noCROTAiais associated with the latitude axis,setreverts to a unityPCi_jamatrix.
- phi0#
doubleThe native latitude of the fiducial point.The point whose celestial coordinates are given in
ref[1:2]. If undefined (NaN) the initialization routine,set, will set this to a projection-specific default.See also
- piximg_matrix#
double array[2][2](read-only) Matrix containing the product of theCDELTiadiagonal matrix and thePCi_jamatrix.
- plephem#
stringThe Solar System ephemeris used for calculating a pathlength delay.See also
- radesys#
stringThe equatorial or ecliptic coordinate system type,RADESYSa.
- restfrq#
doubleRest frequency (Hz) fromRESTFRQa.An undefined value is represented by NaN.
- restwav#
doubleRest wavelength (m) fromRESTWAVa.An undefined value is represented by NaN.
- spec#
int(read-only) The index containing the spectral axis values.
- specsys#
stringSpectral reference frame (standard of rest),SPECSYSa.
- ssysobs#
stringSpectral reference frame.The spectral reference frame in which there is no differential variation in the spectral coordinate across the field-of-view,
SSYSOBSa.
- ssyssrc#
stringSpectral reference frame for redshift.The spectral reference frame (standard of rest) in which the redshift was measured,
SSYSSRCa.
- tab#
list of TabprmTabular coordinate objects.A list of tabular coordinate objects associated with this WCS.
- telapse#
doubleequivalent to the elapsed time between DATE-BEG and DATE-END, in units of TIMEUNIT.See also
- theta0#
doubleThe native longitude of the fiducial point.The point whose celestial coordinates are given in
ref[1:2]. If undefined (NaN) the initialization routine,set, will set this to a projection-specific default.See also
- timedel#
doublethe resolution of the time stamps.See also
- timeoffs#
doubleTime offset, which may be used, for example, to provide a uniform clock correctionfor times referenced to DATEREF.
See also
- timepixr#
doublerelative position of the time stamps in binned time intervals, a value between 0.0 and 1.0.See also
- timesys#
stringTime scale (UTC, TAI, etc.) in which all other time-related auxiliary header values are recorded. Also defines the time scale for an image axis with CTYPEia set to ‘TIME’.See also
- timeunit#
stringTime units in which the following header values are expressed:TSTART,TSTOP,TIMEOFFS,TIMSYER,TIMRDER,TIMEDEL.It also provides the default value for
CUNITiafor time axes.See also
- timrder#
doublethe accuracy of time stamps relative to each other, in units of TIMEUNIT.See also
- timsyer#
doublethe absolute error of the time values, in units of TIMEUNIT.See also
- trefdir#
stringReference direction used in calculating a pathlength delay.See also
- trefpos#
stringLocation in space where the recorded time is valid.See also
- tstart#
doubleequivalent to DATE-BEG expressed as a time in units of TIMEUNIT relative to DATEREF+TIMEOFFS.See also
- tstop#
doubleequivalent to DATE-END expressed as a time in units of TIMEUNIT relative to DATEREF+TIMEOFFS.See also
- velangl#
doubleVelocity angle.The angle in degrees that should be used to decompose an observed velocity into radial and transverse components.
An undefined value is represented by NaN.
- velosys#
doubleRelative radial velocity.The relative radial velocity (m/s) between the observer and the selected standard of rest in the direction of the celestial reference coordinate,
VELOSYSa.An undefined value is represented by NaN.
- velref#
intAIPS velocity code.From
VELREFkeyword.
- wtb#
list of Wtbarrobjects to construct coordinate lookup tables from BINTABLE.
- xposure#
doubleeffective exposure time in units of TIMEUNIT.See also
- zsource#
doubleThe redshift,ZSOURCEa, of the source.An undefined value is represented by NaN.
Methods Documentation
- bounds_check(pix2world, world2pix)#
Enable/disable bounds checking.
- Parameters:
- pix2worldbool, optional
When
True, enable bounds checking for the pixel-to-world (p2x) transformations. Default isTrue.- world2pixbool, optional
When
True, enable bounds checking for the world-to-pixel (s2x) transformations. Default isTrue.
Notes
Note that by default (without calling
bounds_check) strict bounds checking is enabled.
- cdfix()#
Fix erroneously omitted
CDi_jakeywords.Sets the diagonal element of the
CDi_jamatrix to unity if allCDi_jakeywords associated with a given axis were omitted. According to Paper I, if anyCDi_jakeywords at all are given in a FITS header then those not given default to zero. This results in a singular matrix with an intersecting row and column of zeros.- Returns:
- success
python:int Returns
0for success;-1if no change required.
- success
- celfix(/)#
Translates AIPS-convention celestial projection types,
-NCPand-GLS.- Returns:
- success
python:int Returns
0for success;-1if no change required.
- success
- compare(other, cmp=0, tolerance=0.0)#
Compare two Wcsprm objects for equality.
- Parameters:
- other
Wcsprm The other Wcsprm object to compare to.
- cmp
python:int, optional A bit field controlling the strictness of the comparison. When 0, (the default), all fields must be identical.
The following constants, defined in the
astropy.wcsmodule, may be or’ed together to loosen the comparison.WCSCOMPARE_ANCILLARY: Ignores ancillary keywords that don’t change the WCS transformation, such asXPOSUREorEQUINOX. Note that this also ignoresDATE-OBS, which does change the WCS transformation in some cases.WCSCOMPARE_TILING: Ignore integral differences inCRPIXja. This is the ‘tiling’ condition, where two WCSes cover different regions of the same map projection and align on the same map grid.WCSCOMPARE_CRPIX: Ignore any differences at all inCRPIXja. The two WCSes cover different regions of the same map projection but may not align on the same grid map. OverridesWCSCOMPARE_TILING.
- tolerance
python:float, optional The amount of tolerance required. For example, for a value of 1e-6, all floating-point values in the objects must be equal to the first 6 decimal places. The default value of 0.0 implies exact equality.
- other
- Returns:
- equalbool
- cylfix()#
Fixes WCS keyvalues for malformed cylindrical projections.
- Returns:
- success
python:int Returns
0for success;-1if no change required.
- success
- datfix()#
Translates the old
DATE-OBSdate format to year-2000 standard form(yyyy-mm-ddThh:mm:ss)and derivesMJD-OBSfrom it if not already set.Alternatively, if
mjdobsis set anddateobsisn’t, thendatfixderivesdateobsfrom it. If both are set but disagree by more than half a day thenValueErroris raised.- Returns:
- success
python:int Returns
0for success;-1if no change required.
- success
- fix(translate_units='', naxis=0)#
Applies all of the corrections handled separately by
datfix,unitfix,celfix,spcfix,cylfixandcdfix.- Parameters:
- translate_units
python:str, optional Specify which potentially unsafe translations of non-standard unit strings to perform. By default, performs all.
Although
"S"is commonly used to represent seconds, its translation to"s"is potentially unsafe since the standard recognizes"S"formally as Siemens, however rarely that may be used. The same applies to"H"for hours (Henry), and"D"for days (Debye).This string controls what to do in such cases, and is case-insensitive.
If the string contains
"s", translate"S"to"s".If the string contains
"h", translate"H"to"h".If the string contains
"d", translate"D"to"d".
Thus
''doesn’t do any unsafe translations, whereas'shd'does all of them.- naxis
python:intarray, optional Image axis lengths. If this array is set to zero or
None, thencylfixwill not be invoked.
- translate_units
- Returns:
- get_cdelt(/)#
Coordinate increments (
CDELTia) for each coord axis asdouble array[naxis].Returns the
CDELToffsets in read-only form. Unlike thecdeltproperty, this works even when the header specifies the linear transformation matrix in one of the alternativeCDi_jaorCROTAiaforms. This is useful when you want access to the linear transformation matrix, but don’t care how it was specified in the header.
- get_pc(/)#
Returns the
PCmatrix in read-only form asdouble array[naxis][naxis]. Unlike thepcproperty, this works even when the header specifies the linear transformation matrix in one of the alternativeCDi_jaorCROTAiaforms. This is useful when you want access to the linear transformation matrix, but don’t care how it was specified in the header.
- get_ps(/)#
Returns
PSi_makeywords for each i and m as list of tuples.- Returns:
- ps
python:list Returned as a list of tuples of the form (i, m, value):
i: int. Axis number, as in
PSi_ma, (i.e. 1-relative)m: int. Parameter number, as in
PSi_ma, (i.e. 0-relative)value: string. Parameter value.
- ps
See also
astropy.wcs.Wcsprm.set_psSet
PSi_mavalues
- get_pv(/)#
Returns
PVi_makeywords for each i and m as list of tuples.- Returns:
- python:sequence of
python:tuple Returned as a list of tuples of the form (i, m, value):
i: int. Axis number, as in
PVi_ma, (i.e. 1-relative)m: int. Parameter number, as in
PVi_ma, (i.e. 0-relative)value: string. Parameter value.
- python:sequence of
See also
astropy.wcs.Wcsprm.set_pvSet
PVi_mavalues
Notes
Note that, if they were not given,
setresets the entries forPVi_1a,PVi_2a,PVi_3a, andPVi_4afor longitude axis i to match (phi_0,theta_0), the native longitude and latitude of the reference point given byLONPOLEaandLATPOLEa.
- has_cd(/)#
Returns
TrueifCDi_jais present.CDi_jais an alternate specification of the linear transformation matrix, maintained for historical compatibility.Matrix elements in the IRAF convention are equivalent to the product
CDi_ja = CDELTia * PCi_ja, but the defaults differ from that of thePCi_jamatrix. If one or moreCDi_jakeywords are present then all unspecifiedCDi_jadefault to zero. If noCDi_ja(orCROTAia) keywords are present, then the header is assumed to be inPCi_jaform whether or not anyPCi_jakeywords are present since this results in an interpretation ofCDELTiaconsistent with the original FITS specification.While
CDi_jamay not formally co-exist withPCi_ja, it may co-exist withCDELTiaandCROTAiawhich are to be ignored.See also
astropy.wcs.Wcsprm.cdGet the raw
CDi_javalues.
- has_crota(/)#
Returns
TrueifCROTAiais present.CROTAiais an alternate specification of the linear transformation matrix, maintained for historical compatibility.In the AIPS convention,
CROTAiamay only be associated with the latitude axis of a celestial axis pair. It specifies a rotation in the image plane that is applied after theCDELTia; any otherCROTAiakeywords are ignored.CROTAiamay not formally co-exist withPCi_ja.CROTAiaandCDELTiamay formally co-exist withCDi_jabut if so are to be ignored.See also
astropy.wcs.Wcsprm.crotaGet the raw
CROTAiavalues
- has_pc(/)#
Returns
TrueifPCi_jais present.PCi_jais the recommended way to specify the linear transformation matrix.See also
astropy.wcs.Wcsprm.pcGet the raw
PCi_javalues
- mix(mixpix, mixcel, vspan, vstep, viter, world, pixcrd, origin)#
Given either the celestial longitude or latitude plus an element of the pixel coordinate, solves for the remaining elements by iterating on the unknown celestial coordinate element using
s2p.- Parameters:
- mixpix
python:int Which element on the pixel coordinate is given.
- mixcel
python:int Which element of the celestial coordinate is given. If mixcel =
1, celestial longitude is given inworld[self.lng], latitude returned inworld[self.lat]. If mixcel =2, celestial latitude is given inworld[self.lat], longitude returned inworld[self.lng].- vspan(
python:float,python:float) Solution interval for the celestial coordinate, in degrees. The ordering of the two limits is irrelevant. Longitude ranges may be specified with any convenient normalization, for example
(-120,+120)is the same as(240,480), except that the solution will be returned with the same normalization, i.e. lie within the interval specified.- vstep
python:float Step size for solution search, in degrees. If
0, a sensible, although perhaps non-optimal default will be used.- viter
python:int If a solution is not found then the step size will be halved and the search recommenced. viter controls how many times the step size is halved. The allowed range is 5 - 10.
- world
ndarray World coordinate elements as
double array[naxis].world[self.lng]andworld[self.lat]are the celestial longitude and latitude, in degrees. Which is given and which returned depends on the value of mixcel. All other elements are given. The results will be written to this array in-place.- pixcrd
ndarray Pixel coordinates as
double array[naxis]. The element indicated by mixpix is given and the remaining elements will be written in-place.- origin
python:int Specifies the origin of pixel values. The Fortran and FITS standards use an origin of 1. Numpy and C use array indexing with origin at 0.
- mixpix
- Returns:
- result
python:dict Returns a dictionary with the following keys:
phi (
double array[naxis])theta (
double array[naxis])Longitude and latitude in the native coordinate system of the projection, in degrees.
imgcrd (
double array[naxis])Image coordinate elements.
imgcrd[self.lng]andimgcrd[self.lat]are the projected x- and y-coordinates, in decimal degrees.
world (
double array[naxis])Another reference to the world argument passed in.
- result
- Raises:
MemoryErrorMemory allocation failed.
SingularMatrixErrorLinear transformation matrix is singular.
InconsistentAxisTypesErrorInconsistent or unrecognized coordinate axis types.
ValueErrorInvalid parameter value.
InvalidTransformErrorInvalid coordinate transformation parameters.
InvalidTransformErrorIll-conditioned coordinate transformation parameters.
InvalidCoordinateErrorInvalid world coordinate.
NoSolutionErrorNo solution found in the specified interval.
See also
astropy.wcs.Wcsprm.lat,astropy.wcs.Wcsprm.lngGet the axes numbers for latitude and longitude
Notes
Initially, the specified solution interval is checked to see if it’s a “crossing” interval. If it isn’t, a search is made for a crossing solution by iterating on the unknown celestial coordinate starting at the upper limit of the solution interval and decrementing by the specified step size. A crossing is indicated if the trial value of the pixel coordinate steps through the value specified. If a crossing interval is found then the solution is determined by a modified form of “regula falsi” division of the crossing interval. If no crossing interval was found within the specified solution interval then a search is made for a “non-crossing” solution as may arise from a point of tangency. The process is complicated by having to make allowance for the discontinuities that occur in all map projections.
Once one solution has been determined others may be found by subsequent invocations of
mixwith suitably restricted solution intervals.Note the circumstance that arises when the solution point lies at a native pole of a projection in which the pole is represented as a finite curve, for example the zenithals and conics. In such cases two or more valid solutions may exist but
mixonly ever returns one.Because of its generality,
mixis very compute-intensive. For compute-limited applications, more efficient special-case solvers could be written for simple projections, for example non-oblique cylindrical projections.
- p2s(pixcrd, origin)#
Converts pixel to world coordinates.
- Parameters:
- pixcrd
ndarray Array of pixel coordinates as
double array[ncoord][nelem].- origin
python:int Specifies the origin of pixel values. The Fortran and FITS standards use an origin of 1. Numpy and C use array indexing with origin at 0.
- pixcrd
- Returns:
- result
python:dict Returns a dictionary with the following keys:
imgcrd: ndarray
Array of intermediate world coordinates as
double array[ncoord][nelem]. For celestial axes,imgcrd[][self.lng]andimgcrd[][self.lat]are the projected x-, and y-coordinates, in pseudo degrees. For spectral axes,imgcrd[][self.spec]is the intermediate spectral coordinate, in SI units.
phi: ndarray
Array as
double array[ncoord].
theta: ndarray
Longitude and latitude in the native coordinate system of the projection, in degrees, as
double array[ncoord].
world: ndarray
Array of world coordinates as
double array[ncoord][nelem]. For celestial axes,world[][self.lng]andworld[][self.lat]are the celestial longitude and latitude, in degrees. For spectral axes,world[][self.spec]is the intermediate spectral coordinate, in SI units.
stat: ndarray
Status return value for each coordinate as
int array[ncoord].0for success,1+for invalid pixel coordinate.
- result
- Raises:
MemoryErrorMemory allocation failed.
SingularMatrixErrorLinear transformation matrix is singular.
InconsistentAxisTypesErrorInconsistent or unrecognized coordinate axis types.
ValueErrorInvalid parameter value.
ValueErrorx- and y-coordinate arrays are not the same size.
InvalidTransformErrorInvalid coordinate transformation parameters.
InvalidTransformErrorIll-conditioned coordinate transformation parameters.
See also
astropy.wcs.Wcsprm.lat,astropy.wcs.Wcsprm.lngDefinition of the latitude and longitude axes
- print_contents()#
Print the contents of the
Wcsprmobject to stdout. Probably only useful for debugging purposes, and may be removed in the future.To get a string of the contents, use
repr.
- s2p(world, origin)#
Transforms world coordinates to pixel coordinates.
- Parameters:
- world
ndarray Array of world coordinates, in decimal degrees, as
double array[ncoord][nelem].- origin
python:int Specifies the origin of pixel values. The Fortran and FITS standards use an origin of 1. Numpy and C use array indexing with origin at 0.
- world
- Returns:
- result
python:dict Returns a dictionary with the following keys:
phi:
double array[ncoord]theta:
double array[ncoord]Longitude and latitude in the native coordinate system of the projection, in degrees.
imgcrd:
double array[ncoord][nelem]Array of intermediate world coordinates. For celestial axes,
imgcrd[][self.lng]andimgcrd[][self.lat]are the projected x-, and y-coordinates, in pseudo “degrees”. For quadcube projections with aCUBEFACEaxis, the face number is also returned inimgcrd[][self.cubeface]. For spectral axes,imgcrd[][self.spec]is the intermediate spectral coordinate, in SI units.
pixcrd:
double array[ncoord][nelem]Array of pixel coordinates. Pixel coordinates are zero-based.
stat:
int array[ncoord]Status return value for each coordinate.
0for success,1+for invalid pixel coordinate.
- result
- Raises:
MemoryErrorMemory allocation failed.
SingularMatrixErrorLinear transformation matrix is singular.
InconsistentAxisTypesErrorInconsistent or unrecognized coordinate axis types.
ValueErrorInvalid parameter value.
InvalidTransformErrorInvalid coordinate transformation parameters.
InvalidTransformErrorIll-conditioned coordinate transformation parameters.
See also
astropy.wcs.Wcsprm.lat,astropy.wcs.Wcsprm.lngDefinition of the latitude and longitude axes
- set()#
Sets up a WCS object for use according to information supplied within it.
Note that this routine need not be called directly; it will be invoked by
p2sands2pif necessary.Some attributes that are based on other attributes (such as
lattyponctype) may not be correct until aftersetis called.setstrips off trailing blanks in all string members.setrecognizes theNCPprojection and converts it to the equivalentSINprojection and it also recognizesGLSas a synonym forSFL. It does alias translation for the AIPS spectral types (FREQ-LSR,FELO-HEL, etc.) but without changing the input header keywords.- Raises:
MemoryErrorMemory allocation failed.
SingularMatrixErrorLinear transformation matrix is singular.
InconsistentAxisTypesErrorInconsistent or unrecognized coordinate axis types.
ValueErrorInvalid parameter value.
InvalidTransformErrorInvalid coordinate transformation parameters.
InvalidTransformErrorIll-conditioned coordinate transformation parameters.
- set_ps(ps)#
Sets
PSi_makeywords for each i and m.- Parameters:
- pspython:sequence of
python:tuple The input must be a sequence of tuples of the form (i, m, value):
i: int. Axis number, as in
PSi_ma, (i.e. 1-relative)m: int. Parameter number, as in
PSi_ma, (i.e. 0-relative)value: string. Parameter value.
- pspython:sequence of
See also
- set_pv(pv)#
Sets
PVi_makeywords for each i and m.- Parameters:
- pv
python:listofpython:tuple The input must be a sequence of tuples of the form (i, m, value):
i: int. Axis number, as in
PVi_ma, (i.e. 1-relative)m: int. Parameter number, as in
PVi_ma, (i.e. 0-relative)value: float. Parameter value.
- pv
See also
- spcfix(/)#
Translates AIPS-convention spectral coordinate types. {
FREQ,VELO,FELO}-{OBS,HEL,LSR} (e.g.FREQ-LSR,VELO-OBS,FELO-HEL)- Returns:
- success
python:int Returns
0for success;-1if no change required.
- success
- sptr(ctype, i=-1)#
Translates the spectral axis in a WCS object.
For example, a
FREQaxis may be translated intoZOPT-F2Wand vice versa.- Parameters:
- ctype
python:str Required spectral
CTYPEia, maximum of 8 characters. The first four characters are required to be given and are never modified. The remaining four, the algorithm code, are completely determined by, and must be consistent with, the first four characters. Wildcarding may be used, i.e. if the final three characters are specified as"???", or if just the eighth character is specified as"?", the correct algorithm code will be substituted and returned.- i
python:int Index of the spectral axis (0-relative). If
i < 0(or not provided), it will be set to the first spectral axis identified from theCTYPEkeyvalues in the FITS header.
- ctype
- Raises:
MemoryErrorMemory allocation failed.
SingularMatrixErrorLinear transformation matrix is singular.
InconsistentAxisTypesErrorInconsistent or unrecognized coordinate axis types.
ValueErrorInvalid parameter value.
InvalidTransformErrorInvalid coordinate transformation parameters.
InvalidTransformErrorIll-conditioned coordinate transformation parameters.
InvalidSubimageSpecificationErrorInvalid subimage specification (no spectral axis).
- sub(axes)#
Extracts the coordinate description for a subimage from a
WCSobject.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_jamatrix 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.subcan also add axes to a wcsprm object. 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 invokingset.- Parameters:
- axes
python:intorasequence. If an int, include the first N axes in their original order.
If a sequence, may contain a combination of image axis numbers (1-relative) or special axis identifiers (see below). Order is significant;
axes[0]is the axis number of the input image that corresponds to the first axis in the subimage, etc. Use an axis number of 0 to create a new axis using the defaults.If
0,[]orNone, do a deep copy.
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: QuadcubeCUBEFACEaxis'spectral'/WCSSUB_SPECTRAL: Spectral axis'stokes'/WCSSUB_STOKES: Stokes axis'temporal'/WCSSUB_TIME: Time axis (requiresWCSLIBversion 7.8 or greater)'celestial'/WCSSUB_CELESTIAL: An alias for the combination of'longitude','latitude'and'cubeface'.
- axes
- Returns:
- new_wcs
WCSobject
- new_wcs
- Raises:
MemoryErrorMemory allocation failed.
InvalidSubimageSpecificationErrorInvalid subimage specification (no spectral axis).
NonseparableSubimageCoordinateSystemErrorNon-separable subimage coordinate system.
Notes
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_CELESTIALis defined as the combinationWCSSUB_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 (viaaxes[0]) and not subsequently (viaaxes[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.
- to_header(relax=False)#
to_headertranslates a WCS object into a FITS header.The details of the header depends on context:
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, orEND.Deprecated (e.g.
CROTAn) or non-standard usage will be translated to standard (this is partially dependent on whetherfixwas 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_jmatrix 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,LONPOLEaandLATPOLEamay appear.The original keycomments will be lost, although
to_headertries hard to write meaningful comments.Keyword order may be changed.
Keywords can be translated between the image array, binary table, and pixel lists forms by manipulating the
colnumorcolaxmembers of theWCSobject.- Parameters:
- relaxbool or
python:int 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 write. See Header-writing relaxation constants for details.
- relaxbool or
- Returns:
- header
python:str Raw FITS header as a string.
- header
- unitfix(translate_units='')#
Translates non-standard
CUNITiakeyvalues.For example,
DEG->deg, also stripping off unnecessary whitespace.- Parameters:
- translate_units
python:str, optional Do potentially unsafe translations of non-standard unit strings.
Although
"S"is commonly used to represent seconds, its recognizes"S"formally as Siemens, however rarely that may be translation to"s"is potentially unsafe since the standard used. The same applies to"H"for hours (Henry), and"D"for days (Debye).This string controls what to do in such cases, and is case-insensitive.
If the string contains
"s", translate"S"to"s".If the string contains
"h", translate"H"to"h".If the string contains
"d", translate"D"to"d".
Thus
''doesn’t do any unsafe translations, whereas'shd'does all of them.
- translate_units
- Returns:
- success
python:int Returns
0for success;-1if no change required.
- success