OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
DataRecord.hpp
Go to the documentation of this file.
1 
2 #ifndef FOCS_DATARECORD
3 #define FOCS_DATARECORD
4 
5 #include "Variable.hpp"
6 #include "Product.hpp"
7 
8 #include <memory>
9 #include <string>
10 #include <unordered_map>
11 #include <vector>
12 
13 namespace focs {
15  public:
16  TileParameters(size_t lines, size_t pixels, size_t start_line=0, size_t start_pixel=0) : size{lines, pixels}, origin{start_line, start_pixel}, end{origin.first + size.first, origin.second + size.second} {}
17  TileParameters(std::pair<size_t, size_t> size_, std::pair<size_t, size_t> origin_={0,0}) : size{size_}, origin{origin_}, end{origin.first + size.first, origin.second + size.second} {}
18  TileParameters(std::pair<size_t, size_t> size_, std::pair<size_t, size_t> origin_, std::pair<size_t, size_t> data_origin_, bool top_is_bounded_, bool bottom_is_bounded_, bool left_is_bounded_=true, bool right_is_bounded_=true) :
19  size{size_}, origin{origin_}, end{origin.first + size.first, origin.second + size.second}, data_origin{data_origin_}, top_is_bounded{top_is_bounded_}, bottom_is_bounded{bottom_is_bounded_}, left_is_bounded{left_is_bounded_}, right_is_bounded{right_is_bounded_} {}
20 
21  void shrink_to(std::pair<size_t, size_t> new_size){
22  size.first = std::min(size.first, new_size.first);
23  size.second = std::min(size.second, new_size.second);
24  end = {origin.first + size.first, origin.second + size.second};
25  }
26  void offset_up_to(std::pair<size_t, size_t> new_position){
27  origin.first = std::max(origin.first, new_position.first);
28  origin.second = std::max(origin.second, new_position.second);
29  end = {origin.first + size.first, origin.second + size.second};
30  }
32  shrink_to(params.size);
33  offset_up_to(params.origin);
34  data_origin = params.data_origin;
35  top_is_bounded |= params.top_is_bounded;
36  bottom_is_bounded |= params.bottom_is_bounded;
37  left_is_bounded |= params.left_is_bounded;
38  right_is_bounded |= params.right_is_bounded;
39  }
40  bool is_empty(){
41  return size.first == 0 || size.second == 0;
42  }
43 
44  friend std::ostream& operator<<(std::ostream& out, const TileParameters& params){
45  out << "TileParameters[" << params.size.first << "x" << params.size.second << ";" << params.origin.first << "," << params.origin.second << ";";
46  if (params.top_is_bounded){
47  out << "^";
48  }
49  if (params.bottom_is_bounded){
50  out << "v";
51  }
52  if (params.left_is_bounded){
53  out << "<";
54  }
55  if (params.right_is_bounded){
56  out << ">";
57  }
58  out << ";" << params.data_origin.first << "," << params.data_origin.second;
59  return out << "]";
60  }
61 
62  std::pair<size_t, size_t> size{0,0};
63  std::pair<size_t, size_t> origin{0,0};
64  std::pair<size_t, size_t> end{0,0}; // quality-of-life, origin + size
65  std::pair<size_t, size_t> data_origin{0,0};
66  bool top_is_bounded{false};
67  bool bottom_is_bounded{false};
68  bool left_is_bounded{false};
69  bool right_is_bounded{false};
70 };
71 
72 // unused
74  public:
75  private:
76  std::unique_ptr<BaseVariable> input_{};
77  std::unique_ptr<BaseVariable> output_{};
78 };
79 
80 class DataRecord {
81  public:
83  // BaseVariable* get_product(const std::string& product) { return variables_.at(product).get(); }
84 
85  std::unordered_map<std::string, const Product>::const_iterator products_begin() const { return products_.cbegin(); }
86  std::unordered_map<std::string, const Product>::const_iterator products_end() const { return products_.cend(); }
87 
88  std::pair<size_t, size_t> size() const noexcept { return size_; }
89  void size(std::pair<size_t, size_t> size) noexcept { size_ = size; }
90  std::pair<size_t, size_t> max_size() const noexcept { return max_size_; }
91  void max_size(std::pair<size_t, size_t> max_size) noexcept { max_size_ = max_size; }
92  void add(std::unique_ptr<BaseVariable> v){
93  variables_.push_back(std::move(v));
94  }
95  auto& attributes() { return attributes_; }
96  auto& dimensions() { return dimensions_; }
97  auto& variables() { return variables_; }
98  void min_size(size_t min_size){ min_size_ = std::max(min_size, min_size_); }
99  size_t min_size() const { return min_size_; }
100 
101  // Reserves to record size, not data dimensions
102  template<typename T>
103  void reserve_data(std::vector<std::vector<T>>& data, const bool resize=true) const {
104  data.reserve(size_.first);
105  for (size_t i=0;i<size_.first;i++){
106  data.emplace_back(0);
107  }
108  if (resize){
109  for (auto& v : data){
110  v.resize(size_.second);
111  }
112  } else {
113  for (auto& v : data){
114  v.reserve(size_.second);
115  }
116  }
117  }
118 
119  // TODO: should the create_variable functions be extended for interpolation and/or extrapolation?
120  // They'll accept two sets of dimensions and a conversion method.
121  // They will create a hidden variable of the source dimensions and return a real one based on the second set of dimensions.
122  // During the done_reading_input method, the conversion will be performed.
123  // 1. In what form is the conversion method?
124  // enum and 100% controlled here?
125  // object? More work for users, less defaulting.
126  // 2. How are 2D interps done? The kernel size is going to effect most
127  // maths. It'll be up to the input file to set it, but a much larger
128  // min_size_ could be chosen. 8 or 16 rows at a time should not be too
129  // memory heavy, right?
130  template<typename T, size_t N>
131  focs::Variable<T, N>* create_variable(focs::Product& product, const std::vector<std::pair<std::string, size_t>>& dimensions={}, const bool resize=true) {
132  return create_variable<focs::Variable<T, N>>(product, dimensions, resize);
133  }
134 
135  template<typename T=focs::Variable<float, 2>>
136  T* create_variable(focs::Product& product, const std::vector<std::pair<std::string, size_t>>& dimensions={}, const bool resize=true) {
137  auto new_var = std::make_unique<T>(product);
138  reserve_data(new_var->data(), resize);
139 
140  for (const auto& dim : dimensions){
141  new_var->dimensions().emplace_back(dim.first, dim.second);
142  }
143 
144  T* ret = new_var.get();
145  product.variable(ret);
146  variables_.push_back(std::move(new_var));
147  return ret;
148  }
149 
151  }
152 
153  void rotate_data(){
154  if (min_size() > 1){
155  const size_t rotation_size = (min_size() >> 1) * 2;
156  // std::cout << "Rotating " << rotation_size << " lines\n";
157  for (auto& v : variables_){
158  // std::cout << "Rotating variable " << v->name() << "\n";
159  v->rotate(rotation_size);
160  }
161  }
162  }
163 
164  private:
165  std::unordered_map<std::string, size_t> dimensions_{};
166  // std::vector<DataRecordProcessor> variables_to_process_{};
167  std::vector<std::unique_ptr<BaseVariable>> variables_{};
168  std::unordered_map<std::string, const Product> products_{};
169  std::vector<std::unordered_map<std::string, const Attribute>> attributes_{}; // file attributes?
170 
171  std::pair<size_t, size_t> size_{0,0};
172  std::pair<size_t, size_t> max_size_{0,0};
173  size_t min_size_{1};
174 };
175 
176 } // namespace focs
177 
178 #endif // FOCS_DATARECORD
std::pair< size_t, size_t > size() const noexcept
Definition: DataRecord.hpp:88
T * create_variable(focs::Product &product, const std::vector< std::pair< std::string, size_t >> &dimensions={}, const bool resize=true)
Definition: DataRecord.hpp:136
float * vector(long nl, long nh)
Definition: nrutil.c:15
void size(std::pair< size_t, size_t > size) noexcept
Definition: DataRecord.hpp:89
void reserve_data(std::vector< std::vector< T >> &data, const bool resize=true) const
Definition: DataRecord.hpp:103
These are used to scale the SD before writing it to the HDF4 file The default is and which means the product is not scaled at all Since the product is usually stored as a float inside of this is a way to write the float out as a integer l2prod min
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed as required for compatibility with version of the SDP toolkit Corrected test output file names to end in out
Definition: HISTORY.txt:422
TileParameters(std::pair< size_t, size_t > size_, std::pair< size_t, size_t > origin_={0, 0})
Definition: DataRecord.hpp:17
std::pair< size_t, size_t > max_size() const noexcept
Definition: DataRecord.hpp:90
void update(const TileParameters &params)
Definition: DataRecord.hpp:31
TileParameters(size_t lines, size_t pixels, size_t start_line=0, size_t start_pixel=0)
Definition: DataRecord.hpp:16
void add(std::unique_ptr< BaseVariable > v)
Definition: DataRecord.hpp:92
std::pair< size_t, size_t > origin
Definition: DataRecord.hpp:63
size_t min_size() const
Definition: DataRecord.hpp:99
TileParameters(std::pair< size_t, size_t > size_, std::pair< size_t, size_t > origin_, std::pair< size_t, size_t > data_origin_, bool top_is_bounded_, bool bottom_is_bounded_, bool left_is_bounded_=true, bool right_is_bounded_=true)
Definition: DataRecord.hpp:18
std::pair< size_t, size_t > data_origin
Definition: DataRecord.hpp:65
friend std::ostream & operator<<(std::ostream &out, const TileParameters &params)
Definition: DataRecord.hpp:44
void shrink_to(std::pair< size_t, size_t > new_size)
Definition: DataRecord.hpp:21
auto & dimensions()
Definition: DataRecord.hpp:96
void max_size(std::pair< size_t, size_t > max_size) noexcept
Definition: DataRecord.hpp:91
auto & variables()
Definition: DataRecord.hpp:97
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
void min_size(size_t min_size)
Definition: DataRecord.hpp:98
std::pair< size_t, size_t > size
Definition: DataRecord.hpp:62
std::unordered_map< std::string, const Product >::const_iterator products_end() const
Definition: DataRecord.hpp:86
focs::Variable< T, N > * create_variable(focs::Product &product, const std::vector< std::pair< std::string, size_t >> &dimensions={}, const bool resize=true)
Definition: DataRecord.hpp:131
void done_reading_input()
Definition: DataRecord.hpp:150
std::pair< size_t, size_t > end
Definition: DataRecord.hpp:64
int i
Definition: decode_rs.h:71
auto & attributes()
Definition: DataRecord.hpp:95
HISTORY txt for MOD_PR01(step one of PGE01) History follows the following convention needed due to new Aqua ReprocessingActual and the expected LUT revision number from PCF Changed to use PGE version for ProductionHistory Added Archive including ProcessingEnvironment Corrected handling of bad to resovle GSFcd02514 Changed to check staged LUT revision number versus the expected LUT revision number from thereby resolving defect report MODxl02056 This change also avoids the memory access violation reported in MODur00039 Changed the way output arrays were initialized with fill to be more but placed into the L1A output product and thought of as valid packets These packets had an invalid frame count in them and since only the last valid packet of any specific type gets it frame count data written to the output product
Definition: HISTORY.txt:176
std::unordered_map< std::string, const Product >::const_iterator products_begin() const
Definition: DataRecord.hpp:85
void offset_up_to(std::pair< size_t, size_t > new_position)
Definition: DataRecord.hpp:26
l2prod max