ReFRACtor
example_level_1b.cc
Go to the documentation of this file.
1 #include <boost/lexical_cast.hpp>
2 
3 #include "example_level_1b.h"
4 #include "fp_exception.h"
5 #include "observation_id.h"
6 
7 using namespace FullPhysics;
8 using namespace blitz;
9 
10 #ifdef HAVE_LUA
11 #include "register_lua.h"
13 .def(luabind::constructor<const boost::shared_ptr<HdfFile>&, const std::string&>())
15 #endif
16 
17 ExampleLevel1b::ExampleLevel1b(const boost::shared_ptr<HdfFile>& input_file, const std::string& observation_id)
18 :input(input_file)
19 {
20  // All work done in initialization above
21  ObservationId<std::string> obs_id(input_file, "observation_ids", observation_id);
22  data_index = obs_id.data_index();
23 }
24 
25 ExampleLevel1b::ExampleLevel1b(const std::string& input_filename, const std::string& observation_id)
26 :input(new HdfFile(input_filename))
27 {
28  // All work done in initialization above
29  ObservationId<std::string> obs_id(input, "observation_ids", observation_id);
30  data_index = obs_id.data_index();
31 }
32 
34 {
35  TinyVector<int, 2> lat_shape = input->read_shape<2>(group_name + "/latitude");
36  return lat_shape(1);
37 }
38 
40 {
41  std::string rad_ds_name = group_name + "/radiance_" + boost::lexical_cast<std::string>(Spec_index + 1);
42  std::string uncert_ds_name = group_name + "/uncertainty_" + boost::lexical_cast<std::string>(Spec_index + 1);
43 
44  TinyVector<int, 2> rad_ds_shape = input->read_shape<2>(rad_ds_name);
45  TinyVector<int, 2> rad_start, rad_size;
46  rad_start = data_index, 0;
47  rad_size = 1, rad_ds_shape(1);
48  ArrayWithUnit<double, 2> radiance = input->read_field_with_unit<double, 2>(rad_ds_name,
49  Unit("Ph sec^{-1} m^{-2} sr^{-1} um^{-1}"),
50  rad_start, rad_size);
51 
52  if (input->has_object(uncert_ds_name)) {
53  TinyVector<int, 2> uncert_ds_shape = input->read_shape<2>(uncert_ds_name);
54  TinyVector<int, 2> uncert_start, uncert_size;
55  uncert_start = data_index, 0;
56  uncert_size = 1, uncert_ds_shape(1);
57  Array<double, 2> uncertainty = input->read_field<double, 2>(uncert_ds_name, uncert_start, uncert_size);
58 
59  return SpectralRange(radiance(0, Range::all()).value, radiance.units, uncertainty(0, Range::all()));
60  } else {
61  return SpectralRange(radiance(0, Range::all()).value, radiance.units);
62  }
63 }
64 
65 DoubleWithUnit ExampleLevel1b::read_scalar_with_unit(const std::string& dataset_name, int i, const Unit& default_unit) const
66 {
68  TinyVector<int, 2> start, size;
69  start = data_index, i;
70  size = 1, 1;
71  ArrayWithUnit<double, 2> val_arr = input->read_field_with_unit<double, 2>(dataset_name, default_unit, start, size);
72  return val_arr(0, 0);
73 }
74 
75 double ExampleLevel1b::read_scalar(const std::string& dataset_name, int i) const
76 {
78  TinyVector<int, 2> start, size;
79  start = data_index, i;
80  size = 1, 1;
81  Array<double, 2> val_arr = input->read_field<double, 2>(dataset_name, start, size);
82  return val_arr(0, 0);
83 }
84 
85 ArrayWithUnit<double, 1> ExampleLevel1b::read_array_with_unit(const std::string& dataset_name, int i, const Unit& default_unit) const
86 {
88 
89  TinyVector<int, 3> ds_shape = input->read_shape<3>(dataset_name);
90  TinyVector<int, 3> start, size;
91  start = data_index, i, 0;
92  size = 1, 1, ds_shape(2);
93 
94  ArrayWithUnit<double, 3> val_arr = input->read_field_with_unit<double, 3>(dataset_name, default_unit, start, size);
95 
97  ret_val.units = val_arr.units;
98  ret_val.value.resize(ds_shape(2));
99  ret_val.value = val_arr.value(0, 0, Range::all());
100 
101  return ret_val;
102 }
103 
104 Array<double, 1> ExampleLevel1b::read_array(const std::string& dataset_name, int i) const
105 {
107  TinyVector<int, 3> ds_shape = input->read_shape<3>(dataset_name);
108  TinyVector<int, 3> start, size;
109  start = data_index, i, 0;
110  size = 1, 1, ds_shape(2);
111  Array<double, 3> val_arr = input->read_field<double, 3>(dataset_name, start, size);
112  return val_arr(0, 0, Range::all());
113 }
#define range_check(V, Min, Max)
Range check.
Definition: fp_exception.h:140
This is used to wrap the nominal Level 1B file reader.
We frequently have a array of numbers with units associated with them.
Defines a simple mechanism by where a specific dataset from a HDF file is read along with some sort o...
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
ExampleLevel1b(const boost::shared_ptr< HdfFile > &input_file, const std::string &observation_id)
blitz::Array< T, D > value
virtual int number_spectrometer() const
Number of spectrometers.
This class reads and writes a HDF5 file.
Definition: hdf_file.h:39
Apply value function to a blitz array.
We frequently have a double with units associated with it.
We have a number of different spectrums that appear in different parts of the code.
This is an example L1B reader that reads a HDF formatted file that corresponds one-to-one with the ex...
Libraries such as boost::units allow unit handling where we know the units at compile time...
Definition: unit.h:25
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 SpectralRange radiance(int Spec_index) const
Radiance, for given spectral band.
double value(const FullPhysics::AutoDerivative< double > &Ad)

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