ReFRACtor
meteorology.cc
Go to the documentation of this file.
1 #include <boost/algorithm/string.hpp>
2 
3 #include "meteorology.h"
4 #include "log_interpolate.h"
5 #include "old_constant.h"
6 
7 using namespace FullPhysics;
8 using namespace blitz;
9 
10 #ifdef HAVE_LUA
11 #include "register_lua.h"
12 
13 typedef Array<double, 1> (Meteorology::*f_val)() const;
14 typedef Array<double, 1> (Meteorology::*f_interp)(const Array<double, 1>&) const;
15 
16 typedef Array<double, 1> (Meteorology::*f_vmr)(const std::string&) const;
17 typedef Array<double, 1> (Meteorology::*f_vmr_interp)(const std::string&, const Array<double, 1>&) const;
18 
20 .def("pressure_levels", &Meteorology::pressure_levels)
21 .def("specific_humidity", ((f_val) &Meteorology::specific_humidity))
22 .def("specific_humidity", ((f_interp) &Meteorology::specific_humidity))
23 .def("vmr", ((f_vmr) &Meteorology::vmr))
24 .def("vmr", ((f_vmr_interp) &Meteorology::vmr))
25 .def("temperature", ((f_val) &Meteorology::temperature))
26 .def("temperature", ((f_interp) &Meteorology::temperature))
27 .def("surface_pressure", &Meteorology::surface_pressure)
28 .def("windspeed", &Meteorology::windspeed)
29 .def("windspeed_u", &Meteorology::windspeed_u)
30 .def("windspeed_v", &Meteorology::windspeed_v)
32 #endif
33 
34 Array<double, 1> Meteorology::specific_humidity(const Array<double, 1>& Pressure_level) const
35 {
36  return interpolate_to_grid(specific_humidity(), Pressure_level);
37 }
38 
39 Array<double, 1> Meteorology::vmr(const std::string& Species, const Array<double, 1>& Pressure_level) const
40 {
41  return interpolate_to_grid(vmr(Species), Pressure_level);
42 }
43 
44 Array<double, 1> Meteorology::temperature(const Array<double, 1>& Pressure_level) const
45 {
46  return interpolate_to_grid(temperature(), Pressure_level);
47 }
48 
49 double Meteorology::windspeed() const
50 {
51  return sqrt( sqr(windspeed_u()) + sqr(windspeed_v()) );
52 }
53 
54 blitz::Array<double, 1> Meteorology::vmr(const std::string& Species) const
55 {
56  std::string species_upper = Species;
57  boost::to_upper(species_upper);
58  if (species_upper == "H2O") {
59  return h2o_vmr();
60  } else {
61  Exception err;
62  err << "Can not return VMR species " << Species << " handling has not been defined.";
63  throw err;
64  }
65 }
66 
67 blitz::Array<double, 1> Meteorology::h2o_vmr() const
68 {
69  Array<double, 1> s = specific_humidity();
70  Array<double, 1> vmr(s.shape());
72  return vmr;
73 }
74 
75 Array<double, 1> Meteorology::interpolate_to_grid(const Array<double, 1>& Profile, const Array<double, 1>& Dest_pressure_levels) const
76 {
77  LogLogInterpolate<double, double> prof_interp(pressure_levels().begin(), pressure_levels().end(), Profile.begin());
78  Array<double, 1> prof_res(Dest_pressure_levels.shape());
79  for(int i = 0; i < Dest_pressure_levels.rows(); ++i) {
80  prof_res(i) = prof_interp(Dest_pressure_levels(i));
81  }
82  return prof_res;
83 }
84 
virtual double surface_pressure() const =0
Surface pressure in Pascals.
const Unit s("s", 1.0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)
Defines the interface for supplying meteorological data.
Definition: meteorology.h:14
virtual double windspeed_u() const =0
The U component windspeed in m/s.
virtual double windspeed() const
Windspeed magnitude in m/s for the surface.
Definition: meteorology.cc:49
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
virtual blitz::Array< double, 1 > specific_humidity() const =0
Specific humidty on the meteorological pressure levels.
#define REGISTER_LUA_CLASS(X)
Definition: register_lua.h:116
Apply value function to a blitz array.
virtual blitz::Array< double, 1 > vmr(const std::string &Species) const
Volume mixing ratio for a particular species on the meteorological pressure levels.
Definition: meteorology.cc:54
virtual double windspeed_v() const =0
The V component windspeed in m/s.
const double molar_weight_dry_air
Molar weight of dry air, in g mol^-1.
Definition: old_constant.h:24
const double molar_weight_water
Molar weight of water, in g mol^-1.
Definition: old_constant.h:30
double sqr(double x)
virtual blitz::Array< double, 1 > pressure_levels() const =0
Pressure levels in Pascals used for provided meteorological data.
virtual blitz::Array< double, 1 > temperature() const =0
Temperature profile in Kelvins on the meteorological pressure levels.
blitz::Array< double, 1 > interpolate_to_grid(const blitz::Array< double, 1 > &Profile, const blitz::Array< double, 1 > &Dest_pressure_levels) const
Interpolates a profile of data from the internal pressure grid to the supplied one.
Definition: meteorology.cc:75
Wrapper around LinearInterpolate that uses log(x) and log(y) rather than x and y when interpolating...
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
#define REGISTER_LUA_END()
Definition: register_lua.h:134
virtual blitz::Array< double, 1 > h2o_vmr() const
Return the H20 VMR.
Definition: meteorology.cc:67

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:10