FITSCoordinateUtil.h

Go to the documentation of this file.
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 <casacore/casa/aips.h>
00033 #include <casacore/measures/Measures/MDirection.h>
00034 #include <casacore/measures/Measures/MFrequency.h>
00035 #include <casacore/coordinates/Coordinates/ObsInfo.h>
00036 
00037 
00038 struct wcsprm;
00039 
00040 namespace casacore { //# NAMESPACE CASACORE - 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     static Vector<String> cTypeFromDirection (const Projection& proj,
00148                                               const Vector<String>& axisNames,
00149                                               Bool printError);
00150 
00151 private:
00152     // Generate actual FITS keywords
00153     Bool generateFITSKeywords (LogIO& os, Bool& isNCP,
00154                                Double& longPole, Double& latPole,
00155                                Vector<Double>& crval,
00156                                Vector<Double>& crpix,
00157                                Vector<Double>& cdelt,
00158                                //#   Vector<Double>& crota,
00159                                //#   Vector<Double>& projp,
00160                                Vector<Double>& pvi_ma,
00161                                Vector<String>& ctype,
00162                                Vector<String>& cunit,
00163                                Matrix<Double>& pc,
00164                                const CoordinateSystem& cSys,
00165                                Int skyCoord, Int longAxis, Int latAxis,
00166                                Int specAxis, Int stokesAxis, 
00167                                Bool writeWCS, Double offset,
00168                                const String& sprefix) const;
00169 
00170     // Special Stokes processing  for conversion to FITS header
00171     Bool toFITSHeaderStokes(Vector<Double>& crval,
00172                             Vector<Double>& crpix,
00173                             Vector<Double>& cdelt,
00174                             LogIO& os,
00175                             const CoordinateSystem& coordsys,
00176                             Int stokesAxis, Int stokesCoord) const;
00177 
00178     // Look for Coordinate type and add to CS
00179     // <group>
00180     Bool addDirectionCoordinate (CoordinateSystem& cSys, Vector<Int>& axes,
00181                                  const wcsprm& wcs, LogIO& os) const;
00182     Bool addSpectralCoordinate (CoordinateSystem& cSys, Int& axis,
00183                                 const wcsprm& wcs, const IPosition& shape, 
00184                                 LogIO& os) const;
00185     Bool addStokesCoordinate (CoordinateSystem& cSys, Int& axis,  Int& stokesFITSValue,
00186                               const wcsprm& wcs, const IPosition& shape,
00187                               LogIO& os) const;
00188     Bool addLinearCoordinate (CoordinateSystem& cSys, Vector<Int>& axes,
00189                               const wcsprm& wcs, LogIO& os) const;
00190     // </group>
00191 
00192 // Decode values from WCS structures which are generated via the wcs FITS parser
00193     // <group>
00194     Bool directionSystemFromWCS (LogIO& os, MDirection::Types& type, String& errMsg,
00195                                  const wcsprm& wcs) const;
00196     Bool frequencySystemFromWCS (LogIO& os, MFrequency::Types& type, String& errMsg,
00197                                  const wcsprm& wcs) const;
00198     Bool stokesCoordinateFromWCS (LogIO& os, StokesCoordinate& coord,  
00199                                   Int& stokesFITSValue, String& errMSg,
00200                                   const wcsprm& wcs, uInt shape, Bool warnStokes) const;
00201     // </group>
00202 
00203     // Decode ObsInfo from wcs structure
00204     ObsInfo getObsInfo(LogIO& os, RecordInterface& header, const wcsprm& wcs) const;
00205 
00206    // Call wcsset
00207    void setWCS (wcsprm& wcs) const;
00208 
00209     // Decode CD cards from FITS file header (Record interface)
00210     Bool getCDFromHeader(Matrix<Double>& cd, uInt n, const RecordInterface& header);
00211 
00212     // Decode PC matrix from FITS header (Record interface)
00213     void getPCFromHeader(LogIO& os, Int& rotationAxis, Matrix<Double>& pc,
00214                                 uInt n, const RecordInterface& header,
00215                                 const String& sprefix);
00216 
00217     // Helper function to convert a wcs structure holding FITS keywords
00218     // into a Record for later consumption.
00219     void cardsToRecord (LogIO& os, RecordInterface& rec, char* pHeader) const;
00220     
00221     // Fix up Coordinate for zero increments and the like
00222     // Possibly the wcs FITS parser could do this
00223     void fixCoordinate(Coordinate& c, LogIO& os) const;
00224 
00225     // Initialize the wcsprm struct.
00226     // It sets the flag to -1, but furthermore it clears the err pointers
00227     // because wcslib-4.8 (shipped with Ubuntu) sometimes fails to do so.
00228     static void wcsInit (::wcsprm& wcsDest);
00229 };
00230 
00231 } //# NAMESPACE CASACORE - END
00232 
00233 #endif
00234 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1