casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TabularSpectrum.h
Go to the documentation of this file.
1 //# SpectralIndex.h: Models the spectral variation with a spectral index
2 //# Copyright (C) 2010
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: TabularSpectrum.h 21282 2012-11-05 11:04:19Z gervandiepen $
27 
28 #ifndef COMPONENTS_TABULARSPECTRUM_H
29 #define COMPONENTS_TABULARSPECTRUM_H
30 
31 #include <casa/aips.h>
35 namespace casacore{
36 
37 class MFrequency;
38 class RecordInterface;
39 class String;
40 template <class T> class Vector;
41 }
42 
43 namespace casa { //# NAMESPACE CASA - BEGIN
44 
45 
46 // <summary>Models the spectral variation with a spectral index</summary>
47 
48 // <use visibility=export>
49 
50 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralIndex" demos="dSpectralModel">
51 // </reviewed>
52 
53 // <prerequisite>
54 // <li> <linkto class="SpectralModel">SpectralModel</linkto>
55 // </prerequisite>
56 //
57 // <synopsis>
58 
59 // This class models the spectral variation of a component with measured
60 // values at given frequencies. The values are interpolated in betweenm
61 
62 // This class like the other spectral models becomes more useful when used
63 // through the <linkto class=SkyComponent>SkyComponent</linkto> class, which
64 // incorperates the flux and spatial variation of the emission, or through the
65 // <linkto class=ComponentList>ComponentList</linkto> class, which handles
66 // groups of SkyComponent objects.
67 
68 
69 // As with all classes derived from SpectralModel the basic operation of this
70 // class is to model the flux as a function of frequency. This class does not
71 // know what the flux is at the reference frequency. Instead the sample
72 // functions return factors that are used to scale the flux and calculate the
73 // amount of flux at a specified frequency.
74 
75 // Besides the reference frequency this class has one parameter; the spectral
76 // index. This parameter can be set & queried using the general purpose
77 // <src>parameters</src> functions or the class specific <src>index</src>
78 // functions.
79 
80 // This class also contains functions (<src>toRecord</src> &
81 // <src>fromRecord</src>) which perform the conversion between Records and
82 // SpectralIndex objects. These functions define how a SpectralIndex
83 // object is represented in glish. The format of the record that is generated
84 // and accepted by these functions is:
85 // <srcblock>
86 // c = {'type' : 'tabular',
87 // 'frequency' : {'type' : 'frequency',
88 // refer : 'lsr',
89 // m0 :{'value' : [1,1.1, 1.2, 1.3, 1.4], 'unit' : 'GHz'}
90 // },
91 
92 // 'flux' : {'value' : [1.0,1.1, 1.2, 1.3, 1.4], 'unit' : 'Jy'}
93 // }
94 // </srcblock>
95 // The frequency field contains a record representation of a vector frequency
96 // measure
97 // and its format is defined in the Measures module. Its refer field defines
98 // the reference frame for the direction and the m0 field defines the value of
99 // the reference frequency. The parsing of the type field is case
100 // insensitive. The index field contains the spectral index.
101 // </synopsis>
102 
103 //
104 // <example>
105 // These examples are coded in the tSpectralModel.h file.
106 // <h4>Example 1:</h4>
107 // In this example a SpectralIndex object is created and used to calculate the
108 // flux at a number of frequencies.
109 // <srcblock>
110 // SpectralIndex siModel;
111 // siModel.setRefFrequency(casacore::MFrequency(casacore::Quantity(1.0, "GHz")));
112 // siModel.setIndex(1.0, casacore::Stokes::I);
113 // siModel.setIndex(0.5, casacore::Stokes::Q);
114 // siModel.setIndex(0.5, casacore::Stokes::U);
115 // siModel.setIndex(-1.0, casacore::Stokes::V);
116 // const Flux<casacore::Double> LBandFlux(1.0, 1.0, 1.0, 1.0);
117 // const casacore::MVFrequency step(casacore::Quantity(100.0, "MHz"));
118 // casacore::MVFrequency sampleFreq = siModel.refFrequency().getValue();
119 // Flux<casacore::Double> sampleFlux;
120 // cout << "Frequency\t I-Flux\t Q-Flux\t U-Flux\t V-Flux\n";
121 // for (casacore::uInt i = 0; i < 11; i++) {
122 // sampleFlux = LBandFlux.copy();
123 // sampleFlux.convertPol(ComponentType::LINEAR);
124 // sampleFlux.convertUnit(casacore::Unit("WU"));
125 // siModel.sample(sampleFlux,
126 // casacore::MFrequency(sampleFreq, siModel.refFrequency().getRef()));
127 // cout << setprecision(3) << sampleFreq.get("GHz")
128 // << "\t\t " << sampleFlux.value(0u).re
129 // << "\t " << sampleFlux.value(1u).re
130 // << "\t " << sampleFlux.value(2u).re
131 // << "\t " << sampleFlux.value(3u).re
132 // << " " << sampleFlux.unit().getName() << endl;
133 // sampleFreq += step;
134 // }
135 // </srcblock>
136 // </example>
137 //
138 // <motivation> A Spectral Index frequency variation is the most widely used
139 // model in radio astronomy. In particular the NFRA package 'newstar' uses it
140 // extensively.
141 // </motivation>
142 //
143 // <todo asof="1999/11/23">
144 // <li> Nothing I hope
145 // </todo>
146 
147 // <linkfrom anchor="SpectralIndex" classes="SpectralModel ConstantSpectrum">
148 // <here>SpectralIndex</here> - Uses a spectral index to model the spectrum
149 // </linkfrom>
150 
152 {
153 public:
154  // The default SpectralIndex has a reference frequency of 1 GHz in the LSR
155  // frame and a spectral index of zero. As such it is no different from the
156  // ConstantSpectrum class (except slower).
157  TabularSpectrum();
158 
159  // Construct a Tabular values with I and f specified
160  // exponent.
162  const casacore::Vector<Flux<casacore::Double> >& flux, const casacore::MFrequency::Ref& refFrame);
163 
164  // The copy constructor uses copy semantics
165  TabularSpectrum(const TabularSpectrum& other);
166 
167  // The destructor does nothing special.
168  virtual ~TabularSpectrum();
169 
170  // The assignment operator uses copy semantics.
172 
173  // return the actual spectral type ie., ComponentType::TABULAR_SPECTRUM
174  virtual ComponentType::SpectralShape type() const;
175 
176  virtual void setRefFrequency(const casacore::MFrequency& newRefFreq);
177  // set/get the Tabular values
178  // <group>
181  // </group>
182 
183  // Return the scaling factor that indicates what proportion of the flux is at
184  // the specified frequency. ie. if the centreFrequency argument is the
185  // reference frequency then this function will always return one. At other
186  // frequencies it will return a non-negative number.
187  virtual casacore::Double sample(const casacore::MFrequency& centerFrequency) const;
188  virtual void sampleStokes(const casacore::MFrequency& centerFrequency, casacore::Vector<casacore::Double>& iquv) const;
189  // Same as the previous function except that many frequencies can be sampled
190  // at once. The reference frame must be the same for all the specified
191  // frequencies. Uses a customised implementation for improved speed.
192  virtual void sample(casacore::Vector<casacore::Double>& scale,
194  const casacore::MFrequency::Ref& refFrame) const;
195 
198  const casacore::MFrequency::Ref& refFrame) const;
199 
200  // Return a pointer to a copy of this object upcast to a SpectralModel
201  // object. The class that uses this function is responsible for deleting the
202  // pointer. This is used to implement a virtual copy constructor.
203  virtual SpectralModel* clone() const;
204 
205  // return the number of parameters. There is one parameter for this spectral
206  // model, namely the spectral index. So you supply a unit length vector when
207  // using these functions. Otherwise an exception (casacore::AipsError) may be thrown.
208  // <group>
209  virtual casacore::uInt nParameters() const;
210  virtual void setParameters(const casacore::Vector<casacore::Double>& newSpectralParms);
212  virtual void setErrors(const casacore::Vector<casacore::Double>& newSpectralErrs);
214  // </group>
215 
216  // These functions convert between a casacore::Record and a SpectralIndex. These
217  // functions define how a SpectralIndex object is represented in glish and
218  // this is detailed in the synopsis above. These functions return false if
219  // the record is malformed and append an error message to the supplied string
220  // giving the reason.
221  // <group>
222  virtual casacore::Bool fromRecord(casacore::String& errorMessage, const casacore::RecordInterface& record);
223  virtual casacore::Bool toRecord(casacore::String& errorMessage, casacore::RecordInterface& record) const;
224  // </group>
225 
226  // Convert the parameters of the spectral index object to the specified
227  // units. Only one field of the supplied record is used, namely 'index'. This
228  // field is optional as the spectral index is a unitless quantity. If the
229  // index field is specified it must have the empty string as its value. This
230  // function always returns true unless the index field is specified and does
231  // not contain an empty string.
232  virtual casacore::Bool convertUnit(casacore::String& errorMessage,
233  const casacore::RecordInterface& record);
234 
235  // casacore::Function which checks the internal data of this class for consistant
236  // values. Returns true if everything is fine otherwise returns false.
237  virtual casacore::Bool ok() const;
238 
239 private:
240 
249 
250 };
251 
252 } //# NAMESPACE CASA - END
253 
254 #endif
virtual casacore::Bool convertUnit(casacore::String &errorMessage, const casacore::RecordInterface &record)
Convert the parameters of the spectral index object to the specified units.
casacore::Double minFreq_p
A 1-D Specialization of the Array class.
std::vector< double > Vector
Definition: ds9context.h:24
casacore::MFrequency::Ref freqRef_p
void values(casacore::Vector< casacore::MFrequency::MVType > &freq, casacore::Vector< Flux< casacore::Double > > &flux) const
set/get the Tabular values
casacore::Vector< casacore::Double > qval_p
void setValues(const casacore::Vector< casacore::MFrequency::MVType > &frequencies, const casacore::Vector< Flux< casacore::Double > > &flux, const casacore::MFrequency::Ref &refFrame)
virtual ComponentType::SpectralShape type() const
return the actual spectral type ie., ComponentType::TABULAR_SPECTRUM
virtual void setRefFrequency(const casacore::MFrequency &newRefFreq)
set/get the reference frequency
casacore::Vector< casacore::Double > vval_p
virtual casacore::Vector< casacore::Double > parameters() const
virtual casacore::Double sample(const casacore::MFrequency &centerFrequency) const
Return the scaling factor that indicates what proportion of the flux is at the specified frequency...
virtual casacore::Vector< casacore::Double > errors() const
virtual void sampleStokes(const casacore::MFrequency &centerFrequency, casacore::Vector< casacore::Double > &iquv) const
return full casacore::Stokes version especially for models which have different frequency dependence ...
virtual ~TabularSpectrum()
The destructor does nothing special.
A Measure: wave characteristics.
Definition: MFrequency.h:161
casacore::Vector< casacore::Double > refVal_p
virtual void setParameters(const casacore::Vector< casacore::Double > &newSpectralParms)
double Double
Definition: aipstype.h:55
casacore::Vector< casacore::Double > tabFreqVal_p
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Base class for spectral models.
virtual SpectralModel * clone() const
Return a pointer to a copy of this object upcast to a SpectralModel object.
casacore::Vector< Flux< casacore::Double > > flux_p
virtual casacore::Bool ok() const
casacore::Function which checks the internal data of this class for consistant values.
casacore::Double maxFreq_p
SpectralShape
The different functional forms for the spectral variation.
virtual casacore::uInt nParameters() const
return the number of parameters.
casacore::Double referenceFreq_p
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::Vector< casacore::Double > uval_p
TabularSpectrum & operator=(const TabularSpectrum &other)
The assignment operator uses copy semantics.
virtual casacore::Bool toRecord(casacore::String &errorMessage, casacore::RecordInterface &record) const
Convert the class to an Record representation.
Abstract base class for Record classes.
casacore::Vector< casacore::Double > ival_p
virtual casacore::Bool fromRecord(casacore::String &errorMessage, const casacore::RecordInterface &record)
These functions convert between a casacore::Record and a SpectralIndex.
Models the spectral variation with a spectral index.
unsigned int uInt
Definition: aipstype.h:51
TabularSpectrum()
The default SpectralIndex has a reference frequency of 1 GHz in the LSR frame and a spectral index of...
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
virtual void setErrors(const casacore::Vector< casacore::Double > &newSpectralErrs)