IODA
py_dlp.cpp
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 UCAR
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 /// \file py_dlp.cpp
8 /// \brief Python bindings for the ioda / ioda-engines library.
9 
10 #include <pybind11/eigen.h>
11 #include <pybind11/pybind11.h>
12 #include <pybind11/stl.h>
13 
14 #include <iostream>
15 #include <sstream>
16 
17 #include "./macros.h"
18 #include "ioda/Engines/HH.h"
19 #include "ioda/Engines/ObsStore.h"
20 #include "ioda/Group.h"
21 #include "ioda/Layout.h"
23 #include "ioda/ObsGroup.h"
24 
25 namespace py = pybind11;
26 using namespace ioda;
27 
28 std::shared_ptr<const ioda::detail::DataLayoutPolicy> setupDLP(pybind11::module& mDLP) {
29  using namespace ioda::detail;
30  py::class_<DataLayoutPolicy, std::shared_ptr<DataLayoutPolicy>> dlp(mDLP, "DataLayoutPolicy");
31  dlp.doc() = "Data layout policy for the ObsGroup";
32  dlp.def("generate", &DataLayoutPolicy::_py_generate1, "Select policy by string");
33  dlp.def("generate", &DataLayoutPolicy::_py_generate2, "Select policy by enum");
34  dlp.def("doMap", &DataLayoutPolicy::doMap, "Map variable name to name used in underlying backend",
35  py::arg("name"));
36  dlp.def("__repr__", [](const DataLayoutPolicy& d) {
37  std::ostringstream out;
38  out << "<ioda.DLP.DataLayoutPolicy: " << d.name() << ">";
39  return out.str();
40  });
41  dlp.def("__str__", [](const DataLayoutPolicy& d) {
42  std::ostringstream out;
43  out << "<ioda.DLP.DataLayoutPolicy: " << d.name() << ">";
44  return out.str();
45  });
46 
47  py::enum_<DataLayoutPolicy::Policies> pols(dlp, "Policies");
48  // pols.doc() = "Supported policies"; // Can't set
49  pols.value("None", DataLayoutPolicy::Policies::None)
50  .value("ObsGroup", DataLayoutPolicy::Policies::ObsGroup);
51 
53  mDLP.attr("default") = ld;
54  // mDLP.attr("default") = py::int_(-1);
55  return ld;
56 }
Convenience classes for constructing ObsSpaces and setting up new Dimension Scales.
Interfaces for ioda::Group and related classes.
HDF5 engine.
Contains definitions for how data are arranged in ioda internally.
Interfaces for ioda::ObsGroup and related classes.
ObsStore engine.
Policy used for setting locations for Variable access.
Definition: Layout.h:36
static std::shared_ptr< const DataLayoutPolicy > _py_generate1(const std::string &polid)
Definition: Layout.h:76
static std::shared_ptr< const DataLayoutPolicy > generate(const std::string &polid="")
Factory generator.
Definition: Layout.cpp:28
static std::shared_ptr< const DataLayoutPolicy > _py_generate2(Policies pol)
Definition: Layout.h:80
@ None
Do no manipulation of the Group / Variable layout.
virtual std::string name() const
A descriptive name for the policy.
Definition: Layout.cpp:92
virtual std::string doMap(const std::string &) const
Map a user-specified Variable path to the correct location.
Definition: Layout.cpp:94
Python bindings - macros.
std::shared_ptr< const ioda::detail::DataLayoutPolicy > setupDLP(pybind11::module &mDLP)
Definition: py_dlp.cpp:28