source: branches/polybatch/src/STAtmosphere.cpp@ 2124

Last change on this file since 2124 was 1823, checked in by Kana Sugimoto, 14 years ago

New Development: No

JIRA Issue: No (merge: recover logs)

Ready for Test: Yes

Interface Changes: No

Module(s): nothing just logs

Description:

restored several codes from tags/asap-trunk-no-alma to recover change logs.
In addition, STFITSImageWriter.cpp is modified by hand to merge a change in alma branch.

File size: 21.7 KB
Line 
1//#---------------------------------------------------------------------------
2//# STAtmosphere.h: Model of atmospheric opacity
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
5//# ATNF
6//#
7//# The code is based on the Fortran code written by Bob Sault for MIRIAD.
8//# Converted to C++ by Max Voronkov. This code uses a simple model of the
9//# atmosphere and Liebe's model (1985) of the complex refractive index of
10//# air.
11//#
12//# The model of the atmosphere is one with an exponential fall-off in
13//# the water vapour content (scale height of 1540 m) and a temperature lapse
14//# rate of 6.5 mK/m. Otherwise the atmosphere obeys the ideal gas equation
15//# and hydrostatic equilibrium.
16//#
17//# This program is free software; you can redistribute it and/or modify it
18//# under the terms of the GNU General Public License as published by the Free
19//# Software Foundation; either version 2 of the License, or (at your option)
20//# any later version.
21//#
22//# This program is distributed in the hope that it will be useful, but
23//# WITHOUT ANY WARRANTY; without even the implied warranty of
24//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
25//# Public License for more details.
26//#
27//# You should have received a copy of the GNU General Public License along
28//# with this program; if not, write to the Free Software Foundation, Inc.,
29//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
30//#
31//# Correspondence concerning this software should be addressed as follows:
32//# Internet email: Malte.Marquarding@csiro.au
33//# Postal address: Malte Marquarding,
34//# Australia Telescope National Facility,
35//# P.O. Box 76,
36//# Epping, NSW, 2121,
37//# AUSTRALIA
38//#
39//# $Id: STAtmosphere.h 1346 2007-04-26 03:24:41Z mar637 $
40//#---------------------------------------------------------------------------
41
42// own includes
43#include "STAtmosphere.h"
44
45// casa includes
46#include <casa/Utilities/Assert.h>
47#include <casa/Quanta.h>
48
49// std includes
50#include <cmath>
51
52using namespace casa;
53using namespace asap;
54
55/**
56 * Default Constructor (apart from optional parameters).
57 * The class set up this way will assume International Standard Atmosphere (ISA) conditions,
58 * except for humidity. The latter is assumed to be 50%, which seems more realistic for
59 * Australian telescopes than 0%.
60 * @param[in] wvScale water vapour scale height (m), default is 1540m to match MIRIAD's model
61 * @param[in] maxAlt maximum altitude of the model atmosphere (m), plane parallel layers are spread linearly up to
62 * this height, default is 10000m to match MIRIAD.
63 * @param[in] nLayers number of plane parallel layers in the model (essentially for a numberical integration),
64 * default is 50 to match MIRIAD.
65 **/
66STAtmosphere::STAtmosphere(double wvScale, double maxAlt, size_t nLayers) :
67 itsHeights(nLayers), itsTemperatures(nLayers),
68 itsDryPressures(nLayers), itsVapourPressures(nLayers),
69 itsGndTemperature(288.), itsPressure(101325.), itsGndHumidity(0.5),
70 itsLapseRate(0.0065), itsWVScale(wvScale), itsMaxAlt(maxAlt), itsObsHeight(200.)
71{
72 recomputeAtmosphereModel();
73}
74
75/**
76 * Constructor with explicitly given parameters of the atmosphere
77 * @param[in] temperature air temperature at the observatory (K)
78 * @param[in] pressure air pressure at the sea level if the observatory elevation is set
79 * (default is set to 200m) or at the observatory ground level if the elevation
80 * is set to 0 (Pascals)
81 * @param[in] humidity air humidity at the observatory (fraction)
82 * @param[in] lapseRate temperature lapse rate (K/m), default is 0.0065 K/m to match MIRIAD and ISA
83 * @param[in] wvScale water vapour scale height (m), default is 1540m to match MIRIAD's model
84 * @param[in] maxAlt maximum altitude of the model atmosphere (m), plane parallel layers are spread linearly up to
85 * this height, default is 10000m to match MIRIAD.
86 * @param[in] nLayers number of plane parallel layers in the model (essentially for a numberical integration),
87 * default is 50 to match MIRIAD.
88 **/
89STAtmosphere::STAtmosphere(double temperature, double pressure, double humidity, double lapseRate,
90 double wvScale, double maxAlt, size_t nLayers) :
91 itsHeights(nLayers), itsTemperatures(nLayers),
92 itsDryPressures(nLayers), itsVapourPressures(nLayers),
93 itsGndTemperature(temperature), itsPressure(pressure), itsGndHumidity(humidity),
94 itsLapseRate(lapseRate), itsWVScale(wvScale), itsMaxAlt(maxAlt), itsObsHeight(200.)
95{
96 recomputeAtmosphereModel();
97}
98
99/**
100 * Set the new weather station data, recompute the model
101 * @param[in] temperature air temperature at the observatory (K)
102 * @param[in] pressure air pressure at the sea level if the observatory elevation is set to non-zero value
103 * (default is set to 200m) or at the observatory ground level if the elevation
104 * is set to 0 (Pascals)
105 * @param[in] humidity air humidity at the observatory (fraction)
106 **/
107void STAtmosphere::setWeather(double temperature, double pressure, double humidity)
108{
109 itsGndTemperature = temperature;
110 itsPressure = pressure;
111 itsGndHumidity = humidity;
112 recomputeAtmosphereModel();
113}
114
115/**
116 * Set the elevation of the observatory (height above mean sea level)
117 * It affects only interpretation of the pressure supplied as part of the weather data, if this value
118 * is non-zero, the pressure (e.g. in setWeather or constructor) is that at mean sea level. If the
119 * observatory elevation is set to zero, regardless on real elevation, the pressure is that at the
120 * observatory ground level.
121 *
122 * By default, 200m is assumed and the pressure should be a mean sea level pressure..
123 * @param[in] elev elevation in metres
124 **/
125void STAtmosphere::setObservatoryElevation(double elev)
126{
127 itsObsHeight = elev;
128 recomputeAtmosphereModel();
129}
130
131
132/**
133 * Build the atmosphere model based on exponential fall-off, ideal gas and hydrostatic
134 * equilibrium. The model parameters are taken from the data members of this class.
135 **/
136void STAtmosphere::recomputeAtmosphereModel()
137{
138 AlwaysAssert(itsGndTemperature > 0, AipsError);
139 AlwaysAssert(itsPressure > 0., AipsError);
140 AlwaysAssert((itsGndHumidity >= 0.) && (itsGndHumidity<=1.), AipsError);
141 AlwaysAssert(itsMaxAlt > 0., AipsError);
142 AlwaysAssert(itsWVScale > 0., AipsError);
143
144 const double heightStep = itsMaxAlt/double(nLayers());
145 // molar mass of the air
146 const double M = 28.96e-3;
147 // free-fall acceleration
148 const double g = 9.81;
149
150 const double wvGndSaturationPressure = wvSaturationPressure(itsGndTemperature);
151 const double gndPressure = itsPressure*exp(-M*g/(QC::R.get().getValue()*itsGndTemperature)*
152 (itsObsHeight+0.5*itsLapseRate*itsObsHeight*itsObsHeight/itsGndTemperature));
153 for (size_t layer = 0; layer < nLayers(); ++layer) {
154 const double height = double(layer)*heightStep;
155 itsHeights[layer] = height;
156 itsTemperatures[layer] = itsGndTemperature/(1.+itsLapseRate*height/itsGndTemperature);
157 const double pressure = gndPressure * exp(-M*g/(QC::R.get().getValue()*itsGndTemperature)*
158 (height+0.5*itsLapseRate*height*height/itsGndTemperature));
159 itsVapourPressures[layer] = casa::min(itsGndHumidity*exp(-height/itsWVScale)*wvGndSaturationPressure,
160 wvSaturationPressure(itsTemperatures[layer]));
161 itsDryPressures[layer] = pressure - itsVapourPressures[layer];
162 //std::cout<<"layer="<<layer<<": H="<<itsHeights[layer]<<" T="<<itsTemperatures[layer]<<
163 // " Pvap="<<itsVapourPressures[layer]<<" Pdry="<<itsDryPressures[layer]<<endl;
164 }
165}
166
167/**
168 * Obtain the number of model layers, do consistency check that everything is
169 * resized accordingly
170 * @retrun number of model layers
171 **/
172size_t STAtmosphere::nLayers() const
173{
174 const size_t result = itsHeights.size();
175 DebugAssert(result > 2, AipsError);
176 DebugAssert(itsTemperatures.size() == result, AipsError);
177 DebugAssert(itsDryPressures.size() == result, AipsError);
178 DebugAssert(itsVapourPressures.size() == result, AipsError);
179 return result;
180}
181
182/**
183 * Determine the saturation pressure of water vapour for the given temperature.
184 *
185 * Reference:
186 * Waters, Refraction effects in the neutral atmosphere. Methods of
187 * Experimental Physics, vol 12B, p 186-200 (1976).
188 *
189 * @param[in] temperature temperature in K
190 * @return vapour saturation pressure (Pascals)
191 **/
192double STAtmosphere::wvSaturationPressure(double temperature)
193{
194 if (temperature <= 215.) {
195 return 0.;
196 }
197 const double theta = 300.0/temperature;
198 return 1e5/(41.51/std::pow(theta,5)*std::pow(10.,9.834*theta-10.0));
199}
200
201/**
202 * Compute the complex refractivity of the dry components of the atmosphere
203 * (oxygen lines) at the given frequency.
204 * @param[in] freq frequency (Hz)
205 * @param[in] temperature air temperature (K)
206 * @param[in] pDry partial pressure of dry components (Pascals)
207 * @param[in] pVapour partial pressure of water vapour (Pascals)
208 * @return complex refractivity
209 *
210 * Reference:
211 * Liebe, An updated model for millimeter wave propogation in moist air,
212 * Radio Science, 20, 1069-1089 (1985).
213 **/
214std::complex<double> STAtmosphere::dryRefractivity(double freq, double temperature,
215 double pDry, double pVapour)
216{
217 // the number of parameters per atmospheric line and the number of lines taken into account
218 const size_t nLineParams = 7;
219 const size_t nLines = 48;
220 // actual tabulated values
221 const double lines[nLines][nLineParams] =
222 {{49.452379, 0.12E-6, 11.830, 8.40E-3, 0.0, 5.60E-3, 1.7},
223 {49.962257, 0.34E-6, 10.720, 8.50E-3, 0.0, 5.60E-3, 1.7},
224 {50.474238, 0.94E-6, 9.690, 8.60E-3, 0.0, 5.60E-3, 1.7},
225 {50.987748, 2.46E-6, 8.690, 8.70E-3, 0.0, 5.50E-3, 1.7},
226 {51.503350, 6.08E-6, 7.740, 8.90E-3, 0.0, 5.60E-3, 1.8},
227 {52.021409, 14.14E-6, 6.840, 9.20E-3, 0.0, 5.50E-3, 1.8},
228 {52.542393, 31.02E-6, 6.000, 9.40E-3, 0.0, 5.70E-3, 1.8},
229 {53.066906, 64.10E-6, 5.220, 9.70E-3, 0.0, 5.30E-3, 1.9},
230 {53.595748, 124.70E-6, 4.480, 10.00E-3, 0.0, 5.40E-3, 1.8},
231 {54.129999, 228.00E-6, 3.810, 10.20E-3, 0.0, 4.80E-3, 2.0},
232 {54.671157, 391.80E-6, 3.190, 10.50E-3, 0.0, 4.80E-3, 1.9},
233 {55.221365, 631.60E-6, 2.620, 10.79E-3, 0.0, 4.17E-3, 2.1},
234 {55.783800, 953.50E-6, 2.115, 11.10E-3, 0.0, 3.75E-3, 2.1},
235 {56.264777, 548.90E-6, 0.010, 16.46E-3, 0.0, 7.74E-3, 0.9},
236 {56.363387, 1344.00E-6, 1.655, 11.44E-3, 0.0, 2.97E-3, 2.3},
237 {56.968180, 1763.00E-6, 1.255, 11.81E-3, 0.0, 2.12E-3, 2.5},
238 {57.612481, 2141.00E-6, 0.910, 12.21E-3, 0.0, 0.94E-3, 3.7},
239 {58.323874, 2386.00E-6, 0.621, 12.66E-3, 0.0, -0.55E-3, -3.1},
240 {58.446589, 1457.00E-6, 0.079, 14.49E-3, 0.0, 5.97E-3, 0.8},
241 {59.164204, 2404.00E-6, 0.386, 13.19E-3, 0.0, -2.44E-3, 0.1},
242 {59.590982, 2112.00E-6, 0.207, 13.60E-3, 0.0, 3.44E-3, 0.5},
243 {60.306057, 2124.00E-6, 0.207, 13.82E-3, 0.0, -4.13E-3, 0.7},
244 {60.434775, 2461.00E-6, 0.386, 12.97E-3, 0.0, 1.32E-3, -1.0},
245 {61.150558, 2504.00E-6, 0.621, 12.48E-3, 0.0, -0.36E-3, 5.8},
246 {61.800152, 2298.00E-6, 0.910, 12.07E-3, 0.0, -1.59E-3, 2.9},
247 {62.411212, 1933.00E-6, 1.255, 11.71E-3, 0.0, -2.66E-3, 2.3},
248 {62.486253, 1517.00E-6, 0.078, 14.68E-3, 0.0, -4.77E-3, 0.9},
249 {62.997974, 1503.00E-6, 1.660, 11.39E-3, 0.0, -3.34E-3, 2.2},
250 {63.568515, 1087.00E-6, 2.110, 11.08E-3, 0.0, -4.17E-3, 2.0},
251 {64.127764, 733.50E-6, 2.620, 10.78E-3, 0.0, -4.48E-3, 2.0},
252 {64.678900, 463.50E-6, 3.190, 10.50E-3, 0.0, -5.10E-3, 1.8},
253 {65.224067, 274.80E-6, 3.810, 10.20E-3, 0.0, -5.10E-3, 1.9},
254 {65.764769, 153.00E-6, 4.480, 10.00E-3, 0.0, -5.70E-3, 1.8},
255 {66.302088, 80.09E-6, 5.220, 9.70E-3, 0.0, -5.50E-3, 1.8},
256 {66.836827, 39.46E-6, 6.000, 9.40E-3, 0.0, -5.90E-3, 1.7},
257 {67.369595, 18.32E-6, 6.840, 9.20E-3, 0.0, -5.60E-3, 1.8},
258 {67.900862, 8.01E-6, 7.740, 8.90E-3, 0.0, -5.80E-3, 1.7},
259 {68.431001, 3.30E-6, 8.690, 8.70E-3, 0.0, -5.70E-3, 1.7},
260 {68.960306, 1.28E-6, 9.690, 8.60E-3, 0.0, -5.60E-3, 1.7},
261 {69.489021, 0.47E-6, 10.720, 8.50E-3, 0.0, -5.60E-3, 1.7},
262 {70.017342, 0.16E-6, 11.830, 8.40E-3, 0.0, -5.60E-3, 1.7},
263 {118.750341, 945.00E-6, 0.000, 15.92E-3, 0.0, -0.44E-3, 0.9},
264 {368.498350, 67.90E-6, 0.020, 19.20E-3, 0.6, 0.00E00, 1.0},
265 {424.763120, 638.00E-6, 0.011, 19.16E-3, 0.6, 0.00E00, 1.0},
266 {487.249370, 235.00E-6, 0.011, 19.20E-3, 0.6, 0.00E00, 1.0},
267 {715.393150, 99.60E-6, 0.089, 18.10E-3, 0.6, 0.00E00, 1.0},
268 {773.838730, 671.00E-6, 0.079, 18.10E-3, 0.6, 0.00E00, 1.0},
269 {834.145330, 180.00E-6, 0.079, 18.10E-3, 0.6, 0.00E00, 1.0}};
270
271 // convert to the units of Liebe
272 const double theta = 300./temperature;
273 const double kPaPVap = 0.001*pVapour;
274 const double kPaPDry = 0.001*pDry;
275 const double fGHz = freq * 1e-9;
276
277 // some coefficients
278 const double ap = 1.4e-10*(1-1.2e-5*std::pow(fGHz,1.5));
279 const double gamma0 = 5.6e-3*(kPaPDry + 1.1*kPaPVap)*std::pow(theta,0.8);
280 // initial refractivity
281 std::complex<double> result(2.588*kPaPDry*theta +
282 3.07e-4*(1.0/(1.0+std::pow(fGHz/gamma0,2))-1)*kPaPDry*theta*theta,
283 (2*3.07e-4/(gamma0*(1+std::pow(fGHz/gamma0,2))*(1+std::pow(fGHz/60,2))) +
284 ap*kPaPDry*std::pow(theta,2.5))*fGHz*kPaPDry*theta*theta);
285
286 // sum the contributions of all the lines
287 for (size_t l = 0; l < nLines; ++l) {
288 const double S = lines[l][1]*kPaPDry*std::pow(theta,3)*exp(lines[l][2]*(1.-theta));
289 const double gamma = lines[l][3]*(kPaPDry*std::pow(theta,0.8-lines[l][4]) + 1.1*kPaPVap*theta);
290 const double delta = lines[l][5]*kPaPDry*std::pow(theta,lines[l][6]);
291 const double x = (lines[l][0]-fGHz)*(lines[l][0]-fGHz) + gamma*gamma;
292 const double y = (lines[l][0]+fGHz)*(lines[l][0]+fGHz) + gamma*gamma;
293 const double z = (lines[l][0]+gamma*gamma/lines[l][0]);
294 result += std::complex<double> (S*( (z-fGHz)/x + (z+fGHz)/y - 2./lines[l][0] +
295 delta*(1/x-1/y)*gamma*fGHz/lines[l][0]),
296 S*( (1/x+1/y)*gamma*fGHz/lines[l][0] -
297 delta*((lines[l][0]-fGHz)/x + (lines[l][0]+fGHz)/y)*fGHz/lines[l][0]));
298 }
299
300 return result;
301}
302
303/**
304 * Compute the complex refractivity of the water vapour monomers
305 * at the given frequency.
306 * @param[in] freq frequency (Hz)
307 * @param[in] temperature air temperature (K)
308 * @param[in] pDry partial pressure of dry components (Pascals)
309 * @param[in] pVapour partial pressure of water vapour (Pascals)
310 * @return complex refractivity
311 *
312 * Reference:
313 * Liebe, An updated model for millimeter wave propogation in moist air,
314 * Radio Science, 20, 1069-1089 (1985).
315 **/
316std::complex<double> STAtmosphere::vapourRefractivity(double freq, double temperature,
317 double pDry, double pVapour)
318{
319 // the number of parameters per atmospheric line and the number of lines taken into account
320 const size_t nLineParams = 4;
321 const size_t nLines = 30;
322 // actual tabulated values
323 const double lines[nLines][nLineParams] =
324 {{22.235080, 0.1090, 2.143, 27.84E-3},
325 {67.813960, 0.0011, 8.730, 27.60E-3},
326 {119.995940, 0.0007, 8.347, 27.00E-3},
327 {183.310117, 2.3000, 0.653, 28.35E-3},
328 {321.225644, 0.0464, 6.156, 21.40E-3},
329 {325.152919, 1.5400, 1.515, 27.00E-3},
330 {336.187000, 0.0010, 9.802, 26.50E-3},
331 {380.197372, 11.9000, 1.018, 27.60E-3},
332 {390.134508, 0.0044, 7.318, 19.00E-3},
333 {437.346667, 0.0637, 5.015, 13.70E-3},
334 {439.150812, 0.9210, 3.561, 16.40E-3},
335 {443.018295, 0.1940, 5.015, 14.40E-3},
336 {448.001075, 10.6000, 1.370, 23.80E-3},
337 {470.888947, 0.3300, 3.561, 18.20E-3},
338 {474.689127, 1.2800, 2.342, 19.80E-3},
339 {488.491133, 0.2530, 2.814, 24.90E-3},
340 {503.568532, 0.0374, 6.693, 11.50E-3},
341 {504.482692, 0.0125, 6.693, 11.90E-3},
342 {556.936002, 510.000, 0.114, 30.00E-3},
343 {620.700807, 5.0900, 2.150, 22.30E-3},
344 {658.006500, 0.2740, 7.767, 30.00E-3},
345 {752.033227, 250.000, 0.336, 28.60E-3},
346 {841.073593, 0.0130, 8.113, 14.10E-3},
347 {859.865000, 0.1330, 7.989, 28.60E-3},
348 {899.407000, 0.0550, 7.845, 28.60E-3},
349 {902.555000, 0.0380, 8.360, 26.40E-3},
350 {906.205524, 0.1830, 5.039, 23.40E-3},
351 {916.171582, 8.5600, 1.369, 25.30E-3},
352 {970.315022, 9.1600, 1.842, 24.00E-3},
353 {987.926764, 138.000, 0.178, 28.60E-3}};
354
355 // convert to the units of Liebe
356 const double theta = 300./temperature;
357 const double kPaPVap = 0.001*pVapour;
358 const double kPaPDry = 0.001*pDry;
359 const double fGHz = freq * 1e-9;
360
361 // initial refractivity
362 std::complex<double> result(2.39*kPaPVap*theta + 41.6*kPaPVap*theta*theta +
363 6.47e-6*std::pow(fGHz,2.05)*kPaPVap*std::pow(theta,2.4),
364 (0.915*1.40e-6*kPaPDry + 5.41e-5*kPaPVap*theta*theta*theta)*
365 fGHz*kPaPVap*std::pow(theta,2.5));
366
367 // sum contributions of all the lines
368 for (size_t l = 0; l < nLines; ++l) {
369 const double S = lines[l][1]*kPaPVap*std::pow(theta,3.5)*exp(lines[l][2]*(1.-theta));
370 const double gamma = lines[l][3]*(kPaPDry*std::pow(theta,0.8) + 4.80*kPaPVap*theta);
371 const double x = (lines[l][0]-fGHz)*(lines[l][0]-fGHz) + gamma*gamma;
372 const double y = (lines[l][0]+fGHz)*(lines[l][0]+fGHz) + gamma*gamma;
373 const double z = (lines[l][0]+gamma*gamma/lines[l][0]);
374 result += std::complex<double>(S*((z-fGHz)/x + (z+fGHz)/y - 2./lines[l][0]),
375 S*((1./x+1./y)*gamma*fGHz/lines[l][0]));
376 }
377
378 return result;
379}
380
381/**
382 * Calculate zenith opacity at the given frequency. This is a simplified version
383 * of the routine implemented in MIRIAD, which calculates just zenith opacity and
384 * nothing else. Note, that if the opacity is high, 1/sin(el) law is not correct
385 * even in the plane parallel case due to refraction.
386 * @param[in] freq frequency of interest in Hz
387 * @return zenith opacity (nepers, i.e. dimensionless)
388 **/
389double STAtmosphere::zenithOpacity(double freq) const
390{
391 // essentially a numerical integration with the Trapezium method
392 double tau = 0.;
393 for (int layer = int(nLayers()) - 1; layer>=0; --layer) {
394 double dH = 0.;
395 if (layer == 0) {
396 dH = 0.5*(itsHeights[1]-itsHeights[0]);
397 } else if (layer + 1 == int(nLayers())) {
398 dH = 0.5*(itsHeights[nLayers()-1]-itsHeights[nLayers()-2]);
399 } else {
400 dH = 0.5*(itsHeights[layer+1]-itsHeights[layer-1]);
401 }
402 // imaginary part of the total complex refractivity
403 const double nImag = 1e-6*std::imag(dryRefractivity(freq,itsTemperatures[layer],itsDryPressures[layer],
404 itsVapourPressures[layer])+vapourRefractivity(freq,itsTemperatures[layer],itsDryPressures[layer],
405 itsVapourPressures[layer]));
406 tau += dH*4.*casa::C::pi/QC::c.get().getValue()*freq*nImag;
407 }
408 return tau;
409}
410
411/**
412 * Calculate zenith opacity for the range of frequencies. Same as zenithOpacity, but
413 * for a vector of frequencies.
414 * @param[in] freqs vector of frequencies in Hz
415 * @return vector of zenith opacities, one value per frequency (nepers, i.e. dimensionless)
416 **/
417std::vector<double> STAtmosphere::zenithOpacities(const std::vector<double> &freqs) const
418{
419 std::vector<double> result(freqs.size());
420 for (size_t ch = 0; ch<freqs.size(); ++ch) {
421 result[ch] = zenithOpacity(freqs[ch]);
422 }
423 return result;
424}
425
426/**
427 * Calculate opacity at the given frequency and elevation. This is a simplified
428 * version of the routine implemented in MIRIAD, which calculates just the opacity and
429 * nothing else. In contract to zenithOpacity, this method takes into account refraction
430 * and is more accurate than if one assumes 1/sin(el) factor.
431 * @param[in] freq frequency of interest in Hz
432 * @param[in] el elevation in radians
433 * @return zenith opacity (nepers, i.e. dimensionless)
434 **/
435double STAtmosphere::opacity(double freq, double el) const
436{
437 // essentially a numerical integration with the Trapezium method
438 double tau = 0.;
439 const double sineEl = sin(el);
440 for (int layer = int(nLayers()) - 1; layer>=0; --layer) {
441 double dH = 0.;
442 if (layer == 0) {
443 dH = 0.5*(itsHeights[1]-itsHeights[0]);
444 } else if (layer + 1 == int(nLayers())) {
445 dH = 0.5*(itsHeights[nLayers()-1]-itsHeights[nLayers()-2]);
446 } else {
447 dH = 0.5*(itsHeights[layer+1]-itsHeights[layer-1]);
448 }
449 // total complex refractivity
450 const std::complex<double> n = dryRefractivity(freq,itsTemperatures[layer],itsDryPressures[layer],
451 itsVapourPressures[layer]) +
452 vapourRefractivity(freq,itsTemperatures[layer],itsDryPressures[layer],
453 itsVapourPressures[layer]);
454 // real and imaginary part of the total complex refractivity scaled appropriately
455 const double nImag = 1e-6*std::imag(n);
456 const double nReal = 1. + 1e-6*std::real(n);
457 // length increment
458 const double dL = dH*nReal/sqrt(nReal*nReal+sineEl*sineEl-1.);
459 tau += dL*4.*casa::C::pi/QC::c.get().getValue()*freq*nImag;
460 }
461 return tau;
462}
463
464/**
465 * Calculate opacities for the range of frequencies at the given elevation. Same as
466 * opacity, but for a vector of frequencies.
467 * @param[in] freqs vector of frequencies in Hz
468 * @param[in] el elevation in radians
469 * @return vector of opacities, one value per frequency (nepers, i.e. dimensionless)
470 **/
471std::vector<double> STAtmosphere::opacities(const std::vector<double> &freqs, double el) const
472{
473 std::vector<double> result(freqs.size());
474 for (size_t ch = 0; ch<freqs.size(); ++ch) {
475 result[ch] = opacity(freqs[ch],el);
476 }
477 return result;
478}
479
Note: See TracBrowser for help on using the repository browser.