MomentWindow.h

Go to the documentation of this file.
00001 //# MomentWindow.h:
00002 //# Copyright (C) 1997,1999,2000,2001,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: MomentCalculator.h 20299 2008-04-03 05:56:44Z gervandiepen $
00027 
00028 #ifndef IMAGEANALYSIS_MOMENTWINDOW_H
00029 #define IMAGEANALYSIS_MOMENTWINDOW_H
00030 
00031 #include <casa/aips.h>
00032 #include <coordinates/Coordinates/CoordinateSystem.h>
00033 #include <coordinates/Coordinates/SpectralCoordinate.h>
00034 #include <lattices/LatticeMath/LineCollapser.h>
00035 #include <scimath/Functionals/Gaussian1D.h>
00036 #include <scimath/Mathematics/NumericTraits.h>
00037 #include <casa/Arrays/Vector.h>
00038 #include <casa/Logging/LogIO.h>
00039 
00040 namespace casa {
00041 
00042 template <class T> class MomentsBase;
00043 
00044 // <summary> Computes moments from a windowed profile </summary>
00045 // <use visibility=export>
00046 // 
00047 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00048 // </reviewed>
00049 // 
00050 // <prerequisite>
00051 //   <li> <linkto class="MomentsBase">MomentsBase</linkto>
00052 //   <li> <linkto class="ImageMoments">ImageMoments</linkto>
00053 //   <li> <linkto class="MSMoments">MSMoments</linkto>
00054 //   <li> <linkto class="LatticeApply">LatticeApply</linkto>
00055 //   <li> <linkto class="MomentCalcBase">MomentCalcBase</linkto>
00056 //   <li> <linkto class="LineCollapser">LineCollapser</linkto>
00057 // </prerequisite>
00058 //
00059 // <synopsis>
00060 //  This concrete class is derived from the abstract base class MomentCalcBase
00061 //  which provides an interface layer to the ImageMoments or MSMoments driver class.
00062 //  ImageMoments or MSMoments creates a MomentWindow object and passes it to the LatticeApply
00063 //  function lineMultiApply.  This function iterates through a given lattice, 
00064 //  and invokes the <src>multiProcess</src> member function of MomentWindow on each profile
00065 //  of pixels that it extracts from the input lattice.  The <src>multiProcess</src> function 
00066 //  returns a vector of moments which are inserted into the output lattices also
00067 //  supplied to the LatticeApply function.
00068 //
00069 //  MomentWindow computes moments from a subset of the pixels selected from  the
00070 //  input profile.  This subset is a simple index range, or window.  The window is
00071 //  selected, for each profile, that is thought to surround the spectral feature 
00072 //  of interest.  This window can be found from the primary lattice, or from an 
00073 //  ancilliary lattice (ImageMoments or MSMoments offers a smoothed version of the primary 
00074 //  lattice as the ancilliary lattice).  The moments are always computed from 
00075 //  primary lattice data.   
00076 //
00077 //  For each profile, the window can be found either interactively or automatically.
00078 //  There are two interactive methods.  Either you just mark the window with the
00079 //  cursor, or you interactively fit a Gaussian to the profile and the +/- 3-sigma
00080 //  window is returned.  There are two automatic methods.  Either Bosma's converging
00081 //  mean algorithm is used, or an automatically  fit Gaussian +/- 3-sigma window
00082 //  is returned.
00083 // 
00084 //  The constructor takes an MomentsBase object that is actually an ImageMoments or 
00085 //  an MSMoments object; the one that is constructing
00086 //  the MomentWindow object of course.   There is much control information embodied  
00087 //  in the state  of the ImageMoments or MSMoments object.  This information is extracted by the
00088 //  MomentCalcBase class and passed on to MomentWindow for consumption.
00089 //
00090 //  Note that the ancilliary lattice is only accessed if the pointer to it
00091 //  is non zero.
00092 //  
00093 //  See the <linkto class="MomentsBase">MomentsBase</linkto>, 
00094 //  <linkto class="ImageMoments">ImageMoments</linkto>, and 
00095 //  <linkto class="MSMoments">MSMoments</linkto>
00096 //  for discussion about the moments that are available for computation.
00097 //  
00098 // </synopsis>
00099 //
00100 // <example>
00101 // This example comes from ImageMoments.   outPt is a pointer block holding
00102 // pointers to the output lattices.  The ancilliary masking lattice is
00103 // just a smoothed version of the input lattice.  os_P is a LogIO object.
00104 //   
00105 // <srcBlock>
00106 // 
00109 //  
00110 //   MomentCalcBase<T>* pMomentCalculator = 0;
00111 //   if (clipMethod || smoothClipMethod) {
00112 //      pMomentCalculator = new MomentClip<T>(pSmoothedImage, *this, os_p, outPt.nelements());
00113 //   } else if (windowMethod) {
00114 //      pMomentCalculator = new MomentWindow<T>(pSmoothedImage, *this, os_p, outPt.nelements());
00115 //   } else if (fitMethod) {
00116 //      pMomentCalculator = new MomentFit<T>(*this, os_p, outPt.nelements());
00117 //   }
00118 //  
00120 //  
00121 //   LatticeApply<T>::lineMultiApply(outPt, *pInImage_p, *pMomentCalculator,   
00122 //                                   momentAxis_p, pProgressMeter);
00123 //   delete pMomentCalculator;
00124 //  
00125 // </srcBlock>
00126 // </example>
00127 //
00128 // <motivation>
00129 // </motivation>
00130 //
00131 // <note role=tip>
00132 // Note that there are is assignment operator or copy constructor.
00133 // Do not use the ones the system would generate either.
00134 // </note>
00135 //
00136 // <todo asof="yyyy/mm/dd">
00137 // </todo>
00138 
00139 
00140 template <class T> class MomentWindow : public MomentCalcBase<T>
00141 {
00142 public:
00143     using AccumType = typename NumericTraits<T>::PrecisionType;
00144     using DataIterator = typename Vector<T>::const_iterator;
00145     using MaskIterator = Vector<Bool>::const_iterator;
00146 
00147 // Constructor.  The pointer is to a lattice containing the masking
00148 // lattice (created by ImageMoments or MSMoments).   We also need the 
00149 // ImageMoments or MSMoments object which is calling us, its logger,
00150 // and the number of output lattices it has created.
00151    MomentWindow(shared_ptr<Lattice<T>> pAncilliaryLattice,
00152                 MomentsBase<T>& iMom,
00153                 LogIO& os,
00154                 const uInt nLatticeOut);
00155 
00156 // Destructor (does nothing).
00157   ~MomentWindow();
00158 
00159 // This function is not implemented and throws an exception.
00160    virtual void process(T& out,
00161                         Bool& outMask,
00162                         const Vector<T>& in,
00163                         const Vector<Bool>& inMask,
00164                         const IPosition& pos);
00165 
00166 // This function returns a vector of numbers from each input vector.
00167 // the output vector contains the moments known to the ImageMoments
00168 // or MSMoments object passed into the constructor.
00169    virtual void multiProcess(Vector<T>& out,
00170                              Vector<Bool>& outMask,
00171                              const Vector<T>& in,
00172                              const Vector<Bool>& inMask,
00173                              const IPosition& pos);
00174 
00175                              
00176 private:
00177 
00178    shared_ptr<Lattice<T>> _ancilliaryLattice;
00179    MomentsBase<T>& iMom_p;
00180    LogIO os_p;
00181 
00182    const Vector<T>* pProfileSelect_p;
00183    Vector<T> ancilliarySliceRef_p;
00184    Vector<T> selectedData_p;
00185    T stdDeviation_p, peakSNR_p;
00186    Bool doFit_p;
00187    IPosition sliceShape_p;
00188 
00189 // Automatically determine the spectral window
00190    Bool getAutoWindow(uInt& nFailed,
00191                       Vector<Int>& window,
00192                       const Vector<T>& x,
00193                       const Vector<T>& y,
00194                       const Vector<Bool>& mask,
00195                       const T peakSNR,
00196                       const T stdDeviation,
00197                       const Bool doFit) const;
00198 
00199    // Automatically determine the spectral window via Bosma's algorithm
00200    Bool _getBosmaWindow (
00201        Vector<Int>& window, const Vector<T>& y,
00202        const Vector<Bool>& mask, const T peakSNR,
00203        const T stdDeviation
00204    ) const;
00205 
00206 // Take the fitted Gaussian parameters and set an N-sigma window.
00207 // If the window is too small return a Fail condition.
00208    Bool setNSigmaWindow(Vector<Int>& window,  
00209                         const T pos,
00210                         const T width,
00211                         const Int nPts,
00212                         const Int N) const;
00213 
00214 
00215   //# Make members of parent class known.
00216 protected:
00217   using MomentCalcBase<T>::constructorCheck;
00218   using MomentCalcBase<T>::setPosLabel;
00219   //using MomentCalcBase<T>::convertF;
00220   using MomentCalcBase<T>::selectMoments_p;
00221   using MomentCalcBase<T>::calcMoments_p;
00222   using MomentCalcBase<T>::calcMomentsMask_p;
00223   using MomentCalcBase<T>::doMedianI_p;
00224   using MomentCalcBase<T>::doMedianV_p;
00225   using MomentCalcBase<T>::doAbsDev_p;
00226   using MomentCalcBase<T>::cSys_p;
00227   using MomentCalcBase<T>::doCoordProfile_p;
00228   using MomentCalcBase<T>::doCoordRandom_p;
00229   using MomentCalcBase<T>::pixelIn_p;
00230   using MomentCalcBase<T>::worldOut_p;
00231   using MomentCalcBase<T>::sepWorldCoord_p;
00232   using MomentCalcBase<T>::integratedScaleFactor_p;
00233   using MomentCalcBase<T>::momAxisType_p;
00234   using MomentCalcBase<T>::nFailed_p;
00235   using MomentCalcBase<T>::abcissa_p;
00236 };
00237 
00238 }
00239 
00240 #ifndef CASACORE_NO_AUTO_TEMPLATES
00241 #include <imageanalysis/ImageAnalysis/MomentWindow.tcc>
00242 #endif
00243 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1