casacore
Loading...
Searching...
No Matches
Gaussian2DParam.h
Go to the documentation of this file.
1//# Gaussian2DParam.h: Parameter handling for 2 dimensional Gaussian class
2//# Copyright (C) 2001,2002,2003
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 SCIMATH_GAUSSIAN2DPARAM_H
27#define SCIMATH_GAUSSIAN2DPARAM_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31#include <casacore/scimath/Functionals/Function.h>
32#include <casacore/casa/BasicSL/String.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36// <summary> Parameter handling for 2 dimensional Gaussian class
37// </summary>
38
39// <use visibility=local>
40
41// <reviewed reviewer="mwieringa" date="1996/10/d24" tests="tGaussian2D">
42// </reviewed>
43
44// <prerequisite>
45// <li> <linkto class="FunctionParam">FunctionParam</linkto> class
46// <li> <linkto class="Function">Function</linkto> class
47// </prerequisite>
48
49// <etymology>
50// A 2-dimensional Gaussian's parameters.
51// </etymology>
52
53// <synopsis>
54
55// A <src>Gaussian2D</src> is described by a height, center, and width,
56// and position angle.
57
58// The width of the Gaussian (for the constructors or the <src> setWidth
59// </src> function) is always specified in terms of the full width at half
60// maximum (FWHM). The major axis is parallel with the y axis when the
61// position angle is zero. The major axis will always have a larger width
62// than the minor axis.
63//
64// It is not possible to set the width of the major axis (using the <src>
65// setMajorAxis </src> function) smaller than the width of the current minor
66// axis. Similarly it is not possible to set the width of the minor axis
67// (using the <src> setMinorAxis </src> function) to be larger than the
68// current major axis. Exceptions are thrown if these rules are violated or
69// if either the major or minor axis is set to a non-positive width. To
70// set both axis in one hit use the <src> setWidth </src> function. All
71// these restrictions can be overcome when the parameters interface is used
72// (see below).
73//
74// The position angle is the angle between the y axis and the major axis and
75// is measured counter-clockwise, so a position angle of 45 degrees rotates
76// the major axis to the line where <src>y=-x</src>.
77// The position angle is always
78// specified and returned in radians. When using the <src> setPA </src>
79// function its value must be between -2pi and + 2pi, and the returned value
80// from the <src> pa </src> function will always be a value between 0 and
81// pi.
82//
83// The axial ratio can be used as an alternative to specifying the width of
84// the minor axis. It is the ratio between the minor and major axis
85// widths. The axial ratio is constrained to be between zero and one, and
86// specifying something different (using setAxialRatio) will throw an
87// exception.
88//
89// The peak height of the Gaussian can be specified at construction time or
90// by using the <src> setHeight </src> function. Alternatively the <src>
91// setFlux </src> function can be used to implicitly set the peak height by
92// specifying the integrated area under the Gaussian. The height (or flux)
93// can be positive, negative or zero, as this class makes no assumptions on
94// what quantity the height represents.
95//
96// <note role=tip> Changing the width of the Gaussian will not affect
97// its peak height but will change its flux. So you should always set the
98// width before setting the flux. </note>
99//
100// The parameter interface (see
101// <linkto class="FunctionParam">FunctionParam</linkto> class),
102// is used to provide an interface to the
103// <linkto module="Fitting"> Fitting </linkto> classes.
104//
105// There are 6 parameters that are used to describe the Gaussian:
106// <ol>
107// <li> The height of the Gaussian. This is identical to the value
108// returned using the <src> height </src> member function.
109// <li> The center of the Gaussian in the x direction. This is identical to
110// the value returned using the <src> xCenter </src> member function.
111// <li> The center of the Gaussian in the y direction. This is identical to
112// the value returned using the <src> yCenter </src> member function.
113// <li> The width (FWHM) of the Gaussian on one axis. Initially this will be
114// the major axis, but if the parameters are adjusted by a Fitting
115// class, it may become the axis with the smaller width. To aid
116// convergence of the non-linear fitting routines this parameter is
117// allowed to be negative. This does not affect the shape of the
118// Gaussian as the squares of the widths are used when evaluating the
119// function.
120// <li> A modified axial ratio. This parameter is the ratio of the width on
121// the 'other' axis (which initially is the minor axis) and axis given
122// by parameter 4. Because these internal widths are allowed to be
123// negative and because there is no constraints on which axis is the
124// larger one the modified axial ratio is not constrained to be between
125// zero and one.
126// <li> The rotation angle. This represents the angle (in radians) between
127// the axis used by parameter 4, and the y axis, measured
128// counterclockwise. If parameter 4 represents the major axis width
129// then this parameter will be identical to the position angle,
130// otherwise it will be different by 90 degrees. The tight constraints
131// on the value of the rotation angle enforced by the setPA() function
132// are relaxed so that any value between -6000 and 6000 is allowed. It
133// is still interpreted in radians.
134// </ol>
135//
136// An enumeration for the <src>HEIGHT</src>, <src>XCENTER</src>,
137// <src>YCENTER</src>, <src>YWIDTH</src>, <src>RATIO</src>, <src>PANGLE</src>
138// parameter index is provided, enabling the setting
139// and reading of parameters with the <src>[]</src> operator. The
140// <src>mask()</src> methods can be used to check and set the parameter masks.
141//
142// This class is in general used implicitly by the <src>Gaussian2D</src>
143// class only.
144//
145// <note role=tip>
146// Other points to bear in mind when fitting this class to measured data
147// are:
148// <ul>
149// <li> If you need to fit a circular Gaussian to data you MUST set the
150// axial ratio to one, and mask the position angle and axial ratio
151// parameters. This avoids rank deficiency in the fitting routines as
152// the position angle is meaningless when the major and minor axis are
153// equal.
154// <li> If fitting an elliptical Gaussian your initial model should not be a
155// circular Gaussian.
156// </ul>
157// </note>
158//
159// </synopsis>
160
161// <example>
162// <srcblock>
163// Gaussian2D<Double> g(10.0, 0.0, 0.0, 2.0, 1.0, 0.0);
164// Vector<Double> x(2);
165// x(0) = 1.0; x(1) = 0.5;
166// cout << "g(" << x(0) << "," << x(1) << ") = " << g(x) << endl;
167// </srcblock>
168// </example>
169
170// <motivation>
171// Gaussian2D objects allow us to represent models of
172// the sky in a more conventional way than the generic interface used in the
173// GaussianND class does.
174// </motivation>
175
176// <templating arg=T>
177// <li> T should have standard numerical operators and exp() function. Current
178// implementation only tested for real types (and AutoDiff of them).
179// </templating>
180
181// <thrown>
182// <li> Assertion in debug mode if attempt is made to set a negative width
183// <li> AipsError if incorrect parameter number specified.
184// </thrown>
185
186// <todo asof="2001/08/19">
187// <li> Gaussians that know about their DFT's could be required eventually.
188// </todo>
189
190template<class T> class Gaussian2DParam : public Function<T>
191{
192public:
193 //# Enumerations
195
196 //# Constructors
197 // Constructs the two dimensional Gaussians. Defaults:
198 // height=1, center=0, width(FWHM)=1, pa=0.
199 // <group>
202 const Vector<T> &width, const T &pa);
203 Gaussian2DParam(const T &height, const T &xCenter, const T &yCenter,
204 const T &majorAxis, const T &axialRatio,
205 const T &pa);
206 // </group>
207
208 // Copy constructor (deep copy)
209 // <group>
211 template <class W>
213 Function<T>(other),
214 fwhm2int(T(1.0)/sqrt(log(T(16.0)))) { majorAxis(); setPA(PA()); }
215 // </group>
216
217 // Copy assignment (deep copy)
219
220 // Destructor
222
223 //# Operators
224
225 // Variable dimensionality
226 virtual uInt ndim() const { return 2; }
227
228 //# Member functions
229 // Give name of function
230 virtual const String &name() const { static String x("gaussian2d");
231 return x; }
232
233 // Get or set the peak height of the Gaussian
234 // <group>
235 T height() const { return param_p[HEIGHT]; }
236 void setHeight(const T &height) { param_p[HEIGHT] = height; }
237 // </group>
238
239 // Get or set the analytical integrated area underneath the Gaussian.
240 // Use these functions as an alternative to the height functions.
241 // <group>
242 T flux() const;
243 void setFlux(const T &flux);
244 // </group>
245
246 // Get or set the center ordinate of the Gaussian
247 // <group>
250 T xCenter() const { return param_p[XCENTER]; }
251 void setXcenter(const T &cnter) { param_p[XCENTER] = cnter; }
252 T yCenter() const { return param_p[YCENTER]; }
253 void setYcenter(const T &cnter) { param_p[YCENTER] = cnter; }
254 // </group>
255
256 // Set or get the FWHM of the Gaussian.
257 // <group>
260 T majorAxis() const;
261 void setMajorAxis(const T &width);
262 T minorAxis() const;
263 void setMinorAxis(const T &width);
264 T axialRatio() const;
265 void setAxialRatio(const T &axialRatio);
266 // </group>
267
268 // Set/get the rotation angle (orientation) of the Gaussian. PA is given
269 // in radians counterclockwise.
270 // <group>
271 T PA() const;
272 void setPA(const T &pa);
273 // </group>
274
275protected:
276 // Constant to scale halfwidth at 1/e to FWHM
278 // cached vale of the PA
279 mutable T thePA;
280 // cached values of the cos and sine of thePA
281 // <group>
282 mutable T theSpa;
283 mutable T theCpa;
284 // </group>
285 // cached vale of the Xwidth = ratio*theYwidth;
286 mutable T theXwidth;
287
288 //# Make members of parent classes known.
289protected:
290 using Function<T>::param_p;
291public:
292 using Function<T>::nparameters;
293};
294
295
296} //# NAMESPACE CASACORE - END
297
298#ifndef CASACORE_NO_AUTO_TEMPLATES
299#include <casacore/scimath/Functionals/Gaussian2DParam.tcc>
300#endif //# CASACORE_NO_AUTO_TEMPLATES
301#endif
FunctionParam< T > param_p
The parameters and masks.
Definition Function.h:330
uInt nparameters() const
Returns the number of parameters.
Definition Function.h:228
T theXwidth
cached vale of the Xwidth = ratio*theYwidth;
T height() const
Get or set the peak height of the Gaussian.
Gaussian2DParam(const Gaussian2DParam< W > &other)
virtual const String & name() const
Give name of function.
T thePA
cached vale of the PA
void setCenter(const Vector< T > &center)
Vector< T > center() const
Get or set the center ordinate of the Gaussian.
virtual ~Gaussian2DParam()
Destructor.
Gaussian2DParam(const T &height, const T &xCenter, const T &yCenter, const T &majorAxis, const T &axialRatio, const T &pa)
Vector< T > width() const
Set or get the FWHM of the Gaussian.
T fwhm2int
Constant to scale halfwidth at 1/e to FWHM.
T PA() const
Set/get the rotation angle (orientation) of the Gaussian.
void setPA(const T &pa)
Gaussian2DParam(const Gaussian2DParam< T > &other)
Copy constructor (deep copy)
Gaussian2DParam()
Constructs the two dimensional Gaussians.
T theSpa
cached values of the cos and sine of thePA
void setMinorAxis(const T &width)
void setFlux(const T &flux)
void setYcenter(const T &cnter)
void setHeight(const T &height)
virtual uInt ndim() const
Variable dimensionality.
void setMajorAxis(const T &width)
void setAxialRatio(const T &axialRatio)
void setWidth(const Vector< T > &width)
Gaussian2DParam< T > & operator=(const Gaussian2DParam< T > &other)
Copy assignment (deep copy)
void setXcenter(const T &cnter)
T flux() const
Get or set the analytical integrated area underneath the Gaussian.
Gaussian2DParam(const T &height, const Vector< T > &center, const Vector< T > &width, const T &pa)
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.
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode sqrt(const LatticeExprNode &expr)
LatticeExprNode log(const LatticeExprNode &expr)