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