LatticeFit.h

Classes

LatticeFit -- Fit every line of pixels parallel to any axis in a Lattice. (full description)

class LatticeFit

Interface

Public Members
static uInt fitProfiles (Lattice<Float>& outImage, Vector<Float>& fittedParameters, LinearFit<Float>& fitter, const Lattice<Float>& inImage, uInt whichAxis, const Vector<Bool>& fitMask, Bool returnResiduals)
static uInt fitProfiles (MaskedLattice<Float>* pOutFit, MaskedLattice<Float>* pOutResid, MaskedLattice<Float>& in, Lattice<Float>* pSigma, LinearFit<Float>& fitter, uInt axis, Bool showProgress=False)

Description

Prerequisite

Synopsis

For every line in the lattice parallel to axis number whichAxis (often axis number 2, typically the frequency axis in a spectral line cube) independently fit the functions in fitter at the positions where fitMask is true.

Example

Suppose one wanted to subtract a linear polynomial from every spectrum (3d axis) in an image. One could do this as follows:
    Image<Float> myImage("myimage"); // Get the image
    uInt nchan = myImage.shape()(2); // 0 relative axis number
    // Set up the fitter
    Polynomial<AutoDiff<Float> > linear(1);    
    LinearFitSVD<Float> fitter;
    fitter.setFunction(linear);
    Vector<Float> fittedParameters,

    // Set up a mask indicating what channels we want to fit over. We want
    // to fit over all channels.
    Vector<Bool> fitMask(nchan); fitMask = True;

    // Do the fit. True means subtract the fit from the model. In this case,
    // We overwrite the input with the output.
    fitProfiles (myImage, fittedParameters,fitter, myImage, 2, fitMask, True);

Motivation

Baseline fitting/continuum subtraction are important functions. This function essentially implements the IMLIN algorithm.

To Do

fitting functions

Member Description

static uInt fitProfiles (Lattice<Float>& outImage, Vector<Float>& fittedParameters, LinearFit<Float>& fitter, const Lattice<Float>& inImage, uInt whichAxis, const Vector<Bool>& fitMask, Bool returnResiduals)

Fit baseline to lattice. Presently the fit parameters, other than the last one(s) in fitter, are lost. If returnResiduals is True, return data-fit, otherwise return the fit. For baseline and continuum subtraction, returnResiduals would normally be True.

static uInt fitProfiles (MaskedLattice<Float>* pOutFit, MaskedLattice<Float>* pOutResid, MaskedLattice<Float>& in, Lattice<Float>* pSigma, LinearFit<Float>& fitter, uInt axis, Bool showProgress=False)

Fit baseline to MaskedLattice. Fit and residuals can be optionally written (leave pointers at zero to not write out these lattices) You can optionally specify a weights lattice (1.0 if not given).