casa
$Rev:20696$
|
00001 //# FrequenctAligner.h: Align spectra in frequency space 00002 //# Copyright (C) 1998,1999,2000,2001,2003 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 //# $Id: FrequencyAligner.h 20494 2009-01-16 15:29:27Z gervandiepen $ 00027 00028 #ifndef COORDINATES_FREQUENCYALIGNER_H 00029 #define COORDINATES_FREQUENCYALIGNER_H 00030 00031 00032 //# Includes 00033 #include <coordinates/Coordinates/SpectralCoordinate.h> 00034 #include <measures/Measures/MFrequency.h> 00035 #include <measures/Measures/MeasRef.h> 00036 #include <measures/Measures/MeasConvert.h> 00037 #include <scimath/Mathematics/InterpolateArray1D.h> 00038 00039 namespace casa { 00040 00041 //# Forward Declarations 00042 class MEpoch; 00043 class MDirection; 00044 class MPosition; 00045 class String; 00046 00047 00048 00049 // <summary> 00050 // Aligns spectra in frequency space 00051 // </summary> 00052 // 00053 // <use visibility=export> 00054 // 00055 // <reviewed reviewer="" date="" tests="tFrequencyAligner.cc"> 00056 // </reviewed> 00057 // 00058 // <prerequisite> 00059 // <li> <linkto class=InterpolateArray1D>InterpoateArray1D</linkto> 00060 // <li> <linkto class=Array>Array</linkto> 00061 // </prerequisite> 00062 00063 // <synopsis> 00064 // Spectra are converted to the specified reference frame and aligned at 00065 // a specified instant in time. 00066 // 00067 // You should not try to convert from, say, a SpectralCoordinate::TOPO to 00068 // MFrequency::TOPO as this would be meaningless. This class is designed 00069 // mainly to convert say from a SpectralCoordinate::TOPO to say, a BARY 00070 // frame and align. 00071 // </synopsis> 00072 // 00073 // <motivation> 00074 // Required for ASAP single-dish package 00075 // </motivation> 00076 // 00077 // <todo asof="2004/11/01"> 00078 // </todo> 00079 00080 00081 template <class T> class FrequencyAligner 00082 { 00083 public: 00084 00085 // Default constructor (object not viable) 00086 FrequencyAligner(); 00087 00088 // Constructor specifies a SpectralCoordinate (any extra reference conversion 00089 // frame set in it will be ignored), the number of pixels in the spectra to 00090 // be aligned, a reference epoch to which all spectra will 00091 // be aligned, a direction on the sky, a position on the earth (the observatory), 00092 // and desired frequency system to align in. 00093 FrequencyAligner(const SpectralCoordinate& specCoord, uInt nPixels, 00094 const MEpoch& refEpoch, const MDirection& dir, 00095 const MPosition& pos, MFrequency::Types freqSystem); 00096 00097 // Copy constructor (copy semantics) 00098 FrequencyAligner (const FrequencyAligner<T>& other); 00099 00100 // Assignment (copy semantics) 00101 FrequencyAligner& operator=(const FrequencyAligner<T>& other); 00102 00103 // Destructor 00104 ~FrequencyAligner(); 00105 00106 // Set a tolerance (in pixels) to trigger regridding (function <src>align</src>). 00107 // If the maximum abcissa difference for the current spectrum abcissa compared 00108 // to the reference abcissa is greater than <src>tol (pixels)</src> then a 00109 // regrid is triggered. Otherwise the input is just copied to the output when 00110 // function <src>align</src> is called. Set to 0 to turn this tolerance 00111 // assessment off. This function may be not really worth using. 00112 void setTolerance (Double tol) {itsDiffTol = abs(tol);}; 00113 00114 // Align (via regridding) one spectrum taken at the specified epoch to 00115 // the reference epoch. Your provide the ordinate and mask (True==Good) 00116 // for the spectrum. The lengths of these vectors must be the same 00117 // as <src>nPixels</src> given in the constructor. The output vectors 00118 // are resized as needed. 00119 // You can use the last cached abcissa (computed by 00120 // this function) rather than recompute it if you have more than one spectrum 00121 // at the same epoch to convert (e.g. different polarizations). 00122 // If you do this, it is your responsibility to make sure that you 00123 // have called this function at least once with <src>useCachedAbcissa=False</src>. 00124 // If <src>extrapolate</src> is True, the regridding process is allowed 00125 // to extrapolate outside of the abcissa domain. Otherwise masked pixels will result. 00126 // Returns True if a regrid triggered, else False if just copied (see function 00127 // <src>setTolerance</src>. 00128 Bool align (Vector<T>& yOut, Vector<Bool>& maskOut, 00129 const Vector<T>& yIn, const Vector<Bool>& maskIn, 00130 const MEpoch& epoch, Bool useCachedAbcissa, 00131 typename InterpolateArray1D<Double,T>::InterpolationMethod method, 00132 Bool extrapolate=False); 00133 00134 // This function is the same as the previous except that you can specify the input abcissa as well 00135 // as the data and mask. The input abcissa must be in the same units as the Construction 00136 // SpectralCoordinate. The abcissa values must be in the same base reference frame 00137 // as the Construction SpectralCoordinate. So instead of the abcissa (in the 00138 // output reference frame) being computed from the Construction SC, you get to specify 00139 // the abcissa directly. This might be useful if you have more than one set of 00140 // spectra to align, all in the same Frame, but with different attributes such 00141 // as reference value/pixel etc. The output spectrum is still regridded to the 00142 // abcissa at the reference time generated at construction. 00143 // from the current 00144 Bool align (Vector<T>& yOut, Vector<Bool>& maskOut, 00145 const Vector<Double>& xIn, const Vector<T>& yIn, const Vector<Bool>& maskIn, 00146 const MEpoch& epoch, Bool useCachedAbcissa, 00147 typename InterpolateArray1D<Double,T>::InterpolationMethod method, 00148 Bool extrapolate=False); 00149 00150 // Align many spectra stored in an Array along the specified axis. All spectra are aligned 00151 // to the same frequency abcissa (as described in previous function). If any alignment 00152 // returns False, then the return value will be False, otherwise True is returned. 00153 Bool alignMany (Array<T>& yOut, Array<Bool>& maskOut, 00154 const Array<T>& yIn, const Array<Bool>& maskIn, 00155 uInt axis, const MEpoch& epoch, 00156 typename InterpolateArray1D<Double,T>::InterpolationMethod method, 00157 Bool extrapolate=False); 00158 00159 // Get the reference abcissa (as a frequency in the axis units set in the SpectralCoordinate) at the reference epoch 00160 void getReferenceAbcissa (Vector<Double>& xOut) const; 00161 00162 // Get the abcissa (as a frequency in the axis units set in the SpectralCoordinate) last cached by function <src>align</src> 00163 void getAbcissa (Vector<Double>& xOut) const; 00164 00165 // Get new aligned SpectralCoordinate. It is probably non-linear, but if you would 00166 // like a linear approximation, use the doLinear argument. 00167 SpectralCoordinate alignedSpectralCoordinate (Bool doLinear=True) const; 00168 00169 private: 00170 SpectralCoordinate itsSpecCoord; 00171 MFrequency::Convert itsMachine; 00172 MFrequency::Ref itsRefOut; // Need this as there is no easy way to update 00173 // the conversion machines epoch otherwise 00174 MFrequency::Types itsFreqSystem; 00175 // 00176 Vector<Double> itsRefFreqX; // Reference frequency abcissa 00177 Vector<Double> itsFreqX; // Frequency abcissa 00178 00179 Double itsDiffTol; // Tolerance which triggers a regrid 00180 00181 // Internal copy 00182 void copyOther (const FrequencyAligner<T>& other); 00183 00184 // Create the Conversion machine 00185 void makeMachine (const MEpoch& refEpoch, 00186 const MDirection& dir, 00187 const MPosition& pos, 00188 MFrequency::Types freqSystem, 00189 const Unit& unit); 00190 00191 // Generate an abcissa with the machine 00192 Double makeAbcissa (Vector<Double>& f, Bool doMaxDiff); 00193 00194 // Regrid one spectrum 00195 Bool regrid (Vector<T>& yOut, Vector<Bool>& maskOut, 00196 const Vector<Double>& xOut, 00197 const Vector<Double>& xIn, 00198 const Vector<T>& yIn, const Vector<Bool>& maskIn, 00199 typename InterpolateArray1D<Double,T>::InterpolationMethod method, 00200 Bool extrapolate, Double maxDiff) const; 00201 }; 00202 00203 00204 } //# End namespace casa 00205 #ifndef CASACORE_NO_AUTO_TEMPLATES 00206 #include <coordinates/Coordinates/FrequencyAligner.tcc> 00207 #endif //# CASACORE_NO_AUTO_TEMPLATES 00208 #endif