ReFRACtor
ground_lambertian.cc
Go to the documentation of this file.
1 #include "ground_lambertian.h"
2 #include "polynomial_eval.h"
3 #include "ostream_pad.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"
12 .def(luabind::constructor<const blitz::Array<double, 2>&,
13  const blitz::Array<bool, 2>&,
15  const std::vector<std::string>&>())
17 #endif
18 
19 GroundLambertian::GroundLambertian(const blitz::Array<double, 2>& Spec_coeffs,
20  const blitz::Array<bool, 2>& Flag,
21  const ArrayWithUnit<double, 1>& Ref_points,
22  const std::vector<std::string>& Desc_band_names)
23 : reference_points(Ref_points), desc_band_names(Desc_band_names)
24 {
25  if(Spec_coeffs.rows() != Flag.rows()) {
26  Exception err_msg;
27  err_msg << "Number of spectrometers in Spec_coeffs: " << Spec_coeffs.rows() << " does not match the number in Flag: " << Flag.rows();
28  throw err_msg;
29  }
30 
31  if(Spec_coeffs.cols() != Flag.cols()) {
32  Exception err_msg;
33  err_msg << "Number of parameters in Spec_coeffs: " << Spec_coeffs.cols() << " does not match the number in Flag: " << Flag.cols();
34  throw err_msg;
35  }
36 
37  if(Spec_coeffs.rows() != Ref_points.rows()) {
38  Exception err_msg;
39  err_msg << "Number of spectrometers in Spec_coeffs: " << Spec_coeffs.rows() << " does not match the number in Ref_points: " << Ref_points.rows();
40  throw err_msg;
41  }
42 
43  if(Spec_coeffs.rows() != (int) Desc_band_names.size()) {
44  Exception err_msg;
45  err_msg << "Number of spectrometers in Spec_coeffs: " << Spec_coeffs.rows() << " does not match the number in Desc_band_names: " << Desc_band_names.size();
46  throw err_msg;
47  }
48 
49  // Make local arrays to deal with const issues on call to init. The init routine copies the data
50  Array<double, 2> spec_coeffs(Spec_coeffs);
51  Array<bool, 2> flags(Flag);
52 
53  // Flatten arrays for state vector
54  init(Array<double, 1>(spec_coeffs.dataFirst(), TinyVector<int, 1>(Spec_coeffs.rows() * Spec_coeffs.cols()), blitz::neverDeleteData),
55  Array<bool, 1>(flags.dataFirst(), TinyVector<int, 1>(Flag.rows() * Flag.cols()), blitz::neverDeleteData));
56 }
57 
58 // Protected constructor that matches the dimensionality of coeff and flag arrays
59 GroundLambertian::GroundLambertian(const blitz::Array<double, 1>& Spec_coeffs,
60  const blitz::Array<bool, 1>& Flag,
61  const ArrayWithUnit<double, 1>& Ref_points,
62  const std::vector<std::string>& Desc_band_names)
63  : SubStateVectorArray<Ground>(Spec_coeffs, Flag),
64  reference_points(Ref_points), desc_band_names(Desc_band_names)
65 {
66 }
67 
68 ArrayAd<double, 1> GroundLambertian::surface_parameter(const double wn, const int spec_index) const
69 {
70  AutoDerivative<double> wn_albedo = albedo(DoubleWithUnit(wn, units::inv_cm), spec_index);
71  ArrayAd<double, 1> spars(1, wn_albedo.number_variable());
72  spars(0) = wn_albedo;
73  return spars;
74 }
75 
76 const AutoDerivative<double> GroundLambertian::albedo(const DoubleWithUnit Wave_point, const int spec_index) const
77 {
78  // Evaluate in terms of wavenumber
80  double ref_wn = reference_points(spec_index).convert_wave(units::inv_cm).value;
81  // Calculation of albedo from state vector value
82  Poly1d surface_poly(albedo_coefficients(spec_index), false);
83  return surface_poly(wn - ref_wn);
84 }
85 
87 {
88  range_check(spec_index, 0, number_spectrometer());
89 
90  int offset = number_params() * spec_index;
91  return coefficient()(Range(offset, offset + number_params() - 1));
92 }
93 
94 const blitz::Array<double, 2> GroundLambertian::albedo_covariance(const int spec_index) const
95 {
96  range_check(spec_index, 0, number_spectrometer());
97 
98  // Return empty array if covariance is empty due to not being retrieved
99  if(product(statevector_covariance().shape()) == 0) {
100  return Array<double, 2>(0, 0);
101  }
102 
103  int num_params = number_params();
104  int offset = num_params * spec_index;
105 
106  blitz::Array<double, 2> cov(num_params, num_params);
107  for (int param_a = 0; param_a < num_params; param_a++) {
108  for (int param_b = 0; param_b < num_params; param_b++) {
109  cov(param_a, param_b) = statevector_covariance()(offset + param_a, offset + param_b);
110  }
111  }
112  return cov;
113 }
114 
116  return boost::shared_ptr<Ground>(new GroundLambertian(coefficient().value(), used_flag_value(), reference_points, desc_band_names));
117 }
118 
119 std::string GroundLambertian::state_vector_name_i(int i) const {
120  int b_idx = int(i / number_params());
121  int c_idx = i - number_params() * b_idx;
122  return "Ground Lambertian " + desc_band_names[b_idx] + " Albedo Parm " + boost::lexical_cast<std::string>(c_idx + 1);
123 }
124 
125 void GroundLambertian::print(std::ostream& Os) const
126 {
127  OstreamPad opad(Os, " ");
128  Os << "GroundLambertian:" << std::endl;
129  for(int b_idx = 0; b_idx < number_spectrometer(); b_idx++) {
130  opad << "Band: " << desc_band_names[b_idx] << std::endl
131  << "Coefficient: " << albedo_coefficients(b_idx).value() << std::endl
132  << "Flag: ";
133  for(int c_idx = 0; c_idx < number_params(); c_idx++) {
134  opad << used_flag_value()(number_params() * b_idx + c_idx);
135  if(c_idx < number_params()-1) {
136  opad << ", ";
137  }
138  }
139  opad << std::endl << "Reference Point: " << reference_points(b_idx) << std::endl;
140  }
141  opad.strict_sync();
142 }
virtual const ArrayAd< double, 1 > albedo_coefficients(const int spec_index) const
#define range_check(V, Min, Max)
Range check.
Definition: fp_exception.h:140
virtual const int number_params() const
virtual const AutoDerivative< double > albedo(const DoubleWithUnit wave_point, const int spec_index) const
DoubleWithUnit convert_wave(const Unit &R) const
We often need to handle conversion from wavenumber to/from wavelength.
virtual void print(std::ostream &Os) const
blitz::Array< double, 2 > cov
Last covariance matrix updated from the StateVector.
This is a filtering stream that adds a pad to the front of every line written out.
Definition: ostream_pad.h:32
This class implements a Lambertian albedo as a ground type.
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
virtual std::string state_vector_name_i(int i) const
Return state vector name for ith entry in coeff.
const blitz::Array< bool, 1 > & used_flag_value() const
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
This class maintains the ground portion of the state.
Definition: ground.h:22
Apply value function to a blitz array.
const blitz::Array< T, D > & value() const
Definition: array_ad.h:306
const Unit inv_cm("cm^-1", pow(cm, -1))
virtual const blitz::Array< double, 2 > albedo_covariance(const int spec_index) const
A one-dimensional polynomial class.
virtual const int number_spectrometer() const
const blitz::Array< double, 2 > & statevector_covariance() const
int number_variable() const
Number of variables in gradient.
We frequently have a double with units associated with it.
GroundLambertian(const blitz::Array< double, 2 > &Spec_coeffs, const blitz::Array< bool, 2 > &Flag, const ArrayWithUnit< double, 1 > &Ref_points, const std::vector< std::string > &Desc_band_names)
const ArrayAd< double, 1 > & coefficient() const
It is common to have a class that is an Observable with a set of coefficients, a subset of which are ...
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
void init(const blitz::Array< double, 1 > &Coeff, const blitz::Array< bool, 1 > &Used_flag, const boost::shared_ptr< Pressure > &Press=boost::shared_ptr< Pressure >(), bool Mark_according_to_press=true, int Pdep_start=0)
#define REGISTER_LUA_END()
Definition: register_lua.h:134
virtual ArrayAd< double, 1 > surface_parameter(const double wn, const int spec_index) const
Surface parmeters.
virtual boost::shared_ptr< Ground > clone() const
Clone a Ground object.
double value(const FullPhysics::AutoDerivative< double > &Ad)
ArrayWithUnit< T, D > convert_wave(const Unit &R) const
We often need to handle conversion from wavenumber to/from wavelength.

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