casacore
Loading...
Searching...
No Matches
FITSSpectralUtil.h
Go to the documentation of this file.
1// # FITSSpectralUtil.h: Static functions to help with FITS spectral axes.
2// # Copyright (C) 2002
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 FITS_FITSSPECTRALUTIL_H
27#define FITS_FITSSPECTRALUTIL_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31#include <casacore/measures/Measures/MDoppler.h>
32#include <casacore/measures/Measures/MFrequency.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36class RecordInterface;
37class String;
38class LogIO;
39
40// <summary>
41// A class with static functions to help deal with FITS spectral axes.
42// </summary>
43
44// <use visibility=export>
45
46// <reviewed reviewer="Eric Sessoms" date="2002/08/19" tests="tFITSSpectralUtil.cc">
47// </reviewed>
48
49// <prerequisite>
50// <li> General knowlege of FITS, FITS keywords, and FITS coordinate
51// conventions is assumed.
52// <li> Presumably you are using this in conjuction with the
53// <linkto class=FITSKeywordUtil>FITSKeywordUtil</linkto> class
54// to get or set the FITS coordinate axis information.
55// </prerequisite>
56
57// <etymology>
58// This is a collection of static utility functions for use with
59// FITS spectral axes.
60// </etymology>
61
62// <synopsis>
63// This class provides functions to extract information from a FITS
64// header about the spectral axis, to setup a FITS header with
65// appropriate information for the spectral axis, and to translate
66// to and from the MFrequency reference frame codes and their FITS
67// equivalents.
68// It is never necessary to construct a FITSSpectralUtil, just use the
69// static functions to help handle FITS Spectral axes.
70// </synopsis>
71//
72// <example>
73// <srcblock>
74// Record rec;
75// ... extract the FITS keyword values into rec using FITSKeywordUtil
76// Int whichAxis;
77// Double refPix, refFreq, freqInc, restFreq;
78// Vector<Double> freqs;
79// MFrequency::Types refFrame;
80// MDoppler::Types veldef;
81// LogIO logger;
82// FITSSpectralUtil::fromFITSHeader(whichAxis, refPix, refFreq,
83// freqInc, freqs, refFrame, veldef, logger, rec);
84// </srcblock>
85// </example>
86//
87// <motivation>
88// This is designed to be used after the keywords have been extracted from
89// the FITS file using the <linkto class=FITSKeywordUtil>FITSKeywordUtil</linkto>
90// class. Extracting spectral axis and related information requires detailed
91// knowledge of FITS conventions that this class strives to encapsulize.
92// </motivation>
93//
94// <todo asof="2011/11/30">
95// <li> General usage of units for frequency and velocity in "fromFITSHeader"
96// (currently only implemented for wavelength)
97// </todo>
98
100 public:
101 // Get information about the spectral axis from a record containing the
102 // FITS axis information. Usually this will be from a FITS header using,
103 // for example, the FITSKeywordUtil::getKeywords method.
104 // referenceFrequency and deltaFrequency give the best
105 // possible linear frequency scale. prefix is the first character in the
106 // set of keywords describing the axes (e.g. crpix, crval, ctype - the prefix is
107 // 'c'). If oneRelative is False, the returned referenceChannel is decrimented
108 // from that found in header by 1. The naxis keywords are used to determine
109 // the output length of the freqs vector.
110 // This method returns False if:
111 // <ul>
112 // <li> no spectral axis is found. The freqs vector will have a length of zero.
113 // <li> The expected set of axis description keywords is not found.
114 // <li> The spectral axis is FELO but there is no rest frequency (making it
115 // impossible to convert to frequency and construct a freqs vector).
116 // <li> The combination FELO and RADIO is used (which does not make sense).
117 // <li> The combination VELO and OPTICAL is used (not yet implemented).
118 // </ul>
119 static Bool fromFITSHeader(Int &spectralAxis, Double &referenceChannel,
120 Double &referenceFrequency, Double &deltaFrequency,
121 Vector<Double> &frequencies, MFrequency::Types &refFrame,
122 MDoppler::Types &velocityPreference, Double &restFrequency,
123 LogIO &logger, const RecordInterface &header, char prefix = 'c',
124 Bool oneRelative = True);
125
126 // Nearly the inverse of fromFITSHeader. This returns parameters which could
127 // be used in filling in a header record with appropriate values for
128 // the spectral axis given the arguments after the logger.
129 // The alternate axis description values are set when sufficient information is available.
130 // If they have been set, haveAlt will be set to True.
131 // <ul>
132 // <li> Note that the output arguments after "haveAlt"
133 // should not be written to the FITS header unless haveAlt is true.
134 // <li> Note that restfreq is both an input and an output. If there is no
135 // rest frequency, set it to be <=0 on input.
136 // </ul>
137 // If preferVelocity is True, the
138 // axis description parameters will be set to those appropriate for
139 // a velocity axis given the referenceFrame, and velocityPreference
140 // if possible.
141 // If preferWavelength is True, the
142 // axis description parameters will be set to those appropriate for
143 // a wavelength axis given the referenceFrame if possible.
144 // The two preferences cannot be True at the same time.
145 // If airWavelength is True, the
146 // axis description parameters will be set to those appropriate for
147 // an air wavelength axis given the referenceFrame if possible.
148 // This parameter has an effect only if preferWavelength is True.
149
150 // This method always returns True.
152 String &cunit, Bool &haveAlt, Double &altrval, Double &altrpix,
153 Int &velref, Double &restfreq, String &specsys, LogIO &logger,
154 Double refFrequency, Double refChannel, Double freqIncrement,
155 MFrequency::Types referenceFrame, Bool preferVelocity = True,
156 MDoppler::Types velocityPreference = MDoppler::OPTICAL,
157 Bool preferWavelength = False, Bool airWavelength = False,
158 Bool useDeprecatedCtypes = False);
159
160 // Convert a reference frame tag (typically found as the characters
161 // after the first 4 characters in a ctype string for the
162 // frequency-like axis) to a MFrequency::Types value.
163 // A velref value (used in AIPS images to alternatively record
164 // the velocity reference frame) may also optionally be supplied.
165 // If tag is empty, velref will be used if it is >= 0.
166 // This function returns False if:
167 // <ul>
168 // <li> The tag is not empty but is unrecognized.
169 // <li> The tag is empty and velref is unrecognized.
170 // <li> The tag is empty and velref is < 0 (no velref was supplied).
171 // </ul>
172 // The default value (set when the return value is False) is TOPO.
173 static Bool frameFromTag(MFrequency::Types &referenceFrame, const String &tag, Int velref = -1);
174
175 // Construct a reference frame tag from the given referenceFrame
176 // An appropriate velref value is also constructed (this may need
177 // to be adjusted by +256 if the velocity definition is radio before
178 // being used in a FITS file). This returns False if the
179 // reference frame is not recognized. The value of tag defaults
180 // to "-OBS".
181 static Bool tagFromFrame(String &tag, Int &velref, MFrequency::Types referenceFrame);
182
183 // Construct a SPECSYS keyword value from the given referenceFrame
184 // This returns False if the reference frame is not recognized.
185 // The value of tag defaults to "TOPOCENT".
186 static Bool specsysFromFrame(String &specsys, MFrequency::Types referenceFrame);
187
188 static Bool frameFromSpecsys(MFrequency::Types &refFrame, String &specsys);
189
190 // The refractive index of air (argument can be vacuum wavelength or airwavelength)
191 // according to Greisen et al., 2006, A&A, 464, 746.
192 // If vacuum wavelength is used there is an error of the order of 1E-9.
193 // Argument must be in micrometers!
194 static Double refractiveIndex(const Double &lambda_um);
195};
196
197} // namespace casacore
198
199#endif
static Bool toFITSHeader(String &ctype, Double &crval, Double &cdelt, Double &crpix, String &cunit, Bool &haveAlt, Double &altrval, Double &altrpix, Int &velref, Double &restfreq, String &specsys, LogIO &logger, Double refFrequency, Double refChannel, Double freqIncrement, MFrequency::Types referenceFrame, Bool preferVelocity=True, MDoppler::Types velocityPreference=MDoppler::OPTICAL, Bool preferWavelength=False, Bool airWavelength=False, Bool useDeprecatedCtypes=False)
Nearly the inverse of fromFITSHeader.
static Bool fromFITSHeader(Int &spectralAxis, Double &referenceChannel, Double &referenceFrequency, Double &deltaFrequency, Vector< Double > &frequencies, MFrequency::Types &refFrame, MDoppler::Types &velocityPreference, Double &restFrequency, LogIO &logger, const RecordInterface &header, char prefix='c', Bool oneRelative=True)
Get information about the spectral axis from a record containing the FITS axis information.
static Bool frameFromTag(MFrequency::Types &referenceFrame, const String &tag, Int velref=-1)
Convert a reference frame tag (typically found as the characters after the first 4 characters in a ct...
static Bool frameFromSpecsys(MFrequency::Types &refFrame, String &specsys)
static Double refractiveIndex(const Double &lambda_um)
The refractive index of air (argument can be vacuum wavelength or airwavelength) according to Greisen...
static Bool specsysFromFrame(String &specsys, MFrequency::Types referenceFrame)
Construct a SPECSYS keyword value from the given referenceFrame This returns False if the reference f...
static Bool tagFromFrame(String &tag, Int &velref, MFrequency::Types referenceFrame)
Construct a reference frame tag from the given referenceFrame An appropriate velref value is also con...
Types
Types of known MDopplers Warning: The order defines the order in the translation matrix FromTo in th...
Definition MDoppler.h:149
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
double cdelt(int n) const
Definition hdu.h:410
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