casa
$Rev:20696$
|
00001 //# FITSCoordinateUtil.h: functions to inter-convert between CoordinateSystems and FITS 00002 //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003,2004 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id: 00028 00029 #ifndef COORDINATES_FITSCOORDINATEUTIL_H 00030 #define COORDINATES_FITSCOORDINATEUTIL_H 00031 00032 #include <casa/aips.h> 00033 #include <measures/Measures/MDirection.h> 00034 #include <measures/Measures/MFrequency.h> 00035 #include <coordinates/Coordinates/ObsInfo.h> 00036 00037 00038 class wcsprm; 00039 00040 namespace casa { //# NAMESPACE CASA - BEGIN 00041 00042 class Coordinate; 00043 class CoordinateSystem; 00044 class StokesCoordinate; 00045 class Projection; 00046 class IPosition; 00047 class LogIO; 00048 class Record; 00049 00050 00051 00052 00053 // <summary> 00054 // </summary> 00055 00056 // <use visibility=export> 00057 00058 // <reviewed reviewer="" date="" tests=""> 00059 // </reviewed> 00060 // 00061 // <prerequisite> 00062 // <li> <linkto class=Coordinate>CoordinateSystem</linkto> 00063 // </prerequisite> 00064 00065 // <synopsis> 00066 // Helper functions to inter-converft between a CoordinateSystem and FITS 00067 // headers. 00068 // </synopsis> 00069 00070 // <note role=caution> 00071 // </note> 00072 00073 // <example> 00074 // </example> 00075 00076 // <motivation> 00077 // I hate FITS 00078 // </motivation> 00079 // 00080 // <thrown> 00081 // <li> AipsError 00082 // </thrown> 00083 // 00084 // <todo asof="2004/08/23"> 00085 // </todo> 00086 // 00087 00088 00089 class FITSCoordinateUtil 00090 { 00091 public: 00092 00093 // Constructor 00094 FITSCoordinateUtil() {;}; 00095 00096 // Convert CoordinateSystem to a FITS header. In the record 00097 // the keywords are vectors, it is expected that the actual FITS code will 00098 // split them into scalars and upcase the names. Returns False if one of the 00099 // keywords is already taken. 00100 // 00101 // If writeWCS is True, attempt to write the WCS convention (Greisen and 00102 // Calabretta "Representation of celestial coordinates in FITS") as 00103 // approved in version 3.0 of the FITS standard. 00104 // Use <src>oneRelative=True</src> to convert zero-relative pixel coordinates to 00105 // one-relative FITS coordinates. 00106 // 00107 // prefix gives the prefix for the FITS keywords. E.g., 00108 // if prefix="c" then crval, cdelt etc. 00109 // if prefix="d" then drval, ddelt etc. 00110 //# Much of the work in to/from fits should be moved to the individual 00111 //# classes. 00112 Bool toFITSHeader(RecordInterface &header, 00113 IPosition &shape, 00114 const CoordinateSystem& cSys, 00115 Bool oneRelative, 00116 Char prefix = 'c', Bool writeWCS=True, 00117 Bool preferVelocity=True, 00118 Bool opticalVelocity=True, 00119 Bool preferWavelength=False, 00120 Bool airWavelength=False) const; 00121 00122 // Probably even if we return False we should set up the best linear 00123 // coordinate that we can. On output, <src>stokesFITSValue</src> 00124 // holds the FITS value of any unofficial Stokes (beam, optical depth, 00125 // spectral index) for the last unofficial value accessed (-1 if none). 00126 // The idea is that if the Stokes axis is of length one and holds an unofficial value, 00127 // you should drop the STokes axis and convert that value to <src>ImageInfo::ImageTypes</src> 00128 // with <src>ImageInfo::imageTypeFromFITSValue</src>. If on input, <src>stokesFITSValue</src> 00129 // is positive, then a warning is issued if any unofficial values are encountered. 00130 // Otherwise no warning is issued. 00131 //# cf comment in toFITS. 00132 //<group> 00133 Bool fromFITSHeader(Int& stokesFITSValue, 00134 CoordinateSystem& coordsys, 00135 RecordInterface& recHeader, 00136 const Vector<String>& header, 00137 const IPosition& shape, 00138 uInt which=0) const; 00139 //</group> 00140 00141 00142 // Helper function to create a FITS style CTYPE vector from the 00143 // axis names from a DirectionCoordinate 00144 static Vector<String> cTypeFromDirection (Bool& isNCP, const Projection& proj, 00145 const Vector<String>& axisNames, 00146 Double refLat, Bool printError); 00147 00148 private: 00149 // Generate actual FITS keywords 00150 Bool generateFITSKeywords (LogIO& os, Bool& isNCP, 00151 Double& longPole, Double& latPole, 00152 Vector<Double>& crval, 00153 Vector<Double>& crpix, 00154 Vector<Double>& cdelt, 00155 // Vector<Double>& crota, 00156 // Vector<Double>& projp, 00157 Vector<Double>& pvi_ma, 00158 Vector<String>& ctype, 00159 Vector<String>& cunit, 00160 Matrix<Double>& pc, 00161 const CoordinateSystem& cSys, 00162 Int skyCoord, Int longAxis, Int latAxis, 00163 Int specAxis, Int stokesAxis, 00164 Bool writeWCS, Double offset, 00165 const String& sprefix) const; 00166 00167 // Special Stokes processing for conversion to FITS header 00168 Bool toFITSHeaderStokes(Vector<Double>& crval, 00169 Vector<Double>& crpix, 00170 Vector<Double>& cdelt, 00171 LogIO& os, 00172 const CoordinateSystem& coordsys, 00173 Int stokesAxis, Int stokesCoord) const; 00174 00175 // Look for Coordinate type and add to CS 00176 // <group> 00177 Bool addDirectionCoordinate (CoordinateSystem& cSys, Vector<Int>& axes, 00178 const wcsprm& wcs, LogIO& os) const; 00179 Bool addSpectralCoordinate (CoordinateSystem& cSys, Int& axis, 00180 const wcsprm& wcs, const IPosition& shape, 00181 LogIO& os) const; 00182 Bool addStokesCoordinate (CoordinateSystem& cSys, Int& axis, Int& stokesFITSValue, 00183 const wcsprm& wcs, const IPosition& shape, 00184 LogIO& os) const; 00185 Bool addLinearCoordinate (CoordinateSystem& cSys, Vector<Int>& axes, 00186 const wcsprm& wcs, LogIO& os) const; 00187 // </group> 00188 00189 // Decode values from WCS structures which are generated via the wcs FITS parser 00190 // <group> 00191 Bool directionSystemFromWCS (LogIO& os, MDirection::Types& type, String& errMsg, 00192 const wcsprm& wcs) const; 00193 Bool frequencySystemFromWCS (LogIO& os, MFrequency::Types& type, String& errMsg, 00194 const wcsprm& wcs) const; 00195 Bool stokesCoordinateFromWCS (LogIO& os, StokesCoordinate& coord, 00196 Int& stokesFITSValue, String& errMSg, 00197 const wcsprm& wcs, uInt shape, Bool warnStokes) const; 00198 // </group> 00199 00200 // Decode ObsInfo from wcs structure 00201 ObsInfo getObsInfo(LogIO& os, RecordInterface& header, const wcsprm& wcs) const; 00202 00203 // Call wcsset 00204 void setWCS (wcsprm& wcs) const; 00205 00206 // Decode CD cards from FITS file header (Record interface) 00207 Bool getCDFromHeader(Matrix<Double>& cd, uInt n, const RecordInterface& header); 00208 00209 // Decode PC matrix from FITS header (Record interface) 00210 void getPCFromHeader(LogIO& os, Int& rotationAxis, Matrix<Double>& pc, 00211 uInt n, const RecordInterface& header, 00212 const String& sprefix); 00213 00214 // Helper function to convert a wcs structure holding FITS keywords 00215 // into a Record for later consumption. 00216 void cardsToRecord (LogIO& os, RecordInterface& rec, char* pHeader) const; 00217 00218 // Fix up Coordinate for zero increments and the like 00219 // Possibly the wcs FITS parser could do this 00220 void fixCoordinate(Coordinate& c, LogIO& os) const; 00221 }; 00222 00223 } //# NAMESPACE CASA - END 00224 00225 #endif 00226