| 1 | //# SpectralEstimate.cc: 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 | //# $Id: SpectralEstimate.cc 19933 2007-02-27 05:04:51Z Malte.Marquarding $ | 
|---|
| 27 |  | 
|---|
| 28 | //# Includes | 
|---|
| 29 | #include <components/SpectralComponents/SpectralEstimate.h> | 
|---|
| 30 | #include <casa/Arrays/Vector.h> | 
|---|
| 31 | #include <casa/BasicMath/Math.h> | 
|---|
| 32 |  | 
|---|
| 33 | namespace casa { //# NAMESPACE CASA - BEGIN | 
|---|
| 34 |  | 
|---|
| 35 | //# Constructors | 
|---|
| 36 | SpectralEstimate::SpectralEstimate(const uInt maxpar) : | 
|---|
| 37 | useWindow_p(False), rms_p(0), cutoff_p(0), | 
|---|
| 38 | windowLow_p(0), windowEnd_p(0), | 
|---|
| 39 | regionLow_p(0), regionEnd_p(0), | 
|---|
| 40 | q_p(2), sigmin_p(0), | 
|---|
| 41 | deriv_p(0), slist_p(maxpar), lprof_p(0) { | 
|---|
| 42 | setQ(); | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | SpectralEstimate::SpectralEstimate(const Double rms, | 
|---|
| 46 | const Double cutoff, const Double minsigma, | 
|---|
| 47 | const uInt maxpar) : | 
|---|
| 48 | useWindow_p(False), rms_p(rms), cutoff_p(cutoff), | 
|---|
| 49 | windowLow_p(0), windowEnd_p(0), | 
|---|
| 50 | regionLow_p(0), regionEnd_p(0), | 
|---|
| 51 | q_p(2), sigmin_p(minsigma), | 
|---|
| 52 | deriv_p(0), slist_p(maxpar), lprof_p(0) { | 
|---|
| 53 | setQ(); | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 |  | 
|---|
| 57 | SpectralEstimate::SpectralEstimate(const SpectralEstimate &other) : | 
|---|
| 58 | useWindow_p(other.useWindow_p), rms_p(other.rms_p), cutoff_p(other.cutoff_p), | 
|---|
| 59 | windowLow_p(other.windowLow_p), windowEnd_p(other.windowEnd_p), | 
|---|
| 60 | regionLow_p(other.regionLow_p), regionEnd_p(other.regionEnd_p), | 
|---|
| 61 | q_p(other.q_p), sigmin_p(other.sigmin_p), | 
|---|
| 62 | deriv_p(0), slist_p(other.slist_p), lprof_p(other.lprof_p) { | 
|---|
| 63 | setQ(q_p); | 
|---|
| 64 | deriv_p = new Double[lprof_p]; | 
|---|
| 65 | for (uInt i=0; i<lprof_p; i++) deriv_p[i] = other.deriv_p[i]; | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | SpectralEstimate::~SpectralEstimate() { | 
|---|
| 69 | delete [] deriv_p; deriv_p = 0; lprof_p = 0; | 
|---|
| 70 | } | 
|---|
| 71 |  | 
|---|
| 72 | SpectralEstimate &SpectralEstimate::operator=(const SpectralEstimate &other) { | 
|---|
| 73 | if (this != &other) { | 
|---|
| 74 | useWindow_p = other.useWindow_p; | 
|---|
| 75 | rms_p = other.rms_p; | 
|---|
| 76 | cutoff_p = other.cutoff_p; | 
|---|
| 77 | windowLow_p = other.windowLow_p; | 
|---|
| 78 | windowEnd_p = other.windowEnd_p; | 
|---|
| 79 | regionLow_p = other.regionLow_p; | 
|---|
| 80 | regionEnd_p = other.regionEnd_p; | 
|---|
| 81 | q_p = other.q_p; | 
|---|
| 82 | sigmin_p = other.sigmin_p; | 
|---|
| 83 | deriv_p = 0; | 
|---|
| 84 | slist_p = other.slist_p; | 
|---|
| 85 | lprof_p = other.lprof_p; | 
|---|
| 86 | setQ(q_p); | 
|---|
| 87 | deriv_p = new Double[lprof_p]; | 
|---|
| 88 | for (uInt i=0; i<lprof_p; i++) deriv_p[i] = other.deriv_p[i]; | 
|---|
| 89 | }; | 
|---|
| 90 | return *this; | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | void SpectralEstimate::setRMS(const Double rms) { | 
|---|
| 94 | rms_p = abs(rms); | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | void SpectralEstimate::setCutoff(const Double cutoff) { | 
|---|
| 98 | cutoff_p = max(0.0, cutoff); | 
|---|
| 99 | } | 
|---|
| 100 |  | 
|---|
| 101 | void SpectralEstimate::setMinSigma(const Double minsigma) { | 
|---|
| 102 | sigmin_p = max(0.0, minsigma); | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | void SpectralEstimate::setQ(const uInt q) { | 
|---|
| 106 | q_p = max(1, Int(q)); | 
|---|
| 107 | a_p = 90.0/(q_p*(q_p+1)*(4*q_p*q_p-1)*(2*q_p+3)); | 
|---|
| 108 | b_p = (q_p*(q_p+1))/3.0; | 
|---|
| 109 | } | 
|---|
| 110 |  | 
|---|
| 111 | void SpectralEstimate::setRegion(const Int lo, const Int hi) { | 
|---|
| 112 | regionLow_p = regionEnd_p = 0; | 
|---|
| 113 | if (hi > lo) { | 
|---|
| 114 | regionLow_p = lo; | 
|---|
| 115 | regionEnd_p = hi; | 
|---|
| 116 | }; | 
|---|
| 117 | } | 
|---|
| 118 |  | 
|---|
| 119 | void SpectralEstimate::setWindowing(const Bool win) { | 
|---|
| 120 | useWindow_p = win; | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | void SpectralEstimate::setMaxN(const uInt maxpar) { | 
|---|
| 124 | slist_p.set(maxpar); | 
|---|
| 125 | } | 
|---|
| 126 |  | 
|---|
| 127 | } //# NAMESPACE CASA - END | 
|---|
| 128 |  | 
|---|
| 129 |  | 
|---|
| 130 | //# Cater for Double and Float | 
|---|
| 131 | #ifdef AIPS_NO_TEMPLATE_SRC | 
|---|
| 132 | #include <components/SpectralComponents/Spectral2Estimate.tcc> | 
|---|
| 133 |  | 
|---|
| 134 | namespace casa { //# NAMESPACE CASA - BEGIN | 
|---|
| 135 | template SpectralList const & SpectralEstimate::estimate<Float>(Vector<Float> const &, Vector<Float> *); | 
|---|
| 136 | template SpectralList const & SpectralEstimate::estimate<Float>(Vector<Float> const &, Vector<Float> const &); | 
|---|
| 137 | template SpectralElement SpectralEstimate::convertElement<Float>(Vector<Float> const &, | 
|---|
| 138 | SpectralElement const &) const; | 
|---|
| 139 | template void SpectralEstimate::findga<Float>(Vector<Float> const &); | 
|---|
| 140 | template uInt SpectralEstimate::window<Float>(Vector<Float> const &); | 
|---|
| 141 | template void SpectralEstimate::findc2<Float>(Vector<Float> const &); | 
|---|
| 142 |  | 
|---|
| 143 | template SpectralList const & SpectralEstimate::estimate<Double>(Vector<Double> const &, Vector<Double> *); | 
|---|
| 144 | template SpectralList const & SpectralEstimate::estimate<Double>(Vector<Double> const &, Vector<Double> const &); | 
|---|
| 145 | template SpectralElement SpectralEstimate::convertElement<Double>(Vector<Double> const &, | 
|---|
| 146 | SpectralElement const &) const; | 
|---|
| 147 | template void SpectralEstimate::findga<Double>(Vector<Double> const &); | 
|---|
| 148 | template uInt SpectralEstimate::window<Double>(Vector<Double> const &); | 
|---|
| 149 | template void SpectralEstimate::findc2<Double>(Vector<Double> const &); | 
|---|
| 150 | } //# NAMESPACE CASA - END | 
|---|
| 151 | #endif | 
|---|