Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.atnf.csiro.au/computing/software/casacore/casacore-1.2.0/doc/html/ImageFit1D_8h_source.html
Дата изменения: Unknown
Дата индексирования: Mon Feb 14 20:34:51 2011
Кодировка:
casacore: images/Images/ImageFit1D.h Source File

ImageFit1D.h

Go to the documentation of this file.
00001 
00002 //# ImageFit1D.h: Class to fit profiles to vectors from images
00003 //# Copyright (C) 2004
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //#   $Id: ImageFit1D.h 20229 2008-01-29 15:19:06Z gervandiepen $
00028 
00029 #ifndef IMAGES_IMAGEFIT1D_H
00030 #define IMAGES_IMAGEFIT1D_H
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/Arrays/Vector.h>
00035 #include <scimath/Mathematics/NumericTraits.h>
00036 
00037 #include <measures/Measures/MDirection.h>
00038 #include <measures/Measures/MFrequency.h>
00039 #include <measures/Measures/MDoppler.h>
00040 #include <coordinates/Coordinates/CoordinateSystem.h>
00041 #include <components/SpectralComponents/ProfileFit1D.h>
00042 
00043 namespace casa {
00044 
00045 class SpectralElement;
00046 class SpectralList;
00047 class ImageRegion;
00048 template<class T> class ImageInterface;
00049 
00050 
00051 // <summary>
00052 // Fit spectral components to a Vector of data from an image
00053 // </summary>
00054 
00055 // <use visibility=export>
00056 
00057 // <reviewed reviewer="" date="" tests="tImageFit1D.cc">
00058 // </reviewed>
00059 
00060 // <prerequisite>
00061 //   <li> <linkto class="SpectralElement">SpectralElement</linkto> 
00062 //   <li> <linkto class="SpectralList">SpectralList</linkto> 
00063 //   <li> <linkto class="SpectralFit">SpectralFit</linkto> 
00064 //   <li> <linkto class="ProfileFit1D">ProfileFit1D</linkto> 
00065 // </prerequisite>
00066 
00067 // <synopsis> 
00068 // Fit lists (held in class SpectralList) of SpectralElements to a Vector of data 
00069 // from the image.  Each SpectralElement can  be one from a variety of types.
00070 // The values of the parameters for each SpectralElement provide the initial 
00071 // starting guesses for the fitting process.  
00072 //
00073 // You specify the domain in which the fit is to be done via the 
00074 // enum AbcissaType.  The CoordinateSystem in the image is used
00075 // to convert the pixel coordinates to the desired abcissa.  
00076 // You can change the units of the CoordinateSystem if you want
00077 // to fit in different units.  If you set an estimate yourself
00078 // (function setElements or addElement) it is the callers responsibility
00079 // that the elements are in the correct abcissa domain.  Function
00080 // setGaussianElements will automatically make an estimate in the 
00081 // correct domain.
00082 //
00083 // Also, a SpectralElement object holds a mask indicating whether 
00084 // a parameter should be held fixed or solved for.   After the 
00085 // fitting is done, a new SpectralList holding SpectralElements with 
00086 // the fitted parameters is created.  
00087 //
00088 // For all the functions that return a status Bool, True is good. If
00089 // False is returned, an error message can be recovered with function
00090 // <src>errorMessage</src>,  You should not proceed if False is returned.
00091 // 
00092 // Exceptions will be thrown if you do not set the Image and axis 
00093 // via the constructor or <src>setImage</src> function.
00094 // </synopsis> 
00095 
00096 // <example>
00097 // <srcblock>
00098 // PagedImage<Float> im("myimage");
00099 // Int axis = 2;
00100 // ImageFit1D<Float> fitter(image, axis);
00101 // IPosition pos(in.ndim(),0);
00102 // fitter.setData(pos, ImageFit1D<Float>::IM_NATIVE);     // Fit in native coordinate space
00103 // fitter.setGaussianElements(3);                      // FIt 3 Gaussians
00104 // if (fitter.fit()) {
00105 //    cerr << fitter.getList() << endl;                // Print result
00106 // }
00107 // 
00108 // </srcblock>
00109 // </example>
00110 
00111 // <todo asof="2004/07/10">
00112 //   <li> Add constraints
00113 // </todo>
00114 
00115 template <class T> class ImageFit1D 
00116 {
00117 public:
00118 
00119     enum AbcissaType {
00120        PIXEL = 0,
00121        IM_NATIVE = 1,
00122        VELOCITY = 2,
00123        N_TYPES};
00124 
00125     // Default Constructor (no image or axis set, so cannot be used).
00126     // You must call <src>setImage</src> to use this object.
00127     ImageFit1D();
00128 
00129     // Constructor.  Fitting weights are assumed all unity.
00130     ImageFit1D(const ImageInterface<T>& image, uInt axis=0);
00131 
00132     // Constructor with fitting weights image.  The data and weights images must
00133     // be the same shape.
00134     ImageFit1D(const ImageInterface<T>& image, 
00135                const ImageInterface<T>& weights,
00136                uInt axis=0);
00137 
00138     // Destructor
00139     ~ImageFit1D();
00140 
00141     // Copy constructor.  Uses reference semantics.
00142     ImageFit1D(const ImageFit1D& other);
00143 
00144     // Assignment operator. Uses reference semantics.
00145     ImageFit1D& operator=(const ImageFit1D& other);
00146 
00147     // Set Image(s) and axis
00148     // <group>
00149     void setImage (const ImageInterface<T>& im, const ImageInterface<T>& weights, uInt axis);
00150     void setImage (const ImageInterface<T>& im, uInt axis);
00151     // </group>
00152 
00153     // Set the data to be fit.  All non-profile axes data are averaged.
00154     // For the profile axis, the full spectrum is taken.  The abcissa
00155     // world values are computed when you call these functions.  The domain of the
00156     // abcissa values is controlled by <src>AbcissaType</src> and
00157     // <src>doAbs</src> (absolute coordinates).  The CoordinateSystem in
00158     // the image is used to convert from pixels to world values.
00159     // <group>
00160     Bool setData (const IPosition& pos, ImageFit1D<T>::AbcissaType type,
00161                   Bool doAbs=True);
00162     Bool setData (const ImageRegion& region, ImageFit1D<T>::AbcissaType type,
00163                   Bool doAbs=True);
00164     // </group>
00165 
00166     // Set a SpectralList of SpectralElements to fit for.    These elements
00167     // must be in the correct abcissa domain set in function <src>setData</src>.
00168     // You must have already called <src>setData</src> to call this function.
00169     // The SpectralElements in the list hold the
00170     // initial estimates.  They also contain the information about whether
00171     // specific parameters are to be held fixed or allowed to vary in
00172     // the fitting process.
00173     // You can recover the list of elements with function getList.
00174     void setElements (const SpectralList& list) {itsFitter.setElements(list);};
00175 
00176     // Add new SpectralElement(s) to the SpectralList (can be empty)
00177     // of SpectralElements to be fit for.  
00178     // You must have already called <src>setData</src> to call this function.
00179     //<group>
00180     void addElement (const SpectralElement& el) {itsFitter.addElement(el);};
00181     void addElements (const SpectralList& list) {itsFitter.addElements(list);};
00182     // </group>
00183 
00184     // Set a SpectralList of Gaussian SpectralElements to fit for.  
00185     // The initial estimates for the Gaussians will be automatically determined
00186     // in the correct abcissa domain.
00187     // All of the parameters created by this function will be solved for
00188     // by default. You can recover the list of elements with function getList.
00189     // Status is returned, if False, error message can be recovered with <src>errorMessage</src>
00190     Bool setGaussianElements (uInt nGauss);
00191 
00192     // Clear the SpectralList of elements to be fit for
00193     void clearList () {itsFitter.clearList();};
00194 
00195     // Do the fit and return convergence status.  Errors in the fitting
00196     // process will generate an AipsError exception and you should catch
00197     // these yourself.
00198     Bool fit ();
00199 
00200     // Get Chi Squared of fit
00201     Double getChiSquared () const {return itsFitter.getChiSquared();}
00202 
00203     // Get number of iterations for last fit
00204     Double getNumberIterations () const {return itsFitter.getNumberIterations();}
00205 
00206     // Recover the list of elements.  You can get the elements
00207     // as initially estimated (fit=False), or after fitting 
00208     // (fit=True).  In the latter case, the SpectralElements
00209     // hold the parameters and errors of the fit.
00210     const SpectralList& getList (Bool fit=True) const {return itsFitter.getList(fit);};
00211 
00212     // Recover vectors for the estimate, fit and residual.
00213     // If you don't specify which element, all elements are included
00214     // If the Vectors are returned with zero length, it means an error
00215     // condition exists (e.g. asking for fit before you do one). In this
00216     // case an error message can be recovered with function <src>errorMessage</src>.
00217     //<group>
00218     Vector<T> getEstimate (Int which=-1) const;
00219     Vector<T> getFit (Int which=-1) const;
00220     Vector<T> getResidual (Int which=-1, Bool fit=True)  const;
00221     //</group>
00222 
00223     // Get Total Mask (data and range mask)
00224     Vector<Bool> getTotalMask () const {return itsFitter.getTotalMask();};
00225 
00226     // Recover the error message
00227     String errorMessage () const {return itsError;};
00228 
00229     // Helper function.  Sets up the CoordinateSystem to reflect the choice of
00230     // abcissa unit and the doppler (if the axis is spectral).
00231     static Bool setAbcissaState (String& errMsg, ImageFit1D<T>::AbcissaType& type,
00232                                  CoordinateSystem& cSys, const String& xUnit,
00233                                  const String& doppler, uInt pixelAxis);
00234 private:
00235    ImageInterface<T>* itsImagePtr;
00236    ImageInterface<T>* itsWeightPtr;
00237    uInt itsAxis;
00238 
00239 // In the future I will be able to template the fitter on T. For now
00240 // it must be Double.
00241 
00242    typedef typename NumericTraits<T>::PrecisionType FitterType;
00243    ProfileFit1D<FitterType> itsFitter;
00244    CoordinateSystem itsCS;
00245 //
00246    mutable String itsError;                // Error message
00247 
00248 // Functions
00249    
00250    void check() const;
00251    void checkType() const;
00252    void copy (const ImageFit1D<T>& other);
00253    Bool makeAbcissa (Vector<Double>& x, ImageFit1D<T>::AbcissaType type, Bool doAbs);
00254    void setWeightsImage (const ImageInterface<T>& im);
00255 
00256 };
00257 
00258 } //#End casa namespace
00259 
00260 #ifndef CASACORE_NO_AUTO_TEMPLATES
00261 #include <images/Images/ImageFit1D.tcc>
00262 #endif //# CASACORE_NO_AUTO_TEMPLATES
00263 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines