Line data Source code
1 : //# Copyright (C) 2009
2 : //# Associated Universities, Inc. Washington DC, USA.
3 : //#
4 : //# This library is free software; you can redistribute it and/or modify it
5 : //# under the terms of the GNU Library General Public License as published by
6 : //# the Free Software Foundation; either version 2 of the License, or (at your
7 : //# option) any later version.
8 : //#
9 : //# This library is distributed in the hope that it will be useful, but WITHOUT
10 : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 : //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 : //# License for more details.
13 : //#
14 : //# You should have received a copy of the GNU Library General Public License
15 : //# along with this library; if not, write to the Free Software Foundation,
16 : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17 : //#
18 : //# Correspondence concerning AIPS++ should be addressed as follows:
19 : //# Internet email: aips2-request@nrao.edu.
20 : //# Postal address: AIPS++ Project Office
21 : //# National Radio Astronomy Observatory
22 : //# 520 Edgemont Road
23 : //# Charlottesville, VA 22903-2475 USA
24 : //#
25 : //# $Id$
26 :
27 : #ifndef IMAGEANALYSIS_IMAGEMETADATABASE_H
28 : #define IMAGEANALYSIS_IMAGEMETADATABASE_H
29 :
30 : #include <casacore/images/Images/ImageInterface.h>
31 : #include <imageanalysis/ImageTypedefs.h>
32 : #include <casacore/casa/aips.h>
33 :
34 : namespace casa {
35 :
36 : // <summary>
37 : // Base class for image metadata access.
38 : // </summary>
39 :
40 : // <use visibility=export>
41 :
42 : // <reviewed reviewer="" date="" tests="" demos="">
43 : // </reviewed>
44 :
45 : // <prerequisite>
46 : // <li> <linkto class=casacore::ImageInterface>ImageInterface</linkto>
47 : // </prerequisite>
48 :
49 : // <etymology>
50 : // </etymology>
51 :
52 : // <synopsis>
53 : // </synopsis>
54 :
55 : // <example>
56 : // </example>
57 :
58 : // <motivation>
59 :
60 : // </motivation>
61 :
62 : class ImageMetaDataConstants {
63 : public:
64 : const static casacore::String MASKS;
65 :
66 : const static casacore::String _BEAMMAJOR, _BEAMMINOR, _BEAMPA, _BMAJ, _BMIN, _BPA,
67 : _BUNIT, _CDELT, _CRPIX, _CRVAL, _CTYPE, _CUNIT, _DATAMAX, _DATAMIN,
68 : _EPOCH, _EQUINOX, _IMTYPE, _MAXPIXPOS, _MAXPOS, _MINPIXPOS,
69 : _MINPOS, _OBJECT, _OBSDATE, _OBSERVER, _PROJECTION,
70 : _RESTFREQ, _REFFREQTYPE, _SHAPE, _TELESCOPE;
71 :
72 : };
73 :
74 : template <class T> class ImageMetaDataBase {
75 :
76 : public:
77 :
78 :
79 : ImageMetaDataBase() = delete;
80 :
81 0 : virtual ~ImageMetaDataBase() {}
82 :
83 : casacore::CoordinateSystem coordsys(const std::vector<casacore::Int>& axes) const;
84 :
85 : casacore::DataType dataType() const;
86 :
87 : casacore::uInt nChannels() const;
88 :
89 : // Is the specified channel number valid for this image?
90 : casacore::Bool isChannelNumberValid(const casacore::uInt chan) const;
91 :
92 : // Get the pixel number on the polarization axis of the specified stokes parameter.
93 : // If the specified stokes parameter does not exist in the image, the value returned
94 : // is not gauranteed to be anything other than outside the range of 0 to nStokes-1
95 : // inclusive. Return -1 if the specified stokes parameter is not present or
96 : // if this image does not have a polarization axis.
97 :
98 : casacore::Int stokesPixelNumber(const casacore::String& stokesString) const;
99 :
100 : // get the stokes parameter at the specified pixel value on the polarization axis.
101 : // returns "" if the specified pixel is out of range or if no polarization axis.
102 :
103 : casacore::String stokesAtPixel(const casacore::uInt pixel) const;
104 :
105 : // Get the number of stokes parameters in this image.
106 : casacore::uInt nStokes() const;
107 :
108 : // is the specified stokes parameter present in the image?
109 : casacore::Bool isStokesValid(const casacore::String& stokesString) const;
110 :
111 : // Get the shape of the direction axes. Returns a two element
112 : // casacore::Vector if there is a direction coordinate, if not returns a zero element
113 : // vector.
114 :
115 : casacore::Vector<casacore::Int> directionShape() const;
116 :
117 : // if the specified stokes parameter is valid. A message suitable for
118 : // error notification is returned in the form of an in-out parameter
119 : //if one or both of these is invalid.
120 : casacore::Bool areChannelAndStokesValid(
121 : casacore::String& message, const casacore::uInt chan, const casacore::String& stokesString
122 : ) const;
123 :
124 : // get the bounding box in the image for the specified region.
125 : casacore::Record* getBoundingBox(const casacore::Record& region) const;
126 :
127 : // convert the header info to a casacore::Record and list to logger if verbose=true
128 : virtual casacore::Record toRecord(casacore::Bool verbose) const = 0;
129 :
130 : // get the value of the datum corresponding to the given casacore::FITS keyword.
131 : casacore::ValueHolder getFITSValue(const casacore::String& key) const;
132 :
133 : // if doVelocity=true, compute spectral velocities as well as frequencies, if false, only
134 : // compute frequencies.
135 : // <src>dirFrame</src> and <src>freqFrame</src> are the codes for the
136 : // frames for which it is desired that the returned measures should be specified.
137 : // In both cases, one can specify "native" for the native coordinate frame,
138 : // "cl" for the conversion layer frame, or any valid frame string from casacore::MDirection::showType()
139 : // or casacore::MFrequency::showType().
140 : casacore::Record toWorld(
141 : const casacore::Vector<double>& value, const casacore::String& format = "n",
142 : casacore::Bool doVelocity=true, const casacore::String& dirFrame="cl",
143 : const casacore::String& freqFrame="cl"
144 : ) const;
145 :
146 : protected:
147 : ImageMetaDataBase(SPCIIT);
148 :
149 : casacore::LogIO& _getLog() { return _log; }
150 :
151 : virtual const casacore::ImageInfo& _getInfo() const = 0;
152 :
153 : virtual const casacore::CoordinateSystem& _getCoords() const = 0;
154 :
155 : virtual casacore::Vector<casacore::String> _getAxisNames() const = 0;
156 :
157 : virtual casacore::Vector<casacore::String> _getAxisUnits() const = 0;
158 :
159 : virtual casacore::GaussianBeam _getBeam() const = 0;
160 :
161 : virtual casacore::String _getBrightnessUnit() const = 0;
162 :
163 : virtual casacore::String _getImType() const = 0;
164 :
165 : virtual std::vector<casacore::Quantity> _getIncrements() const = 0;
166 :
167 : virtual casacore::Vector<casacore::String> _getMasks() const = 0;
168 :
169 : virtual casacore::String _getObject() const = 0;
170 :
171 : virtual casacore::String _getEquinox() const = 0;
172 :
173 : virtual casacore::MEpoch _getObsDate() const = 0;
174 :
175 : casacore::String _getEpochString() const;
176 :
177 : virtual casacore::String _getObserver() const = 0;
178 :
179 : virtual casacore::String _getProjection() const;
180 :
181 : virtual casacore::String _getRefFreqType() const = 0;
182 :
183 : virtual casacore::Vector<casacore::Double> _getRefPixel() const = 0;
184 :
185 : virtual casacore::Vector<casacore::Quantity> _getRefValue() const = 0;
186 :
187 : virtual casacore::Quantity _getRestFrequency() const = 0;
188 :
189 : casacore::IPosition _getShape() const;
190 :
191 : virtual casacore::Record _getStatistics() const = 0;
192 :
193 : virtual casacore::String _getTelescope() const = 0;
194 :
195 : casacore::Record _makeHeader() const;
196 :
197 : void _toLog(const casacore::Record& header) const;
198 :
199 : casacore::uInt _getAxisNumber(const casacore::String& key) const;
200 :
201 : casacore::Record _calcStats() const;
202 :
203 : const casacore::TableRecord _miscInfo() const;
204 :
205 : casacore::uInt _ndim() const;
206 :
207 : virtual casacore::Vector<casacore::String> _getStokes() const = 0;
208 :
209 : private:
210 : SPCIIT _image;
211 : mutable casacore::LogIO _log;
212 : mutable casacore::IPosition _shape;
213 :
214 : // precision < 0 => use default precision when printing numbers
215 : void _fieldToLog(const casacore::Record& header, const casacore::String& field, casacore::Int precision=-1) const;
216 :
217 : casacore::String _doStandardFormat(casacore::Double value, const casacore::String& unit) const;
218 :
219 : casacore::Record _calcStatsT(
220 : std::shared_ptr<const casacore::ImageInterface<T> > image
221 : ) const;
222 :
223 : static casacore::Record _worldVectorToRecord(
224 : const casacore::CoordinateSystem& csys, const casacore::Vector<casacore::Double>& world, casacore::Int c,
225 : const casacore::String& format,
226 : casacore::Bool isAbsolute, casacore::Bool showAsAbsolute, casacore::Bool doVelocity,
227 : casacore::MDirection::Types dirFrame, casacore::MFrequency::Types freqFrame
228 : );
229 :
230 : static casacore::Record _worldVectorToMeasures(
231 : const casacore::CoordinateSystem& csys,
232 : const casacore::Vector<casacore::Double>& world, casacore::Int c, casacore::Bool abs, casacore::Bool doVelocity,
233 : casacore::MDirection::Types dirFrame, casacore::MFrequency::Types freqFrame
234 : );
235 :
236 : };
237 :
238 : }
239 :
240 : #ifndef AIPS_NO_TEMPLATE_SRC
241 : #include <imageanalysis/ImageAnalysis/ImageMetaDataBase.tcc>
242 : #endif //# AIPS_NO_TEMPLATE_SRC
243 :
244 : #endif
|