MIRIADImage.h

Go to the documentation of this file.
00001 //# MIRIADImage.h: Class providing native access to MIRIAD images
00002 //# Copyright (C) 2001
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_MIRIADIMAGE_H
00029 #define IMAGES_MIRIADIMAGE_H
00030 
00031 
00032 //# Includes
00033 #include <casacore/casa/aips.h>
00034 #include <casacore/images/Images/ImageInterface.h>
00035 #include <casacore/images/Images/MaskSpecifier.h>
00036 #include <casacore/tables/DataMan/TiledFileAccess.h>
00037 #include <casacore/lattices/Lattices/TiledShape.h>
00038 #include <casacore/casa/Containers/Record.h>
00039 #include <casacore/casa/BasicSL/String.h>
00040 #include <casacore/casa/Utilities/DataType.h>
00041 
00042 
00043 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00044 
00045 //# Forward Declarations
00046 template <class T> class Array;
00047 template <class T> class Lattice;
00048 //
00049 class MaskSpecifier;
00050 class IPosition;
00051 class Slicer;
00052 class CoordinateSystem;
00053 class FITSMask;
00054 class FitsInput;
00055 
00056 
00057 // <summary>
00058 // Class providing native access to MIRIAD images.
00059 // </summary>
00060 
00061 // <use visibility=export>
00062 
00063 // <reviewed reviewer="" date="" tests="tMIRIADImage.cc">
00064 // </reviewed>
00065 
00066 // <prerequisite>
00067 //   <li> <linkto class=ImageInterface>ImageInterface</linkto>
00068 //   <li> <linkto class=FITSMask>FITSMask</linkto>
00069 // </prerequisite>
00070 
00071 // <etymology>
00072 //  This class provides native access to MIRIAD images. 
00073 // </etymology>
00074 
00075 // <synopsis> 
00076 //  A MIRIADImage provides native access to MIRIAD images by accessing them
00077 //  with the TiledFileAccess class.  -- or -- the native miriad I/O routines.
00078 //  The MIRIADImage is read only. -- really -- ??
00079 //
00080 // </synopsis> 
00081 
00082 // <example>
00083 // <srcblock>
00084 //    MIRIADImage im("cube1"); 
00085 //    LogIO logger(or);
00086 //    ImageStatistics<Float> stats(im, logger);
00087 //    Bool ok = stats.display();                              // Display statistics
00088 // </srcblock>
00089 // </example>
00090 
00091 // <motivation>
00092 // This provides native access to MIRIAD images.
00093 // </motivation>
00094 
00095 //# <todo asof="2001/09/10">
00096 //# </todo>
00097 
00098 
00099 class MIRIADImage: public ImageInterface<Float>
00100 {
00101 public: 
00102   // Construct a MIRIADImage from the disk MIRIAD dataset name and apply mask.
00103   explicit MIRIADImage(const String& name);
00104 
00105   // Construct a MIRIADImage from the disk MIRIAD file name and apply mask or not.
00106   MIRIADImage(const String& name, const MaskSpecifier&);
00107 
00108   // Copy constructor (reference semantics)
00109   MIRIADImage(const MIRIADImage& other);
00110 
00111   // Destructor does nothing
00112   ~MIRIADImage();
00113 
00114   // Assignment (reference semantics)
00115   MIRIADImage& operator=(const MIRIADImage& other);
00116 
00117   // Function to open a MIRIAD image.
00118   static LatticeBase* openMIRIADImage (const String& name,
00119                                        const MaskSpecifier&);
00120 
00121   // Register the open function.
00122   static void registerOpenFunction();
00123 
00124   //# ImageInterface virtual functions
00125   
00126   // Make a copy of the object with new (reference semantics).
00127   virtual ImageInterface<Float>* cloneII() const;
00128 
00129   // Get the image type (returns MIRIADImage).
00130   virtual String imageType() const;
00131 
00132   // Function which changes the shape of the MIRIADImage.
00133   // Throws an exception as MIRIADImage is not writable.
00134   virtual void resize(const TiledShape& newShape);
00135 
00136   // Functions which get and set the units associated with the image
00137   // pixels (i.e. the "brightness" unit). Initially the unit is empty.
00138   // Although the MIRIADimage is not writable, you can change the
00139   // unit in the MIRIADImage object, but it will not be changed 
00140   // in the MIRIAD disk file.
00141   // <group>   
00142 #if 0
00143   virtual Bool setUnits(const Unit& newUnits);
00144   virtual Unit units() const;
00145 #endif
00146   // </group>
00147 
00148   // Often we have miscellaneous information we want to attach to an image.
00149   // Although MIRIADImage is not writable, you can set a new
00150   // MiscInfo record, but it will not be stored with the MIRIAD file
00151   // <group>
00152   virtual const RecordInterface &miscInfo() const;
00153   virtual Bool setMiscInfo(const RecordInterface &newInfo);
00154   // </group>
00155 
00156   //# MaskedLattice virtual functions
00157 
00158   // Has the object really a mask?  The MIRIADImage always
00159   // has a pixel mask and never has a region mask so this
00160   // should always return True
00161   virtual Bool isMasked() const;
00162 
00163   // MIRIADimage always has a pixel mask so should return True
00164   virtual Bool hasPixelMask() const;
00165 
00166   // Get access to the pixelmask.  MIRIADImage always has a pixel mask.
00167   // <group>
00168   virtual const Lattice<Bool>& pixelMask() const;
00169   virtual Lattice<Bool>& pixelMask();
00170   // </group>
00171 
00172   // Do the actual get of the mask data.   The return value is always 
00173   // False, thus the buffer does not reference another array.
00174   virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
00175 
00176   // Get the region used.  There is no region. 
00177   // Always returns 0.
00178   virtual const LatticeRegion* getRegionPtr() const;
00179 
00180  
00181   //# Lattice virtual functions
00182 
00183   // Do the actual get of the data.
00184   // Returns False as the data do not reference another Array
00185   virtual Bool doGetSlice (Array<Float>& buffer, const Slicer& theSlice);
00186 
00187   // The MIRIADImage is not writable, so this throws an exception.
00188   virtual void doPutSlice (const Array<Float>& sourceBuffer,
00189                            const IPosition& where,
00190                            const IPosition& stride);
00191 
00192   //# LatticeBase virtual functions
00193 
00194   // The lattice is paged to disk.
00195   virtual Bool isPaged() const;
00196 
00197   // The lattice is persistent.
00198   virtual Bool isPersistent() const;
00199 
00200   // The MIRIADImage is not writable.
00201   virtual Bool isWritable() const;
00202 
00203   // Returns the name of the disk file.
00204   virtual String name (Bool stripPath=False) const;
00205   
00206   // return the shape of the MIRIADImage
00207   virtual IPosition shape() const;
00208 
00209   // Returns the maximum recommended number of pixels for a cursor. This is
00210   // the number of pixels in a tile. 
00211   virtual uInt advisedMaxPixels() const;
00212 
00213   // Help the user pick a cursor for most efficient access if they only want
00214   // pixel values and don't care about the order or dimension of the
00215   // cursor. 
00216   virtual IPosition doNiceCursorShape (uInt maxPixels) const;
00217 
00218   // Temporarily close the image.
00219   virtual void tempClose();
00220 
00221   // Reopen a temporarily closed image.
00222   virtual void reopen();
00223 
00224   // Check class invariants.
00225   virtual Bool ok() const;
00226 
00227   // Return the (internal) data type (TpFloat or TpShort).
00228   DataType dataType () const
00229     { return dataType_p; }
00230 
00231   // Maximum size - not necessarily all used. In pixels.
00232   virtual uInt maximumCacheSize() const;
00233 
00234   // Set the maximum (allowed) cache size as indicated.
00235   virtual void setMaximumCacheSize (uInt howManyPixels);
00236 
00237   // Set the cache size as to "fit" the indicated path.
00238   virtual void setCacheSizeFromPath (const IPosition& sliceShape,
00239                                      const IPosition& windowStart,
00240                                      const IPosition& windowLength,
00241                                      const IPosition& axisPath);
00242     
00243   // Set the actual cache size for this Array to be be big enough for the
00244   // indicated number of tiles. This cache is not shared with PagedArrays
00245   // in other rows and is always clipped to be less than the maximum value
00246   // set using the setMaximumCacheSize member function.
00247   // tiles. Tiles are cached using a first in first out algorithm. 
00248   virtual void setCacheSizeInTiles (uInt howManyTiles);
00249 
00250   // Clears and frees up the caches, but the maximum allowed cache size is 
00251   // unchanged from when setCacheSize was called
00252   virtual void clearCache();
00253 
00254   // Report on cache success.
00255   virtual void showCacheStatistics (ostream& os) const;
00256 
00257 private:  
00258   String         name_p;                          // filename, as given
00259   Int            tno_p;                           // miriad file handle
00260   MaskSpecifier  maskSpec_p;
00261   Unit           unit_p;
00262   Record         rec_p;
00263   CountedPtr<TiledFileAccess> pTiledFile_p;
00264   Lattice<Bool>* pPixelMask_p;
00265   //  Float          scale_p;
00266   //  Float          offset_p;
00267   //  Short          magic_p;
00268   TiledShape     shape_p;
00269   Bool           hasBlanks_p;
00270   DataType       dataType_p;                      // always float's for miriad
00271   Int64          fileOffset_p;                    // always 4 for direct (tiled) access
00272   Bool           isClosed_p;
00273 
00274 // Reopen the image if needed.
00275    void reopenIfNeeded() const
00276      { if (isClosed_p) const_cast<MIRIADImage*>(this)->reopen(); }
00277 
00278 // Setup the object (used by constructors).
00279    void setup();
00280 
00281 // Open the image (used by setup and reopen).
00282    void open();
00283 
00284 // Fish things out of the MIRIAD file
00285    void getImageAttributes (CoordinateSystem& cSys,
00286                             IPosition& shape, ImageInfo& info,
00287                             Unit& brightnessUnit, Record& miscInfo, 
00288                             Bool& hasBlanks, const String& name);
00289 
00290 // <group>
00291    void crackHeader (CoordinateSystem& cSys,
00292                      IPosition& shape, ImageInfo& imageInfo,
00293                      Unit& brightnessUnit, Record& miscInfo,
00294                      LogIO&os);
00295 
00296 // </group>
00297 };
00298 
00299 
00300 
00301 } //# NAMESPACE CASACORE - END
00302 
00303 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1