casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ConstantSpectrum.h
Go to the documentation of this file.
00001 //# ConstantSpectrum.h: Model the spectral variation with a constant
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: ConstantSpectrum.h 18093 2004-11-30 17:51:10Z ddebonis $
00027 
00028 #ifndef COMPONENTS_CONSTANTSPECTRUM_H
00029 #define COMPONENTS_CONSTANTSPECTRUM_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>Model the spectral variation with a constant</summary>
00043 
00044 // <use visibility=export>
00045 
00046 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tConstantSpectrum" demos="dConstantSpectrum">
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 as constant,
00056 // ie. unchanging with frequency. It is the simplest possible model for
00057 // spectral variation. 
00058 
00059 // This class like the other spectral models becomes more useful when used
00060 // through the <linkto class=SkyComponent>SkyComponent</linkto> class, which
00061 // incorperates the flux and spatial variation of the emission, or through the
00062 // <linkto class=ComponentList>ComponentList</linkto> class, which handles
00063 // groups of SkyComponent objects.
00064 
00065 // Because the flux is constant with frequency the concept of a reference
00066 // frequency is meaningless with this class. But it can still be accessed using
00067 // the <src>refFrequency</src> and <src>setRefFrequency</src>. However changing
00068 // its value will not affect the behaviour of this class.
00069 
00070 // This class does not have any parameters and the <src>nParameters</src>
00071 // function will return zero. It is an error that will generate an exception
00072 // (in Debug mode) to call the <src>setParameters</src> and
00073 // <src>parameters</src> functions with anything other than a zero length
00074 // vector.
00075 
00076 // The <src>sample</src> functions always return 1.0.
00077 
00078 // This class also contains functions (<src>toRecord</src> &
00079 // <src>fromRecord</src>) which perform the conversion between Records and
00080 // ConstantSpectrum objects. These functions define how a ConstantSpectrum
00081 // object is represented in glish. The format of the record that is generated
00082 // and accepted by these functions is:
00083 // <srcblock>
00084 // c := [type = 'constant',
00085 //       frequency = [type = 'frequency',
00086 //                    refer = 'lsr',
00087 //                    m0 = [value = 1, unit = 'GHz']
00088 //                   ]
00089 //      ]
00090 // </srcblock>
00091 // The frequency field contains a record representation of a frequency measure
00092 // and its format is defined in the Measures module. Its refer field defines
00093 // the reference frame for the direction and the m0 field defines the value of
00094 // the reference frequency. The parsing of the type field is case
00095 // insensitive.
00096 // </synopsis>
00097 
00098 // <example>
00099 // Its hard to think of a good example for this class as it is basically does
00100 // nothing! In this example the spectral variation of a component is set to to
00101 // a constant value.
00102 // <srcblock>
00103 // SkyComponent myComp(...);
00104 // ...
00105 // if (myComp.spectrum().type() != ComponentType::CONSTANT_SPECTRUM) {
00106 //   myComp.spectrum() = ConstantSpectrum();
00107 // }
00108 // </srcblock>
00109 // </example>
00110 //
00111 // <motivation>
00112 // A ConstantSpectrum class is needed for users who are not interested in
00113 // modelling any spectral variation in their components.
00114 // </motivation>
00115 //
00116 // <todo asof="1999/11/23">
00117 //   <li> Nothing I hope!
00118 // </todo>
00119 
00120 // <linkfrom anchor="ConstantSpectrum" classes="SpectralModel SpectralIndex">
00121 //  <here>ConstantSpectrum</here> - Models the spectrum as constant
00122 // </linkfrom>
00123 
00124 class ConstantSpectrum: public SpectralModel
00125 {
00126 public:
00127   // The default constructor is the only one you really need as this class has
00128   // no parameters!
00129   ConstantSpectrum();
00130 
00131   // The copy constructor uses copy semantics
00132   ConstantSpectrum(const ConstantSpectrum& other);
00133 
00134   // The destructor does nothing.
00135   virtual ~ConstantSpectrum();
00136 
00137   // The assignment operator uses copy semantics.
00138   ConstantSpectrum& operator=(const ConstantSpectrum& other);
00139 
00140   // return the actual spectral type. This function always returns
00141   // ComponentType::CONSTANT_SPECTRUM
00142   virtual ComponentType::SpectralShape type() const;
00143 
00144   // Return the scaling factor that indicates the flux is at the specified
00145   // frequency assuming the flux at the reference frequency is one. This
00146   // function always returns one, as the spectrum is constant.
00147   virtual Double sample(const MFrequency& centerFrequency) const;
00148 
00149   // Same as the previous function except that many frequencies can be sampled
00150   // at once. The reference frame must be the same for all the specified
00151   // frequencies. Uses a customised implementation.
00152   virtual void sample(Vector<Double>& scale, 
00153                       const Vector<MFrequency::MVType>& frequencies, 
00154                       const MFrequency::Ref& refFrame) const;
00155 
00156   // Return a pointer to a copy of this object upcast to a SpectralModel
00157   // object. The class that uses this function is responsible for deleting the
00158   // pointer. This is used to implement a virtual copy constructor.
00159   virtual SpectralModel* clone() const;
00160 
00161   // return the number of parameters. There are no parameters for this spectral
00162   // model. So calling <src>setParameters</src> or <src>parameters</src> with
00163   // anything other than a zero length Vector will throw an exception (when
00164   // compiled in debug mode).
00165   // <group>
00166   virtual uInt nParameters() const;
00167   virtual void setParameters(const Vector<Double>& newSpectralParms);
00168   virtual Vector<Double> parameters() const;
00169   virtual void setErrors(const Vector<Double>& newSpectralErrs);
00170   virtual Vector<Double> errors() const;
00171   // </group>
00172 
00173   // These functions convert between a Record and a ConstantSpectrum. These
00174   // functions define how a ConstantSpectrum object is represented in glish and
00175   // this is detailed in the synopsis above. These functions return False if
00176   // the record is malformed and append an error message to the supplied string
00177   // giving the reason.
00178   // <group>
00179   virtual Bool fromRecord(String& errorMessage,
00180                           const RecordInterface& record);
00181   virtual Bool toRecord(String& errorMessage, RecordInterface& record) const;
00182   // </group>
00183 
00184   // Convert the parameters of the spectrum to the specified units. As a
00185   // constant spectrum has no parameters this function does nothing and always
00186   // returns True.
00187   virtual Bool convertUnit(String& errorMessage,
00188                            const RecordInterface& record);
00189  
00190   // Function which checks the internal data of this class for consistant
00191   // values. Returns True if everything is fine otherwise returns False.
00192   virtual Bool ok() const;
00193 };
00194 
00195 } //# NAMESPACE CASA - END
00196 
00197 #endif