DP3
Public Member Functions | Static Public Member Functions | List of all members
PhaseFitter Class Reference

Phase fitter that can force phase solutions over frequency onto a TEC model. More...

#include <PhaseFitter.h>

Public Member Functions

 PhaseFitter ()
 
 PhaseFitter (size_t channelCount)
 
void FitDataToTEC1Model ()
 
double FitDataToTEC1Model (double &alpha)
 
double FitDataToTEC1ModelWithInitialValues (double &alpha)
 
void FitDataToTEC2Model ()
 
double FitDataToTEC2Model (double &alpha, double &beta)
 
double FitDataToTEC2ModelWithInitialValues (double &alpha, double &beta)
 
void FitTEC1ModelParameters (double &alpha) const
 
void FitTEC2ModelParameters (double &alpha, double &beta) const
 
double FittingAccuracy () const
 
const std::vector< double > & GetFrequencies () const
 
void Initialize (const std::vector< double > &frequencies)
 
double * PhaseData ()
 
const double * PhaseData () const
 
void SetFittingAccuracy (double newAccuracy)
 
size_t Size () const
 
double TEC1ModelCost (double alpha) const
 
double TEC2ModelCost (double alpha, double beta) const
 
double * WeightData ()
 
const double * WeightData () const
 

Static Public Member Functions

static double AlphaToTEC (double alpha)
 
static double TEC1ModelFuncWrapped (double nu, double alpha)
 
static double TEC2ModelFunc (double nu, double alpha, double beta)
 
static double TEC2ModelFuncWrapped (double nu, double alpha, double beta)
 

Detailed Description

Phase fitter that can force phase solutions over frequency onto a TEC model.

To use:

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).

Constructor & Destructor Documentation

◆ 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
channelCountnumber of channels.

Member Function Documentation

◆ AlphaToTEC()

static double PhaseFitter::AlphaToTEC ( double  alpha)
inlinestatic

◆ FitDataToTEC1Model() [1/2]

void PhaseFitter::FitDataToTEC1Model ( )
inline

Like FitDataToTEC1Model(double&), but without returning the parameters.

◆ FitDataToTEC1Model() [2/2]

double PhaseFitter::FitDataToTEC1Model ( double &  alpha)

Dummy comment for making the reference near FitDataToTEC1Model() work.

◆ FitDataToTEC1ModelWithInitialValues()

double PhaseFitter::FitDataToTEC1ModelWithInitialValues ( double &  alpha)
inline

◆ FitDataToTEC2Model() [1/2]

void PhaseFitter::FitDataToTEC2Model ( )
inline

Like FitDataToTEC2Model(double&,double&), but without returning the parameters.

◆ 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
alphaFound value for the alpha parameter.
betaFound 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
alphaEstimate of alpha parameter on input, found value on output.
betaEstimate 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
alphaWill be set to the fitted value for the alpha parameter (value on input is not used).
betaWill 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
    frequenciesThe 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

Change the fitting accuracy. See FittingAccuracy().

Parameters
newAccuracyNew accuracy.

◆ 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
alphaTEC parameter
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
nuFrequency in Hz
alphaTEC 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
alphaTEC parameter
betaPhase 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
nuFrequency in Hz
alphaTEC parameter (in undefined units)
betaPhase 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
nuFrequency in Hz
alphaTEC parameter (in undefined units)
betaPhase 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: