casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FITSSpectralUtil.h
Go to the documentation of this file.
00001 //# FITSSpectralUtil.h: Static functions to help with FITS spectral axes.
00002 //# Copyright (C) 2002
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: FITSSpectralUtil.h 21069 2011-05-06 13:59:44Z gervandiepen $
00028 
00029 
00030 #ifndef FITS_FITSSPECTRALUTIL_H
00031 #define FITS_FITSSPECTRALUTIL_H
00032 
00033 #include <casa/aips.h>
00034 #include <measures/Measures/MDoppler.h>
00035 #include <measures/Measures/MFrequency.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 class RecordInterface;
00040 class String;
00041 template<class T> class Vector;
00042 class LogIO;
00043 
00044 // <summary>
00045 // A class with static functions to help deal with FITS spectral axes.
00046 // </summary>
00047 
00048 // <use visibility=export>
00049 
00050 // <reviewed reviewer="Eric Sessoms" date="2002/08/19" tests="tFITSSpectralUtil.cc">
00051 // </reviewed>
00052 
00053 // <prerequisite>
00054 // <li> General knowlege of FITS, FITS keywords, and FITS coordinate
00055 //      conventions is assumed.
00056 // <li> Presumably you are using this in conjuction with the
00057 //      <linkto class=FITSKeywordUtil>FITSKeywordUtil</linkto> class
00058 //      to get or set the FITS coordinate axis information.
00059 // </prerequisite>
00060 
00061 // <etymology>
00062 // This is a collection of static utility functions for use with
00063 // FITS spectral axes.
00064 // </etymology>
00065 
00066 // <synopsis>
00067 // This class provides functions to extract information from a FITS
00068 // header about the spectral axis, to setup a FITS header with
00069 // appropriate information for the spectral axis, and to translate
00070 // to and from the MFrequency reference frame codes and their FITS
00071 // equivalents.
00072 // It is never necessary to construct a FITSSpectralUtil, just use the 
00073 // static functions to help handle FITS Spectral axes.
00074 // </synopsis>
00075 //
00076 // <example>
00077 // <srcblock>
00078 // Record rec;
00079 // ... extract the FITS keyword values into rec using FITSKeywordUtil
00080 // Int whichAxis;
00081 // Double refPix, refFreq, freqInc, restFreq;
00082 // Vector<Double> freqs;
00083 // MFrequency::Types refFrame;
00084 // MDoppler::Types veldef;
00085 // LogIO logger;
00086 // FITSSpectralUtil::fromFITSHeader(whichAxis, refPix, refFreq,
00087 //        freqInc, freqs, refFrame, veldef, logger, rec);
00088 // </srcblock>
00089 // </example>
00090 //
00091 // <motivation>
00092 // This is designed to be used after the keywords have been extracted from
00093 // the FITS file using the <linkto class=FITSKeywordUtil>FITSKeywordUtil</linkto>
00094 // class.  Extracting spectral axis and related information requires detailed
00095 // knowledge of FITS conventions that this class strives to encapsulize.
00096 // </motivation>
00097 //
00098 // <todo asof="2011/11/30">
00099 //   <li> General usage of units for frequency and velocity in "fromFITSHeader"
00100 //        (currently only implemented for wavelength)
00101 // </todo>
00102 
00103 class FITSSpectralUtil
00104 {
00105 public:
00106     // Get information about the spectral axis from a record containing the
00107     // FITS axis information.  Usually this will be from a FITS header using,
00108     // for example, the FITSKeywordUtil::getKeywords method.
00109     // referenceFrequency and deltaFrequency give the best
00110     // possible linear frequency scale.  prefix is the first character in the
00111     // set of keywords describing the axes (e.g. crpix, crval, ctype - the prefix is
00112     // 'c').  If oneRelative is False, the returned referenceChannel is decrimented
00113     // from that found in header by 1.  The naxis keywords are used to determine
00114     // the output length of the freqs vector.
00115     // This method returns False if:
00116     // <ul>
00117     //  <li> no spectral axis is found. The freqs vector will have a length of zero.
00118     //  <li> The expected set of axis description keywords is not found.
00119     //  <li> The spectral axis is FELO but there is no rest frequency (making it
00120     //       impossible to convert to frequency and construct a freqs vector).
00121     //  <li> The combination FELO and RADIO is used (which does not make sense).
00122     //  <li> The combination VELO and OPTICAL is used (not yet implemented).
00123     // </ul>
00124     static Bool fromFITSHeader(Int &spectralAxis,
00125                                Double &referenceChannel,
00126                                Double &referenceFrequency,
00127                                Double &deltaFrequency,
00128                                Vector<Double> &frequencies,
00129                                MFrequency::Types &refFrame,
00130                                MDoppler::Types &velocityPreference,
00131                                Double &restFrequency,
00132                                LogIO &logger,
00133                                const RecordInterface &header,
00134                                char prefix = 'c',
00135                                Bool oneRelative=True);
00136 
00137     // Nearly the inverse of fromFITSHeader. This returns parameters which could
00138     // be used in filling in a header record with appropriate values for
00139     // the spectral axis given the arguments after the logger.
00140     // The alternate axis description values are set when sufficient information is available.
00141     // If they have been set, haveAlt will be set to True.
00142     // <ul>
00143     //  <li> Note that the output arguments after "haveAlt"
00144     //       should not be written to the FITS header unless haveAlt is true. 
00145     //  <li> Note that restfreq is both an input and an output. If there is no
00146     //       rest frequency, set it to be <=0 on input.  
00147     // </ul>
00148     // If preferVelocity is True, the
00149     // axis description parameters will be set to those appropriate for
00150     // a velocity axis given the referenceFrame, and velocityPreference
00151     // if possible.
00152     // If preferWavelength is True, the
00153     // axis description parameters will be set to those appropriate for
00154     // a wavelength axis given the referenceFrame if possible.
00155     // The two preferences cannot be True at the same time.
00156     // If airWavelength is True, the
00157     // axis description parameters will be set to those appropriate for
00158     // an air wavelength axis given the referenceFrame if possible.
00159     // This parameter has an effect only if preferWavelength is True.
00160 
00161     // This method always returns True.
00162     static Bool toFITSHeader(String &ctype, 
00163                              Double &crval, 
00164                              Double &cdelt,
00165                              Double &crpix, 
00166                              String &cunit,
00167                              Bool &haveAlt, 
00168                              Double &altrval,
00169                              Double &altrpix,
00170                              Int &velref,
00171                              Double &restfreq,
00172                              String &specsys,
00173                              LogIO &logger,
00174                              Double refFrequency,
00175                              Double refChannel,
00176                              Double freqIncrement,
00177                              MFrequency::Types referenceFrame,
00178                              Bool preferVelocity = True,
00179                              MDoppler::Types velocityPreference = MDoppler::OPTICAL,
00180                              Bool preferWavelength = False,
00181                              Bool airWavelength = False,
00182                              Bool useDeprecatedCtypes = False);
00183 
00184     // Convert a reference frame tag (typically found as the characters
00185     // after the first 4 characters in a ctype string for the
00186     // frequency-like axis) to a MFrequency::Types value.
00187     // A velref value (used in AIPS images to alternatively record
00188     // the velocity reference frame) may also optionally be supplied.
00189     // If tag is empty, velref will be used if it is >= 0.
00190     // This function returns False if:
00191     // <ul>
00192     //  <li> The tag is not empty but is unrecognized.
00193     //  <li> The tag is empty and velref is unrecognized.
00194     //  <li> The tag is empty and velref is < 0 (no velref was supplied).
00195     // </ul>
00196     // The default value (set when the return value is False) is TOPO.
00197     static Bool frameFromTag(MFrequency::Types &referenceFrame,
00198                              const String &tag,
00199                              Int velref=-1);
00200 
00201     // Construct a reference frame tag from the given referenceFrame
00202     // An appropriate velref value is also constructed (this may need 
00203     // to be adjusted by +256 if the velocity definition is radio before
00204     // being used in a FITS file).  This returns False if the
00205     // reference frame is not recognized.  The value of tag defaults
00206     // to "-OBS".
00207     static Bool tagFromFrame(String &tag, Int &velref,
00208                              MFrequency::Types referenceFrame);
00209 
00210     // Construct a SPECSYS keyword value from the given referenceFrame
00211     // This returns False if the reference frame is not recognized.  
00212     // The value of tag defaults to "TOPOCENT".
00213     static Bool specsysFromFrame(String &specsys,
00214                                  MFrequency::Types referenceFrame);
00215 
00216     static Bool frameFromSpecsys(MFrequency::Types& refFrame, String& specsys);
00217 
00218     // The refractive index of air (argument can be vacuum wavelength or airwavelength)
00219     // according to Greisen et al., 2006, A&A, 464, 746.
00220     // If vacuum wavelength is used there is an error of the order of 1E-9.
00221     // Argument must be in micrometers!
00222     static Double refractiveIndex(const Double& lambda_um);
00223 };
00224 
00225 
00226 } //# NAMESPACE CASA - END
00227 
00228 #endif