casacore
Loading...
Searching...
No Matches
VanVleck.h
Go to the documentation of this file.
1// # VanVleck.h: Class of static functions to aid with vanVleck corrections.
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 SCIMATH_VANVLECK_H
27#define SCIMATH_VANVLECK_H
28
29// #! Includes go here
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/Matrix.h>
32#include <casacore/scimath/Functionals/Interpolate1D.h>
33#include <casacore/casa/BasicSL/Constants.h>
34
35#include <mutex>
36
37namespace casacore { // # NAMESPACE CASACORE - BEGIN
38
39// # Forward Declarations
40
41// <summary>
42// A class of static functions to aid with vanVleck corrections of lag data.
43// </summary>
44
45// <use visibility=export>
46
47// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
48// </reviewed>
49
50// <prerequisite>
51// <li> Familiarity with the issues involved in turning digitally
52// sampled lag data from a correlator into spectral data.
53// </prerequisite>
54//
55// <etymology>
56// This provides the functions necessary to determine the van Vleck correction
57// for a general n-level by m-level correlator.
58// </etymology>
59//
60// <synopsis>
61// This provides the functions necessary to determine the van Vleck correction
62// for a general n-level by m-level correlator.
63// </synopsis>
64//
65// <example>
66// </example>
67//
68// <motivation>
69// The GBT spectrometer provides the measured auto-correlation and
70// cross-correlation lags. The gbt MeasurementSet filler (gbtmsfiller)
71// needs to convert those lags to the spectral domain. These functions
72// allow the filler to calculate the van Vleck correction appropriate
73// for each measured set of lags. They are of general and hence are
74// not specific to the GBT spectrometer.
75//
76// The functions here are static because of the nature of the underlying
77// numerical quadrature fortran code used to integrate the
78// drbyrho function.
79// </motivation>
80//
81// <thrown>
82// <li>
83// <li>
84// </thrown>
85//
86// <todo asof="2002/07/19">
87// <li> The inverse error functions may be more generally useful.
88// It exists here only as a private member function to be
89// used internally.
90// </todo>
91
92class VanVleck {
93 public:
94 // Set the interpolation table size.
95 // Should be an odd number. The default size is 65.
96 static void size(uInt npts);
97
98 // get the current size.
99 static uInt getsize();
100
101 // Set the x and y quantization functions.
102 // Each matrix should have dimensions (2,n)
103 // where n is the number of levels. The first
104 // row (0,...) is the (n-1) threshold levels and
105 // the second row is the n quantizations based
106 // on those thresholds. The thresholds may
107 // include a DC offset. The (0,(n-1)) element is
108 // never used and need not be set.
109 static void setQuantization(const Matrix<Double> &qx, const Matrix<Double> &qy);
110
111 // Set the x and y quantization levels for the case
112 // of equi-spaced levels with a possible non-zero
113 // offset. The total number of levels is given by n,
114 // which must be 3 or 9. If n is not 3 or 9, False
115 // will be returned and no quantization will have been
116 // set. For the 3- and 9- level cases a bivarate normal
117 // integral calculation will be used. That is much faster
118 // than the more general numerical integration used
119 // by setQuantization.
120 static Bool setEquiSpaced(Double xlev, Double ylev, Double xmean, Double ymean, Int n);
121
122 // Get the data used in setting up the interpolation
123 static void getTable(Vector<Double> &rs, Vector<Double> &rhos);
124
125 // Given a rho return the corresponding corrected r
126 // Returns 0.0 if no quantization has been set yet.
127 static Double r(const Double rho);
128
129 // Given a measured zero-lag autocorrelation and number of
130 // levels (n>=3) return the first positive quantizer input
131 // threshold level. This can be used to set the up the
132 // matrix arguments used in setQuantization.
133 static Double thresh(Int n, Double zerolag) {
134 return ((n > 3) ? threshNgt3(n, zerolag) : threshN3(zerolag));
135 }
136
137 // Predict a given zero-lag given n and a threshold. This
138 // is included here to be used as a check against the output
139 // of thresh.
140 static Double predict(Int n, Double threshhold) {
141 return ((n > 3) ? predictNgt3(n, threshhold) : predictN3(threshhold));
142 }
143
144 // Compute an approximation to the mean signal level (DC offset)
145 // and quantizer threshold setting (both in terms of the r.m.s.
146 // signal input level) given the observed positive bias (the
147 // asymptotic limit of the measured autocorrelation at large
148 // lags) and the zero-lag autocorrelation.
149 // dcoffset is the mean signal level, threshold is the quantizer
150 // setting, n is the number of levels, zerolag is the zero-lag
151 // value and bias is the asymptotic bias.
152 // Currently, this is only available for the n==3 level case,
153 // all other cases set the returned dcoffset to 0 and use thresh()
154 // to set the returned value of threshold. A return value of F
155 // indicates that the zerolag and bias values are inconsistent
156 // and the dcoffset can not be determined. In that case,
157 // the returned dcoffset is 0 and thresh() is used to set
158 // the threshold level.
159 static Bool dcoff(Double &dcoffset, Double &threshold, Int n, Double zerolag, Double bias);
160
161 private:
162 // the number of points to use in setting up the interpolator
164
166
168
169 // The interpolator
171
172 // the quantization functions
174
175 // Useful combinations of the above - to speed up drbydrho
176 // these are -1/2*(Qx0*Qx0) and -1/2*(Qy0*Qy0)
177 // These are only used for i up to (itsQx0.nelements() and
178 // for j up to (itsQy0.nelements()).
180 // This is Qx0[i]*Qy0[j]
182 // This is (Qx1[i+1]-Qx1[i])*(Qy1[j+1]*Qy1[j])
184 // The mutex to make the functions thread-safe.
185 static std::mutex theirMutex;
186
187 // The fortran numerical integration function will call this.
188 // For a given rho and quantization functions, this computes,
189 // via Price's theorem, the value dr/drho of the derivative,
190 // with respect to rho, of the expected value of the correlator
191 // output.
192 static Double drbydrho(Double *rho);
193
194 // For a given rhoi, rhof, this produces a high-accuracy numerical
195 // approximation to the integral of drbydrho over the range
196 // rhoi to rhof. It calls the standard QUADPACK adaptive Gaussian quadrature
197 // procedure, dqags, to do the numerical integration.
198 static Double rinc(Double &rhoi, Double &rhof);
199
200 // initialize the interpolator
201 static void initInterpolator();
202
203 // compute first threshhold for a given zerolag for n>3
204 static Double threshNgt3(Int n, Double zerolag);
205
206 // compute first threshhold for a given zerolag for n==3
207 static Double threshN3(Double zerolag) { return sqrt(2.0) * invErfc(zerolag); }
208
209 // inverse err fn - used by invErfc
211
212 // inverse complementary err fn - used by threshN3
214
215 // Predict a zero-lag value given the indicated first threshold level
216 // for n>3.
217 static Double predictNgt3(Int n, Double threshhold);
218
219 // Predict a zero-lag value given the indicated first threshold level
220 // for n=3.
221 static Double predictN3(Double threshhold) { return ::erfc(threshhold / sqrt(2.0)); }
222
223 // implementation of dcoff for the 3-level case
224 static Bool dcoff3(Double &dcoffset, Double &threshold, Double zerolag, Double bias);
225};
226
227} // namespace casacore
228
229#endif
static Double predictNgt3(Int n, Double threshhold)
Predict a zero-lag value given the indicated first threshold level for n>3.
static Double threshNgt3(Int n, Double zerolag)
compute first threshhold for a given zerolag for n>3
static Double itsXmean
Definition VanVleck.h:167
static Vector< Double > itsQy1
Definition VanVleck.h:173
static Matrix< Double > itsQx1Qy1diffs
This is (Qx1[i+1]-Qx1[i])*(Qy1[j+1]*Qy1[j]).
Definition VanVleck.h:183
static Vector< Double > itsQx1
Definition VanVleck.h:173
static Bool dcoff3(Double &dcoffset, Double &threshold, Double zerolag, Double bias)
implementation of dcoff for the 3-level case
static Vector< Double > itsQx0Qx0
Useful combinations of the above - to speed up drbydrho these are -1/2*(Qx0*Qx0) and -1/2*(Qy0*Qy0) T...
Definition VanVleck.h:179
static void getTable(Vector< Double > &rs, Vector< Double > &rhos)
Get the data used in setting up the interpolation.
static Double threshN3(Double zerolag)
compute first threshhold for a given zerolag for n==3
Definition VanVleck.h:207
static Double predict(Int n, Double threshhold)
Predict a given zero-lag given n and a threshold.
Definition VanVleck.h:140
static Vector< Double > itsQx0
the quantization functions
Definition VanVleck.h:173
static void size(uInt npts)
Set the interpolation table size.
static Double itsYlev
Definition VanVleck.h:167
static uInt itsNx
Definition VanVleck.h:163
static Interpolate1D< Double, Double > * itsInterp
The interpolator.
Definition VanVleck.h:170
static Matrix< Double > itsQx0Qy0
This is Qx0[i]*Qy0[j].
Definition VanVleck.h:181
static Double itsXlev
Definition VanVleck.h:167
static Double rinc(Double &rhoi, Double &rhof)
For a given rhoi, rhof, this produces a high-accuracy numerical approximation to the integral of drby...
static Bool itsEquiSpaced
Definition VanVleck.h:165
static void setQuantization(const Matrix< Double > &qx, const Matrix< Double > &qy)
Set the x and y quantization functions.
static uInt itsNy
Definition VanVleck.h:163
static uInt getsize()
get the current size.
static uInt itsSize
the number of points to use in setting up the interpolator
Definition VanVleck.h:163
static Double invErf(Double x)
inverse err fn - used by invErfc
static Double invErfc(Double x)
inverse complementary err fn - used by threshN3
static Double thresh(Int n, Double zerolag)
Given a measured zero-lag autocorrelation and number of levels (n>=3) return the first positive quant...
Definition VanVleck.h:133
static Double drbydrho(Double *rho)
The fortran numerical integration function will call this.
static void initInterpolator()
initialize the interpolator
static Double r(const Double rho)
Given a rho return the corresponding corrected r Returns 0.0 if no quantization has been set yet.
static Double predictN3(Double threshhold)
Predict a zero-lag value given the indicated first threshold level for n=3.
Definition VanVleck.h:221
static std::mutex theirMutex
The mutex to make the functions thread-safe.
Definition VanVleck.h:185
static Bool dcoff(Double &dcoffset, Double &threshold, Int n, Double zerolag, Double bias)
Compute an approximation to the mean signal level (DC offset) and quantizer threshold setting (both i...
static Double itsYmean
Definition VanVleck.h:167
static Vector< Double > itsQy0Qy0
Definition VanVleck.h:179
static Vector< Double > itsQy0
Definition VanVleck.h:173
static Bool setEquiSpaced(Double xlev, Double ylev, Double xmean, Double ymean, Int n)
Set the x and y quantization levels for the case of equi-spaced levels with a possible non-zero offse...
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode sqrt(const LatticeExprNode &expr)
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53