ReFRACtor
uniform_spectrum_sampling.cc
Go to the documentation of this file.
2 
3 using namespace FullPhysics;
4 using namespace blitz;
5 
6 // See base class for description.
7 
9  const SpectralDomain& Lowres_grid,
10  const DoubleWithUnit& Ils_half_width) const
11 {
12  range_check(spec_index, 0, spec_spacing.rows());
13 
14  DoubleWithUnit spacing = spec_spacing(spec_index);
15 
16  // Units we input and want to output and the units we use for computing the grid
17  Unit u_out = Lowres_grid.units();
18  Unit u_grid = spacing.units;
19 
20  // Convert low res grid values to same units as spacing, in sorted order
21  std::vector<double> lowres_conv;
22  BOOST_FOREACH(double v, Lowres_grid.data()) {
23  lowres_conv.push_back(DoubleWithUnit(v, Lowres_grid.units()).convert_wave(u_grid).value);
24  }
25  std::sort(lowres_conv.begin(), lowres_conv.end());
26 
27  // Determine an integral amount of spacing units to add to the beginning and end of the grid
28  DoubleWithUnit offset = round(Ils_half_width.convert_wave(u_grid) / spacing) * spacing;
29 
30  // Determine the bounds of the high resolution grid, account for fact the
31  // low res grid points might be in a different order before conversion
32  double highres_beg = lowres_conv[0] - offset.value;
33  double highres_end = lowres_conv[lowres_conv.size()-1] + offset.value;
34 
35  int nsamples = (int) floor((highres_end - highres_beg) / spacing.value) + 1;
36 
37  std::vector<double> highres_points;
38  for(int i = 0; i < nsamples; ++i) {
39  DoubleWithUnit hr_point(highres_beg + i * spacing.value, u_grid);
40 
41  // Only use points that are within a ils_half_width of a low resolution point
42  auto lr_closest = std::lower_bound(lowres_conv.begin(), lowres_conv.end(), hr_point.value);
43  if (abs(hr_point.value - *lr_closest) <= Ils_half_width.convert_wave(u_grid).value) {
44  highres_points.push_back(hr_point.convert_wave(u_out).value);
45  }
46  }
47 
48  // Make sure the computed grid points are
49  // in sorted order
50  std::sort(highres_points.begin(), highres_points.end());
51 
52  // Create result object
53  Array<double, 1> uniform_vals((int) highres_points.size());
54  std::copy(highres_points.begin(), highres_points.end(), uniform_vals.begin());
55  SpectralDomain uniform_grid = SpectralDomain(uniform_vals, u_out);
56 
57  return uniform_grid;
58 }
59 
60 //-----------------------------------------------------------------------
62 //-----------------------------------------------------------------------
63 
64 void UniformSpectrumSampling::print(std::ostream& Os) const
65 {
66  Os << "UniformSpectrumSampling\n"
67  << " Spacing: " << spec_spacing << "\n";
68 }
#define range_check(V, Min, Max)
Range check.
Definition: fp_exception.h:140
DoubleWithUnit convert_wave(const Unit &R) const
We often need to handle conversion from wavenumber to/from wavelength.
For different instruments, it is more natural to either work with wavenumbers (e.g., GOSAT) or wavelength (e.g., OCO).
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.
Apply value function to a blitz array.
We frequently have a double with units associated with it.
Libraries such as boost::units allow unit handling where we know the units at compile time...
Definition: unit.h:25
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
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