3 #include <boost/make_shared.hpp> 14 const HdfFile& Hdf_static_input,
16 const std::string& Band_name,
17 const std::string& Hdf_group,
18 const blitz::Array<double, 1>& Val)
20 return boost::make_shared<EmpiricalOrthogonalFunction>
21 (Val(0), Used_flag, Hdf_static_input, Uncertainty,
22 static_cast<int>(Val(1)), static_cast<int>(Val(2)),
23 static_cast<int>(Val(3)),
24 Band_name, Hdf_group, Val(4));
28 int,
int,
int,
const std::string&,
const std::string&>())
29 .def(luabind::constructor<
double,
bool,
const HdfFile&,
30 int,
int,
int,
const std::string&,
const std::string&>())
74 const HdfFile& Hdf_static_input,
78 const std::string& Band_name,
79 const std::string& Hdf_group)
84 sounding_number_(Sounding_number),
85 eof_scale_uncertainty_(
false),
89 std::string fldname = hdf_group +
"/EOF_" 90 + boost::lexical_cast<std::string>(Order) +
92 + boost::lexical_cast<std::string>(Spec_index + 1);
95 DataSet d = Hdf_static_input.
h5_file().openDataSet(fldname);
96 DataSpace ds = d.getSpace();
97 if(ds.getSimpleExtentNdims() == 3) {
101 table.
value.reference(full_table.
value(Sounding_number, Range::all(),
103 eof_depend_on_sounding_number_ =
true;
106 eof_depend_on_sounding_number_ =
false;
110 Unit wave_unit(
"cm^-1");
112 wave_unit =
Unit(Hdf_static_input.
read_attribute<std::string>(fldname +
"/WaveUnits"));
115 Array<double, 1>
wn(table.
value(Range::all(), 0));
116 Array<double, 1> waveform(table.
value(Range::all(), 1));
119 waveform_interpolate(
wn.begin(),
wn.end(), waveform.begin(),
122 eof_.units = table.
units;
123 eof_.value.resize(pixel_grid.shape());
124 for(
int i = 0; i < pixel_grid.rows(); ++i)
125 eof_.value(i) = waveform_interpolate(pixel_grid(i));
165 const HdfFile& Hdf_static_input,
169 const std::string& Band_name,
170 const std::string& Hdf_group)
172 band_name(Band_name),
173 hdf_group(Hdf_group),
175 sounding_number_(Sounding_number),
176 eof_scale_uncertainty_(
false),
180 std::string fldname = hdf_group +
"/EOF_" 181 + boost::lexical_cast<std::string>(Order) +
183 + boost::lexical_cast<std::string>(Spec_index + 1);
185 DataSet d = Hdf_static_input.
h5_file().openDataSet(fldname);
186 DataSpace ds = d.getSpace();
187 if(ds.getSimpleExtentNdims() == 2) {
190 eof_.units = full_table.
units;
191 eof_.value.reference(full_table.
value(Sounding_number, Range::all()));
192 eof_depend_on_sounding_number_ =
true;
195 eof_depend_on_sounding_number_ =
false;
246 const HdfFile& Hdf_static_input,
251 const std::string& Band_name,
252 const std::string& Hdf_group,
253 double Scale_to_stddev)
255 band_name(Band_name),
256 hdf_group(Hdf_group),
258 sounding_number_(Sounding_number),
259 eof_scale_uncertainty_(
true),
260 scale_to_stddev_(Scale_to_stddev)
263 std::string fldname = hdf_group +
"/EOF_" 264 + boost::lexical_cast<std::string>(Order) +
266 + boost::lexical_cast<std::string>(Spec_index + 1);
268 DataSet d = Hdf_static_input.
h5_file().openDataSet(fldname);
269 DataSpace ds = d.getSpace();
270 if(ds.getSimpleExtentNdims() == 2) {
271 Array<double, 2> full_table =
272 Hdf_static_input.
read_field<double, 2>(fldname);
273 eof_.units = Uncertainty.
units;
274 eof_.value.reference(full_table(Sounding_number, Range::all()));
275 eof_depend_on_sounding_number_ =
true;
277 eof_.units = Uncertainty.
units;
278 eof_.value.reference(Hdf_static_input.
read_field<
double, 1>(fldname));
279 eof_depend_on_sounding_number_ =
false;
281 eof_.value = eof_.value * Uncertainty.
value;
283 double s = scale_to_stddev_ / sqrt(sum(
sqr(eof_.value - mean(eof_.value))) /
284 (eof_.value.size() - 1));
285 eof_.value = eof_.value *
s;
293 eof_, order_,band_name, hdf_group,
295 eof_depend_on_sounding_number_));
300 const std::vector<int>& Pixel_list,
305 for(
int i = 0; i < Radiance.
data().rows(); ++i) {
307 Radiance.
data()(i) += coeff.value()(0) * eofv.
value(Pixel_list[i]);
310 for(
int i = 0; i < Radiance.
data_ad().
rows(); ++i) {
313 coeff(0) * eofv.
value(Pixel_list[i]);
320 Os <<
"EmpiricalOrthogonalFunction:\n" 321 <<
" Band: " << band_name <<
"\n" 322 <<
" HDF group: " << hdf_group <<
"\n" 323 <<
" Order: " << order_ <<
"\n" 324 <<
" Sounding number: " << sounding_number_ <<
"\n" 325 <<
" Depend on sounding number: " 326 << (eof_depend_on_sounding_number_ ?
"yes" :
"no") <<
"\n" 327 <<
" Scale by uncertainty: " 328 << (eof_scale_uncertainty_ ?
"yes" :
"no") <<
"\n" 329 <<
" Scale: " << coeff(0).value() <<
"\n" 331 << (used_flag(0) ?
"True\n" :
"False\n");
332 if(eof_scale_uncertainty_)
333 Os <<
" Scale to stddev: " << scale_to_stddev_ <<
"\n";
virtual SpectralDomain pixel_grid() const =0
Returns as list of grid points for each instrument pixel, and the gradient of the points wrt the stat...
#define range_check(V, Min, Max)
Range check.
virtual void print(std::ostream &Os) const
const Unit s("s", 1.0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0)
EmpiricalOrthogonalFunction(double Coeff, bool Used_flag, const ArrayWithUnit< double, 1 > &Eof_waveform, int Order, const std::string &Band_name, const std::string &Hdf_group="N/A", int Sounding_number=0, bool Eof_depend_on_sounding_number=false)
Constructor.
blitz::Array< T, D > read_field(const std::string &Dataname) const
Read a given field.
For different instruments, it is more natural to either work with wavenumbers (e.g., GOSAT) or wavelength (e.g., OCO).
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
This class applies a empirical orthogonal function (EOF) correction to instrument data...
blitz::Array< T, D > value
This class reads and writes a HDF5 file.
Apply value function to a blitz array.
const Unit & units() const
Units of data.
blitz::Array< double, 1 > convert_wave(const Unit &Units) const
Return data as the supplied the units.
int number_variable() const
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.
Libraries such as boost::units allow unit handling where we know the units at compile time...
This class calculates the wavenumber for each pixel in a single band of an Instrument.
blitz::Array< T, D > read_attribute(const std::string &Aname) const
Read the given attribute attached to a group or dataset.
Contains classes to abstract away details in various Spurr Radiative Transfer software.
#define REGISTER_LUA_END()
def(luabind::constructor< int >()) .def("rows"
ArrayWithUnit< T, D > read_field_with_unit(const std::string &Dataname) const
Read a given field, along with metadata describing the units.
bool has_attribute(const std::string &Aname) const
Check to see if a attribute is in the file.
virtual boost::shared_ptr< InstrumentCorrection > clone() const
Clone an InstrumentCorrection object.
ArrayWithUnit< T, D > convert(const Unit &R) const
Convert to the given units.
const blitz::Array< double, 1 > & data() const
Underlying data.
This class models an Instrument correction.
virtual void apply_correction(const SpectralDomain &Pixel_grid, const std::vector< int > &Pixel_list, SpectralRange &Radiance) const
Apply correction to radiance values, in place.