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