ReFRACtor
level_1b_average.cc
Go to the documentation of this file.
1 #include "level_1b_average.h"
2 #include <boost/foreach.hpp>
3 using namespace FullPhysics;
4 using namespace blitz;
5 
6 #ifdef HAVE_LUA
7 #include "register_lua.h"
9 .def(luabind::constructor<const std::vector<boost::shared_ptr<Level1b> > &>())
11 #endif
12 
13 
15 {
16  assert_field_equal(&Level1b::number_spectrometer);
17  return l1b[0]->number_spectrometer();
18 }
19 
21 {
22  DoubleWithUnit sum(0, l1b[0]->relative_velocity(Spec_index).units);
23  BOOST_FOREACH(const boost::shared_ptr<Level1b>& f, l1b)
24  sum += f->relative_velocity(Spec_index);
25  return sum / ((int) l1b.size());
26 }
27 
28 Time Level1bAverage::time(int Spec_index) const
29 {
30  return l1b[0]->time(Spec_index);
31 }
32 
34 {
35  assert_field_equal(&Level1b::sample_grid, Spec_index);
36  return l1b[0]->sample_grid(Spec_index);
37 }
38 
40 {
41  DoubleWithUnit sum(0, l1b[0]->latitude(i).units);
42  BOOST_FOREACH(const boost::shared_ptr<Level1b>& f, l1b)
43  sum += f->latitude(i);
44  return sum / ((int) l1b.size());
45 }
46 
48 {
49  DoubleWithUnit sum(0, l1b[0]->longitude(i).units);
50  BOOST_FOREACH(const boost::shared_ptr<Level1b>& f, l1b)
51  sum += f->longitude(i);
52  return sum / ((int) l1b.size());
53 }
54 
56 {
57  DoubleWithUnit sum(0, l1b[0]->sounding_zenith(i).units);
58  BOOST_FOREACH(const boost::shared_ptr<Level1b>& f, l1b)
59  sum += f->sounding_zenith(i);
60  return sum / ((int) l1b.size());
61 }
62 
64 {
65  DoubleWithUnit sum(0, l1b[0]->sounding_azimuth(1).units);
66  BOOST_FOREACH(const boost::shared_ptr<Level1b>& f, l1b)
67  sum += f->sounding_azimuth(i);
68  return sum / ((int) l1b.size());
69 }
70 
71 Array<double, 1> Level1bAverage::stokes_coefficient(int i) const
72 {
73  Array<double, 1> res(l1b[0]->stokes_coefficient(i).rows());
74  res = 0;
75  BOOST_FOREACH(const boost::shared_ptr<Level1b>& f, l1b)
76  res += f->stokes_coefficient(i);
77  res /= (int) l1b.size();
78  return res;
79 }
80 
82 {
83  DoubleWithUnit sum(0, l1b[0]->solar_zenith(i).units);
84  BOOST_FOREACH(const boost::shared_ptr<Level1b>& f, l1b)
85  sum += f->solar_zenith(i);
86  return sum / ((int) l1b.size());
87 }
88 
90 {
91  DoubleWithUnit sum(0, l1b[0]->solar_azimuth(i).units);
92  BOOST_FOREACH(const boost::shared_ptr<Level1b>& f, l1b)
93  sum += f->solar_azimuth(i);
94  return sum / ((int) l1b.size());
95 }
96 
98 {
99  DoubleWithUnit sum(0, l1b[0]->altitude(i).units);
100  BOOST_FOREACH(const boost::shared_ptr<Level1b>& f, l1b)
101  sum += f->altitude(i);
102  return sum / ((int) l1b.size());
103 }
104 
106 {
107  SpectralRange t = l1b[0]->radiance(Spec_index);
108  Array<double, 1> rad(t.data());
109  Array<double, 1> sum(rad.shape());
110  sum = 0;
111  bool have_uncertainty = (t.uncertainty().rows() > 0);
112  if(have_uncertainty)
113  sum += sqr(t.uncertainty());
114  for(int i = 1; i < (int) l1b.size(); ++i) {
115  SpectralRange t2 = l1b[i]->radiance(Spec_index);
116  rad += t2.data() * FullPhysics::conversion(t2.units(), t.units());
117  if(have_uncertainty)
118  sum += sqr(t2.uncertainty() * FullPhysics::conversion(t2.units(), t.units()));
119  }
120  rad /= ((int) l1b.size());
121  Array<double, 1> uncer;
122  if(have_uncertainty)
123  uncer.reference(Array<double,1>(sqrt(sum) / (int) l1b.size()));
124  return SpectralRange(rad, t.units(), uncer);
125 }
126 
127 template <typename T>
128 bool Level1bAverage::check_field_equal(T && check_field) const {
129  auto first_result = std::bind(check_field, l1b[0])();
130  BOOST_FOREACH(const boost::shared_ptr<Level1b>& f, l1b) {
131  if (std::bind(check_field, f)() != first_result) {
132  return false;
133  }
134  }
135  return true;
136 }
137 
138 template <typename T>
139 bool Level1bAverage::check_field_equal(T && check_field, int arg1) const {
140  auto first_result = std::bind(check_field, l1b[0], arg1)();
141  BOOST_FOREACH(const boost::shared_ptr<Level1b>& f, l1b) {
142  if (std::bind(check_field, f, arg1)() != first_result) {
143  return false;
144  }
145  }
146  return true;
147 }
148 
149 /* TODO: change signature to accept string name of function to provide better error output? */
150 template <typename T>
151 void Level1bAverage::assert_field_equal(T && check_field) const {
152  bool field_equal = check_field_equal(check_field);
153  if(!field_equal) {
154  Exception e;
155  e << "All instances of checked field not equal.\n";
156  throw e;
157  }
158 }
159 
160 /* TODO: change signature to accept string name of function to provide better error output? */
161 template <typename T>
162 void Level1bAverage::assert_field_equal(T && check_field, int arg1) const {
163  bool field_equal = check_field_equal(check_field, arg1);
164  if(!field_equal) {
165  Exception e;
166  e << "All instances of checked field not equal.\n";
167  throw e;
168  }
169 }
170 
171 
172 void Level1bAverage::print(std::ostream& Os) const
173 {
174  Os << "Level1bAverage";
175 }
virtual DoubleWithUnit sounding_zenith(int i) const
Sounding zenith.
virtual DoubleWithUnit solar_azimuth(int i) const
Solar azimuth.
virtual int number_spectrometer() const
Number of spectrometers.
For different instruments, it is more natural to either work with wavenumbers (e.g., GOSAT) or wavelength (e.g., OCO).
virtual SpectralDomain sample_grid(int Spec_index) const =0
Returns the sample grid (ie wavenumber, wavelength, etc) for the corresponding radiance values...
virtual SpectralDomain sample_grid(int Spec_index) const
Returns the sample grid (ie wavenumber, wavelength, etc) for the corresponding radiance values...
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
double conversion(const Unit &Dunit_from, const Unit &Dunit_to)
Return conversion factor to go from one unit to another.
Definition: unit.cc:180
virtual SpectralRange radiance(int Spec_index) const
Radiance, for given spectral band.
virtual DoubleWithUnit longitude(int i) const
Longitude.
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
This is used to read a Level 1B file.
Definition: level_1b.h:15
virtual DoubleWithUnit solar_zenith(int i) const
Solar zenith.
Apply value function to a blitz array.
virtual blitz::Array< double, 1 > stokes_coefficient(int i) const
Return stokes coefficients.
const Unit & units() const
Units of data.
virtual DoubleWithUnit latitude(int i) const
Latitude.
const blitz::Array< double, 1 > & uncertainty() const
Uncertainty.
We frequently have a double with units associated with it.
We have a number of different spectrums that appear in different parts of the code.
double sqr(double x)
This is a simple time class.
Definition: fp_time.h:29
virtual void print(std::ostream &Os) const
Print description of 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
virtual DoubleWithUnit sounding_azimuth(int i) const
Sounding azimuth.
This reads averages a set of Level1b classes to get the various values.
virtual Time time(int Spec_index) const
Time of sounding.
virtual DoubleWithUnit altitude(int i) const
Altitude.
const Unit rad("rad", 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0)
const blitz::Array< double, 1 > & data() const
Underlying data.
virtual DoubleWithUnit relative_velocity(int Spec_index) const
Relative velocity.
virtual int number_spectrometer() const =0
Number of spectrometers.

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