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
93{
94public:
95 // Set the interpolation table size.
96 // Should be an odd number. The default size is 65.
97 static void size(uInt npts);
98
99 // get the current size.
100 static uInt getsize();
101
102 // Set the x and y quantization functions.
103 // Each matrix should have dimensions (2,n)
104 // where n is the number of levels. The first
105 // row (0,...) is the (n-1) threshold levels and
106 // the second row is the n quantizations based
107 // on those thresholds. The thresholds may
108 // include a DC offset. The (0,(n-1)) element is
109 // never used and need not be set.
110 static void setQuantization(const Matrix<Double> &qx,
111 const Matrix<Double> &qy);
112
113 // Set the x and y quantization levels for the case
114 // of equi-spaced levels with a possible non-zero
115 // offset. The total number of levels is given by n,
116 // which must be 3 or 9. If n is not 3 or 9, False
117 // will be returned and no quantization will have been
118 // set. For the 3- and 9- level cases a bivarate normal
119 // integral calculation will be used. That is much faster
120 // than the more general numerical integration used
121 // by setQuantization.
122 static Bool setEquiSpaced(Double xlev, Double ylev,
123 Double xmean, Double ymean,
124 Int n);
125
126 // Get the data used in setting up the interpolation
127 static void getTable(Vector<Double> &rs, Vector<Double> &rhos);
128
129 // Given a rho return the corresponding corrected r
130 // Returns 0.0 if no quantization has been set yet.
131 static Double r(const Double rho);
132
133 // Given a measured zero-lag autocorrelation and number of
134 // levels (n>=3) return the first positive quantizer input
135 // threshold level. This can be used to set the up the
136 // matrix arguments used in setQuantization.
137 static Double thresh(Int n, Double zerolag)
138 { return ( (n>3) ? threshNgt3(n,zerolag) : threshN3(zerolag) ); }
139
140 // Predict a given zero-lag given n and a threshold. This
141 // is included here to be used as a check against the output
142 // of thresh.
143 static Double predict(Int n, Double threshhold)
144 { return ( (n>3) ? predictNgt3(n,threshhold) : predictN3(threshhold));}
145
146 // Compute an approximation to the mean signal level (DC offset)
147 // and quantizer threshold setting (both in terms of the r.m.s.
148 // signal input level) given the observed positive bias (the
149 // asymptotic limit of the measured autocorrelation at large
150 // lags) and the zero-lag autocorrelation.
151 // dcoffset is the mean signal level, threshold is the quantizer
152 // setting, n is the number of levels, zerolag is the zero-lag
153 // value and bias is the asymptotic bias.
154 // Currently, this is only available for the n==3 level case,
155 // all other cases set the returned dcoffset to 0 and use thresh()
156 // to set the returned value of threshold. A return value of F
157 // indicates that the zerolag and bias values are inconsistent
158 // and the dcoffset can not be determined. In that case,
159 // the returned dcoffset is 0 and thresh() is used to set
160 // the threshold level.
161 static Bool dcoff(Double &dcoffset, Double &threshold,
162 Int n, Double zerolag, Double bias);
163
164
165private:
166 // the number of points to use in setting up the interpolator
168
170
172
173 // The interpolator
175
176 // the quantization functions
178
179 // Useful combinations of the above - to speed up drbydrho
180 // these are -1/2*(Qx0*Qx0) and -1/2*(Qy0*Qy0)
181 // These are only used for i up to (itsQx0.nelements() and
182 // for j up to (itsQy0.nelements()).
184 // This is Qx0[i]*Qy0[j]
186 // This is (Qx1[i+1]-Qx1[i])*(Qy1[j+1]*Qy1[j])
188 // The mutex to make the functions thread-safe.
189 static std::mutex theirMutex;
190
191
192 // The fortran numerical integration function will call this.
193 // For a given rho and quantization functions, this computes,
194 // via Price's theorem, the value dr/drho of the derivative,
195 // with respect to rho, of the expected value of the correlator
196 // output.
197 static Double drbydrho(Double *rho);
198
199 // For a given rhoi, rhof, this produces a high-accuracy numerical
200 // approximation to the integral of drbydrho over the range
201 // rhoi to rhof. It calls the standard QUADPACK adaptive Gaussian quadrature
202 // procedure, dqags, to do the numerical integration.
203 static Double rinc(Double &rhoi, Double &rhof);
204
205 // initialize the interpolator
206 static void initInterpolator();
207
208 // compute first threshhold for a given zerolag for n>3
209 static Double threshNgt3(Int n, Double zerolag);
210
211 // compute first threshhold for a given zerolag for n==3
212 static Double threshN3(Double zerolag)
213 { return sqrt(2.0)*invErfc(zerolag);}
214
215 // inverse err fn - used by invErfc
217
218 // inverse complementary err fn - used by threshN3
220
221 // Predict a zero-lag value given the indicated first threshold level
222 // for n>3.
223 static Double predictNgt3(Int n, Double threshhold);
224
225 // Predict a zero-lag value given the indicated first threshold level
226 // for n=3.
227 static Double predictN3(Double threshhold)
228 { return ::erfc(threshhold/sqrt(2.0));}
229
230 // implementation of dcoff for the 3-level case
231 static Bool dcoff3(Double &dcoffset, Double &threshold,
232 Double zerolag, Double bias);
233};
234
235
236} //# NAMESPACE CASACORE - END
237
238#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:171
static Vector< Double > itsQy1
Definition VanVleck.h:177
static Matrix< Double > itsQx1Qy1diffs
This is (Qx1[i+1]-Qx1[i])*(Qy1[j+1]*Qy1[j])
Definition VanVleck.h:187
static Vector< Double > itsQx1
Definition VanVleck.h:177
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:183
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:212
static Double predict(Int n, Double threshhold)
Predict a given zero-lag given n and a threshold.
Definition VanVleck.h:143
static Vector< Double > itsQx0
the quantization functions
Definition VanVleck.h:177
static void size(uInt npts)
Set the interpolation table size.
static Double itsYlev
Definition VanVleck.h:171
static uInt itsNx
Definition VanVleck.h:167
static Interpolate1D< Double, Double > * itsInterp
The interpolator.
Definition VanVleck.h:174
static Matrix< Double > itsQx0Qy0
This is Qx0[i]*Qy0[j].
Definition VanVleck.h:185
static Double itsXlev
Definition VanVleck.h:171
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:169
static void setQuantization(const Matrix< Double > &qx, const Matrix< Double > &qy)
Set the x and y quantization functions.
static uInt itsNy
Definition VanVleck.h:167
static uInt getsize()
get the current size.
static uInt itsSize
the number of points to use in setting up the interpolator
Definition VanVleck.h:167
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:137
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:227
static std::mutex theirMutex
The mutex to make the functions thread-safe.
Definition VanVleck.h:189
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:171
static Vector< Double > itsQy0Qy0
Definition VanVleck.h:183
static Vector< Double > itsQy0
Definition VanVleck.h:177
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...
this file contains all the compiler specific defines
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