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

Generated on Mon Sep 1 22:34:43 2008 for NRAOCASA by  doxygen 1.5.1