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{
91public:
92
93 // This enum defines the actual quantity being held in an image
94 // It's really only used for descriptive information.
111
112// Default constructor
113
115
116// Destructor
118
119// Copy constructor (copy semantics)
120 ImageInfo(const ImageInfo &other);
121
122// Assignment (copy semantics)
124
125 // Set and get the Image Type.
126 // <group>
131 // </group>
132
133// Set and get the Image object name
134// <group>
137// </group>
138
139// Functions to interconvert between an ImageInfo and a record. These
140// functions are inherited from class
141// <linkto class=RecordTransformable>RecordTransformable</linkto>. As new
142// fields get added to ImageInfo these functions should be augmented. Missing
143// fields should not generate an error to in fromRecord to allow for
144// backwards compatibility - null values should be supplied instead.
145// The record field names are: "restoringbeam, imagetype, objectname".
146// <group>
147 virtual Bool toRecord(String& error, RecordInterface& outRecord) const;
148 virtual Bool fromRecord(String& error, const RecordInterface& inRecord);
149// </group>
150
151// In some circumstances it might be useful to know what the defaults for
152// the various values are so you can check if they have been set.
153// The default restoring beam is a null vector.
154// <group>
158// </group>
159
160// Functions to interconvert between an ImageInfo and FITS keywords
161// (converted to a Record). Failure of <src>fromFITS</src>
162// should probably not be regarded as fatal as the default ImageInfo
163// values are viable. For each item contained
164// in the ImageInfo, an attempt to decode it from FITS is made.
165// If any of them fail, False is returned, but it attempts to decode
166// them all. For those that fail an error message is held in <src>error</src>
167// in the order restoring beam, and image type.
168// <src>error</src> will be returned of length 0 if the return
169// value is True, else it will be length 2.
170// <group>
171 Bool toFITS(String & error, RecordInterface & outRecord) const;
172 Bool fromFITS(Vector<String>& error, const RecordInterface & inRecord);
173// </group>
174
175// This function takes an unofficial fitsValue found on the Stokes axis
176// and returns the appropriate ImageType. The idea is that you
177// detect the unofficial value, drop the Stokes axis, and store
178// the value as an ImageType in ImageInfo. Only values pertaining
179// to beam, optical depth and spectral index are handled here. All others
180// give back Undefined. See usage in Image FITS conversion classes.
182
183// It might be useful to know what FITS keyword names are used in to/from
184// FITS so we can remove them so they won't be used more than once. The
185// names are in lower case.
187
188// Convert the Miriad 'btype' strings to the ImageType. Some
189// Miriad 'btype's are dealt with in Casacore via the Stokes
190// axis (fractional_polarization, polarized_intensity, position_angle)
191// and so these will return Undefined.
193
194 // Set and get the beam.
195 // Zero-based <src>channel</src> and <src>stokes</src> are
196 // necessary and used if and only if the ImageBeamSet
197 // has multiple beams for such an axis. If just a single beam, that beam
198 // is returned. If no (or a null) beam, a null beam is returned.
199 GaussianBeam restoringBeam(Int channel=-1, Int stokes=-1) const;
200
201 // Set the single global restoring beam. An exception will be
202 // thrown if this object already has multiple beams. In that case,
203 // the caller must call removeRestoringBeam() first.
205 //#/// Added to build casarest with nrao-nov12
207 const Quantum<Double>& minor,
208 const Quantum<Double>& pa)
209 { setRestoringBeam (GaussianBeam (major, minor, pa)); }
210
211 // Remove all beams (global or per plane) associated with this object.
213
214 // Get the beam set associated with this object
215 const ImageBeamSet& getBeamSet() const;
216
217 // Set the beam for a specific plane.
218 // A value of <src>channel</src> or <src>stokes</src> of less than 0
219 // means that particular coordinate does not exist. Obviously, at least
220 // one of these must be zero or greater. The only consistency checking
221 // that is done is to ensure the values of <src>channel</src> and
222 // <src>stokes</src> are consistent with the size of the beam array.
223 // Additional consistency checks are done when this object is added via
224 // ImageInterface<T>::setImageInfo().
225 // <br>This function cannot be used if no beams have been set via set(All)Beams.
226 // <group>
227 void setBeam(Int channel, Int stokes, const Quantity& major,
228 const Quantity& minor, const Quantity& pa);
229
230 void setBeam(Int channel, Int stokes, const GaussianBeam& beam);
231 // </group>
232
233 // does this object contain multiple beams?
235 { return _beams.hasMultiBeam(); }
236
237 // does this object contain a single beam
239 { return _beams.hasSingleBeam(); }
240
241 // Does this object contain one or more beams?
242 Bool hasBeam() const
243 { return ! _beams.empty(); }
244
245 // <group>
246 // Number of channels and stokes in per hyper-plane beam array
248 { return _beams.nchan(); }
249 uInt nStokes() const
250 { return _beams.nstokes(); }
251 // </group>
252
253 // <group>
254 // Initialize all per-plane beams to the same value
256 const uInt nChannels, const uInt nStokes,
257 const GaussianBeam& beam
258 );
259
260 // Set the per plane beams array directly.
261 void setBeams(const ImageBeamSet& beams);
262 // </group>
263
264 // This method is not meant for common use. New code should not use it.
265 // Get the restoring beam from a LoggerHolder (where the history is stored)
266 // as AIPS writes the beam in the FITS history rather than the header
267 // keywords. If there is no beam, False is returned, and the internal
268 // state of the object is unchanged.
270
271 // Convert the given beam to a Record.
272 Record beamToRecord(Int channel, Int stokes) const;
273
274 // Check if the beam set matches the coordinate axes sizes.
275 void checkBeamSet (const CoordinateSystem& coords,
276 const IPosition& shape,
277 const String& imageName) const;
278
279 // Append the other beamset to this one.
280 void appendBeams (ImageInfo& infoThat,
281 Int axis, Bool relax, LogIO& os,
282 const CoordinateSystem& csysThis,
283 const CoordinateSystem& csysThat,
284 const IPosition& shapeThis,
285 const IPosition& shapeThat);
286
287 // Combine beam sets for the concatenation of images and replace
288 // the beamset in this object by the result.
289 // If channel or stokes is the concatenation axis, that beam axis
290 // is concatenated. Otherwise it is checked if both beam sets
291 // match and are merged.
292 // If relax=False, an exception is thrown if mismatching.
293 void combineBeams (const ImageInfo& infoThat,
294 const IPosition& shapeThis,
295 const IPosition& shapeThat,
296 const CoordinateSystem& csysThis,
297 const CoordinateSystem& csysThat,
298 Int axis,
299 Bool relax,
300 LogIO& os);
301
302 // Reset the info and beamset of this image with the appropriate part of
303 // the beam set of the concat image it is part of.
304 // It returns the number of channels or polarizations handled.
305 uInt setInfoSplitBeamSet (uInt ndone, const ImageInfo& concatInfo,
306 const IPosition& shape,
307 const CoordinateSystem& csys, Int concatAxis);
308
309 // Concatenate the beam sets along the frequency axis.
311 const ImageInfo& infoThat,
312 Int nchanThis,
313 Int nchanThat,
314 Bool relax,
315 LogIO& os) const;
316
317 // Concatenate the beam sets along the stokes axis.
319 const ImageInfo& infoThat,
320 Int npolThis,
321 Int npolThat,
322 Bool relax,
323 LogIO& os) const;
324
325 // Merge the beam sets and check if they match.
326 void mergeBeams (ImageBeamSet& beamsOut,
327 const ImageInfo& infoThat,
328 Bool relax,
329 LogIO& os) const;
330
331 // If relax=True, give a warning message if warn=True and set to False.
332 // Otherwise give an error showing msg1 only.
333 static void logMessage(Bool& warn, LogIO& os, Bool relax,
334 const String& msg1, const String msg2=String());
335
336 // Get the beam area in terms of pixel size of the specified
337 // DirectionCoordinate
339 const DirectionCoordinate&) const;
340
342 const GaussianBeam& beam, const DirectionCoordinate& dc
343 );
344
345private:
346 // Common copy ctor/assignment operator code.
347 void copy_other(const ImageInfo &other);
348
349 // Set the restoring beam from the record.
350 void _setRestoringBeam(const Record& inRecord);
351
352 // Check if the beam shape matches the coordinates.
353 // It sets nchan and npol to the values in the image shape.
354 void _checkBeamShape (uInt& nchan, uInt& npol,
355 const IPosition& shape,
356 const CoordinateSystem& csys) const;
357
358 //# Data members
360 mutable Bool _warnBeam; //# tell if warning is already given
363};
364
365// <summary> Global functions </summary>
366// <group name=Output>
367// Output declaration - useful for debugging.
368ostream &operator<<(ostream &os, const ImageInfo &info);
369// </group>
371
372
373} //# NAMESPACE CASACORE - END
374
375#endif
uInt nstokes() const
Get the number of stokes in the beam array.
Bool hasMultiBeam() const
Does this beam set contain multiple beams?
Bool empty() const
Is the beam set empty?
uInt nchan() const
Get the number of channels in the beam array.
Bool hasSingleBeam() const
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:238
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:234
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:359
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:95
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:247
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:206
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:361
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:249
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:242
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
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
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition ExprNode.h:1991
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53
ostream & operator<<(ostream &os, const ImageInfo &info)
Output declaration - useful for debugging.