casacore
Loading...
Searching...
No Matches
LatticeFit.h
Go to the documentation of this file.
1// # LatticeFit.h: Fit every line of pixels parallel to any axis in a Lattice.
2// # Copyright (C) 1994,1995,1999,2000,2002
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef LATTICES_LATTICEFIT_H
27#define LATTICES_LATTICEFIT_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/lattices/Lattices/Lattice.h>
31#include <casacore/lattices/Lattices/MaskedLattice.h>
32#include <casacore/scimath/Fitting/LinearFit.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Fit every line of pixels parallel to any axis in a Lattice.
38// </summary>
39
40// <reviewed reviewer="" date="" tests="" demos="">
41
42// <prerequisite>
43// <li> <linkto class=LinearFit>LinearFit</linkto>
44// <li> <linkto class=Lattice>Lattice</linkto>
45// </prerequisite>
46//
47// <synopsis>
48
49// For every line in the lattice parallel to axis number <src>whichAxis</src>
50// (often axis number 2, typically the frequency axis in a spectral line cube)
51// independently fit the functions in fitter at the positions where
52// <src>fitMask</src> is true.
53// </synopsis>
54//
55// <example>
56// Suppose one wanted to subtract a linear polynomial from every spectrum (3d
57// axis) in an image. One could do this as follows:
58// <srcBlock>
59// Image<Float> myImage("myimage"); // Get the image
60// uInt nchan = myImage.shape()(2); // 0 relative axis number
61// // Set up the fitter
62// Polynomial<AutoDiff<Float> > linear(1);
63// LinearFitSVD<Float> fitter;
64// fitter.setFunction(linear);
65// Vector<Float> fittedParameters,
66//
67// // Set up a mask indicating what channels we want to fit over. We want
68// // to fit over all channels.
69// Vector<Bool> fitMask(nchan); fitMask = True;
70//
71// // Do the fit. True means subtract the fit from the model. In this case,
72// // We overwrite the input with the output.
73// fitProfiles (myImage, fittedParameters,fitter, myImage, 2, fitMask, True);
74// </srcBlock>
75// </example>
76//
77// <motivation>
78// Baseline fitting/continuum subtraction are important functions. This
79// function essentially implements the IMLIN algorithm.
80// </motivation>
81//
82// <todo asof="1995/09/01">
83// <li> Save the model parameters in an (optional) other lattice.
84// <li> Use logging classes, rather than the raw GlishSysEventSource.
85// <li> Allow per-pixel weights.
86// <li> Allow non-linear as well as linear LSQ fits.
87// </todo>
88
89// <linkfrom anchor="Baseline fitting" modules="Fitting"
90// Related <here>fitting functions</here.
91// </linkfrom>
92
94 public:
95 // Fit baseline to lattice. Presently the fit parameters, other than the last
96 // one(s) in fitter, are lost. If <src>returnResiduals</src> is True,
97 // return data-fit, otherwise return the fit. For baseline and continuum
98 // subtraction, returnResiduals would normally be True.
99 static uInt fitProfiles(Lattice<Float>& outImage, Vector<Float>& fittedParameters,
100 LinearFit<Float>& fitter, const Lattice<Float>& inImage, uInt whichAxis,
101 const Vector<Bool>& fitMask, Bool returnResiduals);
102
103 // Fit baseline to MaskedLattice. Fit and residuals can be optionally
104 // written (leave pointers at zero to not write out these lattices)
105 // You can optionally specify a weights lattice (1.0 if not given).
108 LinearFit<Float>& fitter, uInt axis, Bool showProgress = False);
109};
110
111} // namespace casacore
112
113#endif
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.
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.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40