ReFRACtor
aerosol_property_rh_hdf.cc
Go to the documentation of this file.
2 #include "ostream_pad.h"
3 #include <boost/make_shared.hpp>
4 using namespace FullPhysics;
5 using namespace blitz;
6 
7 #ifdef HAVE_LUA
8 #include "register_lua.h"
10 .def(luabind::constructor<const HdfFile&, const std::string&,
14 #endif
15 
16 //-----------------------------------------------------------------------
18 //-----------------------------------------------------------------------
19 
21 (const HdfFile& F,
22  const std::string& Group_name,
23  const boost::shared_ptr<Pressure>& Press,
25 )
26 : rh(Rh), hdf_file(F.file_name()), hdf_group(Group_name)
27 {
28  press = Press;
29  Array<double, 1> wn(F.read_field<double, 1>(Group_name + "/wave_number"));
30  Array<double, 1> rhv(F.read_field<double, 1>(Group_name + "/relative_humidity"));
31  Array<double, 2>
32  qscatv(F.read_field<double, 2>(Group_name + "/scattering_coefficient"));
33  Array<double, 2>
34  qextv(F.read_field<double, 2>(Group_name + "/extinction_coefficient"));
35  Array<double, 4>
36  pfv(F.read_field<double, 4>(Group_name + "/phase_function_moment"));
37  if(rhv.rows() != qscatv.cols() ||
38  rhv.rows() != qextv.cols() ||
39  rhv.rows() != pfv.cols())
40  throw Exception("Mismatch between the number of relative humidity values and the aerosol property arrays");
41  Array<double, 1> qscatvt(qscatv.rows());
42  Array<double, 1> qextvt(qextv.rows());
43  for(int i = 0; i < rhv.rows(); ++i) {
44  rh_val.push_back(rhv(i));
45  rh_val_d.push_back(rhv(i));
46  qscatvt = qscatv(Range::all(), i);
47  qextvt = qextv(Range::all(), i);
48  qext.push_back(boost::make_shared<LinearInterpolate<double, double> >
49  (wn.begin(), wn.end(), qextvt.begin()));
50  qscat.push_back(boost::make_shared<LinearInterpolate<double, double> >
51  (wn.begin(), wn.end(), qscatvt.begin()));
52  std::vector<Array<double, 2> > pf_vec;
53  for(int j = 0; j < pfv.rows(); ++j)
54  pf_vec.push_back(Array<double, 2>(pfv(j, i, Range::all(), Range::all())));
55  pf.push_back(boost::make_shared<ScatteringMomentInterpolate>
56  (wn.begin(), wn.end(), pf_vec.begin()));
57  }
58 }
59 
61 {
62  return clone(press->clone(), rh->clone());
63 }
64 
68 {
69  HdfFile f(hdf_file);
71  (new AerosolPropertyRhHdf(f, hdf_group, Press, Rh));
72 }
73 
74 // Right now we don't support extinction_coefficient_each_layer
75 // having a jacobian,
76 // this has to do with our optimization in the LIDORT jacobian
77 // calculation that uses the "intermediate" variables - see
78 // rt_atmosphere.h for more details on this. So we will just leave
79 // this jacobian out. Not clear what if any impact this will have on
80 // the retrieval, but we'll do this to try things out.
81 
83 (double wn) const
84 {
85  std::vector<AutoDerivative<double> > qextv;
86  for(int i = 0; i < (int) rh_val.size(); ++i)
87  qextv.push_back((*qext[i])(wn));
89  lin(rh_val.begin(), rh_val.end(), qextv.begin());
90  ArrayAd<double, 1> rhl = rh->relative_humidity_layer();
91  blitz::Array<AutoDerivative<double>, 1> res(rhl.rows());
92  for(int i = 0; i < res.rows(); ++i)
93  res(i) = lin(rhl(i));
94  return ArrayAd<double, 1>(res);
95 }
96 
98 (double wn) const
99 {
100  std::vector<double> qextv;
101  for(int i = 0; i < (int) rh_val.size(); ++i)
102  qextv.push_back((*qext[i])(wn));
104  lin(rh_val_d.begin(), rh_val_d.end(), qextv.begin());
105  blitz::Array<double, 1> rhl = rh->relative_humidity_layer().value();
106  blitz::Array<double, 1> res(rhl.rows());
107  for(int i = 0; i < res.rows(); ++i)
108  res(i) = lin(rhl(i));
109  return ArrayAd<double, 1>(res);
110 }
111 
112 // Right now we don't support scattering_coefficient_each_layer
113 // having a jacobian,
114 // this has to do with our optimization in the LIDORT jacobian
115 // calculation that uses the "intermediate" variables - see
116 // rt_atmosphere.h for more details on this. So we will just leave
117 // this jacobian out. Not clear what if any impact this will have on
118 // the retrieval, but we'll do this to try things out.
119 
121 (double wn) const
122 {
123  std::vector<AutoDerivative<double> > qscatv;
124  for(int i = 0; i < (int) rh_val.size(); ++i)
125  qscatv.push_back((*qscat[i])(wn));
127  lin(rh_val.begin(), rh_val.end(), qscatv.begin());
128  ArrayAd<double, 1> rhl = rh->relative_humidity_layer();
129  blitz::Array<AutoDerivative<double>, 1> res(rhl.rows());
130  for(int i = 0; i < res.rows(); ++i)
131  res(i) = lin(rhl(i));
132  return ArrayAd<double, 1>(res);
133 }
134 
136 (double wn) const
137 {
138  std::vector<double> qscatv;
139  for(int i = 0; i < (int) rh_val.size(); ++i)
140  qscatv.push_back((*qscat[i])(wn));
142  lin(rh_val_d.begin(), rh_val_d.end(), qscatv.begin());
143  blitz::Array<double, 1> rhl = rh->relative_humidity_layer().value();
144  blitz::Array<double, 1> res(rhl.rows());
145  for(int i = 0; i < res.rows(); ++i)
146  res(i) = lin(rhl(i));
147  return ArrayAd<double, 1>(res);
148 }
149 
150 // Right now we don't support phase_function_moment having a jacobian,
151 // this has to do with our optimization in the LIDORT jacobian
152 // calculation that uses the "intermediate" variables - see
153 // rt_atmosphere.h for more details on this. So we will just leave
154 // this jacobian out. Not clear what if any impact this will have on
155 // the retrieval, but we'll do this to try things out.
157 (double wn, int nmom, int nscatt) const
158 {
159  firstIndex i1; secondIndex i2; thirdIndex i3; fourthIndex i4;
160  std::vector<blitz::Array<AutoDerivative<double>, 2> > pfv;
161  for(int i = 0; i < (int) rh_val.size(); ++i) {
162  blitz::Array<double, 2> t((*pf[i])(wn, nmom, nscatt));
163  blitz::Array<AutoDerivative<double>, 2> t2(t.shape());
164  for(int j = 0; j < t2.rows(); ++j)
165  for(int k = 0; k < t2.cols(); ++k)
166  t2(j, k) = t(j, k);
167  pfv.push_back(t2);
168  }
170  blitz::Array<AutoDerivative<double>, 2> >
171  lin(rh_val.begin(), rh_val.end(), pfv.begin());
172  ArrayAd<double, 1> rhl = rh->relative_humidity_layer();
173  blitz::Array<AutoDerivative<double>, 3>
174  res(pfv[0].rows(), press->number_layer(), pfv[1].cols());
175  for(int i = 0; i < res.cols(); ++i)
176  res(Range::all(), i, Range::all()) = lin(rhl(i));
177  return ArrayAd<double, 3>(res);
178 }
179 
181 (double wn, int nmom, int nscatt) const
182 {
183  firstIndex i1; secondIndex i2; thirdIndex i3; fourthIndex i4;
184  std::vector<blitz::Array<double, 2> > pfv;
185  for(int i = 0; i < (int) rh_val.size(); ++i) {
186  blitz::Array<double, 2> t((*pf[i])(wn, nmom, nscatt));
187  pfv.push_back(t);
188  }
190  lin(rh_val_d.begin(), rh_val_d.end(), pfv.begin());
191  blitz::Array<double, 1> rhl = rh->relative_humidity_layer().value();
192  blitz::Array<double, 3>
193  res(pfv[0].rows(), press->number_layer(), pfv[1].cols());
194  for(int i = 0; i < res.cols(); ++i)
195  res(Range::all(), i, Range::all()) = lin(rhl(i));
196  return ArrayAd<double, 3>(res);
197 }
198 
199 void AerosolPropertyRhHdf::print(std::ostream& Os) const
200 {
201  Os << "AerosolPropertyRhHdf:\n"
202  << " Hdf file: " << hdf_file << "\n"
203  << " Hdf group: " << hdf_group << "\n";
204 }
virtual ArrayAd< double, 1 > scattering_coefficient_each_layer_not_used(double wn) const
This gives the Aerosol properties for an Aerosol.
blitz::Array< T, D > read_field(const std::string &Dataname) const
Read a given field.
Definition: hdf_file.h:564
virtual ArrayAd< double, 3 > phase_function_moment_each_layer(double wn, int nmom=-1, int nscatt=-1) const
Return phase function moments for the given wave number for each layer.
virtual void print(std::ostream &Os) const
Print to stream.
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
virtual ArrayAd< double, 1 > extinction_coefficient_each_layer_not_used(double wn) const
This class reads and writes a HDF5 file.
Definition: hdf_file.h:39
Apply value function to a blitz array.
const std::string & file_name() const
File name.
Definition: hdf_file.h:131
virtual ArrayAd< double, 1 > extinction_coefficient_each_layer(double wn) const
Return extinction coefficient for the given wave number, for each layer.
This gives the Aerosol properties for an Aerosol.
virtual boost::shared_ptr< AerosolProperty > clone() const
Clone a AerosolProperty object.
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
ArrayAd< double, 3 > phase_function_moment_each_layer_not_used(double wn, int nmom=-1, int nscatt=-1) const
AerosolPropertyRhHdf(const HdfFile &F, const std::string &Group_name, const boost::shared_ptr< Pressure > &Press, const boost::shared_ptr< RelativeHumidity > &Rh)
Read the given group in the given file for the aerosol properties.
virtual ArrayAd< double, 1 > scattering_coefficient_each_layer(double wn) const
Return scattering coefficient for the given wave number for each layer.

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