casa
$Rev:20696$
|
00001 //# LatticeFit.h: Fit every line of pixels parallel to any axis in a Lattice. 00002 //# Copyright (C) 1994,1995,1999,2000,2002 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: LatticeFit.h 18093 2004-11-30 17:51:10Z ddebonis $ 00027 00028 #ifndef LATTICES_LATTICEFIT_H 00029 #define LATTICES_LATTICEFIT_H 00030 00031 #include <casa/aips.h> 00032 #include <lattices/Lattices/Lattice.h> 00033 #include <lattices/Lattices/MaskedLattice.h> 00034 #include <scimath/Fitting/LinearFit.h> 00035 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 00039 // <summary> 00040 // Fit every line of pixels parallel to any axis in a Lattice. 00041 // </summary> 00042 00043 // <reviewed reviewer="" date="" tests="" demos=""> 00044 00045 // <prerequisite> 00046 // <li> <linkto class=LinearFit>LinearFit</linkto> 00047 // <li> <linkto class=Lattice>Lattice</linkto> 00048 // </prerequisite> 00049 // 00050 // <synopsis> 00051 00052 // For every line in the lattice parallel to axis number <src>whichAxis</src> 00053 // (often axis number 2, typically the frequency axis in a spectral line cube) 00054 // independently fit the functions in fitter at the positions where 00055 // <src>fitMask</src> is true. 00056 // </synopsis> 00057 // 00058 // <example> 00059 // Suppose one wanted to subtract a linear polynomial from every spectrum (3d 00060 // axis) in an image. One could do this as follows: 00061 // <srcBlock> 00062 // Image<Float> myImage("myimage"); // Get the image 00063 // uInt nchan = myImage.shape()(2); // 0 relative axis number 00064 // // Set up the fitter 00065 // Polynomial<AutoDiff<Float> > linear(1); 00066 // LinearFitSVD<Float> fitter; 00067 // fitter.setFunction(linear); 00068 // Vector<Float> fittedParameters, 00069 // 00070 // // Set up a mask indicating what channels we want to fit over. We want 00071 // // to fit over all channels. 00072 // Vector<Bool> fitMask(nchan); fitMask = True; 00073 // 00074 // // Do the fit. True means subtract the fit from the model. In this case, 00075 // // We overwrite the input with the output. 00076 // fitProfiles (myImage, fittedParameters,fitter, myImage, 2, fitMask, True); 00077 // </srcBlock> 00078 // </example> 00079 // 00080 // <motivation> 00081 // Baseline fitting/continuum subtraction are important functions. This 00082 // function essentially implements the IMLIN algorithm. 00083 // </motivation> 00084 // 00085 // <todo asof="1995/09/01"> 00086 // <li> Save the model parameters in an (optional) other lattice. 00087 // <li> Use logging classes, rather than the raw GlishSysEventSource. 00088 // <li> Allow per-pixel weights. 00089 // <li> Allow non-linear as well as linear LSQ fits. 00090 // </todo> 00091 00092 // <linkfrom anchor="Baseline fitting" modules="Fitting" 00093 // Related <here>fitting functions</here. 00094 // </linkfrom> 00095 00096 class LatticeFit { 00097 00098 public: 00099 00100 // Fit baseline to lattice. Presently the fit parameters, other than the last 00101 // one(s) in fitter, are lost. If <src>returnResiduals</src> is True, 00102 // return data-fit, otherwise return the fit. For baseline and continuum 00103 // subtraction, returnResiduals would normally be True. 00104 static uInt fitProfiles (Lattice<Float>& outImage, 00105 Vector<Float>& fittedParameters, 00106 LinearFit<Float>& fitter, 00107 const Lattice<Float>& inImage, 00108 uInt whichAxis, 00109 const Vector<Bool>& fitMask, 00110 Bool returnResiduals); 00111 00112 // Fit baseline to MaskedLattice. Fit and residuals can be optionally 00113 // written (leave pointers at zero to not write out these lattices) 00114 // You can optionally specify a weights lattice (1.0 if not given). 00115 static uInt fitProfiles (MaskedLattice<Float>* pOutFit, 00116 MaskedLattice<Float>* pOutResid, 00117 MaskedLattice<Float>& in, 00118 Lattice<Float>* pSigma, 00119 LinearFit<Float>& fitter, 00120 uInt axis, Bool showProgress=False); 00121 }; 00122 00123 00124 } //# NAMESPACE CASA - END 00125 00126 #endif