casacore
FrequencyAligner.h
Go to the documentation of this file.
1 //# FrequenctAligner.h: Align spectra in frequency space
2 //# Copyright (C) 1998,1999,2000,2001,2003
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: aips2-request@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 //# $Id$
27 
28 #ifndef COORDINATES_FREQUENCYALIGNER_H
29 #define COORDINATES_FREQUENCYALIGNER_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/coordinates/Coordinates/SpectralCoordinate.h>
35 #include <casacore/measures/Measures/MFrequency.h>
36 #include <casacore/measures/Measures/MeasRef.h>
37 #include <casacore/measures/Measures/MeasConvert.h>
38 #include <casacore/scimath/Mathematics/InterpolateArray1D.h>
39 
40 namespace casacore {
41 
42 //# Forward Declarations
43 class MEpoch;
44 class MDirection;
45 class MPosition;
46 class String;
47 
48 
49 
50 // <summary>
51 // Aligns spectra in frequency space
52 // </summary>
53 //
54 // <use visibility=export>
55 //
56 // <reviewed reviewer="" date="" tests="tFrequencyAligner.cc">
57 // </reviewed>
58 //
59 // <prerequisite>
60 // <li> <linkto class=InterpolateArray1D>InterpoateArray1D</linkto>
61 // <li> <linkto class=Array>Array</linkto>
62 // </prerequisite>
63 
64 // <synopsis>
65 // Spectra are converted to the specified reference frame and aligned at
66 // a specified instant in time.
67 //
68 // You should not try to convert from, say, a SpectralCoordinate::TOPO to
69 // MFrequency::TOPO as this would be meaningless. This class is designed
70 // mainly to convert say from a SpectralCoordinate::TOPO to say, a BARY
71 // frame and align.
72 // </synopsis>
73 //
74 // <motivation>
75 // Required for ASAP single-dish package
76 // </motivation>
77 //
78 // <todo asof="2004/11/01">
79 // </todo>
80 
81 
82 template <class T> class FrequencyAligner
83 {
84 public:
85 
86 // Default constructor (object not viable)
88 
89 // Constructor specifies a SpectralCoordinate (any extra reference conversion
90 // frame set in it will be ignored), the number of pixels in the spectra to
91 // be aligned, a reference epoch to which all spectra will
92 // be aligned, a direction on the sky, a position on the earth (the observatory),
93 // and desired frequency system to align in.
94  FrequencyAligner(const SpectralCoordinate& specCoord, uInt nPixels,
95  const MEpoch& refEpoch, const MDirection& dir,
96  const MPosition& pos, MFrequency::Types freqSystem);
97 
98 // Copy constructor (copy semantics)
100 
101 // Assignment (copy semantics)
103 
104 // Destructor
106 
107 // Set a tolerance (in pixels) to trigger regridding (function <src>align</src>).
108 // If the maximum abcissa difference for the current spectrum abcissa compared
109 // to the reference abcissa is greater than <src>tol (pixels)</src> then a
110 // regrid is triggered. Otherwise the input is just copied to the output when
111 // function <src>align</src> is called. Set to 0 to turn this tolerance
112 // assessment off. This function may be not really worth using.
113  void setTolerance (Double tol) {itsDiffTol = abs(tol);};
114 
115 // Align (via regridding) one spectrum taken at the specified epoch to
116 // the reference epoch. Your provide the ordinate and mask (True==Good)
117 // for the spectrum. The lengths of these vectors must be the same
118 // as <src>nPixels</src> given in the constructor. The output vectors
119 // are resized as needed.
120 // You can use the last cached abcissa (computed by
121 // this function) rather than recompute it if you have more than one spectrum
122 // at the same epoch to convert (e.g. different polarizations).
123 // If you do this, it is your responsibility to make sure that you
124 // have called this function at least once with <src>useCachedAbcissa=False</src>.
125 // If <src>extrapolate</src> is True, the regridding process is allowed
126 // to extrapolate outside of the abcissa domain. Otherwise masked pixels will result.
127 // Returns True if a regrid triggered, else False if just copied (see function
128 // <src>setTolerance</src>.
129  Bool align (Vector<T>& yOut, Vector<Bool>& maskOut,
130  const Vector<T>& yIn, const Vector<Bool>& maskIn,
131  const MEpoch& epoch, Bool useCachedAbcissa,
133  Bool extrapolate=False);
134 
135 // This function is the same as the previous except that you can specify the input abcissa as well
136 // as the data and mask. The input abcissa must be in the same units as the Construction
137 // SpectralCoordinate. The abcissa values must be in the same base reference frame
138 // as the Construction SpectralCoordinate. So instead of the abcissa (in the
139 // output reference frame) being computed from the Construction SC, you get to specify
140 // the abcissa directly. This might be useful if you have more than one set of
141 // spectra to align, all in the same Frame, but with different attributes such
142 // as reference value/pixel etc. The output spectrum is still regridded to the
143 // abcissa at the reference time generated at construction.
144 // from the current
145  Bool align (Vector<T>& yOut, Vector<Bool>& maskOut,
146  const Vector<Double>& xIn, const Vector<T>& yIn, const Vector<Bool>& maskIn,
147  const MEpoch& epoch, Bool useCachedAbcissa,
149  Bool extrapolate=False);
150 
151 // Align many spectra stored in an Array along the specified axis. All spectra are aligned
152 // to the same frequency abcissa (as described in previous function). If any alignment
153 // returns False, then the return value will be False, otherwise True is returned.
154  Bool alignMany (Array<T>& yOut, Array<Bool>& maskOut,
155  const Array<T>& yIn, const Array<Bool>& maskIn,
156  uInt axis, const MEpoch& epoch,
158  Bool extrapolate=False);
159 
160 // Get the reference abcissa (as a frequency in the axis units set in the SpectralCoordinate) at the reference epoch
162 
163 // Get the abcissa (as a frequency in the axis units set in the SpectralCoordinate) last cached by function <src>align</src>
164  void getAbcissa (Vector<Double>& xOut) const;
165 
166 // Get new aligned SpectralCoordinate. It is probably non-linear, but if you would
167 // like a linear approximation, use the doLinear argument.
169 
170 private:
173  MFrequency::Ref itsRefOut; // Need this as there is no easy way to update
174  // the conversion machines epoch otherwise
176 //
177  Vector<Double> itsRefFreqX; // Reference frequency abcissa
178  Vector<Double> itsFreqX; // Frequency abcissa
179 
180  Double itsDiffTol; // Tolerance which triggers a regrid
181 
182 // Internal copy
183  void copyOther (const FrequencyAligner<T>& other);
184 
185 // Create the Conversion machine
186  void makeMachine (const MEpoch& refEpoch,
187  const MDirection& dir,
188  const MPosition& pos,
189  MFrequency::Types freqSystem,
190  const Unit& unit);
191 
192 // Generate an abcissa with the machine
194 
195 // Regrid one spectrum
196  Bool regrid (Vector<T>& yOut, Vector<Bool>& maskOut,
197  const Vector<Double>& xOut,
198  const Vector<Double>& xIn,
199  const Vector<T>& yIn, const Vector<Bool>& maskIn,
201  Bool extrapolate, Double maxDiff) const;
202 };
203 
204 
205 } //# End namespace casacore
206 #ifndef CASACORE_NO_AUTO_TEMPLATES
207 #include <casacore/coordinates/Coordinates/FrequencyAligner.tcc>
208 #endif //# CASACORE_NO_AUTO_TEMPLATES
209 #endif
void getAbcissa(Vector< Double > &xOut) const
Get the abcissa (as a frequency in the axis units set in the SpectralCoordinate) last cached by funct...
FrequencyAligner()
Default constructor (object not viable)
MFrequency::Convert itsMachine
Bool regrid(Vector< T > &yOut, Vector< Bool > &maskOut, const Vector< Double > &xOut, const Vector< Double > &xIn, const Vector< T > &yIn, const Vector< Bool > &maskIn, typename InterpolateArray1D< Double, T >::InterpolationMethod method, Bool extrapolate, Double maxDiff) const
Regrid one spectrum.
SpectralCoordinate alignedSpectralCoordinate(Bool doLinear=True) const
Get new aligned SpectralCoordinate.
Bool alignMany(Array< T > &yOut, Array< Bool > &maskOut, const Array< T > &yIn, const Array< Bool > &maskIn, uInt axis, const MEpoch &epoch, typename InterpolateArray1D< Double, T >::InterpolationMethod method, Bool extrapolate=False)
Align many spectra stored in an Array along the specified axis.
void copyOther(const FrequencyAligner< T > &other)
Internal copy.
void setTolerance(Double tol)
Set a tolerance (in pixels) to trigger regridding (function align).
FrequencyAligner & operator=(const FrequencyAligner< T > &other)
Assignment (copy semantics)
SpectralCoordinate itsSpecCoord
MFrequency::Types itsFreqSystem
the conversion machines epoch otherwise
FrequencyAligner(const SpectralCoordinate &specCoord, uInt nPixels, const MEpoch &refEpoch, const MDirection &dir, const MPosition &pos, MFrequency::Types freqSystem)
Constructor specifies a SpectralCoordinate (any extra reference conversion frame set in it will be ig...
Bool align(Vector< T > &yOut, Vector< Bool > &maskOut, const Vector< Double > &xIn, const Vector< T > &yIn, const Vector< Bool > &maskIn, const MEpoch &epoch, Bool useCachedAbcissa, typename InterpolateArray1D< Double, T >::InterpolationMethod method, Bool extrapolate=False)
This function is the same as the previous except that you can specify the input abcissa as well as th...
void makeMachine(const MEpoch &refEpoch, const MDirection &dir, const MPosition &pos, MFrequency::Types freqSystem, const Unit &unit)
Create the Conversion machine.
~FrequencyAligner()
Destructor.
FrequencyAligner(const FrequencyAligner< T > &other)
Copy constructor (copy semantics)
Bool align(Vector< T > &yOut, Vector< Bool > &maskOut, const Vector< T > &yIn, const Vector< Bool > &maskIn, const MEpoch &epoch, Bool useCachedAbcissa, typename InterpolateArray1D< Double, T >::InterpolationMethod method, Bool extrapolate=False)
Align (via regridding) one spectrum taken at the specified epoch to the reference epoch.
void getReferenceAbcissa(Vector< Double > &xOut) const
Get the reference abcissa (as a frequency in the axis units set in the SpectralCoordinate) at the ref...
Double makeAbcissa(Vector< Double > &f, Bool doMaxDiff)
Generate an abcissa with the machine.
InterpolationMethod
Interpolation methods.
Types
Types of known MFrequencies Warning: The order defines the order in the translation matrix FromTo in...
Definition: MFrequency.h:176
this file contains all the compiler specific defines
Definition: mainpage.dox:28
const Bool False
Definition: aipstype.h:44
unsigned int uInt
Definition: aipstype.h:51
LatticeExprNode abs(const LatticeExprNode &expr)
Numerical 1-argument functions which result in a real number regardless of input expression type.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43
double Double
Definition: aipstype.h:55