casacore
Loading...
Searching...
No Matches
FITSImage.h
Go to the documentation of this file.
1//# FITSImage.h: Class providing native access to FITS images
2//# Copyright (C) 2001,2002
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: casa-feedback@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#ifndef IMAGES_FITSIMAGE_H
27#define IMAGES_FITSIMAGE_H
28
29
30//# Includes
31#include <casacore/casa/aips.h>
32#include <casacore/casa/Arrays/ArrayFwd.h>
33#include <casacore/images/Images/ImageInterface.h>
34#include <casacore/images/Images/MaskSpecifier.h>
35#include <casacore/tables/DataMan/TiledFileAccess.h>
36#include <casacore/lattices/Lattices/TiledShape.h>
37#include <casacore/fits/FITS/fits.h>
38#include <casacore/casa/BasicSL/String.h>
39#include <casacore/casa/Utilities/DataType.h>
40
41#ifndef WCSLIB_GETWCSTAB
42 #define WCSLIB_GETWCSTAB
43#endif
44
45namespace casacore { //# NAMESPACE CASACORE - BEGIN
46
47//# Forward Declarations
48template <class T> class Lattice;
49//
50class MaskSpecifier;
51class IPosition;
52class Slicer;
53class CoordinateSystem;
54class FITSMask;
55class FitsInput;
56
57
58// <summary>
59// Class providing native access to FITS images.
60// </summary>
61
62// <use visibility=export>
63
64// <reviewed reviewer="" date="" tests="tFITSImage.cc">
65// </reviewed>
66
67// <prerequisite>
68// <li> <linkto class=ImageInterface>ImageInterface</linkto>
69// <li> <linkto class=FITSMask>FITSMask</linkto>
70// </prerequisite>
71
72// <etymology>
73// This class provides native access to FITS images.
74// 64bit, 32bit floating point, 32 bit and 16bit integer FITS images are
75// presently supported.
76// </etymology>
77
78// <synopsis>
79// A FITSImage provides native access to FITS images by accessing them
80// with the TiledFileAccess class. The FITSImage is read only.
81// We could implement a writable FITSImage but putting the mask
82// would lose data values (uses magic blanking) and FITS is really
83// meant as an interchange medium, not an internal format.
84//
85// Because FITS uses magic value blanking, the mask is generated
86// on the fly as needed.
87// </synopsis>
88
89// <example>
90// <srcblock>
91// FITSImage im("in.fits");
92// LogIO logger(or);
93// ImageStatistics<Float> stats(im, logger);
94// Bool ok = stats.display(); // Display statistics
95// </srcblock>
96// </example>
97
98// <motivation>
99// This provides native access to FITS images.
100// </motivation>
101
102//# <todo asof="2001/02/09">
103//# </todo>
104
105
106class FITSImage: public ImageInterface<Float>
107{
108public:
109 // Construct a FITSImage from the disk FITS file name and extension and apply mask.
110 explicit FITSImage(const String& name, uInt whichRep=0, uInt whichHDU=0);
111
112 // Construct a FITSImage from the disk FITS file name and extension and apply mask or not.
113 FITSImage(const String& name, const MaskSpecifier& mask, uInt whichRep=0, uInt whichHDU=0);
114
115 // Copy constructor (reference semantics)
116 FITSImage(const FITSImage& other);
117
118 // Destructor does nothing
119 virtual ~FITSImage() = default;
120
121 // Assignment (reference semantics)
123
124 // Function to open a FITS image (new parser)
126 const MaskSpecifier&);
127
128 // Register the open function.
129 static void registerOpenFunction();
130
131 // Separate any extension specification and return the pure fitsname
132 static String get_fitsname(const String &fullname);
133
134 // Get the extension index for any extension specification given in the full name
135 static uInt get_hdunum(const String &fullname);
136
137 //# ImageInterface virtual functions
138
139 // Make a copy of the object with new (reference semantics).
141
142 // Get the image type (returns FITSImage).
143 virtual String imageType() const;
144
145 // returns "FITSImage". Added so callers don't require an object to get
146 // the image type.
148
149 // Function which changes the shape of the FITSImage.
150 // Throws an exception as FITSImage is not writable.
151 virtual void resize(const TiledShape& newShape);
152
153 //# MaskedLattice virtual functions
154
155 // Has the object really a mask? The FITSImage always
156 // has a pixel mask and never has a region mask so this
157 // always returns True
158 virtual Bool isMasked() const;
159
160 // FITSimage always has a pixel mask so returns True
161 virtual Bool hasPixelMask() const;
162
163 // Get access to the pixelmask. FITSImage always has a pixel mask.
164 // <group>
165 virtual const Lattice<Bool>& pixelMask() const;
167 // </group>
168
169 // Do the actual get of the mask data. The return value is always
170 // False, thus the buffer does not reference another array.
171 virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
172
173 // Get the region used. There is no region.
174 // Always returns 0.
175 virtual const LatticeRegion* getRegionPtr() const;
176
177
178 //# Lattice virtual functions
179
180 // Do the actual get of the data.
181 // Returns False as the data do not reference another Array
182 virtual Bool doGetSlice (Array<Float>& buffer, const Slicer& theSlice);
183
184 // The FITSImage is not writable, so this throws an exception.
185 virtual void doPutSlice (const Array<Float>& sourceBuffer,
186 const IPosition& where,
187 const IPosition& stride);
188
189 //# LatticeBase virtual functions
190
191 // The lattice is paged to disk.
192 virtual Bool isPaged() const;
193
194 // The lattice is persistent.
195 virtual Bool isPersistent() const;
196
197 // The FITSImage is not writable.
198 virtual Bool isWritable() const;
199
200 // Returns the name of the disk file.
201 virtual String name (Bool stripPath=False) const;
202
203 // return the shape of the FITSImage
204 virtual IPosition shape() const;
205
206 // Returns the maximum recommended number of pixels for a cursor. This is
207 // the number of pixels in a tile.
208 virtual uInt advisedMaxPixels() const;
209
210 // Help the user pick a cursor for most efficient access if they only want
211 // pixel values and don't care about the order or dimension of the
212 // cursor.
213 virtual IPosition doNiceCursorShape (uInt maxPixels) const;
214
215 // Temporarily close the image.
216 virtual void tempClose();
217
218 // Reopen a temporarily closed image.
219 virtual void reopen();
220
221 // Check class invariants.
222 virtual Bool ok() const;
223
224 // Return the data type (TpFloat).
225 virtual DataType dataType() const;
226
227 // Return the (internal) data type.
228 DataType internalDataType() const
229 { return dataType_p; }
230
231 // Return the HDU number
232 uInt whichHDU () const
233 { return whichHDU_p; }
234
235 // Maximum size - not necessarily all used. In pixels.
236 virtual uInt maximumCacheSize() const;
237
238 // Set the maximum (allowed) cache size as indicated.
239 virtual void setMaximumCacheSize (uInt howManyPixels);
240
241 // Set the cache size as to "fit" the indicated path.
242 virtual void setCacheSizeFromPath (const IPosition& sliceShape,
243 const IPosition& windowStart,
244 const IPosition& windowLength,
245 const IPosition& axisPath);
246
247 // Set the actual cache size for this Array to be be big enough for the
248 // indicated number of tiles. This cache is not shared with PagedArrays
249 // in other rows and is always clipped to be less than the maximum value
250 // set using the setMaximumCacheSize member function.
251 // tiles. Tiles are cached using a first in first out algorithm.
252 virtual void setCacheSizeInTiles (uInt howManyTiles);
253
254 // Clears and frees up the caches, but the maximum allowed cache size is
255 // unchanged from when setCacheSize was called
256 virtual void clearCache();
257
258 // Report on cache success.
259 virtual void showCacheStatistics (ostream& os) const;
260
261protected:
262 // Set the masking of values 0.0
263 void setMaskZero(Bool filterZero);
264
265private:
269 std::shared_ptr<TiledFileAccess> pTiledFile_p;
270 std::unique_ptr<Lattice<Bool>> pPixelMask_p;
278 DataType dataType_p;
285
286// Reopen the image if needed.
287 void reopenIfNeeded() const
288 { if (isClosed_p) const_cast<FITSImage*>(this)->reopen(); }
289
290// Setup the object (used by constructors).
291 void setup();
292
293// Open the image (used by setup and reopen).
294 void open();
295
296// Fish things out of the FITS file
298 IPosition& shape, ImageInfo& info,
299 Unit& brightnessUnit, RecordInterface& miscInfo,
300 Int& recsize, Int& recno,
302 Float& scale, Float& offset,
303 uChar& uCharMagic, Short& shortMagic,
304 Int& longMagic, Bool& hasBlanks, const String& name,
305 uInt whichRep, uInt whichHDU);
306
307// Crack a primary header
308 template <typename T>
310 Unit& brightnessUnit, RecordInterface& miscInfo,
311 Float& scale, Float& offset, uChar& magicUChar, Short& magicShort,
312 Int& magicLong, Bool& hasBlanks, LogIO& os, FitsInput& infile,
313 uInt whichRep);
314
315// Crack an image extension header
316 template <typename T>
318 Unit& brightnessUnit, RecordInterface& miscInfo,
319 Float& scale, Float& offset, uChar& uCharMagic,
320 Short& magicShort,
321 Int& magicLong, Bool& hasBlanks, LogIO& os, FitsInput& infile,
322 uInt whichRep);
323
324};
325
326
327
328} //# NAMESPACE CASACORE - END
329
330#ifndef CASACORE_NO_AUTO_TEMPLATES
331#include <casacore/images/Images/FITS2Image.tcc>
332#endif //# CASACORE_NO_AUTO_TEMPLATES
333
334#endif
335
336
virtual const Lattice< Bool > & pixelMask() const
Get access to the pixelmask.
virtual const LatticeRegion * getRegionPtr() const
Get the region used.
virtual void setMaximumCacheSize(uInt howManyPixels)
Set the maximum (allowed) cache size as indicated.
std::shared_ptr< TiledFileAccess > pTiledFile_p
Definition FITSImage.h:269
virtual String imageType() const
Get the image type (returns FITSImage).
DataType internalDataType() const
Return the (internal) data type.
Definition FITSImage.h:228
void crackHeader(CoordinateSystem &cSys, IPosition &shape, ImageInfo &imageInfo, Unit &brightnessUnit, RecordInterface &miscInfo, Float &scale, Float &offset, uChar &magicUChar, Short &magicShort, Int &magicLong, Bool &hasBlanks, LogIO &os, FitsInput &infile, uInt whichRep)
Crack a primary header.
std::unique_ptr< Lattice< Bool > > pPixelMask_p
Definition FITSImage.h:270
virtual IPosition shape() const
return the shape of the FITSImage
virtual Bool doGetSlice(Array< Float > &buffer, const Slicer &theSlice)
Do the actual get of the data.
FITSImage(const FITSImage &other)
Copy constructor (reference semantics)
TiledShape shape_p
Definition FITSImage.h:271
FITSImage & operator=(const FITSImage &other)
Assignment (reference semantics)
virtual void clearCache()
Clears and frees up the caches, but the maximum allowed cache size is unchanged from when setCacheSiz...
virtual void resize(const TiledShape &newShape)
Function which changes the shape of the FITSImage.
MaskSpecifier maskSpec_p
Definition FITSImage.h:268
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.
void reopenIfNeeded() const
Reopen the image if needed.
Definition FITSImage.h:287
virtual void doPutSlice(const Array< Float > &sourceBuffer, const IPosition &where, const IPosition &stride)
The FITSImage is not writable, so this throws an exception.
virtual Bool isWritable() const
The FITSImage is not writable.
void open()
Open the image (used by setup and reopen).
uInt whichHDU() const
Return the HDU number.
Definition FITSImage.h:232
static String className()
returns "FITSImage".
FITSImage(const String &name, uInt whichRep=0, uInt whichHDU=0)
Construct a FITSImage from the disk FITS file name and extension and apply mask.
virtual uInt advisedMaxPixels() const
Returns the maximum recommended number of pixels for a cursor.
void setMaskZero(Bool filterZero)
Set the masking of values 0.0.
virtual Bool doGetMaskSlice(Array< Bool > &buffer, const Slicer &section)
Do the actual get of the mask data.
static String get_fitsname(const String &fullname)
Separate any extension specification and return the pure fitsname.
void getImageAttributes(CoordinateSystem &cSys, IPosition &shape, ImageInfo &info, Unit &brightnessUnit, RecordInterface &miscInfo, Int &recsize, Int &recno, FITS::ValueType &dataType, Float &scale, Float &offset, uChar &uCharMagic, Short &shortMagic, Int &longMagic, Bool &hasBlanks, const String &name, uInt whichRep, uInt whichHDU)
Fish things out of the FITS file.
void setup()
Setup the object (used by constructors).
virtual Bool ok() const
Check class invariants.
virtual void reopen()
Reopen a temporarily closed image.
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...
virtual String name(Bool stripPath=False) const
Returns the name of the disk file.
virtual Bool isMasked() const
Has the object really a mask? The FITSImage always has a pixel mask and never has a region mask so th...
virtual Bool isPaged() const
The lattice is paged to disk.
virtual Bool hasPixelMask() const
FITSimage always has a pixel mask so returns True.
virtual Lattice< Bool > & pixelMask()
virtual uInt maximumCacheSize() const
Maximum size - not necessarily all used.
virtual ~FITSImage()=default
Destructor does nothing.
virtual ImageInterface< Float > * cloneII() const
Make a copy of the object with new (reference semantics).
virtual DataType dataType() const
Return the data type (TpFloat).
static LatticeBase * openFITSImage(const String &name, const MaskSpecifier &)
Function to open a FITS image (new parser)
virtual void tempClose()
Temporarily close the image.
void crackExtHeader(CoordinateSystem &cSys, IPosition &shape, ImageInfo &imageInfo, Unit &brightnessUnit, RecordInterface &miscInfo, Float &scale, Float &offset, uChar &uCharMagic, Short &magicShort, Int &magicLong, Bool &hasBlanks, LogIO &os, FitsInput &infile, uInt whichRep)
Crack an image extension header.
FITSImage(const String &name, const MaskSpecifier &mask, uInt whichRep=0, uInt whichHDU=0)
Construct a FITSImage from the disk FITS file name and extension and apply mask or not.
static uInt get_hdunum(const String &fullname)
Get the extension index for any extension specification given in the full name.
virtual void setCacheSizeInTiles(uInt howManyTiles)
Set the actual cache size for this Array to be be big enough for the indicated number of tiles.
virtual Bool isPersistent() const
The lattice is persistent.
static void registerOpenFunction()
Register the open function.
virtual void showCacheStatistics(ostream &os) const
Report on cache success.
ValueType
FITS I/O Error message types.
Definition fits.h:165
fixed-length sequential blocked FITS input
Definition fitsio.h:154
const ImageInfo & imageInfo() const
The ImageInfo object contains some miscellaneous information about the image which unlike that stored...
const TableRecord & miscInfo() const
Often we have miscellaneous information we want to attach to an image.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
unsigned char uChar
Definition aipstype.h:45
const Bool False
Definition aipstype.h:42
short Short
Definition aipstype.h:46
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
long long Int64
Define the extra non-standard types used by Casacore (like proposed uSize, Size)
Definition aipsxtype.h:36
float Float
Definition aipstype.h:52
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40