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

ImageProfileFit.h

Go to the documentation of this file.
00001 //# ImageProfileFit.h: Class to fit profiles in images
00002 //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
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: ImageProfileFit.h 20299 2008-04-03 05:56:44Z gervandiepen $
00027 
00028 #ifndef IMAGES_IMAGEPROFILEFIT_H
00029 #define IMAGES_IMAGEPROFILEFIT_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <coordinates/Coordinates/CoordinateSystem.h>
00035 #include <casa/Quanta/Quantum.h>
00036 #include <casa/Quanta/Unit.h>
00037 #include <measures/Measures/MDoppler.h>
00038 
00039 #include <components/SpectralComponents/SpectralElement.h>
00040 #include <components/SpectralComponents/SpectralFit.h>
00041 #include <casa/Utilities/PtrHolder.h>
00042 
00043 
00044 namespace casa { //# NAMESPACE CASA - BEGIN
00045 
00046 //# Forward declarations
00047 template<class T> class ImageInterface;
00048 template<class T> class MaskedLattice;
00049 class GlishRecord;
00050 class ImageRegion;
00051 class IPosition;
00052 class Slicer;
00053 class LogIO;
00054 
00055 // <summary>
00056 // Class to fit profiles in images
00057 // </summary>
00058 
00059 // <use visibility=export>
00060 
00061 // <reviewed reviewer="" date="" tests="">
00062 // </reviewed>
00063 
00064 // <prerequisite>
00065 //   <li> <linkto class=></linkto>
00066 // </prerequisite>
00067 
00068 // <synopsis> 
00069 // The Record used to contain models/fits is as follows.  Other fields
00070 // will be ignored.
00071 //
00072 // <srcblock>
00073 // Field                     Type             Description
00074 //-----------------------------------------------------------
00075 // xabs                      Bool              Are the x-values absolute or 
00076 //                                             relative to the reference pixel
00077 // xunit                     String            The x unit 
00078 // yunit                     String            The y unit
00079 // doppler                   String            doppler type ('radio', 'optical', 'true' etc)
00080 //                                             Only required if x unit consistent with m/s
00081 // elements                  Record            Holds SpectralElement descriptions.  
00082 // elements[i]               Record            There will be N of these where N is the
00083 //                                             number of spectral elements.  Each elements[i]
00084 //                                             holds a record description that SpectralElement::fromRecord
00085 //                                             can read or writes
00086 //         .type             String            Type of SE (gaussian, polynomial, etc)
00087 //         .parameters       Vector<Double>    The parameters of the element.
00088 //         .errors           Vector<Double>    The errors of parameters of the element.
00089 //         .fixed            Vector<Bool>      Says whether parameter is going to be held fixed when fitting
00090 //                                             This field is not used by SpectralElement.  If its
00091 //                                             not there, all parameters are fitted for.
00092 //
00093 // </srcblock>
00094 // </synopsis> 
00095 // <example>
00096 // <srcblock>
00097 // </srcblock>
00098 // </example>
00099 
00100 // <todo asof="2001/03/01">
00101 // </todo>
00102 
00103 class ImageProfileFit 
00104 {
00105 public:
00106     // Constructor
00107     explicit ImageProfileFit();
00108 
00109     // Destructor
00110     ~ImageProfileFit();
00111 
00112     // Copy constructor.  Uses copy semantics.
00113     ImageProfileFit(const ImageProfileFit& other);
00114 
00115     // Assignment operator. Uses copy semantics.
00116     ImageProfileFit& operator=(const ImageProfileFit& other);
00117 
00118     // Set data via an image. <src>profileAxis</src> specifies the profile pixel
00119     // axis. You can either average the data over all other axes in the
00120     // image (<src>average=True</src>) or fit all profiles in the 
00121     // image.
00122     //<group>
00123     void setData (const ImageInterface<Float>& image,
00124                   const ImageRegion& region,
00125                   uInt profileAxis, Bool average=True);
00126     void setData (const ImageInterface<Float>& image,
00127                   const ImageInterface<Float>& sigma,
00128                   const ImageRegion& region,
00129                   uInt profileAxis, Bool average=True);
00130 //
00131     void setData (const ImageInterface<Float>& image,
00132                   uInt profileAxis, Bool average=True);
00133     void setData (const ImageInterface<Float>& image,
00134                   const ImageInterface<Float>& sigma,
00135                   uInt profileAxis, Bool average=True);
00136 
00137     //</group>
00138 
00139     // Set the data directly, and provide a coordinate system 
00140     // and specify the profile axis in the coordinate system.
00141     // The x-units can be 'pix'. If absolute
00142     // they must be 0-rel pixels. <src>isAbs</src> specifies whether
00143     // the coordinates are absolute or relative to the reference pixel.
00144     // If the weights vector, <src>sigma</src> is of zero length, 
00145     // it is treated as all unity.
00146     //<group>
00147     void setData (const CoordinateSystem& cSys,
00148                   uInt ProfileAxis,
00149                   const Quantum<Vector<Float> >& x, 
00150                   const Quantum<Vector<Float> >& y,
00151                   const Vector<Float>& sigma,
00152                   Bool isAbs, const String& doppler);
00153 
00154     void setData (const CoordinateSystem& cSys,
00155                   uInt ProfileAxis,
00156                   const Quantum<Vector<Float> >& x, 
00157                   const Quantum<Vector<Float> >& y,
00158                   const Vector<Bool>& mask,
00159                   const Vector<Float>& sigma,
00160                   Bool isAbs, const String& doppler);
00161     //</group>
00162 
00163     // Makes an estimate from the set data. This means it generates SpectralElements
00164     // holding the estimate, and replaces all elements you might have
00165     // put in place with function <src>addElement</src>.   Returns
00166     // False if it can't find any elements.
00167     Bool estimate (uInt nMax = 0);
00168 
00169     // Decode the Glish record holding SpectralElements and add
00170     // them to the fitter.   Absolute pixel coordinate units are assumed to be
00171     // 1-rel on input.  Return the number of the element added.
00172     uInt addElements (const RecordInterface& estimate);
00173 
00174     // Gets the internal SpectralElements (either estimate or fit
00175     // depending on what function you called last) into a record.  
00176     // Only returns False if the field is already defined. Absolute pixel 
00177     // coordinate units  are 1-rel on output.
00178     Bool getList (RecordInterface& rec,
00179                   Bool xAbsOut,
00180                   const String& xUnitOut,
00181                   const String& dopplerOut);
00182 
00183     // Gets the internal SpectralElements (either estimate or fit
00184     // depending on what function you called last) into a SpectralList
00185     // Only returns False if the field is already defined. Absolute pixel 
00186     // coordinate units  are 1-rel on output.
00187     SpectralList getList () const;
00188 
00189     // Reset the internal list of SpectralElements to null 
00190     void reset ();
00191 
00192     // Return number of SpectralElements set
00193     uInt nElements ();
00194 
00195     // Do the fit of the averaged profile. Specify the
00196     // order of the baseline you would also like to fit for.
00197     //<group>
00198     Bool fit(Int order=-1);
00199     //</group>
00200 
00201     // Fit all profiles with shapes + optional polynomial in the region and write out images.
00202     // If fillRecord is True, the output record is filled with the the parameters of 
00203     // every fit.  This can get VERY large so use with care.  If the output images
00204     // have a writable mask, the input mask is transferred to the output.
00205     //<group>
00206     void fit (Bool fillRecord, RecordInterface& rec,  
00207               Bool xAbsRec,
00208               const String& xUnitRec,
00209               const String& dopplerRec,
00210               ImageInterface<Float>* pFit,
00211               ImageInterface<Float>* pResid,
00212               Int order=-1);
00213     //</group>
00214 
00215     // Find the residuals (fit or estimate) of the averaged profile
00216     //<group>
00217     void residual(Vector<Float>& resid, const Vector<Float>& x) const;
00218     void residual(Vector<Float>& resid) const;
00219     //</group>
00220 
00221     // Find the model (fit or estimate) of the averaged profile
00222     //<group>
00223     void model (Vector<Float>& model, const Vector<Float>& x) const;
00224     void model (Vector<Float>& model) const;
00225     //</group>
00226 
00227 private:
00228 
00229 // Images holding data and weights.  Will be set only if fitting all profiles in region
00230 
00231    ImageInterface<Float>* itsImagePtr;
00232    ImageInterface<Float>* itsSigmaImagePtr;
00233 //
00234    Bool itsFitDone;
00235 
00236 // Holds the abcissa, ordinate and mask.  x-units will be pixels
00237 // if data source is an image, else as specified in setData
00238 
00239    Quantum<Vector<Float> > itsX, itsY;
00240    Vector<Bool> itsMask;
00241    Vector<Float> itsSigma;
00242 
00243 // The fitters.  The first one does not have a polynomial in it
00244 // The second one may.
00245    SpectralFit* itsSpectralFitPtr;
00246    SpectralFit itsSpectralFitter;
00247 
00248 // The coordinate system if the data source was an image
00249 // itsProfileAxis specified the profile axis in the image
00250 // Will be -1 if data source was just vectors
00251 
00252    CoordinateSystem itsCoords;
00253    Int itsProfileAxis;
00254 
00255 // If the data source was an image, these give the doppler type
00256 // (if any) and x-unit IF an estimate was specified by the user via
00257 // function addElements.  They are used in function getElements
00258 // so that the output record has the same units.
00259 
00260    String itsDoppler;                 // The doppler of the data source 
00261    Bool itsXAbs;                      // Is the data source in absolute coordinates ?
00262    Bool itsFitRegion;                 // True to fit all profiles in region
00263 //
00264    void collapse (Vector<Float>& profile, Vector<Bool>& mask,
00265                          uInt profileAxis,  const MaskedLattice<Float>& lat) const;
00266 
00267 // Convert SE
00268    SpectralElement convertSpectralElement (const SpectralElement& elIn,
00269                                            Bool xAbsIn, Bool xAbsOut,
00270                                            const String& xUnitIn,
00271                                            const String& xUnitOut,
00272                                            const String& dopplerIn,
00273                                            const String& dopplerOut,
00274                                            const String& yUnitIn,
00275                                            const String& yUnitOut);
00276 
00277 // Convert Gaussian model x-units when data source is an image
00278     void convertGaussianElementX (SpectralElement& el,
00279                                   CoordinateSystem& cSys,
00280                                   uInt profileAxis,
00281                                   Bool absIn, Bool absOut,
00282                                   const String& unitIn,
00283                                   const String& unitOut,
00284                                   const String& dopplerIn,
00285                                   const String& dopplerOut);
00286 
00287 // 
00288    SpectralList filterList (const SpectralList& listIn) const;
00289 
00290 //
00291    Bool getElements (RecordInterface& rec,
00292                      Bool xAbsOut,
00293                      const String& xUnitOut,
00294                      const String& dopplerOut,
00295                      const SpectralList& list);
00296 //
00297    void setData (const ImageInterface<Float>*& pSigma,
00298                  const ImageInterface<Float>& image,
00299                  const Slicer& sl, Bool average);
00300 };
00301 
00302 
00303 } //# NAMESPACE CASA - END
00304 
00305 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines