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
34
35struct wcsprm;
36
37namespace casacore { //# NAMESPACE CASACORE - BEGIN
38
39class Coordinate;
40class CoordinateSystem;
41class StokesCoordinate;
42class Projection;
43class IPosition;
44class LogIO;
45class Record;
46
47
48
49
50// <summary>
51// </summary>
52
53// <use visibility=export>
54
55// <reviewed reviewer="" date="" tests="">
56// </reviewed>
57//
58// <prerequisite>
59// <li> <linkto class=Coordinate>CoordinateSystem</linkto>
60// </prerequisite>
61
62// <synopsis>
63// Helper functions to inter-converft between a CoordinateSystem and FITS
64// headers.
65// </synopsis>
66
67// <note role=caution>
68// </note>
69
70// <example>
71// </example>
72
73// <motivation>
74// I hate FITS
75// </motivation>
76//
77// <thrown>
78// <li> AipsError
79// </thrown>
80//
81// <todo asof="2004/08/23">
82// </todo>
83//
84
85
87{
88public:
89
90 // Constructor
92
93 // Convert CoordinateSystem to a FITS header. In the record
94 // the keywords are vectors, it is expected that the actual FITS code will
95 // split them into scalars and upcase the names. Returns False if one of the
96 // keywords is already taken.
97 //
98 // If writeWCS is True, attempt to write the WCS convention (Greisen and
99 // Calabretta "Representation of celestial coordinates in FITS") as
100 // approved in version 3.0 of the FITS standard.
101 // Use <src>oneRelative=True</src> to convert zero-relative pixel coordinates to
102 // one-relative FITS coordinates.
103 //
104 // prefix gives the prefix for the FITS keywords. E.g.,
105 // if prefix="c" then crval, cdelt etc.
106 // if prefix="d" then drval, ddelt etc.
107 //# Much of the work in to/from fits should be moved to the individual
108 //# classes.
111 const CoordinateSystem& cSys,
112 Bool oneRelative,
113 Char prefix = 'c', Bool writeWCS=True,
114 Bool preferVelocity=True,
115 Bool opticalVelocity=True,
116 Bool preferWavelength=False,
117 Bool airWavelength=False) const;
118
119 // Probably even if we return False we should set up the best linear
120 // coordinate that we can. On output, <src>stokesFITSValue</src>
121 // holds the FITS value of any unofficial Stokes (beam, optical depth,
122 // spectral index) for the last unofficial value accessed (-1 if none).
123 // The idea is that if the Stokes axis is of length one and holds an unofficial value,
124 // you should drop the STokes axis and convert that value to <src>ImageInfo::ImageTypes</src>
125 // with <src>ImageInfo::imageTypeFromFITSValue</src>. If on input, <src>stokesFITSValue</src>
126 // is positive, then a warning is issued if any unofficial values are encountered.
127 // Otherwise no warning is issued.
128 //# cf comment in toFITS.
129 //<group>
130 Bool fromFITSHeader(Int& stokesFITSValue,
131 CoordinateSystem& coordsys,
132 RecordInterface& recHeader,
133 const Vector<String>& header,
134 const IPosition& shape,
135 uInt which=0) const;
136 //</group>
137
138
139 // Helper function to create a FITS style CTYPE vector from the
140 // axis names from a DirectionCoordinate
142 const Vector<String>& axisNames,
143 Double refLat, Bool printError);
145 const Vector<String>& axisNames,
146 Bool printError);
147
148private:
149 // Generate actual FITS keywords
151 Double& longPole, Double& latPole,
152 Vector<Double>& crval,
153 Vector<Double>& crpix,
154 Vector<Double>& cdelt,
155 //# Vector<Double>& crota,
156 //# Vector<Double>& projp,
157 Vector<Double>& pvi_ma,
158 Vector<String>& ctype,
159 Vector<String>& cunit,
160 Matrix<Double>& pc,
161 const CoordinateSystem& cSys,
162 Int skyCoord, Int longAxis, Int latAxis,
163 Int specAxis, Int stokesAxis,
164 Bool writeWCS, Double offset,
165 const String& sprefix) const;
166
167 // Special Stokes processing for conversion to FITS header
169 Vector<Double>& crpix,
170 Vector<Double>& cdelt,
171 LogIO& os,
172 const CoordinateSystem& coordsys,
173 Int stokesAxis, Int stokesCoord) const;
174
175 // Look for Coordinate type and add to CS
176 // <group>
178 const wcsprm& wcs, LogIO& os) const;
180 const wcsprm& wcs, const IPosition& shape,
181 LogIO& os) const;
182 Bool addStokesCoordinate (CoordinateSystem& cSys, Int& axis, Int& stokesFITSValue,
183 const wcsprm& wcs, const IPosition& shape,
184 LogIO& os) const;
186 const wcsprm& wcs, LogIO& os) const;
187 // </group>
188
189// Decode values from WCS structures which are generated via the wcs FITS parser
190 // <group>
192 const wcsprm& wcs) const;
194 const wcsprm& wcs) const;
196 Int& stokesFITSValue, String& errMSg,
197 const wcsprm& wcs, uInt shape, Bool warnStokes) const;
198 // </group>
199
200 // Decode ObsInfo from wcs structure
201 ObsInfo getObsInfo(LogIO& os, RecordInterface& header, const wcsprm& wcs) const;
202
203 // Call wcsset
204 void setWCS (wcsprm& wcs) const;
205
206 // Decode CD cards from FITS file header (Record interface)
208
209 // Decode PC matrix from FITS header (Record interface)
210 void getPCFromHeader(LogIO& os, Int& rotationAxis, Matrix<Double>& pc,
211 uInt n, const RecordInterface& header,
212 const String& sprefix);
213
214 // Helper function to convert a wcs structure holding FITS keywords
215 // into a Record for later consumption.
216 void cardsToRecord (LogIO& os, RecordInterface& rec, char* pHeader) const;
217
218 // Fix up Coordinate for zero increments and the like
219 // Possibly the wcs FITS parser could do this
220 void fixCoordinate(Coordinate& c, LogIO& os) const;
221
222 // Initialize the wcsprm struct.
223 // It sets the flag to -1, but furthermore it clears the err pointers
224 // because wcslib-4.8 (shipped with Ubuntu) sometimes fails to do so.
225 static void wcsInit (::wcsprm& wcsDest);
226};
227
228} //# NAMESPACE CASACORE - END
229
230#endif
231
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:185
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition MFrequency.h:173
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition ExprNode.h:1991
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