ReFRACtor
state_vector.cc
Go to the documentation of this file.
1 #include "state_vector.h"
2 #include "spectrum_effect.h"
3 #include "fp_exception.h"
4 #include <boost/lexical_cast.hpp>
5 
6 using namespace FullPhysics;
7 using namespace blitz;
8 
9 #ifdef HAVE_LUA
10 #include "register_lua.h"
11 #include "rt_atmosphere.h"
12 #include "instrument.h"
13 #include "instrument_correction.h"
14 #include "stokes_coefficient.h"
15 #include "absorber_vmr.h"
16 #include "aerosol_optical.h"
17 #include "aerosol_extinction.h"
18 #include "aerosol_property.h"
19 #include "dispersion.h"
20 
21 void state_vector_add_observer_instrument(StateVector& Sv, Instrument& inst)
22 {
23  Sv.add_observer(inst);
24 }
25 
26 void state_vector_add_observer_atm(StateVector& Sv, RtAtmosphere& atm)
27 {
28  Sv.add_observer(atm);
29 }
30 
31 void state_vector_add_observer_scoeff(StateVector& Sv, StokesCoefficient& Scoef)
32 {
33  Sv.add_observer(Scoef);
34 }
35 
36 void state_vector_add_observer_spec_effect(StateVector& Sv, std::vector<std::vector<boost::shared_ptr<SpectrumEffect> > >& se)
37 {
38  BOOST_FOREACH(std::vector<boost::shared_ptr<SpectrumEffect> >& i, se) {
39  BOOST_FOREACH(boost::shared_ptr<SpectrumEffect>& j, i)
40  Sv.add_observer(*j);
41  }
42 }
43 
44 void state_vector_add_observer_inst_corr(StateVector& Sv, std::vector<std::vector<boost::shared_ptr<InstrumentCorrection> > >& se)
45 {
46  BOOST_FOREACH(std::vector<boost::shared_ptr<InstrumentCorrection> >& i, se) {
47  BOOST_FOREACH(boost::shared_ptr<InstrumentCorrection>& j, i)
48  Sv.add_observer(*j);
49  }
50 }
51 
52 void state_vector_add_observer_absorber_vmr(StateVector& Sv, AbsorberVmr& avmr)
53 {
54  Sv.add_observer(avmr);
55 }
56 
57 void state_vector_add_observer_aerosol_optical(StateVector& Sv, AerosolOptical& aopt)
58 {
59  Sv.add_observer(aopt);
60 }
61 
62 void state_vector_add_observer_aerosol_extinction(StateVector& Sv, AerosolExtinction& aext)
63 {
64  Sv.add_observer(aext);
65 }
66 
67 void state_vector_add_observer_aerosol_property(StateVector& Sv, AerosolProperty& aprop)
68 {
69  Sv.add_observer(aprop);
70 }
71 
72 void state_vector_add_observer_pressure(StateVector& Sv, Pressure& press)
73 {
74  Sv.add_observer(press);
75 }
76 
77 void state_vector_add_observer_temperature(StateVector& Sv, Temperature& temp)
78 {
79  Sv.add_observer(temp);
80 }
81 
82 void state_vector_add_observer_ground(StateVector& Sv, Ground& ground)
83 {
84  Sv.add_observer(ground);
85 }
86 
87 
88 void state_vector_add_observer_disp(StateVector& Sv, Dispersion& disp)
89 {
90  Sv.add_observer(disp);
91 }
92 
93 void state_vector_print_names(StateVector& Sv)
94 {
95  BOOST_FOREACH(const std::string & s, Sv.state_vector_name())
96  std::cout << s << "\n";
97 }
98 typedef void (StateVector::*us1)(const blitz::Array<double, 1>&);
99 typedef void (StateVector::*us2)(const blitz::Array<double, 1>&, const blitz::Array<double, 2>&);
101 .def(luabind::constructor<>())
102 .def("add_observer", &state_vector_add_observer_instrument)
103 .def("add_observer", &state_vector_add_observer_atm)
104 .def("add_observer", &state_vector_add_observer_scoeff)
105 .def("add_observer", &state_vector_add_observer_spec_effect)
106 .def("add_observer", &state_vector_add_observer_inst_corr)
107 .def("add_observer", &state_vector_add_observer_absorber_vmr)
108 .def("add_observer", &state_vector_add_observer_aerosol_optical)
109 .def("add_observer", &state_vector_add_observer_aerosol_extinction)
110 .def("add_observer", &state_vector_add_observer_aerosol_property)
111 .def("add_observer", &state_vector_add_observer_pressure)
112 .def("add_observer", &state_vector_add_observer_temperature)
113 .def("add_observer", &state_vector_add_observer_ground)
114 .def("add_observer", &state_vector_add_observer_disp)
115 .def("update_state", ((us1) &StateVector::update_state))
116 .def("update_state", ((us2) &StateVector::update_state))
117 .def("print_names", &state_vector_print_names)
118 .def("state", &StateVector::state)
119 .def("state_covariance", &StateVector::state_covariance)
121 #endif
122 
123 //-----------------------------------------------------------------------
126 //-----------------------------------------------------------------------
127 
128 void StateVector::update_state(const blitz::Array<double, 1>& X)
129 {
130  x_.resize(X.rows(), X.rows());
131  x_.value() = X;
132  x_.jacobian() = 0;
133 
134  for(int i = 0; i < x_.rows(); ++i) {
135  x_.jacobian()(i, i) = 1;
136  }
137 
138  // Only set dummy covariance values when it is empty or the state vector size change. Don't
139  // overwrite anything that may have been written by the other overloaded update_state method
140  if (cov_.rows() != x_.rows() or cov_.cols() == x_.rows()) {
141  cov_.resize(x_.rows(), x_.rows());
142  cov_ = 0;
143 
144  for(int i = 0; i < x_.rows(); ++i) {
145  cov_(i, i) = 1;
146  }
147  }
148 
149  notify_update_do(*this);
150 }
151 
152 //-----------------------------------------------------------------------
154 //-----------------------------------------------------------------------
155 
156 void StateVector::update_state(const blitz::Array<double, 1>& X,
157  const blitz::Array<double, 2>& Cov)
158 {
159  if(X.rows() != Cov.rows() ||
160  X.rows() != Cov.cols()) {
161  throw Exception("X and Cov need to be the same size when updating the StateVector");
162  }
163 
164  x_.resize(X.rows(), X.rows());
165  x_.value() = X;
166  x_.jacobian() = 0;
167 
168  for(int i = 0; i < x_.rows(); ++i) {
169  x_.jacobian()(i, i) = 1;
170  }
171 
172  cov_.reference(Cov.copy());
173  notify_update_do(*this);
174 }
175 
176 
177 //-----------------------------------------------------------------------
182 //-----------------------------------------------------------------------
183 
184 blitz::Array<bool, 1> StateVector::used_flag() const
185 {
186  blitz::Array<bool, 1> res(state().rows());
187  res = false;
188  BOOST_FOREACH(const boost::weak_ptr<Observer<StateVector> >& t, olist) {
190  boost::dynamic_pointer_cast<StateVectorObserver>(t.lock());
191 
192  if(t2) {
193  t2->mark_used(*this, res);
194  }
195  }
196  return res;
197 }
198 
199 //-----------------------------------------------------------------------
201 //-----------------------------------------------------------------------
202 
203 Array<std::string, 1> StateVector::state_vector_name() const
204 {
205  Array<std::string, 1> res(std::max(state().rows(), observer_claimed_size()));
206 
207  for(int i = 0; i < res.rows(); ++i) {
208  res(i) = "State vector " + boost::lexical_cast<std::string>(i + 1);
209  }
210 
211  BOOST_FOREACH(const boost::weak_ptr<Observer<StateVector> >& t, olist) {
213  boost::dynamic_pointer_cast<StateVectorObserver>(t.lock());
214 
215  if(t2) {
216  t2->state_vector_name(*this, res);
217  }
218  }
219  return res;
220 }
221 
222 void StateVector::print(std::ostream& Os) const
223 {
224  const static int sv_num_width = 17;
225  Array<std::string, 1> svname = state_vector_name();
226 
227  for(int i = 0; i < std::max(svname.rows(), state().rows()); ++i) {
228  Os << std::setprecision(sv_num_width - 7)
229  << std::setw(sv_num_width);
230 
231  if(i < state().rows()) {
232  Os << state()(i);
233  } else {
234  Os << "Past end state vector";
235  }
236 
237  Os << " ";
238 
239  if(i < svname.rows()) {
240  Os << svname(i);
241  } else {
242  Os << "Unlabeled row " << i;
243  }
244 
245  Os << std::endl;
246 
247  }
248 }
This gives the Aerosol properties for an Aerosol.
const Unit s("s", 1.0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)
This class is responsible for setting up the atmosphere and ground information needed to run the Radi...
Definition: rt_atmosphere.h:51
const blitz::Array< double, 1 > & state() const
Current state vector.
Definition: state_vector.h:34
blitz::Array< std::string, 1 > state_vector_name() const
Return name of each state vector element.
This class maintains the stokes coefficient portion of the state.
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
This is an observer of a StateVector.
const blitz::Array< double, 2 > & state_covariance() const
Current covariance of the state vector.
Definition: state_vector.h:53
virtual void add_observer(Observer< StateVector > &Obs)
Add an observer.
Definition: state_vector.h:24
This class maintains the ground portion of the state.
Definition: ground.h:22
#define REGISTER_LUA_CLASS(X)
Definition: register_lua.h:116
Apply value function to a blitz array.
This applies a instrument model to radiances.
Definition: instrument.h:17
Implementation of Aerosol.
void update_state(const blitz::Array< double, 1 > &X)
Update the state vector.
This handles informing a set of interested objects when the state vector has updated.
Definition: state_vector.h:16
This gives the Gas Absorber Volumn mixing ratio for a single gas.
Definition: absorber_vmr.h:17
This class maintains the pressure portion of the state.
Definition: pressure.h:32
This class calculates the wavenumber for each pixel in a single band of an Instrument.
Definition: dispersion.h:12
virtual void print(std::ostream &Os) const
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
This class maintains the temperature portion of the state.
Definition: temperature.h:22
blitz::Array< bool, 1 > used_flag() const
Return a Array of boolean values.
This class maps the state vector to the aerosol extinction on each level.

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