ReFRACtor
ils_instrument.cc
Go to the documentation of this file.
1 #include "ils_instrument.h"
2 #include "ostream_pad.h"
3 #include <boost/foreach.hpp>
4 
5 using namespace FullPhysics;
6 using namespace blitz;
7 
8 #ifdef HAVE_LUA
9 #include "register_lua.h"
11 .def(luabind::constructor<const std::vector<boost::shared_ptr<Ils> >&>())
12 .def(luabind::constructor<const std::vector<boost::shared_ptr<Ils> >&,
13  const std::vector<std::vector<boost::shared_ptr<InstrumentCorrection> > >& >())
15 #endif
16 
17 //-----------------------------------------------------------------------
19 //-----------------------------------------------------------------------
20 
22  const std::vector<std::vector<boost::shared_ptr<InstrumentCorrection> > >&
23  Instrument_correction)
24 : ils_(Ils_list), inst_corr(Instrument_correction)
25 {
26  if(inst_corr.size() == 0)
27  inst_corr.resize(ils_.size());
28  if(ils_.size() != inst_corr.size())
29  throw Exception("Ils and Instrument_correction need to be the same size");
30  BOOST_FOREACH(boost::shared_ptr<Ils> i, ils_)
31  i->add_observer(*this);
32  BOOST_FOREACH(std::vector<boost::shared_ptr<InstrumentCorrection> >& i,
33  inst_corr) {
34  BOOST_FOREACH(boost::shared_ptr<InstrumentCorrection>& j, i)
35  j->add_observer(*this);
36  }
37 }
38 
40 {
41  std::vector<boost::shared_ptr<Ils> > ils_vec;
42  BOOST_FOREACH(boost::shared_ptr<Ils> i, ils_)
43  ils_vec.push_back(i->clone());
44  std::vector<std::vector<boost::shared_ptr<InstrumentCorrection> > >
45  inst_corr_vec;
46  BOOST_FOREACH(const std::vector<boost::shared_ptr<InstrumentCorrection> >& i,
47  inst_corr) {
48  std::vector<boost::shared_ptr<InstrumentCorrection> > t;
49  BOOST_FOREACH(const boost::shared_ptr<InstrumentCorrection>& j, i)
50  t.push_back(j->clone());
51  inst_corr_vec.push_back(t);
52  }
53 
54  return boost::shared_ptr<Instrument>(new IlsInstrument(ils_vec,
55  inst_corr_vec));
56 }
57 
59  const Spectrum& High_resolution_spectrum,
60  const std::vector<int>& Pixel_list,
61  int Spec_index) const
62 {
63  range_check(Spec_index, 0, number_spectrometer());
64 
65  SpectralDomain full = pixel_spectral_domain(Spec_index);
66  blitz::Array<double, 1> res_sd((int) Pixel_list.size());
67  for(int i = 0; i < res_sd.rows(); ++i)
68  res_sd(i) = full.data()(Pixel_list[i]);
69  SpectralDomain res_dom(res_sd, full.units());
70 
71  // Gain some speed advantages when running things without autoderivatives
72  // if they are not needed.
73  SpectralRange res_sr;
74  if(High_resolution_spectrum.spectral_range().data_ad().
75  number_variable() > 0) {
76  ArrayAd<double, 1> rad_ad =
77  ils_[Spec_index]->apply_ils
78  (High_resolution_spectrum.spectral_domain().data(),
79  High_resolution_spectrum.spectral_range().data_ad(),
80  Pixel_list);
81  res_sr = SpectralRange(rad_ad,
82  High_resolution_spectrum.spectral_range().units());
83  } else {
84  Array<double, 1> rad =
85  ils_[Spec_index]->apply_ils
86  (High_resolution_spectrum.spectral_domain().data(),
87  High_resolution_spectrum.spectral_range().data(),
88  Pixel_list);
89  res_sr = SpectralRange(rad,
90  High_resolution_spectrum.spectral_range().units());
91  }
92  BOOST_FOREACH(const boost::shared_ptr<InstrumentCorrection>& i,
93  inst_corr[Spec_index])
94  i->apply_correction(ils_[Spec_index]->pixel_grid(), Pixel_list, res_sr);
95 
96  return Spectrum(res_dom, res_sr);
97 }
98 
99 void IlsInstrument::print(std::ostream& Os) const
100 {
101  Os << "IlsInstrument:\n";
102  OstreamPad opad(Os, " ");
103  for(int i = 0; i < number_spectrometer(); ++i) {
104  Os << " " << band_name(i) << ":\n";
105  opad << *ils_[i] << "\n";
106  BOOST_FOREACH(boost::shared_ptr<InstrumentCorrection> ic, inst_corr[i])
107  opad << *ic << "\n";
108  opad.strict_sync();
109  }
110 }
#define range_check(V, Min, Max)
Range check.
Definition: fp_exception.h:140
virtual int number_spectrometer() const
Give number of spectrometers.
virtual Spectrum apply_instrument_model(const Spectrum &High_resolution_spectrum, const std::vector< int > &Pixel_list, int Spec_index) const
Apply the instrument model to both the radiance and derivatives.
IlsInstrument(const std::vector< boost::shared_ptr< Ils > > &Ils_list, const std::vector< std::vector< boost::shared_ptr< InstrumentCorrection > > > &Instrument_correction=std::vector< std::vector< boost::shared_ptr< InstrumentCorrection > > >())
Constructor.
This is a filtering stream that adds a pad to the front of every line written out.
Definition: ostream_pad.h:32
virtual void print(std::ostream &Os) const
For different instruments, it is more natural to either work with wavenumbers (e.g., GOSAT) or wavelength (e.g., OCO).
This is a instrument that uses a Ils object for each spectrometer to model the instrument.
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
const SpectralRange & spectral_range() const
Spectral range (e.g, radiance values)
Definition: spectrum.h:39
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
Apply value function to a blitz array.
const Unit & units() const
Units of data.
This applies a instrument model to radiances.
Definition: instrument.h:17
This is a full spectrum, which contains a SpectralRange and SpectralDomain.
Definition: spectrum.h:18
virtual std::string band_name(int Spec_index) const
Band name for given Spec_index.
We have a number of different spectrums that appear in different parts of the code.
const ArrayAd< double, 1 > & data_ad() const
Underlying data, possibly with a Jacobian.
virtual SpectralDomain pixel_spectral_domain(int Spec_index) const
This is the pixel wavenumber/wavelength for each pixel.
const Unit units() const
Units that go with data()
virtual boost::shared_ptr< Instrument > clone() const
Clone an Instrument 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
const SpectralDomain & spectral_domain() const
Spectral domain (i.e., wavenumber or wavelength).
Definition: spectrum.h:32
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.
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:08