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
36class SpectralCoordinate;
37
38class CoordinateSystem;
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
79// <motivation>
80// Restoring beams are used many places in image analysis tasks.
81// </motivation>
82
83// <todo>
84// </todo>
85
87public:
88
90
91 // Construct an empty beam set.
93
94 // Construct a beam set from an 2-D array of beams representing
95 // the frequency and stokes axis.
96 // Axis length 1 means it is valid for all channels cq. stokes.
97 // If the image has 0 spectral channels or stokes, the corresponding
98 // length of the axis in the provided matrix should be 1.
100 const Matrix<GaussianBeam>& beams
101 );
102
103 // construct an ImageBeamSet representing a single beam which is valid for
104 // all channels and stokes
106
107 // Create an ImageBeamSet of the specified shape with all
108 // GaussianBeams initialized to <src>beam</src>.
110
111 // The copy constructor (reference semantics).
113
115
116 // Assignment can change the shape (copy semantics).
118
119 // Beam sets are equal if the shapes and all corresponding beams are equal.
120 Bool operator== (const ImageBeamSet& other) const;
121 Bool operator!= (const ImageBeamSet& other) const;
122
123 // Beam sets are equivalent if both have no beams or if the
124 // expanded sets are equal. Expanded means that an axis can have
125 // length 0 or 1 and is (virtually) expanded to the length of the matching
126 // axis in the other beam set.
127 Bool equivalent (const ImageBeamSet& that) const;
128
129 // Get the number of elements in the beam array.
130 // <group>
132 { return _beams.size(); }
133 uInt size() const
134 { return _beams.size(); }
135 // </group>
136
138 { return _beams.size() == 1; }
139
140 // Does this beam set contain multiple beams?
142 { return _beams.size() > 1; }
143
144 // Is the beam set empty?
145 Bool empty() const
146 { return _beams.empty(); }
147
148 // Get the shape of the beam array. The minimum value for
149 // a component of the returned IPosition is always 1.
150 const IPosition& shape() const
151 { return _beams.shape(); }
152
153 // Get the number of channels in the beam array. Note that this will
154 // always return a minimum of 1, even if nchan was specified as 0 on construction.
155 uInt nchan() const
156 { return _beams.shape()[0]; }
157
158 // Get the number of stokes in the beam array. Note that this will always
159 // return a minimum of 1, even if nstokes was specified as 0 on construction.
160 uInt nstokes() const
161 { return _beams.shape()[1]; }
162
163 // Get the single global beam. If there are multiple beams,
164 // an exception is thrown.
165 const GaussianBeam& getBeam() const;
166
167 // Get the beam at the specified location.
168 // Note that a single channel or stokes in the beam set is valid for
169 // all channels cq. stokes.
170 // <group>
171 const GaussianBeam& getBeam(Int chan, Int stokes) const;
172 const GaussianBeam &operator()(Int chan, Int stokes) const
173 { return getBeam (chan, stokes); }
174 // </group>
175
176 // Get a beam at the given 2-dim IPosition. It should match exactly,
177 // thus a single channel or stokes in the beam set is not valid for all.
178 // const GaussianBeam& getBeam(const IPosition& pos) const
179 // { return _beams(pos); }
180
181 // Set the beam at the given location.
182 // The location must be within the beam set shape.
183 // If <src>chan</src> or <src>stokes</src> is negative, then the beam applies
184 // to all channels or stokes, respectively. If both are negative, the specified
185 // beam becomes the global beam and the beam set is resized to (1, 1).
186 void setBeam(Int chan, Int stokes, const GaussianBeam& beam);
187
188 // Resize the beam array. <src>nchan</src>=0 or <src>nstokes</src>=0
189 // is silently changed to 1.
191
192 // Return a subset of the beam array.
193 // The slicer is usually the slicer used for a subimage.
194 // The slicer can contain multiple stokes or channels, even if the
195 // beam set has only one.
196 ImageBeamSet subset (const Slicer& imageSlicer,
197 const CoordinateSystem& csys) const;
198
199 // Get the beam array.
201 { return _beams; }
202
203 // Set the beams in this beam set.
204 // The shape of the given array must match the beam set.
205 // It also matches if an axis in array or beam set has length 1, which
206 // means that it expands to the other length.
207 void setBeams(const Matrix<GaussianBeam>& beams);
208
209 // Set all beams to the same value.
210 void set(const GaussianBeam& beam);
211
212 // Get the beam in the set which has the smallest area.
214 { return _minBeam; }
215
216 // Get the beam in the set which has the largest area.
217 // Get the beam in the set which has the largest area.
219 { return _maxBeam; }
220
221 // Get the beam in the set which has the median area.
223
224 // Get the position of the beam with the minimum area.
227
228 // Get the position of the beam with the maximum area.
231
232 // Get the minimal, maximal, and median area beams and positions in the
233 // beam set matrix for the given stokes. If the stokes axis has length 1
234 // in the beam matrix, it is valid for all stokes and no checking is done
235 // that <src>stokes</src> is valid; the requested beam for the entire beam set
236 // is simply returned in this case.
237 // If the number of stokes in the beam matrix is >1, checking is done that
238 // the specified value of <src>stokes</src> is valid and if not, an exception
239 // is thrown.
240 // <group>
242 uInt stokes) const;
243
245 uInt stokes) const;
246
248 uInt stokes) const;
249 // </group>
250
251 static const String& className();
252
253 // Get the beam that has the smallest minor axis. If multiple beams have
254 // the smallest minor axis, the beam in this subset with the smallest area
255 // will be returned.
257
258 // convert ImageBeamSet to and from record
259 // <group>
260 static ImageBeamSet fromRecord(const Record& rec);
262 //</group>
263
264 // If verbose, log all beams, if not just summarize beam stats.
265 void summarize(LogIO& log, Bool verbose, const CoordinateSystem& csys) const;
266
267 // Modify the beam set by rotating all beams counterclockwise through the
268 // specified angle. If unwrap=True, unwrap the new position angle(s) so that
269 // it falls in the range -90 to 90 degrees before setting it.
270 void rotate(const Quantity& angle, Bool unwrap=False);
271
272 // get all the beam areas in a single quantum matrix.
274
275 // get all the major axes, minor axes, and pas in quantum matrices.
276 // The returned map has keys "major", "minor", and "pa".
277 const std::map<String, Quantum<Matrix<double>>> paramMatrices(
278 const Unit& majminUnit=Unit("arcsec"), const Unit& paUnit="deg"
279 ) const;
280
281private:
282
284
290
292
293 // common code for replacing a beam in a multi-beam set
295 const GaussianBeam& beam, const IPosition& location1,
296 const IPosition& location2, Bool overwriteMaxMin
297 );
298
299 // Show the spectral info.
300 static void _chanInfoToStream(
301 ostream& os, const SpectralCoordinate *spCoord,
302 const uInt chan, const uInt chanWidth, const uInt freqPrec,
303 const uInt velWidth, const uInt velPrec
304 );
305
306 // Show the beam info.
307 static void _beamToStream(
308 ostream& os, const GaussianBeam& beam,
309 const Unit& unit
310 );
311};
312
313// Show the beam set info.
314ostream &operator<<(ostream &os, const ImageBeamSet& beamSet);
315
316}
317
318#endif
319
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:223
this file contains all the compiler specific defines
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
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40