ReFRACtor
nonuniform_spectrum_sampling.cc
Go to the documentation of this file.
2 #include "ostream_pad.h"
3 #include <algorithm>
4 
5 using namespace FullPhysics;
6 using namespace std;
7 using namespace blitz;
8 
9 #ifdef HAVE_LUA
10 #include "register_lua.h"
12 .def(luabind::constructor<const SpectralDomain&,
13  const SpectralDomain&,
14  const SpectralDomain&,
17 #endif
18 
19 
20 
21 //-----------------------------------------------------------------------
24 //-----------------------------------------------------------------------
25 
27 const SpectralDomain& Grid,
28 const boost::shared_ptr<SpectrumSampling>& Interpolated_sampling
29 )
30 : SpectrumSampling(1), interpolated_sampling(Interpolated_sampling)
31 {
32  spec_domain.push_back(sort_sd(Grid));
33 }
34 
35 //-----------------------------------------------------------------------
38 //-----------------------------------------------------------------------
39 
41 const SpectralDomain& Grid1,
42 const SpectralDomain& Grid2,
43 const SpectralDomain& Grid3,
44 const boost::shared_ptr<SpectrumSampling>& Interpolated_sampling
45 )
46 : SpectrumSampling(3), interpolated_sampling(Interpolated_sampling)
47 {
48  spec_domain.push_back(sort_sd(Grid1));
49  spec_domain.push_back(sort_sd(Grid2));
50  spec_domain.push_back(sort_sd(Grid3));
51 }
52 
53 SpectralDomain NonuniformSpectrumSampling::sort_sd
54 (const SpectralDomain& In) const
55 {
56  Array<double, 1> res(In.data().copy());
57  sort(res.data(), res.data()+res.size());
58  return SpectralDomain(res, In.units());
59 }
60 
61 //-----------------------------------------------------------------------
63 //-----------------------------------------------------------------------
64 
65 void NonuniformSpectrumSampling::print(std::ostream& Os) const
66 {
67  OstreamPad opad(Os, " ");
68  Os << "NonuniformSpectrumSampling\n";
69  Os << " Uniform spectrum sampling:\n";
70  opad << *interpolated_sampling << "\n";
71  opad.strict_sync();
72  for(int i = 0; i < number_spectrometer(); ++i)
73  if(spec_domain[i].data().rows() <= 0)
74  Os << " Band " << i + 1 << ":\n"
75  << " Nonuniform RT grid not provided, using uniform grid for RT\n";
76  else
77  Os << " Band " << i + 1 << ":\n"
78  << " grid_start: " << spec_domain[i].data()(0) << "\n"
79  << " grid_end: " << spec_domain[i].data()(spec_domain[i].data().rows() - 1) << "\n"
80  << " grid_points: " << spec_domain[i].data().rows() << "\n";
81 }
82 
83 // See base class for description
85 (int spec_index,
86  const SpectralDomain& Lowres_grid,
87  const DoubleWithUnit& Ils_half_width) const
88 {
89  range_check(spec_index, 0, number_spectrometer());
90  SpectralDomain ispec = interpolated_sampling->
91  spectral_domain(spec_index, Lowres_grid, Ils_half_width);
92  // If we aren't actually doing nonuniform sampling, just return the
93  // spectral domain we want to sample to.
94  if(spec_domain[spec_index].data().rows() == 0)
95  return ispec;
96  // Find all points in ispec that are closest to one of the grid points.
97  std::map<double, bool> res;
98  typedef std::map<double, bool>::iterator it_type;
99  typedef std::map<double, bool>::value_type val_type;
100  BOOST_FOREACH(double x, ispec.data())
101  res[x] = false;
102  BOOST_FOREACH(double x, spec_domain[spec_index].convert_wave(ispec.units())) {
103  it_type i = res.lower_bound(x);
104  if(i != res.begin()) {
105  it_type i2 = i;
106  --i2;
107  if(fabs(x - (*i2).first) < fabs(x - (*i).first))
108  i = i2;
109  }
110  (*i).second = true;
111  }
112  // And use those points to make up the spectral domain.
113  std::vector<double> resx;
114  BOOST_FOREACH(const val_type& i, res)
115  if(i.second)
116  resx.push_back(i.first);
117  Array<double, 1> sd(&resx[0], shape((int) resx.size()), duplicateData);
118  return SpectralDomain(sd, ispec.units());
119 }
#define range_check(V, Min, Max)
Range check.
Definition: fp_exception.h:140
This is a filtering stream that adds a pad to the front of every line written out.
Definition: ostream_pad.h:32
For different instruments, it is more natural to either work with wavenumbers (e.g., GOSAT) or wavelength (e.g., OCO).
STL namespace.
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
int number_spectrometer() const
Number of spectrometers we have.
Apply value function to a blitz array.
This determines the sampling of the spectrum that should be used for each of the spectrum indexes...
We frequently have a double with units associated with it.
NonuniformSpectrumSampling(const SpectralDomain &Grid, const boost::shared_ptr< SpectrumSampling > &Interpolated_sampling)
Constructor.
const Unit units() const
Units that go with data()
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 SpectralDomain spectral_domain(int spec_index, const SpectralDomain &Lowres_grid, const DoubleWithUnit &Ils_half_width) const
Wavenumbers/Wavelengths to use for the given spectrometer.
virtual void print(std::ostream &Os) const
Print to stream.
This is a simple SpectrumSampling that is just a nonuniform sampling.
const blitz::Array< double, 1 > & data() const
Return data.

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