17 const HdfFile& Merra_climatology,
18 const HdfFile& Aerosol_property,
22 const blitz::Array<double, 2>& Aerosol_cov,
23 const blitz::Array<double, 1>& val)
27 Latitude, Longitude, Press, Rh, Aerosol_cov,
28 val(0), val(1), static_cast<int>(val(2)),
29 static_cast<int>(val(3)), val(4),
30 static_cast<int>(val(5)) == 1,
31 static_cast<int>(val(6)) == 1));
72 const HdfFile& Aerosol_property,
76 const blitz::Array<double, 2>& Aerosol_cov,
82 bool Relative_humidity_aerosol,
85 : linear_aod(Linear_aod),
86 rh_aerosol(Relative_humidity_aerosol),
90 merra_fname(Merra_climatology.
file_name()),
95 int lat_ind = file_index(Merra_climatology,
"Latitude", Latitude);
96 int lon_ind = file_index(Merra_climatology,
"Longitude", Longitude,
true);
97 TinyVector<int,3> shp = Merra_climatology.
read_shape<3>(
"/AOD_Fraction");
98 Array<double, 3> aod_frac =
99 Merra_climatology.
read_field<double, 3>(
"/AOD_Fraction",
100 shape(0,lat_ind,lon_ind),
102 TinyVector<int,4> shp2 =
103 Merra_climatology.
read_shape<4>(
"/COMPOSITE_AOD_GAUSSIAN");
104 Array<double, 4> aod_gauss =
105 Merra_climatology.
read_field<double, 4>(
"/COMPOSITE_AOD_GAUSSIAN",
106 shape(0,0,lat_ind,lon_ind),
107 shape(shp2[0],shp2[1], 1,1));
108 shp = Merra_climatology.
read_shape<3>(
"/COMPOSITE_AOD_SORT_Index");
109 Array<int, 3> aod_sort_index =
110 Merra_climatology.
read_field<int, 3>(
"/COMPOSITE_AOD_SORT_Index",
111 shape(0,lat_ind,lon_ind),
113 Array<std::string, 1> comp_name =
114 Merra_climatology.
read_field<std::string, 1>(
"/COMPOSITE_NAME");
115 double total_aod = sum(aod_gauss(3, Range::all(), 0, 0));
118 number_merra_particle_ = 0;
119 for(
int counter = 0; counter < aod_sort_index.shape()[0]; ++counter) {
120 int i = aod_sort_index(counter);
122 if(counter < Min_types)
124 else if(aod_frac(counter, 0, 0) > Exp_aod ||
125 (1 - aod_frac(counter, 0, 0)) * total_aod < Max_residual ||
126 counter >= Max_types)
131 ++number_merra_particle_;
132 double aod = aod_gauss(3, i);
133 double peak_height = aod_gauss(1, i);
134 double peak_width = aod_gauss(2, i);
137 std::string aname = comp_name(i);
138 Array<bool, 1> flag(3);
139 Array<double, 1> coeff(3);
140 flag =
true,
true,
true;
142 coeff = aod, peak_height, peak_width;
144 coeff = log(aod), peak_height, peak_width;
160 nig->apriori_covariance(Aerosol_cov);
161 ig->add_builder(nig);
174 aerosol_.reset(
new AerosolOptical(aext, aprop, press, rh, ref_wn));
188 aext.push_back(Aext);
189 aprop.push_back(Aprop);
197 int MerraAerosol::file_index(
const HdfFile& Merra_climatology,
198 const std::string& Field_name,
201 Array<double, 1> value_data =
202 Merra_climatology.
read_field<double, 1>(
"/" + Field_name);
206 value < value_data(0) &&
207 value >= (value_data(value_data.rows() - 1) - 360)) {
208 if(fabs(value - value_data(0)) <
209 fabs(value - (value_data(value_data.rows() - 1) - 360)))
212 return value_data.rows() - 1;
215 value >= value_data(value_data.rows() - 1) &&
216 value < (value_data(0) + 360)) {
217 if(fabs(value - (value_data(0) + 360)) <
218 fabs(value - value_data(value_data.rows() - 1)))
221 return value_data.rows() - 1;
223 if(value < value_data(0) || value >= value_data(value_data.rows() - 1)) {
225 e << Field_name <<
" " << V <<
" is out or the range covered by the\n" 226 <<
"Merra_climatology file " << Merra_climatology.
file_name();
229 if(value == value_data(0))
231 double* f = std::lower_bound(value_data.data(),
232 value_data.data() + value_data.rows(),
234 int i = f - value_data.data();
235 if(((value - value_data(i - 1)) / (value_data(i) - value_data(i - 1))) < 0.5)
247 Os <<
"MerraAerosol: (" 248 << (linear_aod ?
"Linear, " :
"Logarithmic, ")
249 << (rh_aerosol ?
"RH aerosol" :
"Not RH aerosol")
252 <<
" Merra file name: " << merra_fname <<
"\n" 253 <<
" Aerosol property file name: " << prop_fname <<
"\n" 254 <<
" Latitude: " << lat <<
"\n" 255 <<
" Longitude: " << lon <<
"\n";
blitz::TinyVector< int, D > read_shape(const std::string &Dataname) const
Reads the shape of a dataset.
boost::shared_ptr< InitialGuessBuilder > initial_guess() const
Return IntitialGuessBuilder for the Aerosol.
blitz::Array< T, D > read_field(const std::string &Dataname) const
Read a given field.
This class is used to create the Aerosol from a Merra climatology file.
void add_aerosol(const boost::shared_ptr< AerosolExtinction > &Aext, const boost::shared_ptr< AerosolProperty > &Aprop, const boost::shared_ptr< InitialGuessBuilder > &Ig)
Add in an aerosol that comes from some source other than Dijian's files (e.g., hardcoded aerosols to ...
This gives the Aerosol properties for an Aerosol.
This is the base of the exception hierarchy for Full Physics code.
A common way to create an initial guess is to have other classes responsible for portions of the stat...
This class reads and writes a HDF5 file.
#define REGISTER_LUA_CLASS(X)
Apply value function to a blitz array.
MerraAerosol(const HdfFile &Merra_climatology, const HdfFile &Aerosol_property, DoubleWithUnit Latitude, DoubleWithUnit Longitude, const boost::shared_ptr< Pressure > &Press, const boost::shared_ptr< RelativeHumidity > &Rh, const blitz::Array< double, 2 > &Aerosol_cov, double Max_aod=0.2, double Exp_aod=0.8, int Min_types=2, int Max_types=4, bool Linear_aod=false, bool Relative_humidity_aerosol=false, double Max_residual=0.005, double Reference_wn=1e4/0.755)
Constructor.
boost::shared_ptr< Aerosol > aerosol() const
Return the aerosol setup generated from this class.
This is a simple implementation of InitialGuessBuilder that just has variables used to give the aprio...
This class maps the state vector to aerosol extinction defined by a Gaussian parameterization.
Implementation of Aerosol.
We frequently have a double with units associated with it.
const std::string & file_name() const
File name.
DoubleWithUnit convert(const Unit &R) const
Convert to the given units.
This gives the Aerosol properties for an Aerosol.
Libraries such as boost::units allow unit handling where we know the units at compile time...
Contains classes to abstract away details in various Spurr Radiative Transfer software.
#define REGISTER_LUA_END()
virtual void print(std::ostream &Os) const
Print to stream.
def(luabind::constructor< int >()) .def("rows"
int number_merra_particle() const
Number of merra particles.
double value(const FullPhysics::AutoDerivative< double > &Ad)