Phase fitter that can force phase solutions over frequency onto a TEC model.
More...
#include <PhaseFitter.h>
Phase fitter that can force phase solutions over frequency onto a TEC model.
To use:
- Construct and set the frequencies (with FrequencyData() ) and if already possible the weights (WeightData()).
- Perform a calibration iteration.
- Set the phase values (PhaseData()) and, if not yet done, the weights (WeightData()) to the current phase solutions / weights of a single antenna.
- Call FitDataToTEC1Model() or FitDataToTEC2Model().
- Read the new phase values.
- When fitting multiple polarizations, the above steps should be done twice for each diagonal value of the Jones matrix. Also repeat for all antennae.
- Continue the iteration with the new phase values.
Methods with name containing TEC1 refer to a single-parameter TEC model (no delay), while methods with TEC2 refer to dual-parameter TEC model (TEC + delay).
◆ PhaseFitter() [1/2]
| PhaseFitter::PhaseFitter |
( |
| ) |
|
|
inline |
◆ PhaseFitter() [2/2]
| PhaseFitter::PhaseFitter |
( |
size_t |
channelCount | ) |
|
|
inline |
Construct a phase fitter for the given number of channels. Weights are initialized to unity. The fitting accuracy is initialized to 1e-6.
- Parameters
-
| channelCount | number of channels. |
◆ AlphaToTEC()
| static double PhaseFitter::AlphaToTEC |
( |
double |
alpha | ) |
|
|
inlinestatic |
◆ FitDataToTEC1Model() [1/2]
| void PhaseFitter::FitDataToTEC1Model |
( |
| ) |
|
|
inline |
◆ FitDataToTEC1Model() [2/2]
| double PhaseFitter::FitDataToTEC1Model |
( |
double & |
alpha | ) |
|
◆ FitDataToTEC1ModelWithInitialValues()
| double PhaseFitter::FitDataToTEC1ModelWithInitialValues |
( |
double & |
alpha | ) |
|
|
inline |
◆ FitDataToTEC2Model() [1/2]
| void PhaseFitter::FitDataToTEC2Model |
( |
| ) |
|
|
inline |
◆ FitDataToTEC2Model() [2/2]
| double PhaseFitter::FitDataToTEC2Model |
( |
double & |
alpha, |
|
|
double & |
beta |
|
) |
| |
Fits the given phase values to a TEC model and returns the parameters. This function is robust even when phase wrapping occurs. After this call, the PhaseData() satisfy the TEC model. The TEC model has two parameters and are fitted as described in FitTEC2ModelParameters().
- Parameters
-
| alpha | Found value for the alpha parameter. |
| beta | Found value for the beta parameter. |
- Returns
- Cost of the found solution.
◆ FitDataToTEC2ModelWithInitialValues()
| double PhaseFitter::FitDataToTEC2ModelWithInitialValues |
( |
double & |
alpha, |
|
|
double & |
beta |
|
) |
| |
|
inline |
Fits the given phase values to a TEC model using prior estimates of the model parameters. This method is similar to FitDataToTEC2Model(), except that it will use the provided initial values of alpha and beta to speed up the solution. When the provided initial values are not accurate, the fit might not be accurate.
- Todo:
- No fast method has been implemented – instead it will perform a full parameter search.
- Parameters
-
| alpha | Estimate of alpha parameter on input, found value on output. |
| beta | Estimate of beta parameter on input, found value on output. |
◆ FitTEC1ModelParameters()
| void PhaseFitter::FitTEC1ModelParameters |
( |
double & |
alpha | ) |
const |
◆ FitTEC2ModelParameters()
| void PhaseFitter::FitTEC2ModelParameters |
( |
double & |
alpha, |
|
|
double & |
beta |
|
) |
| const |
Fit the data and get the best fitting parameters. The model used is f(nu) = alpha/nu + beta, with possible 2pi wrappings in the data. The phase data is not changed. The alpha parameter is linearly related to the TEC. The beta parameter is a constant phase offset, given in radians. The fitting algorithm uses a combination of brute force searching and binary-like searching (ternary search).
- Parameters
-
| alpha | Will be set to the fitted value for the alpha parameter (value on input is not used). |
| beta | Will be set to the fitted value for the beta parameter (value on input is not used). |
◆ FittingAccuracy()
| double PhaseFitter::FittingAccuracy |
( |
| ) |
const |
|
inline |
Get the fitting accuracy. The fitter will stop once this accuracy is approximately reached. The default value is 1e-6.
- Returns
- Fitting accuracy.
◆ GetFrequencies()
| const std::vector<double>& PhaseFitter::GetFrequencies |
( |
| ) |
const |
|
inline |
Get the frequency values.
- Returns
- Vector of Size() doubles with the frequencies in Hz.
◆ Initialize()
| void PhaseFitter::Initialize |
( |
const std::vector< double > & |
frequencies | ) |
|
|
inline |
- Change the number of channels to be fitted.
- Set the frequency data.
- Discard the phase and weight data.
- Parameters
-
| frequencies | The new frequencies, such that frequencies[ch] is the frequency corresponding to the phase value PhaseData()[ch]. The number of channels becomes the length of this vector. |
◆ PhaseData() [1/2]
| double* PhaseFitter::PhaseData |
( |
| ) |
|
|
inline |
Get a pointer to the array of phase values. This array should be filled with the phases of solutions before calling one of the fit methods. FitDataToTEC1Model() and ~TEC2~ sets this array to the fitted phases. Normally, these values should be set to std::arg(z) or atan2(z.imag(), z.real()), where z is a complex solution for one polarizations. All phases should correspond to the same polarizations, i.e., different polarizations (xx/yy/ll/rr, etc.) should be independently fitted.
- Returns
- Array of Size() doubles with the phases.
◆ PhaseData() [2/2]
| const double* PhaseFitter::PhaseData |
( |
| ) |
const |
|
inline |
Get a constant pointer to the array of values.
- Returns
- Constant array of Size() doubles with the phases.
◆ SetFittingAccuracy()
| void PhaseFitter::SetFittingAccuracy |
( |
double |
newAccuracy | ) |
|
|
inline |
◆ Size()
| size_t PhaseFitter::Size |
( |
| ) |
const |
|
inline |
Number of channels used for the fitter.
- Returns
- Number of channels.
◆ TEC1ModelCost()
| double PhaseFitter::TEC1ModelCost |
( |
double |
alpha | ) |
const |
Evaluate the cost function for given TEC model parameter. The higher the cost, the worser the data fit the given parameters.
- Parameters
-
- Returns
- sum of | alpha / nu_i - theta_i |, and each sum term is phase unwrapped.
◆ TEC1ModelFuncWrapped()
| static double PhaseFitter::TEC1ModelFuncWrapped |
( |
double |
nu, |
|
|
double |
alpha |
|
) |
| |
|
inlinestatic |
- Parameters
-
| nu | Frequency in Hz |
| alpha | TEC parameter (in undefined units) |
- Returns
- | alpha / nu_i + beta | % 2pi
◆ TEC2ModelCost()
| double PhaseFitter::TEC2ModelCost |
( |
double |
alpha, |
|
|
double |
beta |
|
) |
| const |
Evaluate the cost function for given TEC model parameters. The higher the cost, the worser the data fit the given parameters.
- Parameters
-
| alpha | TEC parameter |
| beta | Phase offset parameter |
- Returns
- sum of | nu_i / alpha + beta - theta_i |, and each sum term is phase unwrapped.
◆ TEC2ModelFunc()
| static double PhaseFitter::TEC2ModelFunc |
( |
double |
nu, |
|
|
double |
alpha, |
|
|
double |
beta |
|
) |
| |
|
inlinestatic |
Like TEC2ModelFunc(), but 2-pi wrapped.
- Parameters
-
| nu | Frequency in Hz |
| alpha | TEC parameter (in undefined units) |
| beta | Phase offset parameter (in radians) |
- Returns
- | nu_i / alpha + beta | % 2pi
◆ TEC2ModelFuncWrapped()
| static double PhaseFitter::TEC2ModelFuncWrapped |
( |
double |
nu, |
|
|
double |
alpha, |
|
|
double |
beta |
|
) |
| |
|
inlinestatic |
Like TEC2ModelFunc(), but 2-pi wrapped.
- Parameters
-
| nu | Frequency in Hz |
| alpha | TEC parameter (in undefined units) |
| beta | Phase offset parameter (in radians) |
- Returns
- | nu_i / alpha + beta | % 2pi
◆ WeightData() [1/2]
| double* PhaseFitter::WeightData |
( |
| ) |
|
|
inline |
This array should be filled with the weights of the channel phase solutions. If the solver supports weights during solving, this value should be set to the sum of weights of all visibilities that are used for the solution of this channel. If the solver does not support weights, it should be set to the number of unflagged visibilities used by the solver to generate the corresponding phase. Another way of saying this, is that the weights should be set to the esimated inverse variance of the phase solutions.
The use of weights will make sure that noisy channels do not bias the result. Weighting is for example helpful to avoid that the few remaining samples in a badly RFI contaminated channels cause the fit to be inaccurate.
While the weights could be different for each antenna solution, generally the weight of a channel is constant over the antennas. The latter implies that the weights can be set once before the solution starts, and only the PhaseData() need to be changed within solution iterations.
The weights are initially set to one.
- Returns
- Array of Size() doubles with the weights.
◆ WeightData() [2/2]
| const double* PhaseFitter::WeightData |
( |
| ) |
const |
|
inline |
Constant array of weights, as described above.
- Returns
- Constant array of Size() doubles with weights.
The documentation for this class was generated from the following file: