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