casacore
Loading...
Searching...
No Matches
ImageInfo.h
Go to the documentation of this file.
1// # ImageInfo.h: Miscellaneous information related to an image
2// # Copyright (C) 1998,1999,2000,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_IMAGEINFO_H
27#define IMAGES_IMAGEINFO_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Utilities/RecordTransformable.h>
31
32#include <casacore/casa/Arrays/Vector.h>
33#include <casacore/casa/Quanta/Quantum.h>
34#include <casacore/casa/BasicSL/String.h>
35
36#include <casacore/coordinates/Coordinates/CoordinateSystem.h>
37
38#include <casacore/images/Images/ImageBeamSet.h>
39
40// # Forward declarations
41#include <casacore/casa/iosfwd.h>
42namespace casacore { // # NAMESPACE CASACORE - BEGIN
43
44class LoggerHolder;
45
46// <summary>
47// Miscellaneous information related to an image.
48// </summary>
49
50// <use visibility=export>
51
52// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
53// </reviewed>
54
55// <prerequisite>
56// <li> <linkto class=RecordTransformable>RecordTransformable</linkto>
57// </prerequisite>
58//
59// <synopsis>
60// This class is used to record information about an image.
61// At present it contains the following:
62// <ol>
63// <li> The restoring beam(s)
64// <li> A parameter describing what quantity the image holds.
65// <li> The image object name.
66// </ol>
67//
68// Support for per plane (eg channel) dependent beams have been added.
69// </synopsis>
70//
71// <example>
72// The interface is a simple get/set interface. Note that the "set" methods
73// can be chained together since each set method returns a reference to its
74// object (rather like cout).
75// <srcblock>
76// ImageInfo ii;
77// ii.setRestoringBeam(Quantity(30,"arcsec"), Quantity(10,"arcsec"),
78// Quantity(-18,"deg"));
79// ...
80// cout << "The restoring beam is : " << oi.restoringBeam() << endl;
81// </srcblock>
82// </example>
83//
84// <motivation>
85// This sort of information needed a standard place to go with a
86// standard interface so it could be moved out of MiscInfo.
87// </motivation>
88
90 public:
91 // This enum defines the actual quantity being held in an image
92 // It's really only used for descriptive information.
109
110 // Default constructor
111
113
114 // Destructor
116
117 // Copy constructor (copy semantics)
118 ImageInfo(const ImageInfo& other);
119
120 // Assignment (copy semantics)
122
123 // Set and get the Image Type.
124 // <group>
129 // </group>
130
131 // Set and get the Image object name
132 // <group>
135 // </group>
136
137 // Functions to interconvert between an ImageInfo and a record. These
138 // functions are inherited from class
139 // <linkto class=RecordTransformable>RecordTransformable</linkto>. As new
140 // fields get added to ImageInfo these functions should be augmented. Missing
141 // fields should not generate an error to in fromRecord to allow for
142 // backwards compatibility - null values should be supplied instead.
143 // The record field names are: "restoringbeam, imagetype, objectname".
144 // <group>
145 virtual Bool toRecord(String& error, RecordInterface& outRecord) const;
146 virtual Bool fromRecord(String& error, const RecordInterface& inRecord);
147 // </group>
148
149 // In some circumstances it might be useful to know what the defaults for
150 // the various values are so you can check if they have been set.
151 // The default restoring beam is a null vector.
152 // <group>
156 // </group>
157
158 // Functions to interconvert between an ImageInfo and FITS keywords
159 // (converted to a Record). Failure of <src>fromFITS</src>
160 // should probably not be regarded as fatal as the default ImageInfo
161 // values are viable. For each item contained
162 // in the ImageInfo, an attempt to decode it from FITS is made.
163 // If any of them fail, False is returned, but it attempts to decode
164 // them all. For those that fail an error message is held in <src>error</src>
165 // in the order restoring beam, and image type.
166 // <src>error</src> will be returned of length 0 if the return
167 // value is True, else it will be length 2.
168 // <group>
169 Bool toFITS(String& error, RecordInterface& outRecord) const;
170 Bool fromFITS(Vector<String>& error, const RecordInterface& inRecord);
171 // </group>
172
173 // This function takes an unofficial fitsValue found on the Stokes axis
174 // and returns the appropriate ImageType. The idea is that you
175 // detect the unofficial value, drop the Stokes axis, and store
176 // the value as an ImageType in ImageInfo. Only values pertaining
177 // to beam, optical depth and spectral index are handled here. All others
178 // give back Undefined. See usage in Image FITS conversion classes.
180
181 // It might be useful to know what FITS keyword names are used in to/from
182 // FITS so we can remove them so they won't be used more than once. The
183 // names are in lower case.
185
186 // Convert the Miriad 'btype' strings to the ImageType. Some
187 // Miriad 'btype's are dealt with in Casacore via the Stokes
188 // axis (fractional_polarization, polarized_intensity, position_angle)
189 // and so these will return Undefined.
191
192 // Set and get the beam.
193 // Zero-based <src>channel</src> and <src>stokes</src> are
194 // necessary and used if and only if the ImageBeamSet
195 // has multiple beams for such an axis. If just a single beam, that beam
196 // is returned. If no (or a null) beam, a null beam is returned.
197 GaussianBeam restoringBeam(Int channel = -1, Int stokes = -1) const;
198
199 // Set the single global restoring beam. An exception will be
200 // thrown if this object already has multiple beams. In that case,
201 // the caller must call removeRestoringBeam() first.
203 // #/// Added to build casarest with nrao-nov12
204 void setRestoringBeam(const Quantum<Double>& major, const Quantum<Double>& minor,
205 const Quantum<Double>& pa) {
206 setRestoringBeam(GaussianBeam(major, minor, pa));
207 }
208
209 // Remove all beams (global or per plane) associated with this object.
211
212 // Get the beam set associated with this object
213 const ImageBeamSet& getBeamSet() const;
214
215 // Set the beam for a specific plane.
216 // A value of <src>channel</src> or <src>stokes</src> of less than 0
217 // means that particular coordinate does not exist. Obviously, at least
218 // one of these must be zero or greater. The only consistency checking
219 // that is done is to ensure the values of <src>channel</src> and
220 // <src>stokes</src> are consistent with the size of the beam array.
221 // Additional consistency checks are done when this object is added via
222 // ImageInterface<T>::setImageInfo().
223 // <br>This function cannot be used if no beams have been set via set(All)Beams.
224 // <group>
225 void setBeam(Int channel, Int stokes, const Quantity& major, const Quantity& minor,
226 const Quantity& pa);
227
228 void setBeam(Int channel, Int stokes, const GaussianBeam& beam);
229 // </group>
230
231 // does this object contain multiple beams?
232 Bool hasMultipleBeams() const { return _beams.hasMultiBeam(); }
233
234 // does this object contain a single beam
235 Bool hasSingleBeam() const { return _beams.hasSingleBeam(); }
236
237 // Does this object contain one or more beams?
238 Bool hasBeam() const { return !_beams.empty(); }
239
240 // <group>
241 // Number of channels and stokes in per hyper-plane beam array
242 uInt nChannels() const { return _beams.nchan(); }
243 uInt nStokes() const { return _beams.nstokes(); }
244 // </group>
245
246 // <group>
247 // Initialize all per-plane beams to the same value
248 void setAllBeams(const uInt nChannels, const uInt nStokes, const GaussianBeam& beam);
249
250 // Set the per plane beams array directly.
251 void setBeams(const ImageBeamSet& beams);
252 // </group>
253
254 // This method is not meant for common use. New code should not use it.
255 // Get the restoring beam from a LoggerHolder (where the history is stored)
256 // as AIPS writes the beam in the FITS history rather than the header
257 // keywords. If there is no beam, False is returned, and the internal
258 // state of the object is unchanged.
260
261 // Convert the given beam to a Record.
262 Record beamToRecord(Int channel, Int stokes) const;
263
264 // Check if the beam set matches the coordinate axes sizes.
265 void checkBeamSet(const CoordinateSystem& coords, const IPosition& shape,
266 const String& imageName) const;
267
268 // Append the other beamset to this one.
269 void appendBeams(ImageInfo& infoThat, Int axis, Bool relax, LogIO& os,
270 const CoordinateSystem& csysThis, const CoordinateSystem& csysThat,
271 const IPosition& shapeThis, const IPosition& shapeThat);
272
273 // Combine beam sets for the concatenation of images and replace
274 // the beamset in this object by the result.
275 // If channel or stokes is the concatenation axis, that beam axis
276 // is concatenated. Otherwise it is checked if both beam sets
277 // match and are merged.
278 // If relax=False, an exception is thrown if mismatching.
279 void combineBeams(const ImageInfo& infoThat, const IPosition& shapeThis,
280 const IPosition& shapeThat, const CoordinateSystem& csysThis,
281 const CoordinateSystem& csysThat, Int axis, Bool relax, LogIO& os);
282
283 // Reset the info and beamset of this image with the appropriate part of
284 // the beam set of the concat image it is part of.
285 // It returns the number of channels or polarizations handled.
286 uInt setInfoSplitBeamSet(uInt ndone, const ImageInfo& concatInfo, const IPosition& shape,
287 const CoordinateSystem& csys, Int concatAxis);
288
289 // Concatenate the beam sets along the frequency axis.
290 void concatFreqBeams(ImageBeamSet& beamsOut, const ImageInfo& infoThat, Int nchanThis,
291 Int nchanThat, Bool relax, LogIO& os) const;
292
293 // Concatenate the beam sets along the stokes axis.
294 void concatPolBeams(ImageBeamSet& beamsOut, const ImageInfo& infoThat, Int npolThis, Int npolThat,
295 Bool relax, LogIO& os) const;
296
297 // Merge the beam sets and check if they match.
298 void mergeBeams(ImageBeamSet& beamsOut, const ImageInfo& infoThat, Bool relax, LogIO& os) const;
299
300 // If relax=True, give a warning message if warn=True and set to False.
301 // Otherwise give an error showing msg1 only.
302 static void logMessage(Bool& warn, LogIO& os, Bool relax, const String& msg1,
303 const String msg2 = String());
304
305 // Get the beam area in terms of pixel size of the specified
306 // DirectionCoordinate
307 Double getBeamAreaInPixels(Int channel, Int stokes, const DirectionCoordinate&) const;
308
310
311 private:
312 // Common copy ctor/assignment operator code.
313 void copy_other(const ImageInfo& other);
314
315 // Set the restoring beam from the record.
316 void _setRestoringBeam(const Record& inRecord);
317
318 // Check if the beam shape matches the coordinates.
319 // It sets nchan and npol to the values in the image shape.
320 void _checkBeamShape(uInt& nchan, uInt& npol, const IPosition& shape,
321 const CoordinateSystem& csys) const;
322
323 // # Data members
325 mutable Bool _warnBeam; // # tell if warning is already given
328};
329
330// <summary> Global functions </summary>
331// <group name=Output>
332// Output declaration - useful for debugging.
333ostream& operator<<(ostream& os, const ImageInfo& info);
334// </group>
336} // namespace casacore
337
338#endif
void removeRestoringBeam()
Remove all beams (global or per plane) associated with this object.
void concatPolBeams(ImageBeamSet &beamsOut, const ImageInfo &infoThat, Int npolThis, Int npolThat, Bool relax, LogIO &os) const
Concatenate the beam sets along the stokes axis.
Bool hasSingleBeam() const
does this object contain a single beam
Definition ImageInfo.h:235
virtual Bool toRecord(String &error, RecordInterface &outRecord) const
Functions to interconvert between an ImageInfo and a record.
static ImageInfo::ImageTypes imageTypeFromFITS(Int fitsValue)
This function takes an unofficial fitsValue found on the Stokes axis and returns the appropriate Imag...
void concatFreqBeams(ImageBeamSet &beamsOut, const ImageInfo &infoThat, Int nchanThis, Int nchanThat, Bool relax, LogIO &os) const
Concatenate the beam sets along the frequency axis.
void _setRestoringBeam(const Record &inRecord)
Set the restoring beam from the record.
void setAllBeams(const uInt nChannels, const uInt nStokes, const GaussianBeam &beam)
Initialize all per-plane beams to the same value.
static ImageTypes defaultImageType()
In some circumstances it might be useful to know what the defaults for the various values are so you ...
ImageInfo(const ImageInfo &other)
Copy constructor (copy semantics).
ImageInfo()
Default constructor.
Bool hasMultipleBeams() const
does this object contain multiple beams?
Definition ImageInfo.h:232
void setBeam(Int channel, Int stokes, const Quantity &major, const Quantity &minor, const Quantity &pa)
Set the beam for a specific plane.
static String imageType(ImageInfo::ImageTypes type)
GaussianBeam restoringBeam(Int channel=-1, Int stokes=-1) const
Set and get the beam.
ImageBeamSet _beams
Definition ImageInfo.h:324
Bool toFITS(String &error, RecordInterface &outRecord) const
Functions to interconvert between an ImageInfo and FITS keywords (converted to a Record).
void _checkBeamShape(uInt &nchan, uInt &npol, const IPosition &shape, const CoordinateSystem &csys) const
Check if the beam shape matches the coordinates.
static void logMessage(Bool &warn, LogIO &os, Bool relax, const String &msg1, const String msg2=String())
If relax=True, give a warning message if warn=True and set to False.
void copy_other(const ImageInfo &other)
Common copy ctor/assignment operator code.
void setBeams(const ImageBeamSet &beams)
Set the per plane beams array directly.
uInt setInfoSplitBeamSet(uInt ndone, const ImageInfo &concatInfo, const IPosition &shape, const CoordinateSystem &csys, Int concatAxis)
Reset the info and beamset of this image with the appropriate part of the beam set of the concat imag...
~ImageInfo()
Destructor.
virtual Bool fromRecord(String &error, const RecordInterface &inRecord)
Initialise the class from a Record representation.
static String defaultObjectName()
const ImageBeamSet & getBeamSet() const
Get the beam set associated with this object.
ImageTypes
This enum defines the actual quantity being held in an image It's really only used for descriptive in...
Definition ImageInfo.h:93
void setBeam(Int channel, Int stokes, const GaussianBeam &beam)
static ImageInfo::ImageTypes MiriadImageType(const String &type)
Convert the Miriad 'btype' strings to the ImageType.
Bool getRestoringBeam(LoggerHolder &logger)
This method is not meant for common use.
uInt nChannels() const
Number of channels and stokes in per hyper-plane beam array.
Definition ImageInfo.h:242
ImageInfo::ImageTypes imageType() const
Set and get the Image Type.
void setRestoringBeam(const GaussianBeam &beam)
Set the single global restoring beam.
static ImageInfo::ImageTypes imageType(String type)
void setRestoringBeam(const Quantum< Double > &major, const Quantum< Double > &minor, const Quantum< Double > &pa)
Definition ImageInfo.h:204
void appendBeams(ImageInfo &infoThat, Int axis, Bool relax, LogIO &os, const CoordinateSystem &csysThis, const CoordinateSystem &csysThat, const IPosition &shapeThis, const IPosition &shapeThat)
Append the other beamset to this one.
ImageInfo & setImageType(ImageTypes type)
ImageTypes itsImageType
Definition ImageInfo.h:326
static Vector< String > keywordNamesFITS()
It might be useful to know what FITS keyword names are used in to/from FITS so we can remove them so ...
Bool fromFITS(Vector< String > &error, const RecordInterface &inRecord)
ImageInfo & operator=(const ImageInfo &other)
Assignment (copy semantics).
void mergeBeams(ImageBeamSet &beamsOut, const ImageInfo &infoThat, Bool relax, LogIO &os) const
Merge the beam sets and check if they match.
uInt nStokes() const
Definition ImageInfo.h:243
ImageInfo & setObjectName(const String &object)
String objectName() const
Set and get the Image object name.
void checkBeamSet(const CoordinateSystem &coords, const IPosition &shape, const String &imageName) const
Check if the beam set matches the coordinate axes sizes.
static Double getBeamAreaInPixels(const GaussianBeam &beam, const DirectionCoordinate &dc)
Double getBeamAreaInPixels(Int channel, Int stokes, const DirectionCoordinate &) const
Get the beam area in terms of pixel size of the specified DirectionCoordinate.
Record beamToRecord(Int channel, Int stokes) const
Convert the given beam to a Record.
static GaussianBeam defaultRestoringBeam()
void combineBeams(const ImageInfo &infoThat, const IPosition &shapeThis, const IPosition &shapeThat, const CoordinateSystem &csysThis, const CoordinateSystem &csysThat, Int axis, Bool relax, LogIO &os)
Combine beam sets for the concatenation of images and replace the beamset in this object by the resul...
Bool hasBeam() const
Does this object contain one or more beams?
Definition ImageInfo.h:238
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
LatticeExprNode pa(const LatticeExprNode &left, const LatticeExprNode &right)
This function finds 180/pi*atan2(left,right)/2.
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
unsigned int uInt
Definition aipstype.h:49
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
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
Quantum< Double > Quantity
Definition Quantum.h:40
double Double
Definition aipstype.h:53
ostream & operator<<(ostream &os, const ImageInfo &info)
Output declaration - useful for debugging.