ReFRACtor
error_analysis.h
Go to the documentation of this file.
1 #ifndef ERROR_ANALYSIS_H
2 #define ERROR_ANALYSIS_H
3 #include "connor_solver.h"
4 #include "max_a_posteriori.h"
5 #include "atmosphere_oco.h"
6 #include "forward_model.h"
7 #include "observation.h"
8 #include "fe_disable_exception.h"
9 
10 namespace FullPhysics {
11 /****************************************************************/
35 class ErrorAnalysis : public Printable<ErrorAnalysis> {
36 public:
40  const boost::shared_ptr<Observation>& inst_meas);
41  ErrorAnalysis(const boost::shared_ptr<MaxAPosteriori>& Max_a_posteriori,
44  const boost::shared_ptr<Observation>& inst_meas);
48  const boost::shared_ptr<Observation>& inst_meas);
49  ErrorAnalysis(const boost::shared_ptr<MaxAPosteriori>& Max_a_posteriori,
52  const boost::shared_ptr<Observation>& inst_meas);
53  virtual ~ErrorAnalysis() {}
54 
55 //-----------------------------------------------------------------------
57 //-----------------------------------------------------------------------
58 
59  int num_channels() const { return fm->num_channels();}
60 
61 //-----------------------------------------------------------------------
63 //-----------------------------------------------------------------------
64 
65  blitz::Array<double, 1> modeled_radiance() const
66  {
67  if(residual().rows() == 0)
68  return blitz::Array<double, 1>(0);
69  return blitz::Array<double, 1>
70  (residual() + meas->radiance_all().spectral_range().data());
71  }
72 
73 //-----------------------------------------------------------------------
75 //-----------------------------------------------------------------------
76 
77  double residual_sum_sq(int Band) const {
78  FeDisableException disable_fp;
79  boost::optional<blitz::Range> pr = fm->stacked_pixel_range(Band);
80  if(!pr)
81  return 0;
82  blitz::Array<double, 1> res(residual());
83  if(res.rows() == 0)
84  return 0;
85  return sum(res(*pr) * res(*pr));
86  }
87 
88 //-----------------------------------------------------------------------
90 //-----------------------------------------------------------------------
91 
92  double residual_mean_sq(int Band) const {
93  FeDisableException disable_fp;
94  boost::optional<blitz::Range> pr = fm->stacked_pixel_range(Band);
95  if(!pr)
96  return 0;
97  return sqrt(residual_sum_sq(Band) / pr->length());
98  }
99 
100 //-----------------------------------------------------------------------
102 //-----------------------------------------------------------------------
103 
104  double reduced_chisq(int Band) const
105  {
106  FeDisableException disable_fp;
107  boost::optional<blitz::Range> pr = fm->stacked_pixel_range(Band);
108  if(!pr)
109  return 0;
110  if(solver) {
111  if(solver->residual().rows() == 0)
112  return 0;
113  return chisq_measure_norm(solver->residual()(*pr),
114  solver->residual_covariance_diagonal()(*pr));
115  } else {
116  blitz::Array<double, 1> res(max_a_posteriori->uncert_weighted_model_measure_diff());
117  if(!res.rows()) return 0;
118  return sum(res(*pr)*res(*pr))/pr->length();
119  }
120  }
121 
122 //-----------------------------------------------------------------------
124 //-----------------------------------------------------------------------
125 
126  double relative_residual_mean_sq(int Band) const
127  {
128  FeDisableException disable_fp;
129  boost::optional<blitz::Range> pr = fm->stacked_pixel_range(Band);
130  if(!pr)
131  return 0;
132  double result = residual_mean_sq(Band);
133  return result ? (result/signal(Band)):0;
134  }
135 
136 //-----------------------------------------------------------------------
138 //-----------------------------------------------------------------------
139 
140  double chisq_measure_norm(const blitz::Array<double, 1>& Residual,
141  const blitz::Array<double, 1>& Residual_cov_diag) const
142  {
143  FeDisableException disable_fp;
144  if (residual().rows() == 0)
145  return 0;
146  return sum(Residual * Residual / Residual_cov_diag) / Residual.rows();
147  }
148 
149  double signal(int band) const;
150  double noise(int band) const;
151 
152  double xco2_measurement_error() const;
153  double xco2_smoothing_error() const;
154  double xco2_uncertainty() const;
155  double xco2_interference_error() const;
156  blitz::Array<double, 1> xco2_gain_vector() const;
157 
158 //-----------------------------------------------------------------------
160 //-----------------------------------------------------------------------
161 
162  double gamma_last_step() const
163  { return (solver ? solver->gamma_last_step() : -1); }
164 
165 //-----------------------------------------------------------------------
167 //-----------------------------------------------------------------------
168 
169  double xco2_uncert_noise() const
170  {
171  FeDisableException disable_fp;
172  return sqrt(xco2_measurement_error());
173  }
174 
175 //-----------------------------------------------------------------------
177 //-----------------------------------------------------------------------
178 
179  double xco2_uncert_smooth() const
180  {
181  FeDisableException disable_fp;
182  return sqrt(xco2_smoothing_error());
183  }
184 
185 //-----------------------------------------------------------------------
187 //-----------------------------------------------------------------------
188 
189  double xco2_uncert_interf() const
190  {
191  FeDisableException disable_fp;
192  return sqrt(xco2_interference_error());
193  }
194 
195 //-----------------------------------------------------------------------
200 //-----------------------------------------------------------------------
201 
203  {
204  FeDisableException disable_fp;
205  return sum(averaging_kernel()(i1, i1));
206  }
207 
208 //-----------------------------------------------------------------------
213 //-----------------------------------------------------------------------
214 
215  double degrees_of_freedom_xco2() const
216  {
217  FeDisableException disable_fp;
218  return sum(where(xco2_state_used(),
219  averaging_kernel()(i1, i1), 0));
220  }
221 
222  blitz::Array<double, 1> xco2_avg_kernel() const;
223  blitz::Array<double, 2> co2_averaging_kernel() const;
224  blitz::Array<double, 1> xco2_avg_kernel_full() const;
225  blitz::Array<double, 1> xco2_avg_kernel_norm() const;
226  blitz::Array<double, 1> xco2_correlation_interf() const;
227  blitz::Array<double, 1> interference_smoothing_uncertainty() const;
228 
229  void print(std::ostream& Os) const { Os << "ErrorAnalysis";}
230 private:
231  blitz::Array<double, 1> residual() const
232  {
233  if(solver)
234  return solver->residual();
235  else
236  return max_a_posteriori->model_measure_diff();
237  }
238  blitz::Array<double, 2> averaging_kernel() const
239  {
240  if(solver)
241  return solver->averaging_kernel();
242  else
243  return max_a_posteriori->averaging_kernel();
244  }
245  blitz::Array<double, 2> aposteriori_covariance() const
246  {
247  if(solver)
248  return solver->aposteriori_covariance();
249  else
250  return max_a_posteriori->a_posteriori_covariance();
251  }
252  blitz::Array<double, 2> apriori_covariance() const
253  {
254  if(solver)
255  return solver->apriori_covariance();
256  else
257  return max_a_posteriori->a_priori_cov();
258  }
259  blitz::Array<bool, 1> xco2_state_used() const
260  { return atm->absorber_ptr()->absorber_vmr("CO2")->state_used(); }
261  AutoDerivative<double> xco2() const
262  { return atm->absorber_ptr()->xgas("CO2"); }
263  blitz::Array<double, 1> dxco2_dstate() const;
264  // Only one of solver or max_a_posteriori will be nonnull.
266  boost::shared_ptr<MaxAPosteriori> max_a_posteriori;
270  blitz::Array<double, 2> hmat() const;
271  blitz::Array<double, 2> ht_c_h() const;
272  // Used in a lot of places, so define once here.
273  blitz::firstIndex i1; blitz::secondIndex i2; blitz::thirdIndex i3;
274  blitz::fourthIndex i4;
275 };
276 }
277 #endif
blitz::Array< double, 2 > co2_averaging_kernel() const
Portion of averaging kernel that relates the part of the state vector that is used by the CO2 VMR cal...
double gamma_last_step() const
Levenberg-Marquardt parameter for last step we processed.
blitz::Array< double, 1 > xco2_gain_vector() const
This calculates xco2_gain_vector.
double residual_sum_sq(int Band) const
Return the sum of the squares of the residual for the given band.
double xco2_uncert_smooth() const
Calculate xco2_uncert_smooth.
double residual_mean_sq(int Band) const
Return the residual mean square for the O2 band.
double signal(int band) const
Calculate an approximation to the size of the continuum signal where there is no significant atmosphe...
To detect things like divide by zero, we may turn on floating point exceptions.
double xco2_interference_error() const
Calculate XCO2 interference error.
This is a Mixin for classes that can be printed.
Definition: printable.h:24
blitz::Array< double, 1 > xco2_avg_kernel_norm() const
Calculate the normalized XCO2 averaging kernel.
double xco2_uncertainty() const
XCO2 uncertainty.
double relative_residual_mean_sq(int Band) const
Return the relative residual mean square for the given band.
int num_channels() const
The number of spectral bands associated with forward model.
blitz::Array< double, 1 > xco2_avg_kernel_full() const
This the XCO2 averaging kernel for the full state vector.
blitz::Array< double, 1 > modeled_radiance() const
Modeled radiance.
blitz::Array< double, 1 > xco2_avg_kernel() const
Calculate the XCO2 averaging kernel.
blitz::Array< double, 1 > interference_smoothing_uncertainty() const
Calculate the interference smoothing uncertainty.
double xco2_uncert_noise() const
Calculate xco2_uncert_noise.
double xco2_smoothing_error() const
Calculate XCO2 smoothing error.
double xco2_measurement_error() const
Calculate XCO2 measurement error.
blitz::Array< double, 1 > xco2_correlation_interf() const
Calculate xco2_correlation_interf.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
double degrees_of_freedom_xco2() const
Calculate the degrees of freedom for the portion of the state vector used to determine xco2...
double chisq_measure_norm(const blitz::Array< double, 1 > &Residual, const blitz::Array< double, 1 > &Residual_cov_diag) const
return chisq_measure_norm for the given data.
double reduced_chisq(int Band) const
Return the reduced chisq for band.
This calculates a variety of values to help with the error analysis of a Level 2 Full Physics Run...
ErrorAnalysis(const boost::shared_ptr< ConnorSolver > &Solver, const boost::shared_ptr< AtmosphereOco > &Atm, const boost::shared_ptr< ForwardModel > &Fm, const boost::shared_ptr< Observation > &inst_meas)
Constructor.
void print(std::ostream &Os) const
double degrees_of_freedom_full_vector() const
Calculate the degrees of freedom for the full state vector.
double noise(int band) const
Helper class for sort done in noise.
double xco2_uncert_interf() const
Calculate xco2_uncert_interf.

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