casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpectralIndex.h
Go to the documentation of this file.
1 //# SpectralIndex.h: Models the spectral variation with a spectral index
2 //# Copyright (C) 1998-2014
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: SpectralIndex.h 21229 2012-04-02 12:00:20Z gervandiepen $
27 
28 #ifndef COMPONENTS_SPECTRALINDEX_H
29 #define COMPONENTS_SPECTRALINDEX_H
30 
31 #include <casa/aips.h>
34 
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 a spectral
60 // index.
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 // incorporates 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 // A spectral index is the exponent in a power law model for the variation flux
69 // with frequency. It is mathematically is defined as:
70 // <srcblock>
71 // (nu / nu_0)^alpha
72 // </srcblock>
73 // Where:
74 // <dl compact>
75 // <dt><src>nu_0</src><dd> is the reference frequency
76 // <dt><src>alpha</src><dd> is the spectral index
77 // <dt><src>nu</src><dd> is the user specified frequency
78 // </dl>
79 
80 // As with all classes derived from SpectralModel the basic operation of this
81 // class is to model the flux as a function of frequency. This class does not
82 // know what the flux is at the reference frequency. Instead the sample
83 // functions return factors that are used to scale the flux and calculate the
84 // amount of flux at a specified frequency.
85 
86 // Besides the reference frequency this class has one parameter; the spectral
87 // index. This parameter can be set & queried using the general purpose
88 // <src>parameters</src> functions or the class specific <src>index</src>
89 // functions.
90 
91 //<Dec-2013> Have added a full stokes spectral variation ...
92 // This is done via setting setStokesIndex.
93 // If setIndex is used then only the first element of 4 parameters is set
94 // The 4 elements are
95 // 0) alpha for stokes I ..such that
96 // 1) alpha for linear pol fraction i.e make sure that Q and U is such that sqrt(Q_0^2+U_0^2)/I_0 * (nu/nu_0)^alpha(1)) is obeyed.
97 // 2) Rot measure (RM=alpha(2)) value to rotate linear pol by angle RM*(lambda^2- lambda_0^2)
98 // 3) alpha for circular pol fraction i.e to make V such that V/I=V_0/I_0 *(nu/nu_0)^alpha(3)
99 //</Dec-2013>
100 // This class also contains functions (<src>toRecord</src> &
101 // <src>fromRecord</src>) which perform the conversion between Records and
102 // SpectralIndex objects. These functions define how a SpectralIndex
103 // object is represented in glish. The format of the record that is generated
104 // and accepted by these functions is:
105 // <srcblock>
106 // c := [type = 'spectral index',
107 // frequency = [type = 'frequency',
108 // refer = 'lsr',
109 // m0 = [value = 1, unit = 'GHz']
110 // ],
111 // index = 0.7
112 // ]
113 // </srcblock>
114 // The frequency field contains a record representation of a frequency measure
115 // and its format is defined in the Measures module. Its refer field defines
116 // the reference frame for the direction and the m0 field defines the value of
117 // the reference frequency. The parsing of the type field is case
118 // insensitive. The index field contains the spectral index.
119 // </synopsis>
120 
121 //
122 // <example>
123 // These examples are coded in the tSpectralModel.h file.
124 // <h4>Example 1:</h4>
125 // In this example a SpectralIndex object is created and used to calculate the
126 // flux at a number of frequencies.
127 // <srcblock>
128 //<Dec-2013> The example below was NEVER implemented...
129 // Could well have written the following and call it documentation:
130 // Sous un arbre, vos laitues naissent-elles ?
131 // Si vos laitues naissent, vos navets aussi naissent !
132 // Leaving it as is for archeological purposes
133 // </Dec-2013>
134 // SpectralIndex siModel;
135 // siModel.setRefFrequency(casacore::MFrequency(casacore::Quantity(1.0, "GHz")));
136 // siModel.setIndex(1.0, casacore::Stokes::I);
137 // siModel.setIndex(0.5, casacore::Stokes::Q);
138 // siModel.setIndex(0.5, casacore::Stokes::U);
139 // siModel.setIndex(-1.0, casacore::Stokes::V);
140 // const Flux<casacore::Double> LBandFlux(1.0, 1.0, 1.0, 1.0);
141 // const casacore::MVFrequency step(casacore::Quantity(100.0, "MHz"));
142 // casacore::MVFrequency sampleFreq = siModel.refFrequency().getValue();
143 // Flux<casacore::Double> sampleFlux;
144 // cout << "Frequency\t I-Flux\t Q-Flux\t U-Flux\t V-Flux\n";
145 // for (casacore::uInt i = 0; i < 11; i++) {
146 // sampleFlux = LBandFlux.copy();
147 // sampleFlux.convertPol(ComponentType::LINEAR);
148 // sampleFlux.convertUnit(casacore::Unit("WU"));
149 // siModel.sample(sampleFlux,
150 // casacore::MFrequency(sampleFreq, siModel.refFrequency().getRef()));
151 // cout << setprecision(3) << sampleFreq.get("GHz")
152 // << "\t\t " << sampleFlux.value(0u).re
153 // << "\t " << sampleFlux.value(1u).re
154 // << "\t " << sampleFlux.value(2u).re
155 // << "\t " << sampleFlux.value(3u).re
156 // << " " << sampleFlux.unit().getName() << endl;
157 // sampleFreq += step;
158 // }
159 //<Dec-2013>
160 // Now for an example
162 // const casacore::MFrequency f1(casacore::Quantity(1.0, "GHz"), casacore::MFrequency::LSRK);
163 // const casacore::MFrequency f2(casacore::Quantity(2.0, "GHz"), casacore::MFrequency::LSRK);
164 // SpectralIndex siModel;
165 // siModel.setIndex(1.0);
166 // cout << "scale value at 1 GHz for setIndex 1.0 " << siModel.sample(f1) << endl;
167 // casacore::Vector<casacore::Double> indices(4);
168 // indices(0)=1.0; indices(1)=0.2; indices(2)=0.0005; indices(3)=0.1;
169 // siModel.setStokesIndex(indices);
170 // casacore::Vector<casacore::Double> iquv(4);
171 // iquv(0)=10.0; iquv(1)=0.2; iquv(2)=0.4; iquv(3)=0.1;
172 // cerr << "iquv in " << iquv << " indices " << indices << endl;
173 // siModel.sampleStokes(f1, iquv);
174 // cerr << "scale value of I at 1.0 GHz " << siModel.sample(f1) << " iquv out " << iquv << endl;
175 // siModel.sampleStokes(f2, iquv);
176 // cerr << "scale value of I at 2.0 GHz " << siModel.sample(f2) << " iquv out " << iquv << endl;
177 //</Dec-2013>
178 // </srcblock>
179 // </example>
180 //
181 // <motivation> A Spectral Index frequency variation is the most widely used
182 // model in radio astronomy. In particular the NFRA package 'newstar' uses it
183 // extensively.
184 // </motivation>
185 //
186 // <todo asof="1999/11/23">
187 // <li> Nothing I hope
188 // </todo>
189 
190 // <linkfrom anchor="SpectralIndex" classes="SpectralModel ConstantSpectrum">
191 // <here>SpectralIndex</here> - Uses a spectral index to model the spectrum
192 // </linkfrom>
193 
195 {
196 public:
197  // The default SpectralIndex has a reference frequency of 1 GHz in the LSR
198  // frame and a spectral index of zero. As such it is no different from the
199  // ConstantSpectrum class (except slower).
200  SpectralIndex();
201 
202  // Construct a SpectralIndex with specified reference frequency and
203  // exponent.
204  SpectralIndex(const casacore::MFrequency& refFreq, casacore::Double exponent = 0.0);
205 
206  // The copy constructor uses copy semantics
207  SpectralIndex(const SpectralIndex& other);
208 
209  // The destructor does nothing special.
210  virtual ~SpectralIndex();
211 
212  // The assignment operator uses copy semantics.
213  SpectralIndex& operator=(const SpectralIndex& other);
214 
215  // return the actual spectral type ie., ComponentType::SPECTRAL_INDEX
216  virtual ComponentType::SpectralShape type() const;
217 
218  // set/get the spectral index.
219  // <group>
220  const casacore::Double& index() const;
221  void setIndex(const casacore::Double& newIndex);
224  // </group>
225 
226  // Return the scaling factor that indicates what proportion of the flux is at
227  // the specified frequency. ie. if the centreFrequency argument is the
228  // reference frequency then this function will always return one. At other
229  // frequencies it will return a non-negative number.
230  virtual casacore::Double sample(const casacore::MFrequency& centerFrequency) const;
231 
232  virtual void sampleStokes(const casacore::MFrequency& centerFrequency, casacore::Vector<casacore::Double>& iquv) const;
233  // Same as the previous function except that many frequencies can be sampled
234  // at once. The reference frame must be the same for all the specified
235  // frequencies. Uses a customised implementation for improved speed.
236  virtual void sample(casacore::Vector<casacore::Double>& scale,
238  const casacore::MFrequency::Ref& refFrame) const;
239 
242  const casacore::MFrequency::Ref& refFrame) const;
243 
244  // Return a pointer to a copy of this object upcast to a SpectralModel
245  // object. The class that uses this function is responsible for deleting the
246  // pointer. This is used to implement a virtual copy constructor.
247  virtual SpectralModel* clone() const;
248 
249  // return the number of parameters. There is one parameter or 4 for this spectral
250  // model, namely the spectral index for I or I,Q,U,V. So you supply a unit length vector
251  // or one 4 element long when
252  // using these functions. Otherwise an exception (casacore::AipsError) may be thrown.
253  // <group>
254  virtual casacore::uInt nParameters() const;
255  virtual void setParameters(const casacore::Vector<casacore::Double>& newSpectralParms);
257  virtual void setErrors(const casacore::Vector<casacore::Double>& newSpectralErrs);
259  // </group>
260 
261  // These functions convert between a casacore::Record and a SpectralIndex. These
262  // functions define how a SpectralIndex object is represented in glish and
263  // this is detailed in the synopsis above. These functions return false if
264  // the record is malformed and append an error message to the supplied string
265  // giving the reason.
266  // <group>
267  virtual casacore::Bool fromRecord(casacore::String& errorMessage, const casacore::RecordInterface& record);
268  virtual casacore::Bool toRecord(casacore::String& errorMessage, casacore::RecordInterface& record) const;
269  // </group>
270 
271  // Convert the parameters of the spectral index object to the specified
272  // units. Only one field of the supplied record is used, namely 'index'. This
273  // field is optional as the spectral index is a unitless quantity. If the
274  // index field is specified it must have the empty string as its value. This
275  // function always returns true unless the index field is specified and does
276  // not contain an empty string.
277  virtual casacore::Bool convertUnit(casacore::String& errorMessage,
278  const casacore::RecordInterface& record);
279 
280  // casacore::Function which checks the internal data of this class for consistant
281  // values. Returns true if everything is fine otherwise returns false.
282  virtual casacore::Bool ok() const;
283 
284 private:
288 };
289 
290 } //# NAMESPACE CASA - END
291 
292 #endif
void setIndex(const casacore::Double &newIndex)
virtual void setErrors(const casacore::Vector< casacore::Double > &newSpectralErrs)
std::vector< double > Vector
Definition: ds9context.h:24
virtual casacore::Bool convertUnit(casacore::String &errorMessage, const casacore::RecordInterface &record)
Convert the parameters of the spectral index object to the specified units.
virtual void setParameters(const casacore::Vector< casacore::Double > &newSpectralParms)
virtual casacore::Bool toRecord(casacore::String &errorMessage, casacore::RecordInterface &record) const
Convert the class to an Record representation.
casacore::Double itsIndex
A Measure: wave characteristics.
Definition: MFrequency.h:161
virtual ~SpectralIndex()
The destructor does nothing special.
const casacore::Vector< casacore::Double > & stokesIndex() const
casacore::Double itsError
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...
double Double
Definition: aipstype.h:55
virtual casacore::uInt nParameters() const
return the number of parameters.
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 ...
SpectralIndex()
The default SpectralIndex has a reference frequency of 1 GHz in the LSR frame and a spectral index of...
virtual casacore::Bool fromRecord(casacore::String &errorMessage, const casacore::RecordInterface &record)
These functions convert between a casacore::Record and a SpectralIndex.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Base class for spectral models.
SpectralIndex & operator=(const SpectralIndex &other)
The assignment operator uses copy semantics.
virtual casacore::Bool ok() const
casacore::Function which checks the internal data of this class for consistant values.
SpectralShape
The different functional forms for the spectral variation.
void setStokesIndex(const casacore::Vector< casacore::Double > &newIndex)
Models the spectral variation with a spectral index.
virtual SpectralModel * clone() const
Return a pointer to a copy of this object upcast to a SpectralModel object.
String: the storage and methods of handling collections of characters.
Definition: String.h:223
casacore::Vector< casacore::Double > itsStokesIndex
Abstract base class for Record classes.
virtual casacore::Vector< casacore::Double > parameters() const
virtual ComponentType::SpectralShape type() const
return the actual spectral type ie., ComponentType::SPECTRAL_INDEX
virtual casacore::Vector< casacore::Double > errors() const
const casacore::Double & index() const
set/get the spectral index.
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