source: trunk/external-alma/components/SpectralComponents/SpectralEstimate.h@ 3150

Last change on this file since 3150 was 3106, checked in by Takeshi Nakazato, 8 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes/No

Interface Changes: Yes/No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...


Check-in asap modifications from Jim regarding casacore namespace conversion.

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