Isis 3 Programmer Reference
Isis::ZeroBufferFit Class Reference

Computes non-linear lsq fit of HiRISE Drift (Zd module) More...

#include <ZeroBufferFit.h>

Inheritance diagram for Isis::ZeroBufferFit:
Inheritance graph
Collaboration diagram for Isis::ZeroBufferFit:
Collaboration graph

Public Types

typedef TNT::Array1D< double > NLVector
 
typedef TNT::Array2D< double > NLMatrix
 

Public Member Functions

 ZeroBufferFit (const HiCalConf &conf)
 Compute second level drift correction (Zf module) More...
 
virtual ~ZeroBufferFit ()
 Destructor. More...
 
void setBin (int bin)
 Set binning/summing mode. More...
 
void setLineTime (double ltime)
 Set scan line time. More...
 
int size () const
 Returns the size of the data buffer. More...
 
int nSize () const
 Returns the size of the fitted buffer. More...
 
int nParms () const
 Number of parameter to be fitted. More...
 
void setabsErr (double absError)
 Sets the absolute error parameter. More...
 
void setrelErr (double relError)
 Sets the relative error parameter
More...
 
double absErr () const
 Returns the current value of the absolute error. More...
 
double relErr () const
 Returns the current value of the relative error. More...
 
HiVector Solve (const HiVector &d)
 Compute non-linear fit to (typically) ZeroBufferSmooth module. More...
 
NLVector guess ()
 Compute the initial guess of the fit. More...
 
int checkIteration (const int Iter, const NLVector &fitcoefs, const NLVector &uncerts, double cplxconj, int Istatus)
 Computes the interation check for convergence. More...
 
NLVector f_x (const NLVector &a)
 Computes the function value at the current iteration. More...
 
NLMatrix df_x (const NLVector &a)
 Computes the first derivative of the function at the current iteration. More...
 
double Chisq () const
 Returns the Chi-Square value of the fit solution. More...
 
int DoF () const
 Returns the Degrees of Freedom. More...
 
HiVector Yfit () const
 Computes the solution vector using current coefficents. More...
 
HiVector Normalize (const HiVector &v)
 Compute normalized solution vector from result. More...
 
void setMaxIters (int m)
 Sets the maximum number of iterations. More...
 
int maxIters () const
 Maximum number iterations for valid solution. More...
 
int curvefit ()
 
int status () const
 Return status of last fit processing. More...
 
bool success () const
 Determine success from last fit processing. More...
 
bool success (int status) const
 Check status for success of the given condition
More...
 
std::string statusstr () const
 Return error message pertaining to last fit procesing. More...
 
std::string statusstr (int status) const
 Return error message given status condition. More...
 
NLVector coefs () const
 Return coefficients from last fit processing. More...
 
NLVector uncert () const
 Return uncertainties from last fit processing. More...
 
int nIterations () const
 Return number of iterations from last fit processing. More...
 
QString name () const
 Returns name of component. More...
 
QString getcsvFile () const
 Returns expanded name of last CSV file loaded by loadCsv. More...
 
virtual void Process (const Module &c)
 Invokes the process method on the Module vector. More...
 
virtual void Process (const HiVector &v)
 Default processing behavior makes a reference copy of data array. More...
 
HiVector loadCsv (const QString &csvBase, const HiCalConf &conf, const DbProfile &prof, const int &elements=0)
 Provide generic loading of CSV file for all modules. More...
 
const HiVectorref () const
 Return data via a const reference. More...
 
double operator() (int index) const
 Return individual element of the data vector. More...
 
const HiHistoryHistory () const
 Return recorded history of events. More...
 
virtual void record (PvlGroup &pvl, const QString keyname="ModuleHistory") const
 Record history in Pvl group object. More...
 
void Dump (const QString &fname) const
 Dumps the component to a specified file. More...
 

Protected Types

enum  { DefaultWidth = 10, DefaultPrecision = 6 }
 

Protected Member Functions

void Terminate (const std::string &message="")
 
void Abort (const std::string &reason="")
 
bool doContinue () const
 
QString formatDbl (const double &value) const
 Properly format values that could be special pixels. More...
 

Protected Attributes

QString _name
 Name of component. More...
 
QString _csvFile
 Fully expanded name of CSV file if present. More...
 
HiHistory _history
 Hierarchial component history. More...
 
int _fmtWidth
 Default field with of double. More...
 
int _fmtPrecision
 Default field with of double. More...
 

Private Member Functions

HiVector poly_fit (const HiVector &d, const double line0=0.0) const
 Compute a polyonomial fit using multivariate statistics. More...
 
virtual void printOn (std::ostream &o) const
 Provides virtualized dump of data from this module. More...
 
int goodLines (const HiVector &d) const
 Returns the number of good lines in the image. More...
 
bool gotGoodLines (const HiVector &d) const
 Determines if the vector contains any valid lines. More...
 
NLVector gslToNlsq (const gsl_vector *v) const
 
NLMatrix gslToNlsq (const gsl_matrix *m) const
 
gsl_vector * NlsqTogsl (const NLVector &v, gsl_vector *gv=0) const
 
gsl_matrix * NlsqTogsl (const NLMatrix &m, gsl_matrix *gm=0) const
 
NLVector getUncertainty (const gsl_matrix *m) const
 

Static Private Member Functions

static int f (const gsl_vector *x, void *params, gsl_vector *fx)
 
static int df (const gsl_vector *x, void *params, gsl_matrix *J)
 
static int fdf (const gsl_vector *x, void *params, gsl_vector *fx, gsl_matrix *J)
 

Private Attributes

HiLineTimeEqn _timet
 
HiVector _data
 
HiVector _b2
 
double _absErr
 
double _relErr
 
double _maxLog
 
int _badLines
 
int _sWidth
 
int _sIters
 
bool _skipFit
 
bool _useLinFit
 
int _minLines
 
HiVector _cc
 
HiVector _guess
 
HiVector _coefs
 
HiVector _uncert
 
double _chisq
 
NLVector _fitParms
 
int _nIters
 
int _maxIters
 
int _status
 
bool _userTerminated
 
std::string _userMessage
 

Detailed Description

Computes non-linear lsq fit of HiRISE Drift (Zd module)

This class is best used with individual HiRISE images as the number of lines is critical to proper use. It is best applied by getting the buffer as a reference and applying it during systematic processing.

This class models the drift correction using the Levenberg-Marquardt algorithm.

Author
2007-11-07 Kris Becker
History:
2008-05-23 Kris Becker Added the ZdOnFailUseLinear option.
History:
2010-10-28 Kris Becker Updated parameter names removing "Zd" and replacing with "ZeroBufferFit".

Definition at line 42 of file ZeroBufferFit.h.

Constructor & Destructor Documentation

◆ ZeroBufferFit()

Isis::ZeroBufferFit::ZeroBufferFit ( const HiCalConf &  conf)

Compute second level drift correction (Zf module)

This class provides the second level drift correction that is

Parameters
conf

Definition at line 38 of file ZeroBufferFit.cpp.

References Isis::Module::_history, Isis::ConfKey(), Isis::DbProfile::exists(), Isis::IsEqual(), Isis::IsTrueValue(), Isis::NonLinearLSQ::maxIters(), Isis::DbProfile::Name(), Isis::NonLinearLSQ::setMaxIters(), Isis::toDouble(), Isis::ToDouble(), Isis::toInt(), Isis::ToInteger(), and Isis::ToString().

◆ ~ZeroBufferFit()

virtual Isis::ZeroBufferFit::~ZeroBufferFit ( )
inlinevirtual

Destructor.

Definition at line 47 of file ZeroBufferFit.h.

Member Function Documentation

◆ absErr()

double Isis::ZeroBufferFit::absErr ( ) const
inlinevirtual

Returns the current value of the absolute error.

Reimplemented from Isis::NonLinearLSQ.

Definition at line 101 of file ZeroBufferFit.h.

◆ checkIteration()

int Isis::ZeroBufferFit::checkIteration ( const int  Iter,
const NLVector &  fitcoefs,
const NLVector &  uncerts,
double  cplxconj,
int  Istatus 
)
virtual

Computes the interation check for convergence.

Parameters
IterCurrent iteration
fitcoefsVector of current fit coefficients
uncertsUncertainties
cplxconjComplex conjugate of the current iteration
IstatusState of current iteration
Returns
int Simply passes on the Istatus value

Reimplemented from Isis::NonLinearLSQ.

Definition at line 219 of file ZeroBufferFit.cpp.

◆ Chisq()

double Isis::ZeroBufferFit::Chisq ( ) const
inline

Returns the Chi-Square value of the fit solution.

Definition at line 115 of file ZeroBufferFit.h.

Referenced by Solve().

◆ coefs()

NLVector Isis::NonLinearLSQ::coefs ( ) const
inlineinherited

Return coefficients from last fit processing.

Definition at line 103 of file NonLinearLSQ.h.

Referenced by Solve().

◆ df_x()

NonLinearLSQ::NLMatrix Isis::ZeroBufferFit::df_x ( const NLVector &  a)
virtual

Computes the first derivative of the function at the current iteration.

Implements Isis::NonLinearLSQ.

Definition at line 245 of file ZeroBufferFit.cpp.

References Isis::MIN().

◆ DoF()

int Isis::ZeroBufferFit::DoF ( ) const
inline

Returns the Degrees of Freedom.

Definition at line 117 of file ZeroBufferFit.h.

References nParms(), and nSize().

Referenced by Solve().

◆ Dump()

void Isis::Module::Dump ( const QString &  fname) const
inlineinherited

Dumps the component to a specified file.

Parameters
fnameName of file to dump contents to

Definition at line 131 of file Module.h.

References Isis::FileName::expanded(), and Isis::IException::User.

◆ f_x()

NonLinearLSQ::NLVector Isis::ZeroBufferFit::f_x ( const NLVector &  a)
virtual

Computes the function value at the current iteration.

Implements Isis::NonLinearLSQ.

Definition at line 227 of file ZeroBufferFit.cpp.

References Isis::MIN().

◆ formatDbl()

QString Isis::Module::formatDbl ( const double &  value) const
inlineprotectedinherited

Properly format values that could be special pixels.

This method applies ISIS special pixel value conventions to properly print pixel values.

Parameters
[in](double)value Input value to test for specialness and print as requested by caller
[in](int)width Width of field in which to print the value
[in](int)prec Precision used to format the value
Returns
(string) Formatted double value

Definition at line 169 of file Module.h.

References Isis::Module::_fmtPrecision, Isis::Module::_fmtWidth, Isis::IsSpecial(), and Isis::PixelToString().

Referenced by Isis::Module::printOn(), printOn(), Isis::ZeroBufferSmooth::printOn(), Isis::ZeroDark::printOn(), Isis::ZeroDarkRate::printOn(), and Isis::ZeroReverse::printOn().

◆ getcsvFile()

QString Isis::Module::getcsvFile ( ) const
inlineinherited

Returns expanded name of last CSV file loaded by loadCsv.

Definition at line 71 of file Module.h.

References Isis::Module::_csvFile.

◆ goodLines()

int Isis::ZeroBufferFit::goodLines ( const HiVector d) const
inlineprivate

Returns the number of good lines in the image.

Definition at line 144 of file ZeroBufferFit.h.

Referenced by gotGoodLines(), and Solve().

◆ gotGoodLines()

bool Isis::ZeroBufferFit::gotGoodLines ( const HiVector d) const
inlineprivate

Determines if the vector contains any valid lines.

Definition at line 146 of file ZeroBufferFit.h.

References goodLines().

Referenced by Solve(), and Yfit().

◆ guess()

NonLinearLSQ::NLVector Isis::ZeroBufferFit::guess ( )
virtual

Compute the initial guess of the fit.

This method provides the non-linear fit with an initial guess of the solution. It involves a linear fit to the latter half of the data to provide the first two coefficents, the difference of the averages of the residuals at both ends of the data set and 5 times the last line time as the final (fourth) element...a bit involved really.

Returns
NLVector 4-element vector of the initial guess coefficients

Implements Isis::NonLinearLSQ.

Definition at line 162 of file ZeroBufferFit.cpp.

References Isis::Module::_history, Isis::Statistics::AddData(), Isis::Statistics::Average(), Isis::MIN(), poly_fit(), Isis::Module::ref(), Isis::Statistics::Reset(), and Isis::ToString().

◆ History()

const HiHistory& Isis::Module::History ( ) const
inlineinherited

Return recorded history of events.

Definition at line 116 of file Module.h.

References Isis::Module::_history.

Referenced by Isis::ZeroBufferSmooth::init(), and Isis::ZeroReverse::init().

◆ loadCsv()

HiVector Isis::Module::loadCsv ( const QString &  csvBase,
const HiCalConf &  conf,
const DbProfile prof,
const int &  elements = 0 
)
inlineinherited

Provide generic loading of CSV file for all modules.

This method provides generalized access to CSV files through the standardized format.

Author
Kris Becker - 4/16/2010
Parameters
cvsBaseName of base keyword for CSV file
confConfiguration parameters
profModule profile parameters
samplesNumber of expect elements to be read from CSV file
Returns
HiVector

Definition at line 101 of file Module.h.

References Isis::Module::_csvFile, and Isis::Module::_history.

◆ maxIters()

int Isis::NonLinearLSQ::maxIters ( ) const
inlineinherited

Maximum number iterations for valid solution.

Returns
int Maximum resolutions

Definition at line 70 of file NonLinearLSQ.h.

Referenced by ZeroBufferFit().

◆ name()

QString Isis::Module::name ( ) const
inlineinherited

Returns name of component.

Definition at line 69 of file Module.h.

References Isis::Module::_name.

◆ nIterations()

int Isis::NonLinearLSQ::nIterations ( ) const
inlineinherited

Return number of iterations from last fit processing.

Definition at line 107 of file NonLinearLSQ.h.

Referenced by Solve().

◆ Normalize()

HiVector Isis::ZeroBufferFit::Normalize ( const HiVector v)

Compute normalized solution vector from result.

Definition at line 282 of file ZeroBufferFit.cpp.

References Isis::Module::_history, and Isis::ToString().

◆ nParms()

int Isis::ZeroBufferFit::nParms ( ) const
inlinevirtual

Number of parameter to be fitted.

This is the number of parameters that ZeroBufferFit needs to fit. This method is a requirement of the NonLinearLSQ class.

Returns
int Number of parameter to fit

Implements Isis::NonLinearLSQ.

Definition at line 94 of file ZeroBufferFit.h.

Referenced by DoF().

◆ nSize()

int Isis::ZeroBufferFit::nSize ( ) const
inlinevirtual

Returns the size of the fitted buffer.

Important: This returns the size of the buffer being fitted and not the size of original data buffer. This is a requirement of the NonLinearLSQ class. USE WITH CAUTION!

Returns
int Size of buffer being fitted

Implements Isis::NonLinearLSQ.

Definition at line 84 of file ZeroBufferFit.h.

Referenced by DoF().

◆ operator()()

double Isis::Module::operator() ( int  index) const
inlineinherited

Return individual element of the data vector.

Definition at line 113 of file Module.h.

References Isis::Module::_data.

◆ poly_fit()

HiVector Isis::ZeroBufferFit::poly_fit ( const HiVector d,
const double  line0 = 0.0 
) const
private

Compute a polyonomial fit using multivariate statistics.

Used as a fallback solution, this method computes a linear statistical solution from the linear regression analysis of the multivariate statistics of the data.

Parameters
dData vector to fit
line0Current line number in the image
Returns
HiVector Returns the fitted data

Definition at line 305 of file ZeroBufferFit.cpp.

References Isis::MultivariateStatistics::AddData(), and Isis::MultivariateStatistics::LinearRegression().

Referenced by guess(), and Solve().

◆ printOn()

void Isis::ZeroBufferFit::printOn ( std::ostream &  o) const
privatevirtual

Provides virtualized dump of data from this module.

Reimplemented from Isis::Module.

Definition at line 319 of file ZeroBufferFit.cpp.

References Isis::Module::_fmtWidth, Isis::Module::_history, Isis::Module::formatDbl(), and Yfit().

◆ Process() [1/2]

virtual void Isis::Module::Process ( const HiVector v)
inlinevirtualinherited

Default processing behavior makes a reference copy of data array.

Reimplemented in Isis::SplineFill, and Isis::LowPassFilter.

Definition at line 81 of file Module.h.

References Isis::Module::_data.

◆ Process() [2/2]

virtual void Isis::Module::Process ( const Module c)
inlinevirtualinherited

Invokes the process method on the Module vector.

Definition at line 76 of file Module.h.

References Isis::Module::ref().

◆ record()

virtual void Isis::Module::record ( PvlGroup pvl,
const QString  keyname = "ModuleHistory" 
) const
inlinevirtualinherited

Record history in Pvl group object.

Definition at line 119 of file Module.h.

References Isis::Module::_history.

◆ ref()

const HiVector& Isis::Module::ref ( ) const
inlineinherited

Return data via a const reference.

Definition at line 111 of file Module.h.

References Isis::Module::_data.

Referenced by guess(), Isis::ZeroBufferSmooth::init(), Isis::ZeroReverse::init(), and Isis::Module::Process().

◆ relErr()

double Isis::ZeroBufferFit::relErr ( ) const
inlinevirtual

Returns the current value of the relative error.

Reimplemented from Isis::NonLinearLSQ.

Definition at line 103 of file ZeroBufferFit.h.

◆ setabsErr()

void Isis::ZeroBufferFit::setabsErr ( double  absError)
inline

Sets the absolute error parameter.

Definition at line 97 of file ZeroBufferFit.h.

◆ setBin()

void Isis::ZeroBufferFit::setBin ( int  bin)
inline

Set binning/summing mode.

Parameters
binSumming mode of observatio

Definition at line 54 of file ZeroBufferFit.h.

◆ setLineTime()

void Isis::ZeroBufferFit::setLineTime ( double  ltime)
inline

Set scan line time.

Parameters
ltimeScan line time

Definition at line 61 of file ZeroBufferFit.h.

◆ setMaxIters()

void Isis::NonLinearLSQ::setMaxIters ( int  m)
inlineinherited

Sets the maximum number of iterations.

Parameters
mUser provides the maximum number iterations

Definition at line 62 of file NonLinearLSQ.h.

Referenced by ZeroBufferFit().

◆ setrelErr()

void Isis::ZeroBufferFit::setrelErr ( double  relError)
inline

Sets the relative error parameter

Definition at line 99 of file ZeroBufferFit.h.

◆ size()

int Isis::ZeroBufferFit::size ( ) const
inline

Returns the size of the data buffer.

This is the size of the original data buffer.

See also
nSize()
Returns
int Size of the input buffer

Definition at line 71 of file ZeroBufferFit.h.

◆ Solve()

HiVector Isis::ZeroBufferFit::Solve ( const HiVector d)

Compute non-linear fit to (typically) ZeroBufferSmooth module.

This method computes a non-linear fit to the result of the ZeroBufferSmooth module. There are several things that can go wrong and some config conditions that dictate behavior of this process.

Should the image be a short exposure (i.e., not many lines) the fit will not succeed so it simply skips this entire module providing the input result (d) as the solution. This wil also occur when the user has selected the skip option for the module.

A fit is attempted on the ZeroBufferSmooth data. The non-linear solution must converge within the specifed number of iterations (MaximumIterations) or a polynomial fit will be used in leui of a valid solution.

Parameters
dZeroBufferSmooth data solution as input to this method
Returns
HiVector Returns result of the processing

Definition at line 91 of file ZeroBufferFit.cpp.

References Isis::Module::_history, Chisq(), Isis::NonLinearLSQ::coefs(), DoF(), goodLines(), gotGoodLines(), Isis::NonLinearLSQ::nIterations(), poly_fit(), Isis::NonLinearLSQ::statusstr(), Isis::NonLinearLSQ::success(), Isis::ToString(), Isis::NonLinearLSQ::uncert(), and Yfit().

◆ status()

int Isis::NonLinearLSQ::status ( ) const
inlineinherited

Return status of last fit processing.

Definition at line 81 of file NonLinearLSQ.h.

Referenced by Isis::NonLinearLSQ::statusstr(), and Isis::NonLinearLSQ::success().

◆ statusstr() [1/2]

std::string Isis::NonLinearLSQ::statusstr ( ) const
inlineinherited

Return error message pertaining to last fit procesing.

Definition at line 87 of file NonLinearLSQ.h.

Referenced by Solve().

◆ statusstr() [2/2]

std::string Isis::NonLinearLSQ::statusstr ( int  status) const
inlineinherited

Return error message given status condition.

Definition at line 91 of file NonLinearLSQ.h.

References Isis::NonLinearLSQ::status().

◆ success() [1/2]

bool Isis::NonLinearLSQ::success ( ) const
inlineinherited

Determine success from last fit processing.

Definition at line 83 of file NonLinearLSQ.h.

Referenced by Solve().

◆ success() [2/2]

bool Isis::NonLinearLSQ::success ( int  status) const
inlineinherited

Check status for success of the given condition

Definition at line 85 of file NonLinearLSQ.h.

References Isis::NonLinearLSQ::status().

◆ uncert()

NLVector Isis::NonLinearLSQ::uncert ( ) const
inlineinherited

Return uncertainties from last fit processing.

Definition at line 105 of file NonLinearLSQ.h.

Referenced by Solve().

◆ Yfit()

HiVector Isis::ZeroBufferFit::Yfit ( ) const

Computes the solution vector using current coefficents.

Definition at line 266 of file ZeroBufferFit.cpp.

References gotGoodLines().

Referenced by printOn(), and Solve().

Member Data Documentation

◆ _csvFile

QString Isis::Module::_csvFile
protectedinherited

Fully expanded name of CSV file if present.

Definition at line 150 of file Module.h.

Referenced by Isis::Module::getcsvFile(), and Isis::Module::loadCsv().

◆ _fmtPrecision

int Isis::Module::_fmtPrecision
protectedinherited

Default field with of double.

Definition at line 154 of file Module.h.

Referenced by Isis::Module::formatDbl().

◆ _fmtWidth

int Isis::Module::_fmtWidth
protectedinherited

◆ _history

◆ _name

QString Isis::Module::_name
protectedinherited

Name of component.

Definition at line 149 of file Module.h.

Referenced by Isis::Module::name().


The documentation for this class was generated from the following files: