casacore
MIRIADImage.h
Go to the documentation of this file.
1 //# MIRIADImage.h: Class providing native access to MIRIAD images
2 //# Copyright (C) 2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef IMAGES_MIRIADIMAGE_H
29 #define IMAGES_MIRIADIMAGE_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/images/Images/ImageInterface.h>
35 #include <casacore/images/Images/MaskSpecifier.h>
36 #include <casacore/tables/DataMan/TiledFileAccess.h>
37 #include <casacore/lattices/Lattices/TiledShape.h>
38 #include <casacore/casa/Containers/Record.h>
39 #include <casacore/casa/BasicSL/String.h>
40 #include <casacore/casa/Utilities/DataType.h>
41 
42 
43 namespace casacore { //# NAMESPACE CASACORE - BEGIN
44 
45 //# Forward Declarations
46 template <class T> class Array;
47 template <class T> class Lattice;
48 //
49 class MaskSpecifier;
50 class IPosition;
51 class Slicer;
52 class CoordinateSystem;
53 class FITSMask;
54 class FitsInput;
55 
56 
57 // <summary>
58 // Class providing native access to MIRIAD images.
59 // </summary>
60 
61 // <use visibility=export>
62 
63 // <reviewed reviewer="" date="" tests="tMIRIADImage.cc">
64 // </reviewed>
65 
66 // <prerequisite>
67 // <li> <linkto class=ImageInterface>ImageInterface</linkto>
68 // <li> <linkto class=FITSMask>FITSMask</linkto>
69 // </prerequisite>
70 
71 // <etymology>
72 // This class provides native access to MIRIAD images.
73 // </etymology>
74 
75 // <synopsis>
76 // A MIRIADImage provides native access to MIRIAD images by accessing them
77 // with the TiledFileAccess class. -- or -- the native miriad I/O routines.
78 // The MIRIADImage is read only. -- really -- ??
79 //
80 // </synopsis>
81 
82 // <example>
83 // <srcblock>
84 // MIRIADImage im("cube1");
85 // LogIO logger(or);
86 // ImageStatistics<Float> stats(im, logger);
87 // Bool ok = stats.display(); // Display statistics
88 // </srcblock>
89 // </example>
90 
91 // <motivation>
92 // This provides native access to MIRIAD images.
93 // </motivation>
94 
95 //# <todo asof="2001/09/10">
96 //# </todo>
97 
98 
99 class MIRIADImage: public ImageInterface<Float>
100 {
101 public:
102  // Construct a MIRIADImage from the disk MIRIAD dataset name and apply mask.
103  explicit MIRIADImage(const String& name);
104 
105  // Construct a MIRIADImage from the disk MIRIAD file name and apply mask or not.
106  MIRIADImage(const String& name, const MaskSpecifier&);
107 
108  // Copy constructor (reference semantics)
109  MIRIADImage(const MIRIADImage& other);
110 
111  // Destructor does nothing
112  ~MIRIADImage();
113 
114  // Assignment (reference semantics)
115  MIRIADImage& operator=(const MIRIADImage& other);
116 
117  // Function to open a MIRIAD image.
118  static LatticeBase* openMIRIADImage (const String& name,
119  const MaskSpecifier&);
120 
121  // Register the open function.
122  static void registerOpenFunction();
123 
124  //# ImageInterface virtual functions
125 
126  // Make a copy of the object with new (reference semantics).
127  virtual ImageInterface<Float>* cloneII() const;
128 
129  // Get the image type (returns MIRIADImage).
130  virtual String imageType() const;
131 
132  // Function which changes the shape of the MIRIADImage.
133  // Throws an exception as MIRIADImage is not writable.
134  virtual void resize(const TiledShape& newShape);
135 
136  // Functions which get and set the units associated with the image
137  // pixels (i.e. the "brightness" unit). Initially the unit is empty.
138  // Although the MIRIADimage is not writable, you can change the
139  // unit in the MIRIADImage object, but it will not be changed
140  // in the MIRIAD disk file.
141  // <group>
142 #if 0
143  virtual Bool setUnits(const Unit& newUnits);
144  virtual Unit units() const;
145 #endif
146  // </group>
147 
148  // Often we have miscellaneous information we want to attach to an image.
149  // Although MIRIADImage is not writable, you can set a new
150  // MiscInfo record, but it will not be stored with the MIRIAD file
151  // <group>
152  virtual const RecordInterface &miscInfo() const;
153  virtual Bool setMiscInfo(const RecordInterface &newInfo);
154  // </group>
155 
156  //# MaskedLattice virtual functions
157 
158  // Has the object really a mask? The MIRIADImage always
159  // has a pixel mask and never has a region mask so this
160  // should always return True
161  virtual Bool isMasked() const;
162 
163  // MIRIADimage always has a pixel mask so should return True
164  virtual Bool hasPixelMask() const;
165 
166  // Get access to the pixelmask. MIRIADImage always has a pixel mask.
167  // <group>
168  virtual const Lattice<Bool>& pixelMask() const;
169  virtual Lattice<Bool>& pixelMask();
170  // </group>
171 
172  // Do the actual get of the mask data. The return value is always
173  // False, thus the buffer does not reference another array.
174  virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
175 
176  // Get the region used. There is no region.
177  // Always returns 0.
178  virtual const LatticeRegion* getRegionPtr() const;
179 
180 
181  //# Lattice virtual functions
182 
183  // Do the actual get of the data.
184  // Returns False as the data do not reference another Array
185  virtual Bool doGetSlice (Array<Float>& buffer, const Slicer& theSlice);
186 
187  // The MIRIADImage is not writable, so this throws an exception.
188  virtual void doPutSlice (const Array<Float>& sourceBuffer,
189  const IPosition& where,
190  const IPosition& stride);
191 
192  //# LatticeBase virtual functions
193 
194  // The lattice is paged to disk.
195  virtual Bool isPaged() const;
196 
197  // The lattice is persistent.
198  virtual Bool isPersistent() const;
199 
200  // The MIRIADImage is not writable.
201  virtual Bool isWritable() const;
202 
203  // Returns the name of the disk file.
204  virtual String name (Bool stripPath=False) const;
205 
206  // return the shape of the MIRIADImage
207  virtual IPosition shape() const;
208 
209  // Returns the maximum recommended number of pixels for a cursor. This is
210  // the number of pixels in a tile.
211  virtual uInt advisedMaxPixels() const;
212 
213  // Help the user pick a cursor for most efficient access if they only want
214  // pixel values and don't care about the order or dimension of the
215  // cursor.
216  virtual IPosition doNiceCursorShape (uInt maxPixels) const;
217 
218  // Temporarily close the image.
219  virtual void tempClose();
220 
221  // Reopen a temporarily closed image.
222  virtual void reopen();
223 
224  // Check class invariants.
225  virtual Bool ok() const;
226 
227  // Return the (internal) data type (TpFloat or TpShort).
228  DataType dataType () const
229  { return dataType_p; }
230 
231  // Maximum size - not necessarily all used. In pixels.
232  virtual uInt maximumCacheSize() const;
233 
234  // Set the maximum (allowed) cache size as indicated.
235  virtual void setMaximumCacheSize (uInt howManyPixels);
236 
237  // Set the cache size as to "fit" the indicated path.
238  virtual void setCacheSizeFromPath (const IPosition& sliceShape,
239  const IPosition& windowStart,
240  const IPosition& windowLength,
241  const IPosition& axisPath);
242 
243  // Set the actual cache size for this Array to be be big enough for the
244  // indicated number of tiles. This cache is not shared with PagedArrays
245  // in other rows and is always clipped to be less than the maximum value
246  // set using the setMaximumCacheSize member function.
247  // tiles. Tiles are cached using a first in first out algorithm.
248  virtual void setCacheSizeInTiles (uInt howManyTiles);
249 
250  // Clears and frees up the caches, but the maximum allowed cache size is
251  // unchanged from when setCacheSize was called
252  virtual void clearCache();
253 
254  // Report on cache success.
255  virtual void showCacheStatistics (ostream& os) const;
256 
257 private:
258  String name_p; // filename, as given
259  Int tno_p; // miriad file handle
265  // Float scale_p;
266  // Float offset_p;
267  // Short magic_p;
270  DataType dataType_p; // always float's for miriad
271  Int64 fileOffset_p; // always 4 for direct (tiled) access
273 
274 // Reopen the image if needed.
275  void reopenIfNeeded() const
276  { if (isClosed_p) const_cast<MIRIADImage*>(this)->reopen(); }
277 
278 // Setup the object (used by constructors).
279  void setup();
280 
281 // Open the image (used by setup and reopen).
282  void open();
283 
284 // Fish things out of the MIRIAD file
286  IPosition& shape, ImageInfo& info,
287  Unit& brightnessUnit, Record& miscInfo,
288  Bool& hasBlanks, const String& name);
289 
290 // <group>
291  void crackHeader (CoordinateSystem& cSys,
293  Unit& brightnessUnit, Record& miscInfo,
294  LogIO&os);
295 
296 // </group>
297 };
298 
299 
300 
301 } //# NAMESPACE CASACORE - END
302 
303 #endif
casacore::MIRIADImage::pixelMask
virtual const Lattice< Bool > & pixelMask() const
Get access to the pixelmask.
casacore::CoordinateSystem
Interconvert pixel and world coordinates.
Definition: CoordinateSystem.h:217
casacore::ImageInterface
A base class for astronomical images.
Definition: ImageFITSConverter.h:48
casacore::Slicer
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:289
casacore::MIRIADImage::shape_p
TiledShape shape_p
Float scale_p; Float offset_p; Short magic_p;.
Definition: MIRIADImage.h:268
casacore::IPosition
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
casacore::MIRIADImage::setup
void setup()
Setup the object (used by constructors).
casacore::MIRIADImage::name_p
String name_p
Definition: MIRIADImage.h:258
casacore::ImageInterface< Float >::setUnits
virtual Bool setUnits(const Unit &newUnits)
Function which get and set the units associated with the image pixels (i.e.
casacore::MIRIADImage::name
virtual String name(Bool stripPath=False) const
Returns the name of the disk file.
casacore::MIRIADImage::pPixelMask_p
Lattice< Bool > * pPixelMask_p
Definition: MIRIADImage.h:264
casacore::MIRIADImage::resize
virtual void resize(const TiledShape &newShape)
Function which changes the shape of the MIRIADImage.
casacore::MIRIADImage::setMiscInfo
virtual Bool setMiscInfo(const RecordInterface &newInfo)
casacore::MIRIADImage
Class providing native access to MIRIAD images.
Definition: MIRIADImage.h:99
casacore::CountedPtr
Referenced counted pointer for constant data.
Definition: CountedPtr.h:80
casacore::MIRIADImage::showCacheStatistics
virtual void showCacheStatistics(ostream &os) const
Report on cache success.
casacore::MIRIADImage::operator=
MIRIADImage & operator=(const MIRIADImage &other)
Assignment (reference semantics)
casacore::MIRIADImage::clearCache
virtual void clearCache()
Clears and frees up the caches, but the maximum allowed cache size is unchanged from when setCacheSiz...
casacore::MIRIADImage::doGetSlice
virtual Bool doGetSlice(Array< Float > &buffer, const Slicer &theSlice)
Do the actual get of the data.
casacore::MIRIADImage::open
void open()
Open the image (used by setup and reopen).
casacore::MIRIADImage::tno_p
Int tno_p
Definition: MIRIADImage.h:259
casacore::MIRIADImage::openMIRIADImage
static LatticeBase * openMIRIADImage(const String &name, const MaskSpecifier &)
Function to open a MIRIAD image.
casacore::MIRIADImage::registerOpenFunction
static void registerOpenFunction()
Register the open function.
casacore::LatticeRegion
An optionally strided region in a Lattice.
Definition: LatticeRegion.h:74
casacore::MIRIADImage::hasPixelMask
virtual Bool hasPixelMask() const
MIRIADimage always has a pixel mask so should return True.
casacore::MIRIADImage::isPersistent
virtual Bool isPersistent() const
The lattice is persistent.
casacore::MIRIADImage::crackHeader
void crackHeader(CoordinateSystem &cSys, IPosition &shape, ImageInfo &imageInfo, Unit &brightnessUnit, Record &miscInfo, LogIO &os)
casacore::MIRIADImage::tempClose
virtual void tempClose()
Temporarily close the image.
casacore::MIRIADImage::MIRIADImage
MIRIADImage(const String &name)
Construct a MIRIADImage from the disk MIRIAD dataset name and apply mask.
casacore::LogIO
ostream-like interface to creating log messages.
Definition: LogIO.h:167
casacore::MIRIADImage::dataType
DataType dataType() const
Return the (internal) data type (TpFloat or TpShort).
Definition: MIRIADImage.h:228
casacore::MIRIADImage::advisedMaxPixels
virtual uInt advisedMaxPixels() const
Returns the maximum recommended number of pixels for a cursor.
casacore::MIRIADImage::isMasked
virtual Bool isMasked() const
Has the object really a mask? The MIRIADImage always has a pixel mask and never has a region mask so ...
casacore::MIRIADImage::miscInfo
virtual const RecordInterface & miscInfo() const
Functions which get and set the units associated with the image pixels (i.e.
casacore::False
const Bool False
Definition: aipstype.h:44
casacore::uInt
unsigned int uInt
Definition: aipstype.h:51
casacore::MIRIADImage::reopenIfNeeded
void reopenIfNeeded() const
Reopen the image if needed.
Definition: MIRIADImage.h:275
casacore::MIRIADImage::maskSpec_p
MaskSpecifier maskSpec_p
Definition: MIRIADImage.h:260
casacore::MIRIADImage::shape
virtual IPosition shape() const
return the shape of the MIRIADImage
casacore::MIRIADImage::ok
virtual Bool ok() const
Check class invariants.
casacore::LatticeBase
A non-templated, abstract base class for array-like objects.
Definition: LatticeBase.h:80
casacore::MaskSpecifier
Class to specify which mask to use in an image.
Definition: MaskSpecifier.h:69
casacore::MIRIADImage::~MIRIADImage
~MIRIADImage()
Destructor does nothing.
casacore::MIRIADImage::getImageAttributes
void getImageAttributes(CoordinateSystem &cSys, IPosition &shape, ImageInfo &info, Unit &brightnessUnit, Record &miscInfo, Bool &hasBlanks, const String &name)
Fish things out of the MIRIAD file.
casacore::MIRIADImage::doPutSlice
virtual void doPutSlice(const Array< Float > &sourceBuffer, const IPosition &where, const IPosition &stride)
The MIRIADImage is not writable, so this throws an exception.
casacore::MIRIADImage::rec_p
Record rec_p
Definition: MIRIADImage.h:262
casacore::Int
int Int
Definition: aipstype.h:50
casacore
this file contains all the compiler specific defines
Definition: mainpage.dox:28
casacore::MIRIADImage::setCacheSizeFromPath
virtual void setCacheSizeFromPath(const IPosition &sliceShape, const IPosition &windowStart, const IPosition &windowLength, const IPosition &axisPath)
Set the cache size as to "fit" the indicated path.
casacore::MIRIADImage::isPaged
virtual Bool isPaged() const
The lattice is paged to disk.
casacore::MIRIADImage::setMaximumCacheSize
virtual void setMaximumCacheSize(uInt howManyPixels)
Set the maximum (allowed) cache size as indicated.
casacore::MIRIADImage::pTiledFile_p
CountedPtr< TiledFileAccess > pTiledFile_p
Definition: MIRIADImage.h:263
casacore::ImageInterface< Float >::units
virtual const Unit & units() const
Definition: ImageInterface.h:182
casacore::MIRIADImage::unit_p
Unit unit_p
Definition: MIRIADImage.h:261
casacore::RecordInterface
Abstract base class for Record classes.
Definition: RecordInterface.h:144
casacore::ImageInterface< Float >::imageInfo
const ImageInfo & imageInfo() const
The ImageInfo object contains some miscellaneous information about the image which unlike that stored...
Definition: ImageInterface.h:240
casacore::Int64
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition: aipsxtype.h:38
casacore::Lattice< Bool >
casacore::MIRIADImage::reopen
virtual void reopen()
Reopen a temporarily closed image.
casacore::Array< Bool >
casacore::MIRIADImage::isClosed_p
Bool isClosed_p
Definition: MIRIADImage.h:272
casacore::MIRIADImage::doGetMaskSlice
virtual Bool doGetMaskSlice(Array< Bool > &buffer, const Slicer &section)
Do the actual get of the mask data.
casacore::String
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::MIRIADImage::isWritable
virtual Bool isWritable() const
The MIRIADImage is not writable.
casacore::MIRIADImage::imageType
virtual String imageType() const
Get the image type (returns MIRIADImage).
casacore::MIRIADImage::dataType_p
DataType dataType_p
Definition: MIRIADImage.h:270
casacore::MIRIADImage::fileOffset_p
Int64 fileOffset_p
Definition: MIRIADImage.h:271
casacore::Record
A hierarchical collection of named fields of various types.
Definition: Record.h:180
casacore::MIRIADImage::cloneII
virtual ImageInterface< Float > * cloneII() const
Make a copy of the object with new (reference semantics).
casacore::MIRIADImage::setCacheSizeInTiles
virtual void setCacheSizeInTiles(uInt howManyTiles)
Set the actual cache size for this Array to be be big enough for the indicated number of tiles.
casacore::Unit
defines physical units
Definition: Unit.h:189
casacore::MIRIADImage::doNiceCursorShape
virtual IPosition doNiceCursorShape(uInt maxPixels) const
Help the user pick a cursor for most efficient access if they only want pixel values and don't care a...
casacore::MIRIADImage::getRegionPtr
virtual const LatticeRegion * getRegionPtr() const
Get the region used.
casacore::TiledShape
Define the shape and tile shape.
Definition: TiledShape.h:99
casacore::ImageInfo
Miscellaneous information related to an image.
Definition: ImageInfo.h:92
casacore::MIRIADImage::maximumCacheSize
virtual uInt maximumCacheSize() const
Maximum size - not necessarily all used.
casacore::MIRIADImage::hasBlanks_p
Bool hasBlanks_p
Definition: MIRIADImage.h:269