casa
$Rev:20696$
|
00001 //# SpectralIndex.h: Models the spectral variation with a spectral index 00002 //# Copyright (C) 1998,1999,2000,2003 00003 //# 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 addressed 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 //# $Id: SpectralIndex.h 21229 2012-04-02 12:00:20Z gervandiepen $ 00027 00028 #ifndef COMPONENTS_SPECTRALINDEX_H 00029 #define COMPONENTS_SPECTRALINDEX_H 00030 00031 #include <casa/aips.h> 00032 #include <components/ComponentModels/ComponentType.h> 00033 #include <components/ComponentModels/SpectralModel.h> 00034 00035 namespace casa { //# NAMESPACE CASA - BEGIN 00036 00037 class MFrequency; 00038 class RecordInterface; 00039 class String; 00040 template <class T> class Vector; 00041 00042 // <summary>Models the spectral variation with a spectral index</summary> 00043 00044 // <use visibility=export> 00045 00046 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralIndex" demos="dSpectralModel"> 00047 // </reviewed> 00048 00049 // <prerequisite> 00050 // <li> <linkto class="SpectralModel">SpectralModel</linkto> 00051 // </prerequisite> 00052 // 00053 // <synopsis> 00054 00055 // This class models the spectral variation of a component with a spectral 00056 // index. 00057 00058 // This class like the other spectral models becomes more useful when used 00059 // through the <linkto class=SkyComponent>SkyComponent</linkto> class, which 00060 // incorporates the flux and spatial variation of the emission, or through the 00061 // <linkto class=ComponentList>ComponentList</linkto> class, which handles 00062 // groups of SkyComponent objects. 00063 00064 // A spectral index is the exponent in a power law model for the variation flux 00065 // with frequency. It is mathematically is defined as: 00066 // <srcblock> 00067 // (nu / nu_0)^alpha 00068 // </srcblock> 00069 // Where: 00070 // <dl compact> 00071 // <dt><src>nu_0</src><dd> is the reference frequency 00072 // <dt><src>alpha</src><dd> is the spectral index 00073 // <dt><src>nu</src><dd> is the user specified frequency 00074 // </dl> 00075 00076 // As with all classes derived from SpectralModel the basic operation of this 00077 // class is to model the flux as a function of frequency. This class does not 00078 // know what the flux is at the reference frequency. Instead the sample 00079 // functions return factors that are used to scale the flux and calculate the 00080 // amount of flux at a specified frequency. 00081 00082 // Besides the reference frequency this class has one parameter; the spectral 00083 // index. This parameter can be set & queried using the general purpose 00084 // <src>parameters</src> functions or the class specific <src>index</src> 00085 // functions. 00086 00087 // This class also contains functions (<src>toRecord</src> & 00088 // <src>fromRecord</src>) which perform the conversion between Records and 00089 // SpectralIndex objects. These functions define how a SpectralIndex 00090 // object is represented in glish. The format of the record that is generated 00091 // and accepted by these functions is: 00092 // <srcblock> 00093 // c := [type = 'spectral index', 00094 // frequency = [type = 'frequency', 00095 // refer = 'lsr', 00096 // m0 = [value = 1, unit = 'GHz'] 00097 // ], 00098 // index = 0.7 00099 // ] 00100 // </srcblock> 00101 // The frequency field contains a record representation of a frequency measure 00102 // and its format is defined in the Measures module. Its refer field defines 00103 // the reference frame for the direction and the m0 field defines the value of 00104 // the reference frequency. The parsing of the type field is case 00105 // insensitive. The index field contains the spectral index. 00106 // </synopsis> 00107 00108 // 00109 // <example> 00110 // These examples are coded in the tSpectralModel.h file. 00111 // <h4>Example 1:</h4> 00112 // In this example a SpectralIndex object is created and used to calculate the 00113 // flux at a number of frequencies. 00114 // <srcblock> 00115 // SpectralIndex siModel; 00116 // siModel.setRefFrequency(MFrequency(Quantity(1.0, "GHz"))); 00117 // siModel.setIndex(1.0, Stokes::I); 00118 // siModel.setIndex(0.5, Stokes::Q); 00119 // siModel.setIndex(0.5, Stokes::U); 00120 // siModel.setIndex(-1.0, Stokes::V); 00121 // const Flux<Double> LBandFlux(1.0, 1.0, 1.0, 1.0); 00122 // const MVFrequency step(Quantity(100.0, "MHz")); 00123 // MVFrequency sampleFreq = siModel.refFrequency().getValue(); 00124 // Flux<Double> sampleFlux; 00125 // cout << "Frequency\t I-Flux\t Q-Flux\t U-Flux\t V-Flux\n"; 00126 // for (uInt i = 0; i < 11; i++) { 00127 // sampleFlux = LBandFlux.copy(); 00128 // sampleFlux.convertPol(ComponentType::LINEAR); 00129 // sampleFlux.convertUnit(Unit("WU")); 00130 // siModel.sample(sampleFlux, 00131 // MFrequency(sampleFreq, siModel.refFrequency().getRef())); 00132 // cout << setprecision(3) << sampleFreq.get("GHz") 00133 // << "\t\t " << sampleFlux.value(0u).re 00134 // << "\t " << sampleFlux.value(1u).re 00135 // << "\t " << sampleFlux.value(2u).re 00136 // << "\t " << sampleFlux.value(3u).re 00137 // << " " << sampleFlux.unit().getName() << endl; 00138 // sampleFreq += step; 00139 // } 00140 // </srcblock> 00141 // </example> 00142 // 00143 // <motivation> A Spectral Index frequency variation is the most widely used 00144 // model in radio astronomy. In particular the NFRA package 'newstar' uses it 00145 // extensively. 00146 // </motivation> 00147 // 00148 // <todo asof="1999/11/23"> 00149 // <li> Nothing I hope 00150 // </todo> 00151 00152 // <linkfrom anchor="SpectralIndex" classes="SpectralModel ConstantSpectrum"> 00153 // <here>SpectralIndex</here> - Uses a spectral index to model the spectrum 00154 // </linkfrom> 00155 00156 class SpectralIndex: public SpectralModel 00157 { 00158 public: 00159 // The default SpectralIndex has a reference frequency of 1 GHz in the LSR 00160 // frame and a spectral index of zero. As such it is no different from the 00161 // ConstantSpectrum class (except slower). 00162 SpectralIndex(); 00163 00164 // Construct a SpectralIndex with specified reference frequency and 00165 // exponent. 00166 SpectralIndex(const MFrequency& refFreq, Double exponent = 0.0); 00167 00168 // The copy constructor uses copy semantics 00169 SpectralIndex(const SpectralIndex& other); 00170 00171 // The destructor does nothing special. 00172 virtual ~SpectralIndex(); 00173 00174 // The assignment operator uses copy semantics. 00175 SpectralIndex& operator=(const SpectralIndex& other); 00176 00177 // return the actual spectral type ie., ComponentType::SPECTRAL_INDEX 00178 virtual ComponentType::SpectralShape type() const; 00179 00180 // set/get the spectral index. 00181 // <group> 00182 const Double& index() const; 00183 void setIndex(const Double& newIndex); 00184 // </group> 00185 00186 // Return the scaling factor that indicates what proportion of the flux is at 00187 // the specified frequency. ie. if the centreFrequency argument is the 00188 // reference frequency then this function will always return one. At other 00189 // frequencies it will return a non-negative number. 00190 virtual Double sample(const MFrequency& centerFrequency) const; 00191 00192 // Same as the previous function except that many frequencies can be sampled 00193 // at once. The reference frame must be the same for all the specified 00194 // frequencies. Uses a customised implementation for improved speed. 00195 virtual void sample(Vector<Double>& scale, 00196 const Vector<MFrequency::MVType>& frequencies, 00197 const MFrequency::Ref& refFrame) const; 00198 00199 // Return a pointer to a copy of this object upcast to a SpectralModel 00200 // object. The class that uses this function is responsible for deleting the 00201 // pointer. This is used to implement a virtual copy constructor. 00202 virtual SpectralModel* clone() const; 00203 00204 // return the number of parameters. There is one parameter for this spectral 00205 // model, namely the spectral index. So you supply a unit length vector when 00206 // using these functions. Otherwise an exception (AipsError) may be thrown. 00207 // <group> 00208 virtual uInt nParameters() const; 00209 virtual void setParameters(const Vector<Double>& newSpectralParms); 00210 virtual Vector<Double> parameters() const; 00211 virtual void setErrors(const Vector<Double>& newSpectralErrs); 00212 virtual Vector<Double> errors() const; 00213 // </group> 00214 00215 // These functions convert between a Record and a SpectralIndex. These 00216 // functions define how a SpectralIndex object is represented in glish and 00217 // this is detailed in the synopsis above. These functions return False if 00218 // the record is malformed and append an error message to the supplied string 00219 // giving the reason. 00220 // <group> 00221 virtual Bool fromRecord(String& errorMessage, const RecordInterface& record); 00222 virtual Bool toRecord(String& errorMessage, RecordInterface& record) const; 00223 // </group> 00224 00225 // Convert the parameters of the spectral index object to the specified 00226 // units. Only one field of the supplied record is used, namely 'index'. This 00227 // field is optional as the spectral index is a unitless quantity. If the 00228 // index field is specified it must have the empty string as its value. This 00229 // function always returns True unless the index field is specified and does 00230 // not contain an empty string. 00231 virtual Bool convertUnit(String& errorMessage, 00232 const RecordInterface& record); 00233 00234 // Function which checks the internal data of this class for consistant 00235 // values. Returns True if everything is fine otherwise returns False. 00236 virtual Bool ok() const; 00237 00238 private: 00239 Double itsIndex; 00240 Double itsError; 00241 }; 00242 00243 } //# NAMESPACE CASA - END 00244 00245 #endif