Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python interface for TUVX functions. #181

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
pybind11_add_module(musica_python
wrapper.cpp
${PROJECT_SOURCE_DIR}/src/micm/micm.cpp
${PROJECT_SOURCE_DIR}/src/tuvx/tuvx.cpp
${PROJECT_SOURCE_DIR}/src/component_versions.cpp
${PROJECT_SOURCE_DIR}/src/util.cpp
${CMAKE_BINARY_DIR}/version.cpp
)

# target_link_libraries(musica_python PRIVATE nlohmann_json::nlohmann_json)
# target_link_libraries(musica_python PUBLIC musica::musica)
target_link_libraries(musica_python PRIVATE yaml-cpp)

target_compile_features(musica_python PUBLIC cxx_std_20)
Expand All @@ -15,12 +18,14 @@ set_target_properties(musica_python PROPERTIES OUTPUT_NAME musica)
target_include_directories(musica_python
PUBLIC
$<BUILD_INTERFACE:${micm_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${tuvx_SOURCE_DIR}/include/tuvx>
$<INSTALL_INTERFACE:${MUSICA_INSTALL_INCLUDE_DIR}>
)

target_include_directories(musica_python
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}h/include/tuvx>
$<INSTALL_INTERFACE:${MUSICA_INSTALL_INCLUDE_DIR}>
)

Expand Down
48 changes: 46 additions & 2 deletions python/wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (C) 2023-2024 National Center for Atmospheric Research
// SPDX-License-Identifier: Apache-2.0
#include <musica/micm.hpp>

#include <musica/tuvx/tuvx.hpp>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace py = pybind11;

// Wraps micm.cpp
// Wraps micm.cpp and tuvx.cpp
PYBIND11_MODULE(musica, m)
{
py::class_<musica::MICM>(m, "micm").def(py::init<>()).def("__del__", [](musica::MICM &micm) {});
Expand Down Expand Up @@ -204,4 +204,48 @@ PYBIND11_MODULE(musica, m)
return map;
},
"Return map of reaction rates");
/*
* Wrap tuvx
*/


py::class_<musica::TUVX>(m,"tuvx")
.def(py::init<>())
.def("__del__", [](musica::TUVX &tuvx) {});

m.def(
"create_tuvx",
[](const char *config_path)
{
musica::Error error;
musica::TUVX *tuvx = musica::CreateTuvx(config_path,&error);
if (!musica::IsSuccess(error))
{
std::string message = "Error creating Tuvx: " + std::string(error.message_.value_);
DeleteError(&error);
throw std::runtime_error(message);

}
return tuvx;
});
m.def("delete_tuvx", &musica::DeleteTuvx);

m.def(
"tuvx_get_grid_map",
[](musica::TUVX *tuvx)
{
musica::Error error;
musica::GridMap map = musica::GetGridMap(tuvx,&error);
if (!musica::IsSuccess(error))
{
std::string message = "Error getting tuvx gridmap: " + std::string(error.message_.value_);
DeleteError(&error);
throw std::runtime_error(message);

}

return map;

});

}
Loading