source: trunk/external-alma/components/SpectralComponents/PCFSpectralElement.cc@ 2996

Last change on this file since 2996 was 2980, checked in by Malte Marquarding, 10 years ago

Add a copy of casacore/components/SpectralComponents to external-alma directory to prepare for its removal from casacore-trunk. DOn;t activate in SConscript yet.

File size: 5.2 KB
Line 
1//# SpectralElement.cc: Describes (a set of related) spectral lines
2//# Copyright (C) 2001,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//# $Id: PCFSpectralElement.cc 21451 2014-06-10 07:48:08Z gervandiepen $
27
28//# Includes
29#include <components/SpectralComponents/PCFSpectralElement.h>
30
31#include <casa/BasicSL/Constants.h>
32#include <scimath/Functionals/Gaussian1D.h>
33#include <casa/iostream.h>
34
35namespace casa { //# NAMESPACE CASA - BEGIN
36
37
38//# Constructors
39PCFSpectralElement::PCFSpectralElement()
40: SpectralElement() {
41 _initFunction();
42}
43
44PCFSpectralElement::PCFSpectralElement(
45 SpectralElement::Types type
46) : SpectralElement(type, Vector<Double>(3, 1)) {
47 _initFunction();
48 setCenter(0);
49}
50
51PCFSpectralElement::PCFSpectralElement(
52 SpectralElement::Types type, const Vector<Double>& param
53) : SpectralElement(type, param) {
54 if (param.size() != 3) {
55 throw AipsError(
56 "PCFSpectralElement: PCF function must have "
57 "3 parameters"
58 );
59 }
60 if (param[0] == 0) {
61 throw AipsError(
62 "PCFSpectralElement: PCF amplitude cannot equal 0"
63 );
64 }
65 _initFunction();
66
67}
68
69PCFSpectralElement::PCFSpectralElement(
70 SpectralElement::Types type, Double amp,
71 Double center, Double width
72) : SpectralElement(type, vector<Double>(3)) {
73 _initFunction();
74 setAmpl(amp);
75 setCenter(center);
76 setWidth(width);
77}
78
79PCFSpectralElement::PCFSpectralElement(const PCFSpectralElement& other)
80: SpectralElement(other) {}
81
82PCFSpectralElement::~PCFSpectralElement() {}
83
84Double PCFSpectralElement::getAmpl() const {
85 return get()[AMP];
86}
87
88Double PCFSpectralElement::getCenter() const {
89 return get()[CENTER];
90}
91
92Double PCFSpectralElement::getWidth() const {
93 return get()[WIDTH];
94}
95
96Double PCFSpectralElement::getAmplErr() const {
97 return getError()[AMP];
98}
99
100Double PCFSpectralElement::getCenterErr() const {
101 return getError()[CENTER];
102}
103
104Double PCFSpectralElement::getWidthErr() const {
105 return getError()[WIDTH];
106}
107
108void PCFSpectralElement::setAmpl(const Double ampl) {
109 if (ampl == 0) {
110 throw AipsError("PCF amplitude cannot equal 0");
111 }
112 Vector<Double> p = get();
113 p(0) = ampl;
114 _set(p);
115 Vector<Double> err = getError();
116 err[AMP] = 0;
117 setError(err);
118}
119
120void PCFSpectralElement::setCenter(const Double center) {
121 Vector<Double> p = get();
122 p[1] = center;
123 _set(p);
124 Vector<Double> err = getError();
125 err[CENTER] = 0;
126 setError(err);
127}
128
129void PCFSpectralElement::setWidth(const Double width) {
130
131 Vector<Double> p = get();
132 p[2] = width > 0 ? width : -width;
133 _set(p);
134 Vector<Double> err = getError();
135 err[WIDTH] = 0;
136 setError(err);
137}
138void PCFSpectralElement::fixAmpl(const Bool isFixed) {
139 Vector<Bool> myFixed = fixed();
140 myFixed[AMP] = isFixed;
141 fix(myFixed);
142}
143
144void PCFSpectralElement::fixCenter(const Bool isFixed) {
145 Vector<Bool> myFixed = fixed();
146 myFixed[CENTER] = isFixed;
147 fix(myFixed);
148}
149
150void PCFSpectralElement::fixWidth(const Bool isFixed) {
151 Vector<Bool> myFixed = fixed();
152 myFixed[WIDTH] = isFixed;
153 fix(myFixed);
154}
155
156void PCFSpectralElement::fixByString(const String& s) {
157 String fix(s);
158 fix.downcase();
159 if (fix.contains("p")) {
160 fixAmpl(True);
161 }
162 if (fix.contains("c")) {
163 fixCenter(True);
164 }
165 if (fix.contains("f")) {
166 fixWidth(True);
167 }
168}
169
170Bool PCFSpectralElement::fixedAmpl() const {
171 return fixed()[AMP];
172}
173
174Bool PCFSpectralElement::fixedCenter() const {
175 return fixed()[CENTER];
176}
177
178Bool PCFSpectralElement::fixedWidth() const {
179 return fixed()[WIDTH];
180}
181
182void PCFSpectralElement::set(const Vector<Double>& params) {
183 if (params.nelements() != 3) {
184 throw AipsError(
185 "PCFSpectralElement: PCF must have "
186 "3 parameters"
187 );
188 }
189 if (params[AMP] == 0) {
190 throw AipsError("PCF amplitude cannot equal 0");
191 }
192 Vector<Double> p = params.copy();
193 if (p[WIDTH] < 0) {
194 p[WIDTH] *= -1;
195 }
196 _set(p);
197}
198
199Double PCFSpectralElement::getIntegralErr() const {
200 Double damp = getAmplErr()/getAmpl();
201 Double dwidth = getWidthErr()/getWidth();
202 return sqrt(damp*damp + dwidth*dwidth) * getIntegral();
203}
204
205void PCFSpectralElement::_initFunction() {
206 // Just need something we can instantiate, subclasses should set their
207 // own functions in their constructors
208 _setFunction(
209 std::tr1::shared_ptr<Function<Double> >(
210 new Gaussian1D<Double>()
211 )
212 );
213}
214
215
216
217} //# NAMESPACE CASA - END
218
Note: See TracBrowser for help on using the repository browser.