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