ReFRACtor
spectral_domain.cc
Go to the documentation of this file.
1 #include "spectral_domain.h"
2 #include "fp_exception.h"
3 #include "old_constant.h"
4 using namespace FullPhysics;
5 using namespace blitz;
6 
7 #ifdef HAVE_LUA
8 #include "register_lua.h"
9 
10 std::string spec_domain_type_preference(const SpectralDomain& dom)
11 {
13  return "wavenumber";
15  return "wavelength";
16  else
17  return "UNKNOWN";
18 }
19 
21 .def("data", &SpectralDomain::data)
22 .def("units", &SpectralDomain::units)
23 .def("type_preference", &spec_domain_type_preference)
24 .def(luabind::constructor<const ArrayAd<double, 1>&, const Unit&>())
25 .def(luabind::constructor<const Array<double, 1>&>())
26 .def(luabind::constructor<const Array<double, 1>&, const Unit&>())
27 .def(luabind::constructor<const ArrayWithUnit<double, 1>&>())
28 .def(luabind::constructor<const ArrayAd<double, 1>&, const blitz::Array<int, 1>&,const Unit&>())
29 .def(luabind::constructor<const Array<double, 1>&, const blitz::Array<int, 1>&>())
30 .def(luabind::constructor<const Array<double, 1>&, const blitz::Array<int, 1>&, const Unit&>())
31 .def(luabind::constructor<const ArrayWithUnit<double, 1>&, const blitz::Array<int, 1>&>())
33 #endif
34 
35 //-----------------------------------------------------------------------
38 //-----------------------------------------------------------------------
40  const Unit& Units)
41 : data_(Data),
42  units_(Units)
43 {
44  if(!Units.is_commensurate(units::micron) &&
46  Exception e;
47  e << "The units passed to SpectralDomain must be Length or Length^-1.\n"
48  << "Units passed in: \n" << Units;
49  throw e;
50  }
51 }
52 
53 //-----------------------------------------------------------------------
56 //-----------------------------------------------------------------------
58  const blitz::Array<int, 1>& Sindex,
59  const Unit& Units)
60 : data_(Data),
61  sindex_(Sindex),
62  units_(Units)
63 {
64  if(!Units.is_commensurate(units::micron) &&
66  Exception e;
67  e << "The units passed to SpectralDomain must be Length or Length^-1.\n"
68  << "Units passed in: \n" << Units;
69  throw e;
70  }
71  if(data_.rows() != sindex_.rows())
72  throw Exception("Data and Sindex must be the same size");
73 }
74 
75 //-----------------------------------------------------------------------
78 //-----------------------------------------------------------------------
79  SpectralDomain::SpectralDomain(const blitz::Array<double, 1>& Data,
80  const Unit& Units)
81 : data_(Data),
82  units_(Units)
83 {
84  if(!Units.is_commensurate(units::micron) &&
86  Exception e;
87  e << "The units passed to SpectralDomain must be Length or Length^-1.\n"
88  << "Units passed in: \n" << Units;
89  throw e;
90  }
91 }
92 
93 //-----------------------------------------------------------------------
96 //-----------------------------------------------------------------------
97  SpectralDomain::SpectralDomain(const blitz::Array<double, 1>& Data,
98  const blitz::Array<int, 1>& Sindex,
99  const Unit& Units)
100 : data_(Data),
101  sindex_(Sindex),
102  units_(Units)
103 {
104  if(!Units.is_commensurate(units::micron) &&
105  !Units.is_commensurate(units::inv_cm)) {
106  Exception e;
107  e << "The units passed to SpectralDomain must be Length or Length^-1.\n"
108  << "Units passed in: \n" << Units;
109  throw e;
110  }
111  if(data_.rows() != sindex_.rows())
112  throw Exception("Data and Sindex must be the same size");
113 }
114 
115 //-----------------------------------------------------------------------
118 //-----------------------------------------------------------------------
120  : data_(Data.value),
121  units_(Data.units)
122 {
123  if(!units_.is_commensurate(units::micron) &&
124  !units_.is_commensurate(units::inv_cm)) {
125  Exception e;
126  e << "The units passed to SpectralDomain must be Length or Length^-1.\n"
127  << "Units passed in: \n" << units_;
128  throw e;
129  }
130 }
131 
132 //-----------------------------------------------------------------------
135 //-----------------------------------------------------------------------
137  const blitz::Array<int, 1>& Sindex)
138  : data_(Data.value),
139  sindex_(Sindex),
140  units_(Data.units)
141 {
142  if(!units_.is_commensurate(units::micron) &&
143  !units_.is_commensurate(units::inv_cm)) {
144  Exception e;
145  e << "The units passed to SpectralDomain must be Length or Length^-1.\n"
146  << "Units passed in: \n" << units_;
147  throw e;
148  }
149  if(data_.rows() != sindex_.rows())
150  throw Exception("Data and Sindex must be the same size");
151 }
152 
153 //-----------------------------------------------------------------------
155 //-----------------------------------------------------------------------
156 
157 Array<double, 1> SpectralDomain::convert_wave(const Unit& Units) const
158 {
159  if(units_.is_commensurate(Units))
160  return Array<double, 1>(FullPhysics::conversion(units_, Units) * data_.value());
161  else
162  return Array<double, 1>(FullPhysics::conversion(1 / units_, Units) / data_.value());
163 }
164 
165 //-----------------------------------------------------------------------
170 //-----------------------------------------------------------------------
171 
172 Array<double, 1> SpectralDomain::wavenumber(const Unit& Units) const
173 {
174  if (Units.is_commensurate(units::inv_cm))
175  return convert_wave(Units);
176  else {
177  stringstream err_msg;
178  err_msg << "Supplied units: "
179  << Units.name()
180  << " are not commensurate with target units: "
181  << units::inv_cm.name();
182  throw Exception(err_msg.str());
183  }
184 }
185 
186 //-----------------------------------------------------------------------
191 //-----------------------------------------------------------------------
192 
193 Array<double, 1> SpectralDomain::wavelength(const Unit& Units) const
194 {
195  if (Units.is_commensurate(units::micron))
196  return convert_wave(Units);
197  else {
198  stringstream err_msg;
199  err_msg << "Supplied units: "
200  << Units.name()
201  << " are not commensurate with target units: "
202  << units::micron.name();
203  throw Exception(err_msg.str());
204  }
205 }
206 
207 //-----------------------------------------------------------------------
210 //-----------------------------------------------------------------------
211 
213 {
214  using namespace units;
215  // Desired output units. Note this is just a convenience, since we
216  // typically give wavelength in microns and wavenumber in cm^-1. The
217  // conversion could also be handled outside of this class.
218  const Unit output_units = (W / inv_cm) / (ph / s / micron);
219  const Unit wavenumber_unit = inv_cm;
222  res.value.reference
223  (Array<double, 1>(alpha.value / wavenumber(wavenumber_unit)));
224  res.units = alpha.units / wavenumber_unit / ph;
225  return res.convert(output_units);
226 }
const DoubleWithUnit planck(6.6260693e-34, units::J *units::s)
Planck&#39;s constant, in J s.
const Unit s("s", 1.0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)
SpectralDomain()
Default constructor needed for SWIG.
For different instruments, it is more natural to either work with wavenumbers (e.g., GOSAT) or wavelength (e.g., OCO).
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
blitz::Array< double, 1 > wavelength(const Unit &Units=units::micron) const
Return data as wavelengths You can optionally supply the units to use.
const Unit micron("micron", 1e-6 *m)
blitz::Array< T, D > value
#define REGISTER_LUA_CLASS(X)
Definition: register_lua.h:116
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))
blitz::Array< double, 1 > convert_wave(const Unit &Units) const
Return data as the supplied the units.
We frequently have a double with units associated with it.
TypePreference type_preference() const
Indicate if this class prefers wavelength or wavenumber.
ArrayWithUnit< double, 1 > photon_to_radiance_factor() const
We may want to convert from photon number per second to radiance units.
Libraries such as boost::units allow unit handling where we know the units at compile time...
Definition: unit.h:25
blitz::Array< double, 1 > wavenumber(const Unit &Units=units::inv_cm) const
Return data as wavenumbers.
const Unit units() const
Units that go with data()
bool is_commensurate(const Unit &Units) const
Test if this set of units is commensurate with another set.
Definition: unit.h:68
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
const Unit ph("ph", 1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0)
const std::string & name() const
Name of unit. May be an empty string if a name wasn&#39;t assigned.
Definition: unit.h:77
double value(const FullPhysics::AutoDerivative< double > &Ad)
ArrayWithUnit< T, D > convert(const Unit &R) const
Convert to the given units.
const blitz::Array< double, 1 > & data() const
Return data.
const DoubleWithUnit speed_of_light(299792458, units::m/units::s)
Speed of light, in m/s.
const Unit W("W", J/s)
int rows() const
Definition: array_ad.h:368

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