casacore
Loading...
Searching...
No Matches
FITSCoordinateUtil.h
Go to the documentation of this file.
1// # FITSCoordinateUtil.h: functions to inter-convert between CoordinateSystems and FITS
2// # Copyright (C) 1997,1998,1999,2000,2001,2002,2003,2004
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef COORDINATES_FITSCOORDINATEUTIL_H
27#define COORDINATES_FITSCOORDINATEUTIL_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/measures/Measures/MDirection.h>
31#include <casacore/measures/Measures/MFrequency.h>
32#include <casacore/coordinates/Coordinates/ObsInfo.h>
33
34struct wcsprm;
35
36namespace casacore { // # NAMESPACE CASACORE - BEGIN
37
38class Coordinate;
41class Projection;
42class IPosition;
43class LogIO;
44class Record;
45
46// <summary>
47// </summary>
48
49// <use visibility=export>
50
51// <reviewed reviewer="" date="" tests="">
52// </reviewed>
53//
54// <prerequisite>
55// <li> <linkto class=Coordinate>CoordinateSystem</linkto>
56// </prerequisite>
57
58// <synopsis>
59// Helper functions to inter-converft between a CoordinateSystem and FITS
60// headers.
61// </synopsis>
62
63// <note role=caution>
64// </note>
65
66// <example>
67// </example>
68
69// <motivation>
70// I hate FITS
71// </motivation>
72//
73// <thrown>
74// <li> AipsError
75// </thrown>
76//
77// <todo asof="2004/08/23">
78// </todo>
79//
80
82 public:
83 // Constructor
85
86 // Convert CoordinateSystem to a FITS header. In the record
87 // the keywords are vectors, it is expected that the actual FITS code will
88 // split them into scalars and upcase the names. Returns False if one of the
89 // keywords is already taken.
90 //
91 // If writeWCS is True, attempt to write the WCS convention (Greisen and
92 // Calabretta "Representation of celestial coordinates in FITS") as
93 // approved in version 3.0 of the FITS standard.
94 // Use <src>oneRelative=True</src> to convert zero-relative pixel coordinates to
95 // one-relative FITS coordinates.
96 //
97 // prefix gives the prefix for the FITS keywords. E.g.,
98 // if prefix="c" then crval, cdelt etc.
99 // if prefix="d" then drval, ddelt etc.
100 // # Much of the work in to/from fits should be moved to the individual
101 // # classes.
103 Bool oneRelative, Char prefix = 'c', Bool writeWCS = True,
104 Bool preferVelocity = True, Bool opticalVelocity = True,
105 Bool preferWavelength = False, Bool airWavelength = False) const;
106
107 // Probably even if we return False we should set up the best linear
108 // coordinate that we can. On output, <src>stokesFITSValue</src>
109 // holds the FITS value of any unofficial Stokes (beam, optical depth,
110 // spectral index) for the last unofficial value accessed (-1 if none).
111 // The idea is that if the Stokes axis is of length one and holds an unofficial value,
112 // you should drop the STokes axis and convert that value to <src>ImageInfo::ImageTypes</src>
113 // with <src>ImageInfo::imageTypeFromFITSValue</src>. If on input, <src>stokesFITSValue</src>
114 // is positive, then a warning is issued if any unofficial values are encountered.
115 // Otherwise no warning is issued.
116 // # cf comment in toFITS.
117 //<group>
118 Bool fromFITSHeader(Int& stokesFITSValue, CoordinateSystem& coordsys, RecordInterface& recHeader,
119 const Vector<String>& header, const IPosition& shape, uInt which = 0) const;
120 //</group>
121
122 // Helper function to create a FITS style CTYPE vector from the
123 // axis names from a DirectionCoordinate
125 const Vector<String>& axisNames, Double refLat,
126 Bool printError);
127 static Vector<String> cTypeFromDirection(const Projection& proj, const Vector<String>& axisNames,
128 Bool printError);
129
130 private:
131 // Generate actual FITS keywords
132 Bool generateFITSKeywords(LogIO& os, Bool& isNCP, Double& longPole, Double& latPole,
134 // # Vector<Double>& crota,
135 // # Vector<Double>& projp,
137 Matrix<Double>& pc, const CoordinateSystem& cSys, Int skyCoord,
138 Int longAxis, Int latAxis, Int specAxis, Int stokesAxis, Bool writeWCS,
139 Double offset, const String& sprefix) const;
140
141 // Special Stokes processing for conversion to FITS header
143 LogIO& os, const CoordinateSystem& coordsys, Int stokesAxis,
144 Int stokesCoord) const;
145
146 // Look for Coordinate type and add to CS
147 // <group>
149 LogIO& os) const;
150 Bool addSpectralCoordinate(CoordinateSystem& cSys, Int& axis, const wcsprm& wcs,
151 const IPosition& shape, LogIO& os) const;
152 Bool addStokesCoordinate(CoordinateSystem& cSys, Int& axis, Int& stokesFITSValue,
153 const wcsprm& wcs, const IPosition& shape, LogIO& os) const;
154 Bool addLinearCoordinate(CoordinateSystem& cSys, Vector<Int>& axes, const wcsprm& wcs,
155 LogIO& os) const;
156 // </group>
157
158 // Decode values from WCS structures which are generated via the wcs FITS parser
159 // <group>
161 const wcsprm& wcs) const;
163 const wcsprm& wcs) const;
165 String& errMSg, const wcsprm& wcs, uInt shape,
166 Bool warnStokes) const;
167 // </group>
168
169 // Decode ObsInfo from wcs structure
170 ObsInfo getObsInfo(LogIO& os, RecordInterface& header, const wcsprm& wcs) const;
171
172 // Call wcsset
173 void setWCS(wcsprm& wcs) const;
174
175 // Decode CD cards from FITS file header (Record interface)
177
178 // Decode PC matrix from FITS header (Record interface)
179 void getPCFromHeader(LogIO& os, Int& rotationAxis, Matrix<Double>& pc, uInt n,
180 const RecordInterface& header, const String& sprefix);
181
182 // Helper function to convert a wcs structure holding FITS keywords
183 // into a Record for later consumption.
184 void cardsToRecord(LogIO& os, RecordInterface& rec, char* pHeader) const;
185
186 // Fix up Coordinate for zero increments and the like
187 // Possibly the wcs FITS parser could do this
188 void fixCoordinate(Coordinate& c, LogIO& os) const;
189
190 // Initialize the wcsprm struct.
191 // It sets the flag to -1, but furthermore it clears the err pointers
192 // because wcslib-4.8 (shipped with Ubuntu) sometimes fails to do so.
193 static void wcsInit(::wcsprm& wcsDest);
194};
195
196} // namespace casacore
197
198#endif
ObsInfo getObsInfo(LogIO &os, RecordInterface &header, const wcsprm &wcs) const
Decode ObsInfo from wcs structure.
static void wcsInit(::wcsprm &wcsDest)
Initialize the wcsprm struct.
Bool fromFITSHeader(Int &stokesFITSValue, CoordinateSystem &coordsys, RecordInterface &recHeader, const Vector< String > &header, const IPosition &shape, uInt which=0) const
Probably even if we return False we should set up the best linear coordinate that we can.
void fixCoordinate(Coordinate &c, LogIO &os) const
Fix up Coordinate for zero increments and the like Possibly the wcs FITS parser could do this.
Bool addStokesCoordinate(CoordinateSystem &cSys, Int &axis, Int &stokesFITSValue, const wcsprm &wcs, const IPosition &shape, LogIO &os) const
void getPCFromHeader(LogIO &os, Int &rotationAxis, Matrix< Double > &pc, uInt n, const RecordInterface &header, const String &sprefix)
Decode PC matrix from FITS header (Record interface).
void cardsToRecord(LogIO &os, RecordInterface &rec, char *pHeader) const
Helper function to convert a wcs structure holding FITS keywords into a Record for later consumption.
Bool addDirectionCoordinate(CoordinateSystem &cSys, Vector< Int > &axes, const wcsprm &wcs, LogIO &os) const
Look for Coordinate type and add to CS.
void setWCS(wcsprm &wcs) const
Call wcsset.
Bool toFITSHeader(RecordInterface &header, IPosition &shape, const CoordinateSystem &cSys, Bool oneRelative, Char prefix='c', Bool writeWCS=True, Bool preferVelocity=True, Bool opticalVelocity=True, Bool preferWavelength=False, Bool airWavelength=False) const
Convert CoordinateSystem to a FITS header.
Bool stokesCoordinateFromWCS(LogIO &os, StokesCoordinate &coord, Int &stokesFITSValue, String &errMSg, const wcsprm &wcs, uInt shape, Bool warnStokes) const
Bool addLinearCoordinate(CoordinateSystem &cSys, Vector< Int > &axes, const wcsprm &wcs, LogIO &os) const
Bool toFITSHeaderStokes(Vector< Double > &crval, Vector< Double > &crpix, Vector< Double > &cdelt, LogIO &os, const CoordinateSystem &coordsys, Int stokesAxis, Int stokesCoord) const
Special Stokes processing for conversion to FITS header.
Bool addSpectralCoordinate(CoordinateSystem &cSys, Int &axis, const wcsprm &wcs, const IPosition &shape, LogIO &os) const
Bool generateFITSKeywords(LogIO &os, Bool &isNCP, Double &longPole, Double &latPole, Vector< Double > &crval, Vector< Double > &crpix, Vector< Double > &cdelt, Vector< Double > &pvi_ma, Vector< String > &ctype, Vector< String > &cunit, Matrix< Double > &pc, const CoordinateSystem &cSys, Int skyCoord, Int longAxis, Int latAxis, Int specAxis, Int stokesAxis, Bool writeWCS, Double offset, const String &sprefix) const
Generate actual FITS keywords.
Bool frequencySystemFromWCS(LogIO &os, MFrequency::Types &type, String &errMsg, const wcsprm &wcs) const
static Vector< String > cTypeFromDirection(const Projection &proj, const Vector< String > &axisNames, Bool printError)
Bool getCDFromHeader(Matrix< Double > &cd, uInt n, const RecordInterface &header)
Decode CD cards from FITS file header (Record interface).
static Vector< String > cTypeFromDirection(Bool &isNCP, const Projection &proj, const Vector< String > &axisNames, Double refLat, Bool printError)
Helper function to create a FITS style CTYPE vector from the axis names from a DirectionCoordinate.
Bool directionSystemFromWCS(LogIO &os, MDirection::Types &type, String &errMsg, const wcsprm &wcs) const
Decode values from WCS structures which are generated via the wcs FITS parser.
Types
Types of known MDirections Warning: The order defines the order in the translation matrix FromTo in ...
Definition MDirection.h:187
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition MFrequency.h:175
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
char * ctype(int n) const
Definition hdu.h:406
int offset(int, int) const
compute a linear offset from array indicies
unsigned int uInt
Definition aipstype.h:49
double cdelt(int n) const
Definition hdu.h:410
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
double crpix(int n) const
Definition hdu.h:407
double crval(int n) const
Definition hdu.h:409
RecordInterface()
The default constructor creates an empty record with a variable structure.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53
char Char
Definition aipstype.h:44