RebinLattice.h

Go to the documentation of this file.
00001 //# RebinLattice.h: rebin a masked lattices
00002 //# Copyright (C) 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 receied 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 LATTICES_REBINLATTICE_H
00029 #define LATTICES_REBINLATTICE_H
00030 
00031 
00032 //# Includes
00033 #include <casacore/casa/aips.h>
00034 #include <casacore/casa/Arrays/Array.h>
00035 #include <casacore/casa/Arrays/Slicer.h>
00036 #include <casacore/lattices/Lattices/MaskedLattice.h>
00037 
00038 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00039 
00040 //# Forward Declarations
00041 
00042 class IPosition;
00043 
00044 
00045 // <summary>
00046 // Rebin a masked lattice.
00047 // </summary>
00048 
00049 // <use visibility=local>
00050 
00051 // <reviewed reviewer="" date="" tests="tRebinLattice.cc">
00052 // </reviewed>
00053 
00054 // <prerequisite>
00055 //   <li> <linkto class="MaskedLattice">MaskedLattice</linkto>
00056 // </prerequisite>
00057 
00058 // <synopsis>
00059 //  This class enables you to rebin (data are averaged over bin) a MaskedLattice by 
00060 //  a given factor per axis
00061 // </synopsis>
00062 
00063 // <example>
00064 // <srcblock>
00065 //    IPosition shape(2, 10, 20);
00066 //    TiledShape tShape(shape);
00067 //    TempLattice<Float> latIn(tShape);
00068 //    IPosition factors(2, 2, 5);
00069 //    RebinLattice<Float> rl(latIn, factors);
00070 //    cerr << "Binned data = " << rl.get() << endl;
00071 // </srcblock>
00072 // </example>
00073 
00074 // <motivation>
00075 // </motivation>
00076 
00077 
00078 template<class T>
00079 class RebinLattice : public MaskedLattice<T>
00080 {
00081 public:
00082 
00083   // Default constructor (Object is unuseable)
00084   RebinLattice();
00085 
00086   // Constructor.  The bins don't have to fit integrally. Whatever
00087   // is left over at the end is treated as a full bin.
00088   RebinLattice(const MaskedLattice<T>& lattice, const IPosition& bin);
00089 
00090   // Copy constructor (reference semantics)
00091   RebinLattice(const RebinLattice<T>& other);
00092 
00093   // Destructor.
00094   virtual ~RebinLattice();
00095 
00096   // Assignment (reference semantics)
00097   RebinLattice<T>& operator=(const RebinLattice<T>& other);
00098 
00099   // Make a copy of the object (reference semantics).
00100   virtual MaskedLattice<T>* cloneML() const;
00101 
00102   // Is the lattice masked?
00103   // It is if its parent lattice is masked.
00104   virtual Bool isMasked() const;
00105 
00106   // Is the lattice paged to disk?
00107   virtual Bool isPaged() const;
00108 
00109   // The lattice is not writable.
00110   virtual Bool isWritable() const;
00111 
00112   // Handle locking of the lattice which is delegated to its parent.
00113   // <br>It is strongly recommended to use class
00114   // <linkto class=LatticeLocker>LatticeLocker</linkto> to
00115   // handle lattice locking. It also contains a more detailed
00116   // explanation of the locking process.
00117   // <group>
00118   virtual Bool lock (FileLocker::LockType, uInt nattempts);
00119   virtual void unlock();
00120   virtual Bool hasLock (FileLocker::LockType) const;
00121   // </group>
00122 
00123   // Resynchronize the Lattice object with the lattice file.
00124   // This function is only useful if no read-locking is used, ie.
00125   // if the table lock option is UserNoReadLocking or AutoNoReadLocking.
00126   // In that cases the table system does not acquire a read-lock, thus
00127   // does not synchronize itself automatically.
00128   virtual void resync();
00129 
00130   // Flush the data.
00131   virtual void flush();
00132 
00133   // Close the Lattice temporarily (if it is paged to disk).
00134   // It'll be reopened automatically when needed or when
00135   // <src>reopen</src> is called explicitly.
00136   virtual void tempClose();
00137 
00138   // If needed, reopen a temporarily closed Lattice.
00139   virtual void reopen();
00140 
00141   // Get a pointer the region/mask object.
00142   // It returns 0.
00143   virtual const LatticeRegion* getRegionPtr() const;
00144 
00145   // Returns the shape of the lattice.
00146   virtual IPosition shape() const;
00147   
00148   // Return the name of the parent lattice.
00149   virtual String name (Bool stripPath=False) const;
00150 
00151   // This function returns the recommended maximum number of pixels to
00152   // include in the cursor of an iterator.
00153   virtual uInt advisedMaxPixels() const;
00154 
00155   // Check class internals - used for debugging. Should always return True
00156   virtual Bool ok() const;
00157 
00158   // Do the actual getting of an array of values.
00159   // Slicers with non-unit stride are not yet supported
00160   virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
00161 
00162   // Do the actual putting of an array of values.
00163   // The lattice is not writable.
00164   virtual void doPutSlice (const Array<T>& sourceBuffer,
00165                            const IPosition& where,
00166                            const IPosition& stride);
00167   
00168   // Get a section of the mask.
00169   // Slicers with non-unit stride are not yet supported
00170   virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
00171 
00172   // Static function needed by LEL.  Applies binning factors
00173   // to shape to give the shape of the output lattice.  Will
00174   // give the same result as function 'shape'
00175   static IPosition rebinShape (const IPosition& shapeLatticeIn,
00176                                const IPosition& bin);  
00177 
00178 private:
00179   Slicer findOriginalSlicer (const Slicer& section) const;
00180   void getDataAndMask (const Slicer& section);
00181   void bin(const Array<T>& dataIn);
00182   void bin(const Array<T>& dataIn, const Array<Bool>& maskIn);
00183 //
00184   MaskedLattice<T>* itsLatticePtr;
00185   IPosition itsBin;
00186   Bool      itsAllUnity;
00187 // Cache
00188   Array<T>    itsData;
00189   Array<Bool> itsMask;
00190   Slicer      itsSlicer;
00191 };
00192 
00193 
00194 
00195 } //# NAMESPACE CASACORE - END
00196 
00197 #ifndef CASACORE_NO_AUTO_TEMPLATES
00198 #include <casacore/lattices/Lattices/RebinLattice.tcc>
00199 #endif //# CASACORE_NO_AUTO_TEMPLATES
00200 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1