casacore
Loading...
Searching...
No Matches
ImageBeamSet.h
Go to the documentation of this file.
1// # Copyright (C) 1996,1997,1998,1999,2000,2001,2003
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: casa-feedback@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#ifndef IMAGES_IMAGEBEAMSET_H
26#define IMAGES_IMAGEBEAMSET_H
27
28#include <casacore/casa/aips.h>
29#include <casacore/casa/Arrays/Matrix.h>
30#include <casacore/scimath/Mathematics/GaussianBeam.h>
31// #include <casacore/measures/Measures/Stokes.h>
32#include <map>
33
34namespace casacore {
35
37
39
40// <summary>
41// Represents a set of restoring beams associated with an image.
42// </summary>
43
44// <use visibility=export>
45
46// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
47// </reviewed>
48
49// <prerequisite>
50// </prerequisite>
51
52// <etymology>
53// A Set of Beams associated with an Image.
54// </etymology>
55
56// <synopsis>
57// This class represents a set of restoring beams associated with
58// a deconvolved image. Internally, the beams are stored in a Matrix in
59// which the first dimension represents the spectral axis and the second
60// dimension represents the polarization axis. Methods which take the number
61// of channels and stokes as the input parameters will accept 0 for either of
62// these, in the cases where the corresponding axis is absent, but internally,
63// the associated axis of the storage Matrix will be set to one since a Matrix
64// with one dimension of length 0 must be empty. If one (or both) of the axes is
65// of length 1, the beam associated with that position is valid for all channels or
66// stokes at the position. For example, if one has an image with 10 spectral channels
67// and 4 stokes, and one has a beam set of dimensions (1, 4) associated with that image,
68// all channels for a given stokes will have the same beam. Similarly, if the beam set
69// is of shape (10, 1) in this case, all stokes will have the same beam for a given channel.
70// If the axis lengths of the beam set are greater than one, they must be exactly
71// the same length of the corresponding axes in the associated image.
72// </synopsis>
73//
74// <example>
75
76// </example>
77
78// <motivation>
79// Restoring beams are used many places in image analysis tasks.
80// </motivation>
81
82// <todo>
83// </todo>
84
86 public:
88
89 // Construct an empty beam set.
91
92 // Construct a beam set from an 2-D array of beams representing
93 // the frequency and stokes axis.
94 // Axis length 1 means it is valid for all channels cq. stokes.
95 // If the image has 0 spectral channels or stokes, the corresponding
96 // length of the axis in the provided matrix should be 1.
98
99 // construct an ImageBeamSet representing a single beam which is valid for
100 // all channels and stokes
102
103 // Create an ImageBeamSet of the specified shape with all
104 // GaussianBeams initialized to <src>beam</src>.
106
107 // The copy constructor (reference semantics).
109
111
112 // Assignment can change the shape (copy semantics).
114
115 // Beam sets are equal if the shapes and all corresponding beams are equal.
116 Bool operator==(const ImageBeamSet& other) const;
117 Bool operator!=(const ImageBeamSet& other) const;
118
119 // Beam sets are equivalent if both have no beams or if the
120 // expanded sets are equal. Expanded means that an axis can have
121 // length 0 or 1 and is (virtually) expanded to the length of the matching
122 // axis in the other beam set.
123 Bool equivalent(const ImageBeamSet& that) const;
124
125 // Get the number of elements in the beam array.
126 // <group>
127 uInt nelements() const { return _beams.size(); }
128 uInt size() const { return _beams.size(); }
129 // </group>
130
131 Bool hasSingleBeam() const { return _beams.size() == 1; }
132
133 // Does this beam set contain multiple beams?
134 Bool hasMultiBeam() const { return _beams.size() > 1; }
135
136 // Is the beam set empty?
137 Bool empty() const { return _beams.empty(); }
138
139 // Get the shape of the beam array. The minimum value for
140 // a component of the returned IPosition is always 1.
141 const IPosition& shape() const { return _beams.shape(); }
142
143 // Get the number of channels in the beam array. Note that this will
144 // always return a minimum of 1, even if nchan was specified as 0 on construction.
145 uInt nchan() const { return _beams.shape()[0]; }
146
147 // Get the number of stokes in the beam array. Note that this will always
148 // return a minimum of 1, even if nstokes was specified as 0 on construction.
149 uInt nstokes() const { return _beams.shape()[1]; }
150
151 // Get the single global beam. If there are multiple beams,
152 // an exception is thrown.
153 const GaussianBeam& getBeam() const;
154
155 // Get the beam at the specified location.
156 // Note that a single channel or stokes in the beam set is valid for
157 // all channels cq. stokes.
158 // <group>
159 const GaussianBeam& getBeam(Int chan, Int stokes) const;
160 const GaussianBeam& operator()(Int chan, Int stokes) const { return getBeam(chan, stokes); }
161 // </group>
162
163 // Get a beam at the given 2-dim IPosition. It should match exactly,
164 // thus a single channel or stokes in the beam set is not valid for all.
165 // const GaussianBeam& getBeam(const IPosition& pos) const
166 // { return _beams(pos); }
167
168 // Set the beam at the given location.
169 // The location must be within the beam set shape.
170 // If <src>chan</src> or <src>stokes</src> is negative, then the beam applies
171 // to all channels or stokes, respectively. If both are negative, the specified
172 // beam becomes the global beam and the beam set is resized to (1, 1).
173 void setBeam(Int chan, Int stokes, const GaussianBeam& beam);
174
175 // Resize the beam array. <src>nchan</src>=0 or <src>nstokes</src>=0
176 // is silently changed to 1.
178
179 // Return a subset of the beam array.
180 // The slicer is usually the slicer used for a subimage.
181 // The slicer can contain multiple stokes or channels, even if the
182 // beam set has only one.
183 ImageBeamSet subset(const Slicer& imageSlicer, const CoordinateSystem& csys) const;
184
185 // Get the beam array.
186 const Matrix<GaussianBeam>& getBeams() const { return _beams; }
187
188 // Set the beams in this beam set.
189 // The shape of the given array must match the beam set.
190 // It also matches if an axis in array or beam set has length 1, which
191 // means that it expands to the other length.
192 void setBeams(const Matrix<GaussianBeam>& beams);
193
194 // Set all beams to the same value.
195 void set(const GaussianBeam& beam);
196
197 // Get the beam in the set which has the smallest area.
199
200 // Get the beam in the set which has the largest area.
201 // Get the beam in the set which has the largest area.
203
204 // Get the beam in the set which has the median area.
206
207 // Get the position of the beam with the minimum area.
209
210 // Get the position of the beam with the maximum area.
212
213 // Get the minimal, maximal, and median area beams and positions in the
214 // beam set matrix for the given stokes. If the stokes axis has length 1
215 // in the beam matrix, it is valid for all stokes and no checking is done
216 // that <src>stokes</src> is valid; the requested beam for the entire beam set
217 // is simply returned in this case.
218 // If the number of stokes in the beam matrix is >1, checking is done that
219 // the specified value of <src>stokes</src> is valid and if not, an exception
220 // is thrown.
221 // <group>
223
225
227 // </group>
228
229 static const String& className();
230
231 // Get the beam that has the smallest minor axis. If multiple beams have
232 // the smallest minor axis, the beam in this subset with the smallest area
233 // will be returned.
235
236 // convert ImageBeamSet to and from record
237 // <group>
238 static ImageBeamSet fromRecord(const Record& rec);
240 //</group>
241
242 // If verbose, log all beams, if not just summarize beam stats.
243 void summarize(LogIO& log, Bool verbose, const CoordinateSystem& csys) const;
244
245 // Modify the beam set by rotating all beams counterclockwise through the
246 // specified angle. If unwrap=True, unwrap the new position angle(s) so that
247 // it falls in the range -90 to 90 degrees before setting it.
248 void rotate(const Quantity& angle, Bool unwrap = False);
249
250 // get all the beam areas in a single quantum matrix.
252
253 // get all the major axes, minor axes, and pas in quantum matrices.
254 // The returned map has keys "major", "minor", and "pa".
255 const std::map<String, Quantum<Matrix<double>>> paramMatrices(
256 const Unit& majminUnit = Unit("arcsec"), const Unit& paUnit = "deg") const;
257
258 private:
260
266
268
269 // common code for replacing a beam in a multi-beam set
270 void _replaceBeam(const GaussianBeam& beam, const IPosition& location1,
271 const IPosition& location2, Bool overwriteMaxMin);
272
273 // Show the spectral info.
274 static void _chanInfoToStream(ostream& os, const SpectralCoordinate* spCoord, const uInt chan,
275 const uInt chanWidth, const uInt freqPrec, const uInt velWidth,
276 const uInt velPrec);
277
278 // Show the beam info.
279 static void _beamToStream(ostream& os, const GaussianBeam& beam, const Unit& unit);
280};
281
282// Show the beam set info.
283ostream& operator<<(ostream& os, const ImageBeamSet& beamSet);
284
285} // namespace casacore
286
287#endif
ConstIteratorSTL const_iterator
Definition Array.h:808
static const GaussianBeam NULL_BEAM
Matrix< GaussianBeam > _beams
void summarize(LogIO &log, Bool verbose, const CoordinateSystem &csys) const
If verbose, log all beams, if not just summarize beam stats.
void rotate(const Quantity &angle, Bool unwrap=False)
Modify the beam set by rotating all beams counterclockwise through the specified angle.
Array< GaussianBeam >::const_iterator BeamIter
uInt nstokes() const
Get the number of stokes in the beam array.
void setBeam(Int chan, Int stokes, const GaussianBeam &beam)
Get a beam at the given 2-dim IPosition.
IPosition getMinAreaBeamPosition() const
Get the position of the beam with the minimum area.
GaussianBeam getMedianAreaBeam() const
Get the beam in the set which has the median area.
Bool operator!=(const ImageBeamSet &other) const
void setBeams(const Matrix< GaussianBeam > &beams)
Set the beams in this beam set.
const std::map< String, Quantum< Matrix< double > > > paramMatrices(const Unit &majminUnit=Unit("arcsec"), const Unit &paUnit="deg") const
get all the major axes, minor axes, and pas in quantum matrices.
Bool equivalent(const ImageBeamSet &that) const
Beam sets are equivalent if both have no beams or if the expanded sets are equal.
ImageBeamSet(uInt nchan, uInt nstokes, const GaussianBeam &beam=GaussianBeam::NULL_BEAM)
Create an ImageBeamSet of the specified shape with all GaussianBeams initialized to beam.
ImageBeamSet & operator=(const ImageBeamSet &other)
Assignment can change the shape (copy semantics).
Record toRecord() const
Bool hasMultiBeam() const
Does this beam set contain multiple beams?
const GaussianBeam & getBeam(Int chan, Int stokes) const
Get the beam at the specified location.
static void _beamToStream(ostream &os, const GaussianBeam &beam, const Unit &unit)
Show the beam info.
ImageBeamSet(const GaussianBeam &beam)
construct an ImageBeamSet representing a single beam which is valid for all channels and stokes
ImageBeamSet(const ImageBeamSet &other)
The copy constructor (reference semantics).
static void _chanInfoToStream(ostream &os, const SpectralCoordinate *spCoord, const uInt chan, const uInt chanWidth, const uInt freqPrec, const uInt velWidth, const uInt velPrec)
Show the spectral info.
ImageBeamSet subset(const Slicer &imageSlicer, const CoordinateSystem &csys) const
Return a subset of the beam array.
uInt nelements() const
Get the number of elements in the beam array.
const IPosition & shape() const
Get the shape of the beam array.
const GaussianBeam & getMaxAreaBeamForPol(IPosition &pos, uInt stokes) const
void set(const GaussianBeam &beam)
Set all beams to the same value.
GaussianBeam getMinAreaBeam() const
Get the beam in the set which has the smallest area.
const GaussianBeam & getMinAreaBeamForPol(IPosition &pos, uInt stokes) const
Get the minimal, maximal, and median area beams and positions in the beam set matrix for the given st...
Bool operator==(const ImageBeamSet &other) const
Beam sets are equal if the shapes and all corresponding beams are equal.
GaussianBeam getMaxAreaBeam() const
Get the beam in the set which has the largest area.
static ImageBeamSet fromRecord(const Record &rec)
convert ImageBeamSet to and from record
Bool empty() const
Is the beam set empty?
const Quantum< Matrix< double > > getAreas() const
get all the beam areas in a single quantum matrix.
Matrix< Double > _areas
const GaussianBeam & getBeam() const
Get the single global beam.
uInt nchan() const
Get the number of channels in the beam array.
ImageBeamSet(const Matrix< GaussianBeam > &beams)
Construct a beam set from an 2-D array of beams representing the frequency and stokes axis.
const GaussianBeam & getMedianAreaBeamForPol(IPosition &pos, uInt stokes) const
ImageBeamSet()
Construct an empty beam set.
Bool hasSingleBeam() const
const Matrix< GaussianBeam > & getBeams() const
Get the beam array.
IPosition getMaxAreaBeamPosition() const
Get the position of the beam with the maximum area.
void _replaceBeam(const GaussianBeam &beam, const IPosition &location1, const IPosition &location2, Bool overwriteMaxMin)
common code for replacing a beam in a multi-beam set
const GaussianBeam getSmallestMinorAxisBeam() const
Get the beam that has the smallest minor axis.
void resize(uInt nchan, uInt nstokes)
Resize the beam array.
const GaussianBeam & operator()(Int chan, Int stokes) const
static const String & className()
static const String _DEFAULT_AREA_UNIT
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
ostream & operator<<(ostream &os, const IComplex &)
Show on ostream.
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode log(const LatticeExprNode &expr)
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