casacore
Loading...
Searching...
No Matches
ImageAttrGroup.h
Go to the documentation of this file.
1// # ImageAttrGroup.h: Abstract base class for an image attributes group
2// # Copyright (C) 2012
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_IMAGEATTRGROUP_H
27#define IMAGES_IMAGEATTRGROUP_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Containers/ValueHolder.h>
32#include <casacore/casa/Arrays/Vector.h>
33
34namespace casacore {
35
36// <summary>
37// Abstract base class for an image attributes group.
38// </summary>
39
40// <use visibility=export>
41
42// <reviewed reviewer="" date="" tests="tPagedmage.cc" demos="dPagedImage.cc">
43// </reviewed>
44
45// <prerequisite>
46// <li> <linkto class=ImageInterface>ImageInterface</linkto>
47// </prerequisite>
48
49// <etymology>
50// This class makes it possible to store extra attributes with an image to
51// describe atrbitrary meta information.
52// </etymology>
53
54// <synopsis>
55// For LOFAR it is needed to store extra meta information and be possible to
56// convert it from casacore table format to HDF5 format and vice-versa.
57// Furthermore, it must be possible to access the information in a way that
58// arbitrary attributes can be stored and retrieved in a way that is agnostic
59// to the format the image is stored in. It must also work fine for an image
60// stored in FITS format, be it that such an image cannot have such attributes.
61//
62// The attributes are divided into groups. A group resides in a subtable
63// of a casacore image or in a group of an HDF5 image. This class handles
64// the attributes of a group. It can get and put the attribute values, as well
65// as their unit and measure info (type and reference frame type).
66// For HDF5 images the unit is stored in attribute <src>attrname>_UNIT</src>
67// and the measure info in <src>attrname>_MEASINFO</src>. For casacore images
68// that info is stored as TableMeasure info in the column keywords.
69//
70// All attributes in a group must have the same number of values, where each
71// value can be a scalar or (small) array. The unit and measure info have
72// only one value, thus all values of an attribute have the same unit.
73// </synopsis>
74
75// <example>
76// This example shows how to get attributes from an image.
77// <srcblock>
78// // Open the image.
79// PagedImage<Float> myimage ("image.name");
80// // Open the attribute handler.
81// ImageAttrHandler& attrHandler = myimage.attrHandler();
82// // Get access to attibute group LOFAR_SOURCE.
83// ImageAttrGroup& lofarSource = attrHandler.openGroup ("LOFAR_SOURCE");
84// // Get the names of all attributes in this group.
85// Vector<String> attrNames = lofarSource.attrNames();
86// // Get the value of the ATTRNAME attribute (if there).
87// if (lofarSource.hasAttr ("ATTRNAME)) {
88// ValueHolder vh (lofarSource.getData ("ATTRNAME"));
89// Vector<String> name = vh.asString();
90// }
91// </srcblock>
92// The following example shows how to add a group and attribute.
93// <srcblock>
94// // Open the image.
95// PagedImage<Float> myimage ("image.name");
96// // Open the attribute handler.
97// ImageAttrHandler& attrHandler = myimage.attrHandler();
98// // Add attribute group LOFAR_SOURCE.
99// ImageAttrGroup& lofarSource = attrHandler.createGroup (LOFAR_SOURCE);
100// // Add an attribute which has unit Hz.
101// // The value has 2 values (e.g. for 2 frequency bands).
102// Vector<double> freqs(2);
103// freqs[0]=4.5e7; freqs[1]=5.5e7;
104// lofarSource.putData ("CENTER_FREQ", ValueHolder(freqs),
105// Vector<String(1,"Hz"));
106// </srcblock>
107// </example>
108//
109// <motivation>
110// LOFAR needed functionality to store arbitrary attributes.
111// </motivation>
113class ImageAttrGroup {
114 public:
115 // Default constructor.
116 ImageAttrGroup() {}
118 virtual ~ImageAttrGroup();
119
120 // Get the number of rows in the group.
121 virtual uInt nrows() const = 0;
122
123 // Test if an attribute exists.
124 virtual Bool hasAttr(const String& attrName) const = 0;
125
126 // Get all attribute names.
127 virtual Vector<String> attrNames() const = 0;
128
129 // Get the datatype of a attribute.
130 // It returns TpOther if the attribute is not defined.
131 virtual DataType dataType(const String& attrName) const = 0;
132
133 // Get the data of the given attribute in the given row
134 virtual ValueHolder getData(const String& attrName, uInt rownr) = 0;
135
136 // Get the data of all attributes in a rows.
137 virtual Record getDataRow(uInt rownr) = 0;
138
139 // Get the possible units of the values.
140 // An empty vector is returned if the attribute has no units.
141 virtual Vector<String> getUnit(const String& attrName) = 0;
142
143 // Get the possible measure info as type and Ref.
144 // An empty vector is returned if the attribute has no MEASINFO.
145 virtual Vector<String> getMeasInfo(const String& attrName) = 0;
146
147 // Put the data of the given attribute in the given row.
148 // If the row or attribute is new, it will be added. Note that the
149 // new row must be directly after the last row in the group.
150 // <br>If not empty, the units and MEASINFO will be put as column keywords.
151 // The MEASINFO vector must be given as type,Ref.
152 virtual void putData(const String& attrName, uInt rownr, const ValueHolder& data,
153 const Vector<String>& units = Vector<String>(),
154 const Vector<String>& measInfo = Vector<String>()) = 0;
155};
156
157} // namespace casacore
158
159#endif
virtual DataType dataType(const String &attrName) const =0
Get the datatype of a attribute.
virtual ValueHolder getData(const String &attrName, uInt rownr)=0
Get the data of the given attribute in the given row.
virtual Bool hasAttr(const String &attrName) const =0
Test if an attribute exists.
virtual void putData(const String &attrName, uInt rownr, const ValueHolder &data, const Vector< String > &units=Vector< String >(), const Vector< String > &measInfo=Vector< String >())=0
Put the data of the given attribute in the given row.
ImageAttrGroup()
Default constructor.
virtual uInt nrows() const =0
Get the number of rows in the group.
virtual Vector< String > getUnit(const String &attrName)=0
Get the possible units of the values.
virtual Vector< String > attrNames() const =0
Get all attribute names.
virtual Record getDataRow(uInt rownr)=0
Get the data of all attributes in a rows.
virtual Vector< String > getMeasInfo(const String &attrName)=0
Get the possible measure info as type and Ref.
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 int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40