casacore
Loading...
Searching...
No Matches
FITSImgParser.h
Go to the documentation of this file.
1// # FITSImgParser.h: Class for parsing multi-extension 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_FITSImgParser_H
27#define IMAGES_FITSImgParser_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/fits/FITS/fits.h>
31#include <casacore/casa/Arrays/Vector.h>
32#include <casacore/casa/BasicSL/String.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// # Forward Declarations
37class FITSExtInfo;
38class HeaderDataUnit;
39
40// <summary>
41// Class for handling FITS Image extensions
42// </summary>
43
44// <use visibility=export>
45
46// <reviewed reviewer="" date="" tests="tFITSImgParser.cc">
47// </reviewed>
48
49// <prerequisite>
50// <li> <linkto class=FITSExtInfo>FITSExtInfo</linkto>
51// <li> <linkto class=HeaderDataUnit>HeaderDataUnit</linkto>
52// </prerequisite>
53
54// <etymology>
55// This class parses through a FITS image and stores essential information
56// for each extension.
57// </etymology>
58
59// <synopsis>
60// The class parses through a FITS image and extracts information
61// on its extensions, e.g. the extension name and the extension version.
62// It is possible to identify a certain extension and to get the its
63// extension index.
64//
65// It is also explored whether some of the FITS extensions can be
66// loaded as a quality image (data + error + mask).
67// </synopsis>
68
69// <example>
70// <srcblock>
71// FITSImgParser fitsImg("in.fits");
72// uInt numHDU = fitsImg.get_numhdu(); // get the total number of HDU's
73// uInt firstdata = fitsImg.get_firstdata_index(); // get the first HDU with data
74// String allExts = fitsImg.get_extlist_string(String("\n")); // get a string representation of
75// all extensions String hasQual = fitsImg.has_qualityimg(); // check whether some of
76// the extensions form quality image
77// </srcblock>
78// </example>
79
80// <motivation>
81// Investigate and select FITS extensions
82// </motivation>
83
84// # <todo asof="2011/08/16">
85// # </todo>
86
88 public:
89 // Construct a parser from the FITS file.
91
92 // Copy constructor (reference semantics).
94
95 // Destructor, does not much.
97
98 // Assignment (reference semantics).
100
101 // Returns the name of the disk file.
102 String fitsname(Bool stripPath = False) const;
103
104 // Identify the index of an extension.
105 Int get_index(const FITSExtInfo &extinfo);
106
107 // Find an extension; return -1 if not found.
108 Int find_extension(const String &extname, const Int &extversion = -1);
109
110 // Get the index of the first extension with data.
112
113 // Get the number of extensions.
114 uInt get_numhdu(void) { return numhdu_p; };
115
116 // Get a string representation of the extension list.
117 String get_extlist_string(const String &delimiter, const String &qualmarker = "",
118 const String &fitsmarker = "", const Bool &listall = True);
119
120 // Get the flag indicating at least one quality image.
121 Bool has_qualityimg(void) { return qualimglist_p.size() > 0 ? True : False; };
122
123 // Check whether the extensions named in the extension expression
124 // can be loaded as a quality image.
125 Bool is_qualityimg(const String &extexpr);
126
127 // Find all necessary access information for the extensions to be loaded
128 // as a quality image.
129 Bool get_quality_data(const String &extexpr, Int &data_HDU, Int &error_HDU, String &error_type,
130 Int &mask_HDU, String &mask_type, Int &mask_value);
131
132 private:
135
138
140
141 static const char *storeKwords_p[];
142 static const int nKwords_p;
143
144 // Setup the object (used by constructors).
145 void setup(void);
146
147 // Get the information on an extension.
148 void process_extension(HeaderDataUnit *h, const uInt &extindex);
149
150 // Extract the list of extensions from the extension expression.
151 Bool get_extlist(const String &extexpr, Vector<String> &extlist);
152
153 // Get the first extension with HDU type "data" from the
154 // list of indices. Returns "-1" if there is none.
155 Int get_dataindex(const Vector<Int> &extindex);
156
157 // Get the error extension name for the given data extension.
158 String get_errorext(const Int &ext_index);
159
160 // Get the mask extension name for the given data extension.
161 String get_maskext(const Int &ext_index);
162
163 // Check the keywords with fixed values
164 Bool confirm_fix_keywords(const Int &ext_index);
165
166 // Check whether the extension has a certain HDU type.
167 Bool index_is_HDUtype(const Int &ext_index, const String &hdutype);
168
169 // Find and store all set of extensions
170 // that can be loaded as a quality image.
172};
173
174// class FitsKeywordList;
175
176// <summary>
177// Class for storing FITS Image extension information
178// </summary>
179
180// <use visibility=export>
181
182// <reviewed reviewer="" date="" tests="tFITSImgParser.cc">
183// </reviewed>
184
185// <prerequisite>
186// </prerequisite>
187
188// <etymology>
189// The class stores the essential information on a FITS
190// image extension.
191// </etymology>
192
193// <synopsis>
194// The class stores the essential information on a FITS image extension,
195// which is the FITS file name, the extension name, the extension version,
196// the index within the FITS file.
197// </synopsis>
198//
199// <example>
200// <srcblock>
201// FITSImgParser fitsImg("in.fits");
202// FITSExtInfo extinfo("in.fits", 0, "SCI", 1, True);
203// Int index = fitsImg.get_index(extinfo); // get the index of extension "[SCI, 1]"
204// </srcblock>
205// </example>
206//
207// <motivation>
208// Helper class for accessing multi-extension FITS files.
209// </motivation>
210//
211// # <todo asof="2011/02/17">
212// # </todo>
214 public:
215 // Construct the object
216 FITSExtInfo(const String &name, const uInt &extindex, const String &extname,
217 const Int &extversion, const Bool &hasdata);
218
219 // Construct the object
220 FITSExtInfo() { FITSExtInfo("", 0, "", 0, False); };
221
222 // Copy constructor (reference semantics)
224
225 // Destructor does nothing.
227
228 // Assignment (reference semantics).
230
231 // Relational operator.
232 Bool operator==(const FITSExtInfo &extinfo);
233
234 // All extension information as a string.
236
237 // Return the extension name.
238 String get_extname(void) { return extname_p; };
239
240 // Return the extension version.
241 Int get_extversion(void) { return extversion_p; };
242
243 // Return whether there is data.
244 Bool has_data(void) { return hasdata_p; };
245
246 // Add a list of keywords.
248
249 // Return a keyword.
250 FitsKeyword *get_keyword(const String kname) { return kwlist_p(kname.c_str()); };
251
252 private:
259};
260
261} // namespace casacore
262
263#endif
class FitsKeywordList;
Int get_extversion(void)
Return the extension version.
FITSExtInfo()
Construct the object.
FITSExtInfo(const FITSExtInfo &other)
Copy constructor (reference semantics).
String get_extexpr(void)
All extension information as a string.
~FITSExtInfo()
Destructor does nothing.
Bool operator==(const FITSExtInfo &extinfo)
Relational operator.
FITSExtInfo & operator=(const FITSExtInfo &other)
Assignment (reference semantics).
FitsKeywordList kwlist_p
FitsKeyword * get_keyword(const String kname)
Return a keyword.
Bool has_data(void)
Return whether there is data.
void add_kwlist(FitsKeywordList &kwlist)
Add a list of keywords.
FITSExtInfo(const String &name, const uInt &extindex, const String &extname, const Int &extversion, const Bool &hasdata)
Construct the object.
String get_extname(void)
Return the extension name.
void process_extension(HeaderDataUnit *h, const uInt &extindex)
Get the information on an extension.
FITSImgParser(const FITSImgParser &other)
Copy constructor (reference semantics).
String get_errorext(const Int &ext_index)
Get the error extension name for the given data extension.
uInt get_firstdata_index(void)
Get the index of the first extension with data.
void setup(void)
Setup the object (used by constructors).
static const int nKwords_p
Bool get_extlist(const String &extexpr, Vector< String > &extlist)
Extract the list of extensions from the extension expression.
uInt get_numhdu(void)
Get the number of extensions.
Vector< String > qualimglist_p
Bool is_qualityimg(const String &extexpr)
Check whether the extensions named in the extension expression can be loaded as a quality image.
Bool has_qualityimg(void)
Get the flag indicating at least one quality image.
Int get_index(const FITSExtInfo &extinfo)
Identify the index of an extension.
FITSImgParser(const String &name)
Construct a parser from the FITS file.
static const char * storeKwords_p[]
Bool confirm_fix_keywords(const Int &ext_index)
Check the keywords with fixed values.
Bool get_quality_data(const String &extexpr, Int &data_HDU, Int &error_HDU, String &error_type, Int &mask_HDU, String &mask_type, Int &mask_value)
Find all necessary access information for the extensions to be loaded as a quality image.
Int find_extension(const String &extname, const Int &extversion=-1)
Find an extension; return -1 if not found.
Bool find_qualimgs(void)
Find and store all set of extensions that can be loaded as a quality image.
Int get_dataindex(const Vector< Int > &extindex)
Get the first extension with HDU type "data" from the list of indices.
String get_maskext(const Int &ext_index)
Get the mask extension name for the given data extension.
FITSImgParser & operator=(const FITSImgParser &other)
Assignment (reference semantics).
String fitsname(Bool stripPath=False) const
Returns the name of the disk file.
Bool index_is_HDUtype(const Int &ext_index, const String &hdutype)
Check whether the extension has a certain HDU type.
String get_extlist_string(const String &delimiter, const String &qualmarker="", const String &fitsmarker="", const Bool &listall=True)
Get a string representation of the extension list.
~FITSImgParser()
Destructor, does not much.
linked list of FITS keywords
Definition fits.h:983
FITS keyword.
Definition fits.h:737
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
const Bool False
Definition aipstype.h:42
unsigned int uInt
Definition aipstype.h:49
String name() const
Return the name of the field.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41