IODA
py_groups.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_groups.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 void setupGroups(pybind11::module& m) {
29  py::class_<Group, std::shared_ptr<Group>> grp(m, "Group");
30  grp.doc() = "A group";
31 
32  grp.def("list", &Group::list, "The names of all child groups")
33  .def("exists", &Group::exists, "Does a group exist with the specified name?", py::arg("name"))
34  .def("create", &Group::create, "Create a group", py::arg("name"))
35  .def("open", &Group::open, "Open a group", py::arg("name"))
36  .def_readwrite("atts", &Group::atts, "Attributes for this group")
37  .def_readwrite("vars", &Group::vars, "Variables in this group")
38  .def("__repr__",
39  [](const Group& g) {
40  std::ostringstream out;
41  auto names = g.list();
42  out << "<ioda.Group at " << &g
43  << ". Use list(), atts.list() and vars.list() to see contents.>";
44 
45  return out.str();
46  })
47  .def("__str__", [](const Group& g) {
48  std::ostringstream out;
49  auto names = g.list();
50  out << "<ioda.Group: [ ";
51  for (const auto& s : names) out << s << " ";
52  out << "]>";
53 
54  return out.str();
55  });
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.
Groups are a new implementation of ObsSpaces.
Definition: Group.h:159
Has_Attributes atts
Use this to access the metadata for the group / ObsSpace.
Definition: Group.h:120
virtual Group open(const std::string &name) const
Open a group.
Definition: Group.cpp:87
Has_Variables vars
Use this to access variables.
Definition: Group.h:123
virtual bool exists(const std::string &name) const
Definition: Group.cpp:65
virtual Group create(const std::string &name)
Create a group.
Definition: Group.cpp:76
std::vector< std::string > list() const
List all one-level child groups in this group.
Definition: Group.cpp:43
Python bindings - macros.
void setupGroups(pybind11::module &m)
Definition: py_groups.cpp:28