Skip to content

Commit

Permalink
wip python bindings
Browse files Browse the repository at this point in the history
Also use RING scheme (slower for getting the neighbors but more flexible
regarding the choice of the nside value).
  • Loading branch information
benbovy committed Jun 19, 2024
1 parent 97f6c77 commit d4c7d82
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
5 changes: 2 additions & 3 deletions include/fastscapelib/grid/healpix_grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ namespace fastscapelib
, m_radius(radius)
{
m_healpix_obj_ptr
= std::make_unique<healpix_type>(nside, Healpix_Ordering_Scheme::NEST, SET_NSIDE);
= std::make_unique<healpix_type>(nside, Healpix_Ordering_Scheme::RING, SET_NSIDE);

m_size = static_cast<size_type>(m_healpix_obj_ptr->Npix());
m_shape = { static_cast<typename shape_type::value_type>(m_size) };
Expand Down Expand Up @@ -253,8 +253,7 @@ namespace fastscapelib
void healpix_grid<S, T>::neighbors_indices_impl(neighbors_indices_impl_type& neighbors,
const size_type& idx) const
{
const auto& size = m_neighbors_count[idx].size();
neighbors.resize(size);
const auto& size = m_neighbors_count[idx];

for (size_type i = 0; i < size; i++)
{
Expand Down
2 changes: 2 additions & 0 deletions python/fastscapelib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
create_flow_kernel,
)
from fastscapelib.grid import ( # type: ignore[import]
HealpixGrid,
Neighbor,
Node,
NodeStatus,
Expand All @@ -32,6 +33,7 @@
__all__ = [
"__version__",
"DiffusionADIEroder",
"HealpixGrid",
"SPLEroder",
"Neighbor",
"Node",
Expand Down
2 changes: 2 additions & 0 deletions python/fastscapelib/grid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from _fastscapelib_py.grid import ( # type: ignore[import]
HealpixGrid,
Neighbor,
Node,
NodeStatus,
Expand All @@ -12,6 +13,7 @@
)

__all__ = [
"HealpidxGrid",
"Neighbor",
"Node",
"NodeStatus",
Expand Down
1 change: 1 addition & 0 deletions python/src/flow_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ add_flow_graph_bindings(py::module& m)
fs::register_py_flow_graph_init<fs::py_profile_grid>(pyfgraph, true);
fs::register_py_flow_graph_init<fs::py_raster_grid>(pyfgraph, false);
fs::register_py_flow_graph_init<fs::py_trimesh>(pyfgraph, false);
fs::register_py_flow_graph_init<fs::py_healpix_grid>(pyfgraph, false);

pyfgraph.def_property_readonly(
"operators",
Expand Down
15 changes: 15 additions & 0 deletions python/src/grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ add_grid_bindings(py::module& m)
fs::register_base_grid_properties(tmesh);
fs::register_grid_methods(tmesh);

/*
** Healpix grid
*/

py::class_<fs::py_healpix_grid> hgrid(m, "HealpixGrid", "A HEALPix grid.");

hgrid.def(py::init<int, const fs::py_healpix_grid::nodes_status_array_type&, double>(),
py::arg("nside"),
py::arg("nodes_status"),
py::arg("radius"));

fs::register_grid_static_properties(hgrid);
fs::register_base_grid_properties(hgrid);
fs::register_grid_methods(hgrid);

/*
** Profile Grid
*/
Expand Down
2 changes: 2 additions & 0 deletions python/src/grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "xtensor-python/pytensor.hpp"

#include "fastscapelib/grid/base.hpp"
#include "fastscapelib/grid/healpix_grid.hpp"
#include "fastscapelib/grid/profile_grid.hpp"
#include "fastscapelib/grid/raster_grid.hpp"
#include "fastscapelib/grid/trimesh.hpp"
Expand All @@ -29,6 +30,7 @@ namespace fastscapelib
using py_profile_grid = fs::profile_grid<fs::xt_python_selector>;
using py_raster_grid = fs::raster_grid<fs::xt_python_selector, fs::raster_connect::queen>;
using py_trimesh = fs::trimesh_xt<fs::xt_python_selector>;
using py_healpix_grid = fs::healpix_grid<fs::xt_python_selector>;

template <class G>
void register_grid_static_properties(py::class_<G>& pyg)
Expand Down

0 comments on commit d4c7d82

Please sign in to comment.