casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FluxCalcLogFreqPolynomial.h
Go to the documentation of this file.
00001 //# FluxCalcLogFreqPolynomial.h: Implementation base classes for flux standards
00002 //# which are (possibly broken) polynomials of log10(frequency).
00003 //# Copyright (C) 2010 Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be adressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 #ifndef COMPONENTS_FLUXCALCLOGFREQPOLYNOMIAL_H
00028 #define COMPONENTS_FLUXCALCLOGFREQPOLYNOMIAL_H
00029 
00030 #include <components/ComponentModels/FluxStandard.h>
00031 #include <components/ComponentModels/FluxCalcQS.h>
00032 #include <casa/BasicSL/String.h>
00033 #include <measures/Measures/MFrequency.h>
00034 
00035 //# Handy for passing anonymous arrays to functions.
00036 #include <scimath/Mathematics/RigidVector.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 // <summary> 
00041 // FluxCalcLogFreqPolynomial: Implementation base class for flux standards
00042 // which are polynomials of log10(frequency).
00043 // </summary>
00044 
00045 // <use visibility=export>
00046 
00047 // <reviewed reviewer="" date="" tests="" demos="">
00048 
00049 // <prerequisite>
00050 // <li><linkto class="FluxStandard">FluxStandard</linkto> module
00051 // <li><linkto class="FluxCalcQS">FluxCalcQS</linkto> module
00052 // </prerequisite>
00053 //
00054 // <etymology>
00055 // From "flux density", "calculator", "log10(frequency)", and "polynomial".
00056 // </etymology>
00057 //
00058 // <synopsis>
00059 // The FluxCalcLogFreqPolynomial class provides machinery to compute total flux
00060 // densities for specified non-variable sources where the flux density is well
00061 // described by a low order polynomial of log(frequency).
00062 // </synopsis>
00063 //
00064 // <example>
00065 // <srcblock>
00066 // </srcblock>
00067 // </example>
00068 //
00069 // <motivation>
00070 // Encapsulate the machinery for most of the flux density standards in one class.
00071 //
00072 // The flux standards for cm astronomy are deliberately chosen to be distant,
00073 // non-varying, and bright around 1 GHz.  Since such objects tend to be
00074 // dominated by synchrotron radiation their flux density is usually described
00075 // by a polynomial of log(frequency).
00076 // </motivation>
00077 //
00078 
00079 class FluxCalcLogFreqPolynomial : public virtual FluxCalcQS {
00080 public:
00081   // Some abbreviations, since the classes derived from this have to
00082   // define many polynomial coefficients.
00083   typedef RigidVector<Float, 3> RVF3;
00084   typedef RigidVector<Float, 4> RVF4;
00085   typedef RigidVector<Float, 5> RVF5;
00086   
00087   // Set the log10(frequency) polynomial coefficients for calculating the flux
00088   // density and its uncertainty, and the unit (typically "MHz" or "GHz") that
00089   // the coefficients assume.  Note that errcoeffs does not have to have the
00090   // same number of terms as lfcoeffs, or any terms at all, and that each term
00091   // in its polynomial is (errcoeff[order] * pow(log10(freq), order))**2.
00092   //FluxCalcLogFreqPolynomial(const String& freqUnit, const Vector<Double>& lfcoeffs,
00093   //                          const Vector<Double>& errcoeffs);
00094 
00095   // Set value and error with the expected flux density and its uncertainty
00096   // (0.0 if unknown) at mfreq.
00097   virtual Bool operator()(Flux<Double>& value, Flux<Double>& error,
00098                           const MFrequency& mfreq);
00099 
00100   virtual Bool setSource(const String& sourceName);
00101   void setFreqUnit(const String& freqUnit);
00102 
00103   // Functions for setting up coeffs_p by taking a bunch of numbers
00104   // (packaged in RigidVectors) and formatting them into coeffs_p.
00105 
00106   // Takes a RigidVector for the flux density coefficients and
00107   // second one for the uncertainty coefficients, and fills coeffs_p with them.
00108   template<Int lford, Int errord>
00109   void fill_coeffs(const RigidVector<Float, lford>& lfrv,
00110                    const RigidVector<Float, errord>& errrv);
00111 
00112   // Like fill_coeffs(lfrv, errrv), but it only takes the flux density
00113   // coefficients, and substitutes an empty Vector for the error coefficients.
00114   template<Int lford>
00115   void fill_coeffs(const RigidVector<Float, lford>& lfrv);
00116 
00117   void fill_coeffs(const Vector<Float>& lfv);
00118 
00119 private:
00120   virtual Bool setSourceCoeffs() = 0;
00121 
00122   // The first element of this pair of Vectors is a Vector of coefficients for
00123   // the flux density polynomial (of log10(frequency)).  The second element is
00124   // for estimating the flux density's uncertainty with a similar polynomial,
00125   // but each term is (coeff * log10(freq))**2.  It does not need to have the
00126   // same number of coefficients as the first element, or even any
00127   // coefficients.  Both Vectors start with the 0th order term.
00128   RigidVector<Vector<Float>, 2> coeffs_p;
00129 
00130   // The frequency unit (e.g. "MHz" or "GHz") assumed by coeffs_p.
00131   String freqUnit_p;
00132 };
00133 
00134 // <summary> 
00135 // FluxCalcLogFreqBrokenPolynomial: Implementation base class for flux standards
00136 // which are broken polynomials of log10(frequency).
00137 // </summary>
00138 
00139 // <use visibility=export>
00140 
00141 // <reviewed reviewer="" date="" tests="" demos="">
00142 
00143 // <prerequisite>
00144 // <li><linkto class="FluxCalcLogFreqPolynomial">FluxCalcLogFreqPolynomial</linkto> module
00145 // </prerequisite>
00146 //
00147 // <etymology>
00148 // From FluxCalcLogFreqPolynomial  and "broken".
00149 // </etymology>
00150 //
00151 // <synopsis>
00152 // The FluxCalcLogFreqBrokenPolynomial class extends FluxCalcLogFreqPolynomial
00153 // to allow one set of coefficients to be used below a certain frequency (the
00154 // break frequency) and another above it.  Ideally the sets should mesh well
00155 // enough to make the resulting function at least roughly continuous.
00156 // </synopsis>
00157 //
00158 // <example>
00159 // <srcblock>
00160 // </srcblock>
00161 // </example>
00162 //
00163 // <motivation>
00164 // Some of the flux classes use a broken polynomial for 1934-638, and some do not.
00165 // </motivation>
00166 //
00167 // <todo asof="2010/07/26">
00168 // <li> Handle an arbitrary number of breaks.
00169 // </todo>
00170 class FluxCalcLogFreqBrokenPolynomial : public virtual FluxCalcLogFreqPolynomial {
00171 public:
00172   FluxCalcLogFreqBrokenPolynomial();
00173   
00174   template <Int lford>
00175   void fill_lohi_coeffs(const RigidVector<Float, lford>& lorv,
00176                         const MFrequency& break_freq,
00177                         const RigidVector<Float, lford>& hirv);
00178 
00179   virtual Bool operator()(Flux<Double>& value, Flux<Double>& error,
00180                           const MFrequency& mfreq);
00181 private:
00182   MFrequency    break_freq_p;
00183   Bool          in_low_state_p;
00184   Vector<Float> low_coeffs_p;
00185   Vector<Float> high_coeffs_p;
00186 };
00187 
00188 } //# NAMESPACE CASA - END
00189 
00190 #ifndef AIPS_NO_TEMPLATE_SRC
00191 #include <components/ComponentModels/FluxCalcLogFreqPolynomial.tcc>
00192 #endif //# AIPS_NO_TEMPLATE_SRC
00193 
00194 #endif