16#include "ZeroBufferFit.h" 
   18#include "HiCalTypes.h" 
   21#include "LeastSquares.h" 
   22#include "LowPassFilter.h" 
   23#include "MultivariateStatistics.h" 
   24#include "IException.h" 
   41    _history.add(
"Profile["+ prof.Name()+
"]");
 
   42    _timet.setBin(
ToInteger(prof(
"Summing")));
 
   43    _timet.setLineTime(
ToDouble(prof(
"ScanExposureDuration")));
 
   45    _skipFit = 
IsEqual(
ConfKey(prof, 
"ZeroBufferFitSkipFit", QString(
"TRUE")), 
"TRUE");
 
   46    _useLinFit = 
IsTrueValue(prof, 
"ZeroBufferFitOnFailUseLinear");
 
   52    _sWidth = 
toInt(
ConfKey(prof, 
"GuessFilterWidth", QString(
"17")));
 
   53    _sIters = 
toInt(
ConfKey(prof, 
"GuessFilterIterations", QString(
"1")));
 
   55    if ( prof.exists(
"MaximumIterations") ) {
 
   61    _minLines = 
toInt(
ConfKey(prof,
"ZeroBufferFitMinimumLines", QString(
"100")));
 
   64    QString histstr = 
"ZeroBufferFit(AbsErr[" + 
ToString(_absErr) +
 
 
  101        hist << 
"NotEnoughLines(GoodLines[" << 
goodLines(d)
 
  102             << 
"],MinimumLines[" << _minLines << 
"]);";
 
  105      hist << 
"SkipFit(TRUE: Not using LMFit)";
 
  115             << 
"],DoF[" << 
DoF() << 
"])";
 
  132        hist << 
"Failed::Reason("<< 
statusstr() << 
"),#Iters[" 
  140          _history.add(
"OnFailureUse(LinearFit(Zf))");
 
  144          _history.add(
"OnFailureUse(ZfBuffer)");
 
 
  164    int nb = n - _badLines;
 
  166    HiVector b1 = _data.subarray(0, nb-1);
 
  178    int n0 = MIN(nb, 20);
 
  179    for ( 
int k = 0 ; k < n0 ; k++ ) {
 
  180      double d = _b2[k] - (cc[0] + cc[1] * _timet(k));
 
  183    double head = s.Average();
 
  187    n0 = (int) (0.9 * nb);
 
  188    for ( 
int l = n0 ; l < nb ; l++ ) {
 
  189      double d = _b2[l] - (cc[0] + cc[1] * _timet(l));
 
  192    double tail = s.Average();
 
  199    g[3] = -5.0/_timet(nb-1);
 
 
  220                     const NLVector &uncerts, 
double cplxconj,
 
  222      _chisq = pow(cplxconj, 2.0);
 
 
  235    for (
int i = 0 ; i < n ; i++) {
 
  236        double lt = _timet(i);
 
  238        double Yi = a0 + (a1 * lt) + a2 * exp(MIN(et,_maxLog));
 
  239        f[i] = (Yi - _b2[i]);
 
 
  253    for (
int i = 0; i < n; i++) {
 
  254      double lt = _timet(i);
 
  256      double p0 = exp (MIN(et,_maxLog));
 
  260      J[i][3] = a2 * lt * p0;
 
 
  268      return (_data.copy());
 
  273      for ( 
int i = 0 ; i < dcorr.dim() ; i++ ) {
 
  274        double lt = _timet(i);
 
  275        dcorr[i] = a[0] + (a[1] * lt) + a[2] * exp(a[3] * lt);
 
 
  286    for ( 
int i = 0 ; i < v.dim() ; i++ ) {
 
  287      vNorm[i] = v[i] - v0;
 
 
  309    for ( 
int i = 0 ; i < n ; i++ ) {
 
  310      double t = _timet(line0+i);
 
  311      fit.AddData(&t, &d[i], 1);
 
  314    fit.LinearRegression(cc[0], cc[1]);
 
 
  320    o << 
"#  History = " << 
_history << endl;
 
  328    for (
int i = 0 ; i < _data.dim() ; i++) {
 
 
A DbProfile is a container for access parameters to a database.
 
Compute a low pass filter from a Module class content.
 
Module manages HiRISE calibration vectors from various sources.
 
HiHistory _history
Hierarchial component history.
 
int _fmtWidth
Default field with of double.
 
QString formatDbl(const double &value) const
Properly format values that could be special pixels.
 
Container of multivariate statistics.
 
NonLinearLSQ Computes a fit using a Levenberg-Marquardt algorithm.
 
NLVector uncert() const
Return uncertainties from last fit processing.
 
void setMaxIters(int m)
Sets the maximum number of iterations.
 
int nIterations() const
Return number of iterations from last fit processing.
 
bool success() const
Determine success from last fit processing.
 
int maxIters() const
Maximum number iterations for valid solution.
 
std::string statusstr() const
Return error message pertaining to last fit procesing.
 
NLVector coefs() const
Return coefficients from last fit processing.
 
This class is used to accumulate statistics on double arrays.
 
virtual void printOn(std::ostream &o) const
Provides virtualized dump of data from this module.
 
bool gotGoodLines(const HiVector &d) const
Determines if the vector contains any valid lines.
 
HiVector Yfit() const
Computes the solution vector using current coefficents.
 
HiVector Normalize(const HiVector &v)
Compute normalized solution vector from result.
 
int DoF() const
Returns the Degrees of Freedom.
 
NLMatrix df_x(const NLVector &a)
Computes the first derivative of the function at the current iteration.
 
int checkIteration(const int Iter, const NLVector &fitcoefs, const NLVector &uncerts, double cplxconj, int Istatus)
Computes the interation check for convergence.
 
NLVector guess()
Compute the initial guess of the fit.
 
HiVector Solve(const HiVector &d)
Compute non-linear fit to (typically) ZeroBufferSmooth module.
 
double Chisq() const
Returns the Chi-Square value of the fit solution.
 
HiVector poly_fit(const HiVector &d, const double line0=0.0) const
Compute a polyonomial fit using multivariate statistics.
 
NLVector f_x(const NLVector &a)
Computes the function value at the current iteration.
 
int goodLines(const HiVector &d) const
Returns the number of good lines in the image.
 
ZeroBufferFit(const HiCalConf &conf)
Compute second level drift correction (Zf module)
 
This is free and unencumbered software released into the public domain.
 
int toInt(const QString &string)
Global function to convert from a string to an integer.
 
T ConfKey(const DbProfile &conf, const QString &keyname, const T &defval, int index=0)
Find a keyword in a profile using default for non-existant keywords.
 
bool IsTrueValue(const DbProfile &prof, const QString &key, const QString &value="TRUE")
Determines if the keyword value is the expected value.
 
TNT::Array1D< double > HiVector
1-D Buffer
 
QString ToString(const T &value)
Helper function to convert values to strings.
 
double ToDouble(const T &value)
Helper function to convert values to doubles.
 
double toDouble(const QString &string)
Global function to convert from a string to a double.
 
int ToInteger(const T &value)
Helper function to convert values to Integers.
 
bool IsEqual(const QString &v1, const QString &v2="TRUE")
Shortened string equality test.
 
Namespace for the standard library.