casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpectralModel.h
Go to the documentation of this file.
1 //# SpectralModel.h: Base class for Spectral Models
2 //# Copyright (C) 1998,1999,2000,2003
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: SpectralModel.h 18093 2004-11-30 17:51:10Z ddebonis $
27 
28 #ifndef COMPONENTS_SPECTRALMODEL_H
29 #define COMPONENTS_SPECTRALMODEL_H
30 
31 #include <casa/aips.h>
35 #include <casa/Quanta/Unit.h>
36 #include <casa/Quanta/Quantum.h>
37 
38 namespace casacore{
39 
40 class RecordInterface;
41 class String;
42 template <class T> class Vector;
43 }
44 
45 namespace casa { //# NAMESPACE CASA - BEGIN
46 
47 
48 // <summary>Base class for spectral models</summary>
49 
50 // <use visibility=export>
51 
52 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tConstantSpectrum" demos="dSpectralModel">
53 // </reviewed>
54 
55 // <prerequisite>
56 // <li> <linkto class=casacore::MFrequency>MFrequency</linkto>
57 // </prerequisite>
58 //
59 // <synopsis>
60 
61 // This abstract base class defines the interface for different classes which
62 // model the spectrum of a component. The most fundamental derived class is the
63 // <linkto class=ConstantSpectrum>ConstantSpectrum</linkto> class but the
64 // <linkto class=SpectralIndex>SpectralIndex</linkto> class is also
65 // available. These classes model the spectrum of emission from the sky.
66 
67 // Classes derived from the
68 // <linkto class=ComponentShape>ComponentShape</linkto> class are used to model
69 // the shape and the <linkto class=Flux>Flux</linkto> class is used to model
70 // the flux. The <linkto class=SkyComponent>SkyComponent</linkto> class
71 // incorporates these three characteristics (flux, shape & spectrum) and the
72 // <linkto class=ComponentList>ComponentList</linkto> class handles groups of
73 // SkyComponent objects.
74 
75 // This class parameterises spectral models with two quantities.
76 // <dl>
77 // <dt><em> A reference frequency.</em>
78 // <dd> This is specified using an <linkto class=casacore::MFrequency>MFrequency</linkto>
79 // object and defines a frequency where the model
80 // is interesting. See the description of derived classes for the
81 // specific interpretation of the reference frequency.
82 // <dt> <em>A casacore::Vector of parameters.</em>
83 // <dd> This contains other parameters that the are defined differently for
84 // different spectral models. The length of the vector may vary for
85 // different spectral models.
86 // </dl>
87 //
88 
89 // The basic operation of classes using this interface is to model the flux as
90 // a function of frequency. Classes derived from this one do not know what the
91 // flux is at the reference frequency. Instead the sample functions return
92 // factors that are used to scale the flux and calculate the amount of flux at
93 // a specified frequency.
94 
95 // Any allowed frequency reference frame can be used. However the reference
96 // frame must be adequately specified in order to allow conversions to other
97 // reference frames. For example if the reference frame code for the frequency
98 // is casacore::MFrequency::TOPO then the reference frame must also contain the time,
99 // position on the earth, and direction of the observation that corresponds to
100 // the specified frequency. This way the sample functions can convert the
101 // frequency to a value in the LSR reference frame (if you specify the sample
102 // frequency in the LSR frame).
103 
104 // </synopsis>
105 //
106 // <example>
107 // Because this is an abstract base class, an actual instance of this class
108 // cannot be constructed. However the interface it defines can be used inside a
109 // function. This is always recommended as it allows functions which have
110 // SpectralModels as arguments to work for any derived class.
111 
112 // In this example the plotSpectrum function prints out the type of spectral
113 // model it is working with and the reference frequency of that model. It then
114 // uses the model to calculate the proportion of the flux at other
115 // frequencies. This example is coded in the dSpectralModel.cc file.
116 
117 // <srcblock>
118 // void plotSpectrum(const SpectralModel& modelSpectrum) {
119 // cout << "This is a "
120 // << ComponentType::name(modelSpectrum.type())
121 // << " spectrum with a reference frequency of: "
122 // << setprecision(4) << modelSpectrum.refFrequency().get("GHz") << " ("
123 // << modelSpectrum.refFrequency().getRefString() << ")"
124 // << endl;
125 // const casacore::MVFrequency step(casacore::Quantity(100.0, "MHz"));
126 // casacore::MVFrequency sampleFreq(casacore::Quantity(1, "GHz"));
127 // casacore::MeasFrame obsFrame;
128 // {
129 // casacore::Quantity obsRa; casacore::MVAngle::read(obsRa, "19:39:");
130 // casacore::Quantity obsDec; casacore::MVAngle::read(obsDec, "-63.43.");
131 // casacore::Quantity obsDay; casacore::MVTime::read(obsDay, "1996/11/20/5:20");
132 // obsFrame.set(casacore::MEpoch(obsDay, casacore::MEpoch::UTC),
133 // casacore::MDirection(obsRa, obsDec, casacore::MDirection::J2000));
134 // }
135 // casacore::MFrequency::Ref obsRef(casacore::MFrequency::GEO, obsFrame);
136 // cout << "Frequency\t scale\n";
137 // for (casacore::uInt i = 0; i < 11; i++) {
138 // cout << setprecision(7) << sampleFreq.get("GHz")
139 // << "\t\t " << modelSpectrum.sample(casacore::MFrequency(sampleFreq, obsRef))
140 // << endl;
141 // sampleFreq += step;
142 // }
143 // }
144 // </srcblock>
145 // </example>
146 //
147 // <motivation>
148 // The SpectralModel base class was seperated from the ComponentShape base
149 // class so that mixing components with different spatial and spectral shapes
150 // did not result in a combinatorial explosion in the number of classes
151 // required.
152 // </motivation>
153 //
154 // <todo asof="1999/11/23">
155 // <li> I would not be surprised if the base class will need to be updated
156 // when classes modelling spectral lines are written.
157 // </todo>
158 
160 {
161 public:
162  // a virtual destructor is needed so that the actual destructor in the
163  // derived class will be used.
164  virtual ~SpectralModel();
165 
166  // return the actual spectral type. The ident function returns it as a
167  // String.
168  // <group>
169  virtual ComponentType::SpectralShape type() const = 0;
170  virtual const casacore::String& ident() const;
171  // </group>
172 
173  // set/get the reference frequency
174  // <group>
175  virtual void setRefFrequency(const casacore::MFrequency& newRefFreq);
176  const casacore::MFrequency& refFrequency() const;
177  // </group>
178 
179  // get the frequency unit, and change the default frequency unit to the
180  // specified one. This will only affect the units used in the casacore::Record returned
181  // by the toRecord function.
182  // <group>
183  const casacore::Unit& frequencyUnit() const;
184  void convertFrequencyUnit(const casacore::Unit& freqUnit);
185  // </group>
186 
187  // set/get the error in the reference frequency. Values must be positive
188  // angular quantities otherwise an casacore::AipsError exception is thrown. The errors
189  // are usually interpreted as the 1-sigma bounds in latitude/longitude and
190  // implicitly assume a Gaussian distribution. They must have units with the
191  // same dimensions as the Hz.
192  // <group>
195  // </group>
196 
197  // Return the scaling factor that indicates what proportion of the flux is at
198  // the specified frequency. ie. if the centreFrequency argument is the
199  // reference frequency then this function will always return one. At other
200  // frequencies it will return a non-negative number.
201  virtual casacore::Double sample(const casacore::MFrequency& centerFrequency) const = 0;
202 
203  // return full casacore::Stokes version especially for models which have different
204  // frequency dependence for the casacore::Stokes param (1 or 4 elements)
205  // So as allow for fractional pol change and angle change of linear pol w.r.t frequency
206  // A a four casacore::Vector of original IQUV should be passed in and it will hold the return values
207 
208  virtual void sampleStokes(const casacore::MFrequency& centerFrequency, casacore::Vector<casacore::Double>& stokesval ) const = 0;
209  // Same as the previous function except that many frequencies can be sampled
210  // at once. The reference frame must be the same for all the specified
211  // frequencies. A default implementation of this function is available that
212  // uses the sample function described above. However customised versions of
213  // this function will be more efficient as intermediate values only need to
214  // be computed once.
215  virtual void sample(casacore::Vector<casacore::Double>& scale,
217  const casacore::MFrequency::Ref& refFrame) const = 0;
218 
219 // So as allow for fractional pol change and angle change of linear pol w.r.t frequency
220 // casacore::Vector of four Vectors of original IQUV should be passed in and it will hold the return values
221 // Uitimately this math should really go in Flux and FluxRep to where a rotation of linear pol is allowed
222 
225  const casacore::MFrequency::Ref& refFrame) const = 0;
226  // Return a pointer to a copy of the derived object upcast to a SpectralModel
227  // object. The class that uses this function is responsible for deleting the
228  // pointer. This is used to implement a virtual copy constructor.
229  virtual SpectralModel* clone() const = 0;
230 
231  // return the number of parameters in this spectral shape and set/get them.
232  // <group>
233  virtual casacore::uInt nParameters() const = 0;
234  virtual void setParameters(const casacore::Vector<casacore::Double>& newParms) = 0;
236  virtual void setErrors(const casacore::Vector<casacore::Double>& newErrors) = 0;
237  virtual casacore::Vector<casacore::Double> errors() const = 0;
238  // </group>
239 
240  // These functions convert between a record and a SpectralModel. This way
241  // derived classes can interpret fields in the record in a class specific
242  // way. They return false if the record is malformed and append an error
243  // message to the supplied string giving the reason. These functions define
244  // how a spectral model is represented in glish. All records should have
245  // 'type' & 'frequency' fields which contain respectively; a string
246  // indicating which spectral model is actually used, and a record
247  // representation of a frequency measure. The interpretation of all other
248  // fields depends on the specific spectral model used.
249  // <group>
250  virtual casacore::Bool fromRecord(casacore::String& errorMessage,
251  const casacore::RecordInterface& record) = 0;
252  virtual casacore::Bool toRecord(casacore::String& errorMessage,
253  casacore::RecordInterface& record) const = 0;
254  // </group>
255 
256  // Convert the parameters of the spectral model to the specified units. The
257  // casacore::Record must contain the same fields that the to/from casacore::Record functions have
258  // (with the exception of the frequency & type fields). These fields will
259  // contain strings (and not Quantums) that specify the new units for these
260  // parameters. The new units must have the same dimensions as the existing
261  // ones. If there is any problem parsing the record then an error message is
262  // appended to the supplied string and the function returns false.
263  virtual casacore::Bool convertUnit(casacore::String& errorMessage,
264  const casacore::RecordInterface& record) = 0;
265 
266  // Return the spectral shape that the supplied record represents. The
267  // spectral shape is determined by parsing a 'type' field in the supplied
268  // record. Returns ComponentType::UNKNOWN_SPECTRAL_SHAPE if the type field
269  // (which contains a string) could not be translated into a known spectral
270  // shape. It then appends an appropriate error message to the errorMessage
271  // String.
273  const casacore::RecordInterface& record);
274 
275  // casacore::Function which checks the internal data of this class for correct
276  // dimensionality and consistant values. Returns true if everything is fine
277  // otherwise returns false.
278  virtual casacore::Bool ok() const;
279 
280 protected:
281  // The constructors and assignment operator are protected as only derived
282  // classes should use them.
283  // <group>
284  //# The default reference frequency is at 1 GHz in the LSR frame
285  SpectralModel();
286 
287  //# Construct a SpectralModel at the specified reference frequency.
288  SpectralModel(const casacore::MFrequency& refFreq, const casacore::Unit& = casacore::Unit("GHz"));
289 
290  //# The copy constructor uses copy semantics.
291  SpectralModel(const SpectralModel& other);
292 
293  //# The assignment operator uses copy semantics.
294  SpectralModel& operator=(const SpectralModel& other);
295  // </group>
296 
297  // Return the value refFrequency in the requested frame...
298  //exception is thrown if convert does not work.
299  //No direction or epoch is available..so better ask for a frame
300  // that works or better convert to the frame of the refFrequency .
302  // returns true if the quantum is not a non-negative quantity with units
303  // dimensionally identical to the Hz
305 
306 private:
307  //# The reference frequency of the spectral model
309  //# the units (Hz, GHz etc.) that the record functions should use for the
310  //# reference frequency.
313 };
314 
315 } //# NAMESPACE CASA - END
316 
317 #endif
virtual casacore::Bool convertUnit(casacore::String &errorMessage, const casacore::RecordInterface &record)=0
Convert the parameters of the spectral model to the specified units.
virtual casacore::Vector< casacore::Double > parameters() const =0
virtual casacore::Double sample(const casacore::MFrequency &centerFrequency) const =0
Return the scaling factor that indicates what proportion of the flux is at the specified frequency...
std::vector< double > Vector
Definition: ds9context.h:24
static casacore::Bool badError(const casacore::Quantum< casacore::Double > &quantum)
returns true if the quantum is not a non-negative quantity with units dimensionally identical to the ...
casacore::Double refFreqInFrame(const casacore::MFrequency::Ref &frame) const
Return the value refFrequency in the requested frame...
virtual void setErrors(const casacore::Vector< casacore::Double > &newErrors)=0
Interface class for converting to/from records.
void convertFrequencyUnit(const casacore::Unit &freqUnit)
virtual void sampleStokes(const casacore::MFrequency &centerFrequency, casacore::Vector< casacore::Double > &stokesval) const =0
return full casacore::Stokes version especially for models which have different frequency dependence ...
defines physical units
Definition: Unit.h:189
A Measure: wave characteristics.
Definition: MFrequency.h:161
virtual void setRefFrequency(const casacore::MFrequency &newRefFreq)
set/get the reference frequency
virtual const casacore::String & ident() const
Specify the identification of the record (e.g.
virtual SpectralModel * clone() const =0
Return a pointer to a copy of the derived object upcast to a SpectralModel object.
const casacore::MFrequency & refFrequency() const
casacore::Quantity itsFreqErr
double Double
Definition: aipstype.h:55
virtual casacore::uInt nParameters() const =0
return the number of parameters in this spectral shape and set/get them.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
static ComponentType::SpectralShape getType(casacore::String &errorMessage, const casacore::RecordInterface &record)
Return the spectral shape that the supplied record represents.
Base class for spectral models.
virtual casacore::Bool fromRecord(casacore::String &errorMessage, const casacore::RecordInterface &record)=0
These functions convert between a record and a SpectralModel.
SpectralShape
The different functional forms for the spectral variation.
virtual casacore::Bool toRecord(casacore::String &errorMessage, casacore::RecordInterface &record) const =0
Convert the class to an Record representation.
virtual void setParameters(const casacore::Vector< casacore::Double > &newParms)=0
casacore::Unit itsFreqUnit
virtual ComponentType::SpectralShape type() const =0
return the actual spectral type.
virtual casacore::Bool ok() const
casacore::Function which checks the internal data of this class for correct dimensionality and consis...
SpectralModel & operator=(const SpectralModel &other)
virtual casacore::Vector< casacore::Double > errors() const =0
String: the storage and methods of handling collections of characters.
Definition: String.h:223
Abstract base class for Record classes.
virtual ~SpectralModel()
a virtual destructor is needed so that the actual destructor in the derived class will be used...
SpectralModel()
The constructors and assignment operator are protected as only derived classes should use them...
void setRefFrequencyError(const casacore::Quantum< casacore::Double > &newRefFreqErr)
set/get the error in the reference frequency.
casacore::MFrequency itsRefFreq
const casacore::Unit & frequencyUnit() const
get the frequency unit, and change the default frequency unit to the specified one.
const casacore::Quantum< casacore::Double > & refFrequencyError() const
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42