IODA Bundle
IodaDescription.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 NOAA/NWS/NCEP/EMC
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #pragma once
9 
10 #include <map>
11 #include <memory>
12 #include <string>
13 #include <vector>
14 
15 #include "eckit/config/LocalConfiguration.h"
16 #include "ioda/Engines/Factory.h"
17 #include "ioda/Group.h"
18 
19 namespace Ingester
20 {
21  struct Range
22  {
23  float start;
24  float end;
25  };
26 
28  {
29  std::string name;
30  std::string size;
31  };
32 
34  {
35  std::string name;
36  std::string source;
37  std::vector<std::string> dimensions;
38  std::string longName;
39  std::string units;
40  std::shared_ptr<std::string> coordinates; // Optional
41  std::shared_ptr<Range> range; // Optional
42  std::vector<ioda::Dimensions_t> chunks; // Optional
43  int compressionLevel; // Optional
44  };
45 
47  {
48  std::string name;
49  virtual void addTo(ioda::Group& group) = 0;
50  };
51 
52  template<typename T>
53  struct is_vector : public std::false_type {};
54 
55  template<typename T, typename A>
56  struct is_vector<std::vector<T, A>> : public std::true_type {};
57 
58  template<typename T>
60  {
61  T value;
62 
63  void addTo(ioda::Group& group) final
64  {
65  _addTo(group);
66  }
67 
68  private:
69  // T is something other than a std::vector
70  template<typename U = void>
71  void _addTo(ioda::Group& group,
72  typename std::enable_if<!is_vector<T>::value, U>::type* = nullptr)
73  {
74  ioda::Attribute attr = group.atts.create<T>(name, {1});
75  attr.write<T>({value});
76  }
77 
78  // T is a vector
79  template<typename U = void>
80  void _addTo(ioda::Group& group,
81  typename std::enable_if<is_vector<T>::value, U>::type* = nullptr)
82  {
83  ioda::Attribute attr = group.atts.create<typename T::value_type>(name, \
84  {static_cast<int>(value.size())});
85  attr.write<typename T::value_type>(value);
86  }
87  };
88 
89  typedef std::vector<DimensionDescription> DimDescriptions;
90  typedef std::vector<VariableDescription> VariableDescriptions;
91  typedef std::vector<std::shared_ptr<GlobalDescriptionBase>> GlobalDescriptions;
92 
93  /// \brief Describes how to write data to IODA.
95  {
96  public:
97  IodaDescription() = default;
98  explicit IodaDescription(const eckit::Configuration& conf);
99 
100  /// \brief Add Dimension defenition
101  void addDimension(const DimensionDescription& scale);
102 
103  /// \brief Add Variable defenition
105 
106  /// \brief Add Globals defenition
107  void addGlobal(const std::shared_ptr<GlobalDescriptionBase>& global);
108 
109  // Setters
110  inline void setBackend(const ioda::Engines::BackendNames& backend) { backend_ = backend; }
111  inline void setFilepath(const std::string& filepath) { filepath_ = filepath; }
112 
113  // Getters
115  inline std::string getFilepath() const { return filepath_; }
116  inline DimDescriptions getDims() const { return dimensions_; }
117  inline VariableDescriptions getVariables() const { return variables_; }
118  inline GlobalDescriptions getGlobals() const { return globals_; }
119 
120  private:
121  /// \brief The backend type to use
123 
124  /// \brief The relative path of the output file to create
125  std::string filepath_;
126 
127  /// \brief Collection of defined dimensions
129 
130  /// \brief Collection of defined variables
132 
133  /// \brief Collection of defined globals
135 
136  /// \brief Collection of defined variables
137  void setBackend(const std::string& backend);
138  };
139 } // namespace Ingester
Definitions for setting up backends with file and memory I/O.
Interfaces for ioda::Group and related classes.
Describes how to write data to IODA.
ioda::Engines::BackendNames getBackend() const
std::string filepath_
The relative path of the output file to create.
void addDimension(const DimensionDescription &scale)
Add Dimension defenition.
VariableDescriptions getVariables() const
VariableDescriptions variables_
Collection of defined variables.
GlobalDescriptions getGlobals() const
void addVariable(const VariableDescription &variable)
Add Variable defenition.
std::string getFilepath() const
void setBackend(const ioda::Engines::BackendNames &backend)
void addGlobal(const std::shared_ptr< GlobalDescriptionBase > &global)
Add Globals defenition.
ioda::Engines::BackendNames backend_
The backend type to use.
GlobalDescriptions globals_
Collection of defined globals.
DimDescriptions getDims() const
void setFilepath(const std::string &filepath)
DimDescriptions dimensions_
Collection of defined dimensions.
This class represents attributes, which may be attached to both Variables and Groups.
Definition: Attribute.h:493
Groups are a new implementation of ObsSpaces.
Definition: Group.h:159
virtual Attribute_Implementation write(gsl::span< char > data, const Type &type)
The fundamental write function. Backends overload this function to implement all write operations.
Definition: Attribute.cpp:65
Has_Attributes atts
Use this to access the metadata for the group / ObsSpace.
Definition: Group.h:120
virtual Attribute create(const std::string &attrname, const Type &in_memory_dataType, const std::vector< Dimensions_t > &dimensions={1})
Create an Attribute without setting its data.
BackendNames
Backend names.
Definition: Factory.h:28
std::vector< DimensionDescription > DimDescriptions
std::vector< std::shared_ptr< GlobalDescriptionBase > > GlobalDescriptions
std::vector< VariableDescription > VariableDescriptions
character(maxvarlen) function variable(this, jj)
Definition: encode.cc:30
virtual void addTo(ioda::Group &group)=0
void _addTo(ioda::Group &group, typename std::enable_if<!is_vector< T >::value, U >::type *=nullptr)
void addTo(ioda::Group &group) final
void _addTo(ioda::Group &group, typename std::enable_if< is_vector< T >::value, U >::type *=nullptr)
std::shared_ptr< Range > range
std::shared_ptr< std::string > coordinates
std::vector< std::string > dimensions
std::vector< ioda::Dimensions_t > chunks