casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpectralEstimate.h
Go to the documentation of this file.
1 //# SpectralEstimate.h: Get an initial estimate for spectral lines
2 //# Copyright (C) 2001,2002,2003,2004
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: aips2-request@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 //#
27 //# $Id: SpectralEstimate.h 20229 2008-01-29 15:19:06Z gervandiepen $
28 
29 #ifndef COMPONENTS_SPECTRALESTIMATE_H
30 #define COMPONENTS_SPECTRALESTIMATE_H
31 
32 #include <casa/aips.h>
35 
36 namespace casacore{
37 
38 template <class T> class Vector;
39 }
40 
41 namespace casa { //# NAMESPACE CASA - BEGIN
42 
43 //# Forward Declarations
44 class GaussianSpectralElement;
45 
46 // <summary>
47 // Get an initial estimate for spectral lines
48 // </summary>
49 
50 // <use visibility=export>
51 
52 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralFit" demos="">
53 // </reviewed>
54 
55 // <prerequisite>
56 // <li> <linkto class=SpectralFit>SpectralFit</linkto> class
57 // </prerequisite>
58 //
59 // <etymology>
60 // From spectral line and estimate
61 // </etymology>
62 //
63 // <synopsis>
64 // The SpectralEstimate class obtains an initial guess for spectral
65 // components. The current implementation uses the entire
66 // profile as signal region, or can set a window to be searched around
67 // the highest peak automatically. A window can also be set manually.
68 // The second derivative of
69 // the profile in the signal region is calculated by fitting
70 // a second degree polynomal. The smoothing parameter Q
71 // determines the number of points used for this (=2*Q+1).
72 // The gaussians can then be estimated as described by
73 // Schwarz, 1968, Bull.Astr.Inst.Netherlands, Volume 19, 405.
74 //
75 // The elements guessed can be used in the
76 // <linkto class=SpectralFit>SpectralFit</linkto> class.
77 //
78 // The default type found is a Gaussian, defined as:
79 // <srcblock>
80 // AMPL.exp[ -(x-CENTER)<sup>2</sup>/2 SIGMA<sup>2</sup>]
81 // </srcblock>
82 //
83 // The parameter estimates are returned in units of zero-based
84 // pixel indices.
85 // </synopsis>
86 //
87 // <example>
88 // </example>
89 //
90 // <motivation>
91 // To have an automatic method to find spectral lines
92 // </motivation>
93 //
94 // <todo asof="2001/02/14">
95 // <li> find a way to get to absorption lines as well
96 // <li> add more estimation options
97 // </todo>
98 
100  public:
101  //# Constants
102  // Default maximum number of components to be found
103  static const casacore::uInt MAXPAR = 200;
104  //# Enumerations
105  //# Friends
106 
107  //# Constructors
108  // Default constructor creates a default estimator (default max number
109  // of components to be found is 200) with the given maximum number
110  // of components that will be found. A value of zero will indicate
111  // an unlimited number.
112  explicit SpectralEstimate(const casacore::uInt maxpar=MAXPAR);
113  // Create an estimator with the given maximum number of possible
114  // elements. A value of zero will indicate an unlimited number.
115  // Construct with a given rms in profiles, a cutoff for amplitudes
116  // found, and a minimum width. Cutoff and minsigma default to 0.0, maximum
117  // size of list produced to 200.
118  explicit SpectralEstimate(const casacore::Double rms,
119  const casacore::Double cutoff=0.0, const casacore::Double minsigma=0.0,
120  const casacore::uInt maxpar=MAXPAR);
121  // Copy constructor (deep copy)
122  SpectralEstimate(const SpectralEstimate &other);
123 
124  //#Destructor
125  // Destructor
127 
128  //# Operators
129  // Assignment (copy semantics)
131 
132  //# Member functions
133  // Generate the estimates for a profile and return the
134  // list found. The first function returns component parameters
135  // in units of pixel indices. The second function calls the first
136  // and then converts to the specified abcissa space (the supplied
137  // vector must be monotonic); if the pixel-based center is out of range
138  // of the supplied abcissa vector the conversion is done via extrapolation.
139  // The der pointer is meant for debugging, and can return
140  // the derivative profile. The second function throws an AipsError
141  // if the vectors are not the same length.
142  // <group>
143  template <class MT>
144  const SpectralList& estimate(const casacore::Vector<MT>& ordinate,
145  casacore::Vector<MT> *der = 0);
146  template <class MT>
147  const SpectralList& estimate(const casacore::Vector<MT>& abcissa,
148  const casacore::Vector<MT>& ordinate);
149  // </group>
150 
151  // Return the list found.
152  const SpectralList &list() const {return slist_p; };
153 
154  // Set estimation parameters
155  // <group>
156  // Set the profile's estimated rms (forced to abs(rms))
157  void setRMS(const casacore::Double rms=0.0);
158  // Set the amplitude cutoff for valid estimate (forced to max(0,cutoff))
159  void setCutoff(const casacore::Double cutoff=0.0);
160  // Set the minimum width allowed (forced to max(0,minsigma))
161  void setMinSigma(const casacore::Double minsigma=0.0);
162  // Set the number of points consider at each side of test point (i.e. a
163  // width of 2q+1 is taken). Default internally is 2; max(1,q) taken.
164  void setQ(const casacore::uInt q=2);
165  // Set a region [lo,hi] over which to estimate. Lo and hi are given as
166  // zero-based vector indices.
167  void setRegion(const casacore::Int lo, const casacore::Int hi);
168  // Do you want to look in an automatically determined window with signal?
169  // Default is false, meaning the full (possibly regioned) profile.
170  void setWindowing(const casacore::Bool win=false);
171  // Set the maximum number of estimates to find (forced to >=1; 200 default)
172  void setMaxN(const casacore::uInt maxpar=MAXPAR);
173  // </group>
174 
175  private:
176  //#Data
177  // Use window search
179  // rms estimate in profile
181  // Source cutoff amplitude
183  // Window low and end value
184  // <group>
187  // </group>
188  // Region low and high value
189  // <group>
192  // </group>
193  // Smoothing parameter. I.e. 2q+1 points are taken
195  // Internal cashing of calculated values based on q
196  // <group>
199  // </group>
200  // The minimum Gaussian width
202  // The second derivatives
204  // The list of components
206  // The length of the current profile being estimated
208 
209  //# Member functions
210  // Get the window or the total spectrum
211  template <class MT>
213  // Get the second derivatives
214  template <class MT>
215  void findc2(const casacore::Vector<MT> &prof);
216  // Find the Gaussians
217  template <class MT>
218  void findga(const casacore::Vector<MT> &prof);
219  // Convert the parameters of the components in the list from
220  // pixel-based indices to the given abcissa-vector space.
221  template <class MT> GaussianSpectralElement convertElement (const casacore::Vector<MT>& abcissa,
222  const GaussianSpectralElement& el) const;
223 };
224 
225 
226 } //# NAMESPACE CASA - END
227 
228 #ifndef CASACORE_NO_AUTO_TEMPLATES
229 #include <components/SpectralComponents/Spectral2Estimate.tcc>
230 #endif //# CASACORE_NO_AUTO_TEMPLATES
231 #endif
GaussianSpectralElement convertElement(const casacore::Vector< MT > &abcissa, const GaussianSpectralElement &el) const
Convert the parameters of the components in the list from pixel-based indices to the given abcissa-ve...
void setQ(const casacore::uInt q=2)
Set the number of points consider at each side of test point (i.e.
A 1-D Specialization of the Array class.
int Int
Definition: aipstype.h:50
std::vector< double > Vector
Definition: ds9context.h:24
casacore::Bool useWindow_p
Use window search.
const SpectralList & estimate(const casacore::Vector< MT > &ordinate, casacore::Vector< MT > *der=0)
Generate the estimates for a profile and return the list found.
void setRMS(const casacore::Double rms=0.0)
Set estimation parameters.
casacore::uInt window(const casacore::Vector< MT > &prof)
Get the window or the total spectrum.
casacore::Double a_p
Internal cashing of calculated values based on q.
const SpectralList & list() const
Return the list found.
void setMaxN(const casacore::uInt maxpar=MAXPAR)
Set the maximum number of estimates to find (forced to &gt;=1; 200 default)
casacore::Int regionLow_p
Region low and high value.
~SpectralEstimate()
Destructor.
casacore::Int windowLow_p
Window low and end value.
static const casacore::uInt MAXPAR
Default maximum number of components to be found.
casacore::Double * deriv_p
The second derivatives.
void findc2(const casacore::Vector< MT > &prof)
Get the second derivatives.
SpectralEstimate(const casacore::uInt maxpar=MAXPAR)
Default constructor creates a default estimator (default max number of components to be found is 200)...
void setCutoff(const casacore::Double cutoff=0.0)
Set the amplitude cutoff for valid estimate (forced to max(0,cutoff))
casacore::Int q_p
Smoothing parameter.
void setMinSigma(const casacore::Double minsigma=0.0)
Set the minimum width allowed (forced to max(0,minsigma))
void findga(const casacore::Vector< MT > &prof)
Find the Gaussians.
double Double
Definition: aipstype.h:55
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Double cutoff_p
Source cutoff amplitude.
Get an initial estimate for spectral lines.
void setRegion(const casacore::Int lo, const casacore::Int hi)
Set a region [lo,hi] over which to estimate.
casacore::Double rms_p
rms estimate in profile
A set of SpectralElements.
Definition: SpectralList.h:85
TableExprNode rms(const TableExprNode &array)
Definition: ExprNode.h:1637
SpectralList slist_p
The list of components.
casacore::uInt lprof_p
The length of the current profile being estimated.
SpectralEstimate & operator=(const SpectralEstimate &other)
Assignment (copy semantics)
Describes a Gaussian spectral line.
unsigned int uInt
Definition: aipstype.h:51
void setWindowing(const casacore::Bool win=false)
Do you want to look in an automatically determined window with signal? Default is false...
casacore::Double sigmin_p
The minimum Gaussian width.
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42