ReFRACtor
aerosol_consolidated_output.cc
Go to the documentation of this file.
1 #include <boost/algorithm/string.hpp>
2 #include <boost/lexical_cast.hpp>
5 #include "fill_value.h"
6 
7 using namespace FullPhysics;
8 using namespace blitz;
9 
10 #ifdef HAVE_LUA
11 #include "register_lua.h"
13 .def(luabind::constructor<const boost::shared_ptr<Aerosol>&, const std::vector<std::string>&>())
15 #endif
16 
18 public:
19  AerosolOutputHelper(const boost::shared_ptr<AerosolOptical>& Aerosol, const std::vector<std::string>& All_aer_names)
20  : aerosol(Aerosol), all_aer_names(All_aer_names) { initialize(); }
21 
22  Array<double, 2> aerosol_aod_matrix() const {
23  // Limits for low/high aerosol types
24  double minv = std::numeric_limits<double>::min();
25  double maxv = std::numeric_limits<double>::max();
26 
27  Array<double, 2> aer_aod_matrix_(all_aer_names.size(), 4);
28  aer_aod_matrix_ = fill_value<double>();
29 
30  for(int out_aer_idx = 0; out_aer_idx < all_aer_names.size(); out_aer_idx++) {
31  auto match_iter = std::find(ret_aer_names.begin(), ret_aer_names.end(), all_aer_names[out_aer_idx]);
32 
33  if(match_iter != ret_aer_names.end()) {
34  int in_aer_idx = std::distance(ret_aer_names.begin(), match_iter);
35 
36  // total
37  aer_aod_matrix_(out_aer_idx, 0) = aerosol->aerosol_optical_depth(in_aer_idx, minv, maxv);
38 
39  // low
40  aer_aod_matrix_(out_aer_idx, 1) = aerosol->aerosol_optical_depth(in_aer_idx, low_boundary, maxv);
41 
42  // mid
43  aer_aod_matrix_(out_aer_idx, 2) = aerosol->aerosol_optical_depth(in_aer_idx, high_boundary, low_boundary);
44 
45  // low
46  aer_aod_matrix_(out_aer_idx, 3) = aerosol->aerosol_optical_depth(in_aer_idx, minv, high_boundary);
47  }
48  }
49  return aer_aod_matrix_;
50  }
51 
52  Array<double, 2> aerosol_param_matrix() const {
53  Array<double, 2> aer_param_matrix_(all_aer_names.size(), max_num_param);
54  aer_param_matrix_ = fill_value<double>();
55 
56  for(int out_aer_idx = 0; out_aer_idx < all_aer_names.size(); out_aer_idx++) {
57  auto match_iter = std::find(ret_aer_names.begin(), ret_aer_names.end(), all_aer_names[out_aer_idx]);
58 
59  if(match_iter != ret_aer_names.end()) {
60  int in_aer_idx = std::distance(ret_aer_names.begin(), match_iter);
61 
62  auto aer_ext = boost::dynamic_pointer_cast<AerosolExtinctionImpBase>(aerosol->aerosol_extinction(in_aer_idx));
63  if (!aer_ext)
64  throw Exception("Could not ast aerosol extinction into AerosolExctinctionImpBase");
65 
66  Range param_r = Range(0, aer_ext->aerosol_parameter().rows()-1);
67  aer_param_matrix_(out_aer_idx, param_r) = aer_ext->aerosol_parameter();
68  }
69  }
70  return aer_param_matrix_;
71  }
72 
73  Array<double, 2> aerosol_param_uncert_matrix() const {
74  Array<double, 2> aer_param_uncert_matrix_(all_aer_names.size(), max_num_param);
75  aer_param_uncert_matrix_ = fill_value<double>();
76 
77  for(int out_aer_idx = 0; out_aer_idx < all_aer_names.size(); out_aer_idx++) {
78  auto match_iter = std::find(ret_aer_names.begin(), ret_aer_names.end(), all_aer_names[out_aer_idx]);
79 
80  if(match_iter != ret_aer_names.end()) {
81  int in_aer_idx = std::distance(ret_aer_names.begin(), match_iter);
82 
83  auto aer_ext = boost::dynamic_pointer_cast<AerosolExtinctionImpBase>(aerosol->aerosol_extinction(in_aer_idx));
84  if (!aer_ext)
85  throw Exception("Could not ast aerosol extinction into AerosolExctinctionImpBase");
86 
87  Range param_r = Range(0, aer_ext->aerosol_parameter().rows()-1);
88  aer_param_uncert_matrix_(out_aer_idx, param_r) = aer_ext->aerosol_parameter_uncertainty();
89  }
90  }
91  return aer_param_uncert_matrix_;
92  }
93 
94  blitz::Array<std::string, 1> aerosol_model_types() const { return aer_model_types_; }
95  blitz::Array<int, 1> aerosol_type_retrieved() const { return type_retrieved_; }
96 
97  blitz::Array<std::string, 1> all_aerosol_names() const {
98  // Convert to blitz array for output
99  blitz::Array<std::string, 1> out_aer_names(all_aer_names.size());
100  for(int i; i < all_aer_names.size(); i++)
101  out_aer_names(i) = all_aer_names[i];
102  return out_aer_names;
103  }
104 
105 private:
106 
107  void initialize()
108  {
109  ret_aer_names = aerosol->aerosol_name();
110 
111  aer_model_types_.resize(all_aer_names.size());
112  aer_model_types_ = "";
113 
114  type_retrieved_.resize(all_aer_names.size());
115  type_retrieved_ = 0;
116 
117  // Find the maximum number of parameters and also fill in the model types array
118  max_num_param = 0;
119  for(int out_aer_idx = 0; out_aer_idx < all_aer_names.size(); out_aer_idx++) {
120  auto match_iter = std::find(ret_aer_names.begin(), ret_aer_names.end(), all_aer_names[out_aer_idx]);
121 
122  if(match_iter != ret_aer_names.end()) {
123  int in_aer_idx = std::distance(ret_aer_names.begin(), match_iter);
124 
125  auto aer_ext = boost::dynamic_pointer_cast<AerosolExtinctionImpBase>(aerosol->aerosol_extinction(in_aer_idx));
126  if (!aer_ext)
127  throw Exception("Could not ast aerosol extinction into AerosolExctinctionImpBase");
128  max_num_param = max(max_num_param, aer_ext->aerosol_parameter().rows());
129 
130  aer_model_types_(out_aer_idx) = aer_ext->model_short_name();
131  type_retrieved_(out_aer_idx) = 1;
132  }
133  }
134  }
135 
136 private:
138  const double low_boundary = 800e2;
139 
141  const double high_boundary = 500e2;
142 
144  std::vector<std::string> all_aer_names;
145  std::vector<std::string> ret_aer_names;
146  int max_num_param;
147 
148  Array<std::string, 1> aer_model_types_;
149  Array<int, 1> type_retrieved_;
150 
151 };
152 
154 : all_aer_names(All_aer_names)
155 {
156  // Right now we only work with AerosolOptical. Not sure if this is
157  // a *real* requirement, or just that our Aerosol base class should
158  // have the additional functions AerosolOptical supplies. But for
159  // now just fail miserably if we are using a different kind of
160  // Aerosol.
161  aerosol = boost::dynamic_pointer_cast<AerosolOptical>(Aerosol);
162  if(!aerosol)
163  throw Exception("Currently only support AerosolOptical");
164 }
165 
166 
167 
168 // See base class for description
170 {
171  // Freeze the state
173  boost::dynamic_pointer_cast<AerosolOptical>(aerosol->clone());
174  boost::shared_ptr<AerosolOutputHelper> h(new AerosolOutputHelper(afreeze, all_aer_names));
175 
176  out->register_data_source("/RetrievalResults/aerosol_param_apriori", &AerosolOutputHelper::aerosol_param_matrix, h);
177 }
178 
180 {
181  boost::shared_ptr<AerosolOutputHelper> h(new AerosolOutputHelper(aerosol, all_aer_names));
182 
183  out->register_data_source("/Metadata/AllAerosolTypes", &AerosolOutputHelper::all_aerosol_names, h);
184 
185  out->register_data_source("/RetrievalResults/aerosol_model", &AerosolOutputHelper::aerosol_model_types, h);
186  out->register_data_source("/RetrievalResults/aerosol_type_retrieved", &AerosolOutputHelper::aerosol_type_retrieved, h);
187 
188  out->register_data_source("/RetrievalResults/aerosol_aod", &AerosolOutputHelper::aerosol_aod_matrix, h);
189  out->register_data_source("/RetrievalResults/aerosol_param", &AerosolOutputHelper::aerosol_param_matrix, h);
190  out->register_data_source("/RetrievalResults/aerosol_param_uncert", &AerosolOutputHelper::aerosol_param_uncert_matrix, h);
191 
192  // Also include total optical depth. This is a duplicate of what
193  // we had in AerosolAodOutput. Hopefully this doesn't cause any
194  // problems, I don't believe we plan on having this both on at the
195  // same time. But if we do, we might need to add some simple logic
196  // here (e.g., add a flag to AerosolConsolidatedOutput to turn
197  // this on or off here).
198  double minv = std::numeric_limits<double>::min();
199  double maxv = std::numeric_limits<double>::max();
200  boost::function<double ()> func_tot_all =
201  boost::bind(&AerosolOptical::aerosol_optical_depth_total, aerosol,
202  minv, maxv);
203  out->register_data_source("/RetrievalResults/aerosol_total_aod", func_tot_all);
204 }
205 
Array< double, 2 > aerosol_param_uncert_matrix() const
virtual void register_output_apriori(const boost::shared_ptr< Output > &out) const
Register apriori portions of class.
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
Array< double, 2 > aerosol_aod_matrix() const
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
double aerosol_optical_depth_total(double pmin=std::numeric_limits< double >::min(), double pmax=std::numeric_limits< double >::max()) const
This gives the total optical depth for each particle, plus adds the total optical depth for all parti...
Apply value function to a blitz array.
Array< double, 2 > aerosol_param_matrix() const
This class maintains the aerosol portion of the state.
Definition: aerosol.h:24
blitz::Array< int, 1 > aerosol_type_retrieved() const
Implementation of Aerosol.
This registers the portions of the Aerosol class that should be written as output.
As described in the Output class, we have a decentralized model of producing output for L2 Full Physi...
AerosolConsolidatedOutput(const boost::shared_ptr< Aerosol > &Aerosol, const std::vector< std::string > &All_aer_names)
Constructor.
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
As a design principle, we have each base class with the absolutely minimum interface needed for use f...
AerosolOutputHelper(const boost::shared_ptr< AerosolOptical > &Aerosol, const std::vector< std::string > &All_aer_names)
virtual void register_output(const boost::shared_ptr< Output > &out) const
Register portions of class that will be written to output.
blitz::Array< std::string, 1 > aerosol_model_types() const
blitz::Array< std::string, 1 > all_aerosol_names() const

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