casacore
Loading...
Searching...
No Matches
Gaussian3DParam.h
Go to the documentation of this file.
1// # Gaussian3DParam.h: Parameter handling for 3 dimensional Gaussian class
2// # Copyright (C) 2001,2002,2005
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_GAUSSIAN3DPARAM_H
27#define SCIMATH_GAUSSIAN3DPARAM_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/ArrayFwd.h>
31#include <casacore/casa/BasicSL/String.h>
32#include <casacore/scimath/Functionals/Function.h>
33#include <casacore/scimath/Mathematics/AutoDiff.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// <summary> Parameter handling for 3 dimensional Gaussian class
38// </summary>
39
40// <use visibility=local>
41
42// <reviewed reviewer="" date="" tests="tGaussian3DParam">
43// </reviewed>
44
45// <prerequisite>
46// <li> <linkto class="FunctionParam">FunctionParam</linkto> class
47// <li> <linkto class="Function">Function</linkto> class
48// </prerequisite>
49
50// <etymology>
51// A 3-dimensional Gaussian's parameters.
52// </etymology>
53
54// <synopsis>
55
56// A <src>Gaussian3D</src> is described by a height, center, width,
57// and two position angles.
58
59// The width of the Gaussian is now specified in terms of the full width
60// at half maximum (FWHM), as with the 1D and 2D Gaussian functional classes.
61
62// The three axis values refer to the x, y, and z axes, and unlike with the
63// 2D Gaussian any of the three axes may be the longest. Instead, the position
64// angles are restricted: The first position angle, theta, is the longitudinal
65// angle, referring to the rotation (counterclockwise) around the z-axis. The
66// second, phi, is the latidudinal angle, referring to the rotation around
67// the theta-rotated y axis. The domain of both angles is -pi/4 < A < pi/4.
68// (Note that the use of theta and phi corresponds to the mathematical
69// convention for these angles, not the physics convention.)
70
71// The parameter interface (see
72// <linkto class="FunctionParam">FunctionParam</linkto> class),
73// is used to provide an interface to the
74// <linkto module="Fitting"> Fitting </linkto> classes.
75//
76// There are 9 parameters that are used to describe the Gaussian:
77// <ol>
78// <li> The height of the Gaussian. This is identical to the value
79// returned using the <src> height </src> member function.
80// <li> The center of the Gaussian in the x direction. This is identical to
81// the value returned using the <src> xCenter </src> member function.
82// <li> The center of the Gaussian in the y direction. This is identical to
83// the value returned using the <src> yCenter </src> member function.
84// <li> The center of the Gaussian in the z direction. This is identical to
85// the value returned using the <src> zCenter </src> member function.
86// <li> The width of the Gaussian along the x-axis.
87// <li> The width of the Gaussian along the y-axis.
88// <li> The width of the Gaussian along the z-axis.
89// <li> The longitudinal position angle, theta (in radians)
90// <li> The latitudinal position angle, phi (also in radians).
91// </ol>
92
93// An enumeration for the <src>H</src>, <src>CX</src>,
94// <src>CY</src>,<src>CZ</src>, <src>AX</src>, <src>AY</src>,
95// <src>AZ</src>, <src>THETA</src>, <src>PHI</src>
96// parameter index is provided, enabling the setting
97// and reading of parameters with the <src>[]</src> operator. The
98// <src>mask()</src> methods can be used to check and set the parameter masks.
99//
100// This class is in general used implicitly by the <src>Gaussian3D</src>
101// class only.
102//
103// <note role=tip>
104// Other points to bear in mind when fitting this class to measured data
105// are:
106// <ul>
107// <li> If you need to fit a circular Gaussian to data you should mask one or
108// both position angles. This avoids rank deficiency in the fitting
109// routines as the position angle is meaningless when the axes are
110// equal.
111// </ul>
112// </note>
113//
114// </synopsis>
115
116// <example>
117// <srcblock>
118// Gaussian3D<Double> g(9.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0);
119// Vector<Double> x(3);
120// x(0) = 1.0; x(1) = 0.5; x(2) = 0.0
121// cout << "g(" << x(0) << "," << x(1) << "," << x(2) << ")=" << g(x) << endl;
122// </srcblock>
123// </example>
124
125// <templating arg=T>
126// <li> T should have standard numerical operators and exp() function. Current
127// implementation only tested for real types (and AutoDiff of them).
128// </templating>
129
130// <thrown>
131// <li> Assertion in debug mode if attempt is made to set a negative width
132// <li> AipsError if incorrect parameter number specified.
133// <li> others?
134// </thrown>
135
136// <todo asof="2002/07/19">
137// <li> Gaussians that know about their DFT's could be required eventually.
138// </todo>
139
140template <class Type>
141class Gaussian3DParam : public Function<Type> {
142 // Parameter handling for the functional for 3D Gaussian Class.
143 // Similar to Gaussian2DParam, but width parameters are not adjusted
144 // for FWHM; they are identical to the parameters used in the function.
145
146 // Position angle parameters are restricted to -PI/4 < angle < PI/4.
147
148 public:
149 // #Enumerations
150 enum {
151 H = 0, // value of Gaussian at the center
152 CX, // X center value
153 CY, // Y center value
154 CZ, // Z center value
155 AX, // width along X axis when T = P = 0
156 AY, // width along Y axis when T = P = 0
157 AZ, // width along Z axis when T = P = 0
158 THETA, // rotation about Z axis.
159 PHI, // rotation around X and Y axes (which depends on T).
160 NPAR // number of total parameters (9)
161 };
162
163 // Constructs the three dimensional Gaussians. Defaults:
164 // height = 1, center = {0,0,0}, width = {1,1,1}, theta = phi = 0
165 // <group>
168 Type phi);
169 Gaussian3DParam(Type &height, Type &xCenter, Type &yCenter, Type &zCenter, Type &xWidth,
170 Type &yWidth, Type &zWidth, Type &theta, Type &phi);
171 // </group>
172
173 // Copy construcor
174 // <group>
176 template <class W>
178 : Function<Type>(other), fwhm2int(Type(1.0) / sqrt(log(Type(16.0)))) {
179 settrigvals();
180 }
181 // </group>
182
183 // Copy assignment
185
186 // Destructor
188
189 // # Member functions
190 // Give name of function
191 virtual const String &name() const {
192 static String x("gaussian3d");
193 return x;
194 }
195
196 // Return dimensionality
197 virtual uInt ndim() const { return 3; }
198
199 // Get or set the peak height of the Gaussian
200 // <group>
201 Type height() const;
202 void setHeight(const Type &height);
203 // </group>
204
205 // Get or set the total flux of the Gaussian. (Note: Since this changes
206 // the height of the Gaussian but not its width, always set the width
207 // before setting the flux.)
208 // <group>
209 Type flux() const;
210 void setFlux(const Type &flux);
211 // </group>
212
213 // Get or cet the center coordinates of the Gaussian
214 // <group>
217 Type xCenter() const;
218 void setXcenter(const Type &xcenter);
219 Type yCenter() const;
220 void setYcenter(const Type &ycenter);
221 Type zCenter() const;
222 void setZcenter(const Type &zcenter);
223 // </group>
224
225 // Get or set the sigma-width of the Gaussian
226 // <group>
229 void setXwidth(const Type &xwidth);
230 Type xWidth() const;
231 void setYwidth(const Type &ywidth);
232 Type yWidth() const;
233 void setZwidth(const Type &zwidth);
234 Type zWidth() const;
235 // </group>
236
237 // Get or set the rotation angles of the Gaussian.
238 // Theta=logitude, phi=latitude
239 // <group>
240 Type theta() const;
241 void settheta(const Type &sT);
242 Type phi() const;
243 void setphi(const Type &sP);
244 // </group>
245
246 protected:
247 void settrigvals() const;
248
249 Type fwhm2int; // const to scale halfwidth at 1/e to FWHM
250
251 mutable Type stoT_p; // used to check if cached values below are updated
252 mutable Type stoP_p; //
253 mutable Type cosT_p, sinT_p; // cached values of the cos and sine of THETA
254 mutable Type cosP_p, sinP_p; // PHI
255 mutable Type cosTcosP_p; // cached values of products of cos/sine of angles
256 mutable Type cosTsinP_p;
257 mutable Type sinTcosP_p;
258 mutable Type sinTsinP_p;
259
260 // # Make members of parent classes known.
261 protected:
262 using Function<Type>::param_p;
263
264 public:
265 using Function<Type>::nparameters;
266};
267
268} // namespace casacore
269
270#ifndef CASACORE_NO_AUTO_TEMPLATES
271#include <casacore/scimath/Functionals/Gaussian3DParam.tcc>
272#endif // # CASACORE_NO_AUTO_TEMPLATES
273#endif
FunctionParam< Type > param_p
Definition Function.h:337
Vector< Type > center() const
Get or cet the center coordinates of the Gaussian.
void setYwidth(const Type &ywidth)
Vector< Type > width() const
Get or set the sigma-width of the Gaussian.
void setCenter(const Vector< Type > &center)
void setYcenter(const Type &ycenter)
void setZcenter(const Type &zcenter)
void settheta(const Type &sT)
void setWidth(const Vector< Type > &width)
Gaussian3DParam(const Gaussian3DParam< Type > &other)
Copy construcor.
Gaussian3DParam(Type height, const Vector< Type > &center, const Vector< Type > &width, Type theta, Type phi)
Type flux() const
Get or set the total flux of the Gaussian.
Type height() const
Get or set the peak height of the Gaussian.
virtual const String & name() const
Give name of function.
void setZwidth(const Type &zwidth)
Gaussian3DParam< Type > & operator=(const Gaussian3DParam< Type > &other)
Copy assignment.
void setHeight(const Type &height)
virtual ~Gaussian3DParam()
Destructor.
Gaussian3DParam(Type &height, Type &xCenter, Type &yCenter, Type &zCenter, Type &xWidth, Type &yWidth, Type &zWidth, Type &theta, Type &phi)
void setphi(const Type &sP)
void setXcenter(const Type &xcenter)
Gaussian3DParam()
Constructs the three dimensional Gaussians.
void setXwidth(const Type &xwidth)
virtual uInt ndim() const
Return dimensionality.
Gaussian3DParam(const Gaussian3DParam< W > &other)
void setFlux(const Type &flux)
Type theta() const
Get or set the rotation angles of the Gaussian.
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
LatticeExprNode sqrt(const LatticeExprNode &expr)
LatticeExprNode log(const LatticeExprNode &expr)