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

Add Healpix grid #162

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ca9ab8f
add Healpix cmake config + class boilerplate
benbovy Jun 17, 2024
0809724
add size and shape implementations
benbovy Jun 18, 2024
b12b7f1
implement nodes_area
benbovy Jun 18, 2024
b3aadb3
wip implement neighbors
benbovy Jun 18, 2024
dc68d23
implement neighbors
benbovy Jun 19, 2024
97f6c77
implement nodes_status
benbovy Jun 19, 2024
d4c7d82
wip python bindings
benbovy Jun 19, 2024
f6bdbcb
add tests
benbovy Aug 12, 2024
f36ba80
disable healpix on windows
benbovy Sep 4, 2024
51c0171
cmake older versions compat?
benbovy Sep 4, 2024
f3784ca
fix CI C++ tests healpix skip install win
benbovy Sep 4, 2024
e613085
cmake config: force healpix off on windows
benbovy Sep 4, 2024
2ecce0a
missing ifdef
benbovy Sep 4, 2024
bcf5315
python ignore Healpix import error
benbovy Sep 4, 2024
069eb42
forgot remove HealpixGrid import
benbovy Sep 4, 2024
93d62cb
let's set HealpixGrid to None if not supported
benbovy Sep 4, 2024
e91cda2
remove gtest and benchmark from conda dev env
benbovy Sep 4, 2024
d6e1ef9
ignore mypy error
benbovy Sep 4, 2024
f1e6223
ci mypy: install healpix
benbovy Sep 4, 2024
ac19e5b
doc conda env: add healpix
benbovy Sep 4, 2024
d7d7d90
add nodes_lonlat methods
benbovy Sep 6, 2024
91717ac
add HealpixGrid.__init__ docstrings
benbovy Sep 6, 2024
c495217
rename EARTH_RADIUS -> EARTH_RADIUS_METERS
benbovy Sep 6, 2024
41397a7
add nodes_xyz methods + grid nside/radius bindings
benbovy Sep 6, 2024
ccf2caf
ci tests: update macos versions
benbovy Sep 6, 2024
de9be92
Merge branch 'main' into healpix-grid
benbovy Oct 10, 2024
c7515da
ci test numpy 1.xx: disable healpix
benbovy Oct 10, 2024
e44766b
pip command: try quotes for cmake args
benbovy Oct 10, 2024
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
4 changes: 4 additions & 0 deletions .github/workflows/ci-additional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
environment-file: environment-python-dev.yml
cache-environment: true

- name: Install Healpix
run: |
micromamba install healpix_cxx

- name: Build and install Fastscapelib Python
run: |
python -m pip install . -v --no-build-isolation
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ jobs:
cache-environment: true
cache-downloads: false

- name: Install Healpix (Linux and MacOS)
if: matrix.cfg.os != 'windows-latest'
run: |
micromamba install healpix_cxx

- name: Configure Fastscapelib (CMake)
run: |
cmake -S . -B build \
Expand Down Expand Up @@ -78,6 +83,11 @@ jobs:
create-args: >-
python=${{ matrix.python-version }}

- name: Install Healpix (Linux and MacOS)
if: matrix.os != 'windows-latest'
run: |
micromamba install healpix_cxx

- name: Build and install Fastscapelib Python
run: |
python -m pip install . -v --no-build-isolation
Expand All @@ -100,7 +110,7 @@ jobs:

- name: Build and install Fastscapelib Python (Numpy 2.x)
run: |
python -m pip install . --config-settings=cmake.define.FS_DOWNLOAD_XTENSOR_PYTHON=ON
python -m pip install . --config-settings=cmake.args="-DFS_DOWNLOAD_XTENSOR_PYTHON=ON;-DFS_WITH_HEALPIX=OFF"

- name: Run tests (Numpy 1.xx)
run: |
Expand Down
20 changes: 19 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ OPTION(FS_GTEST_SRC_DIR "Build gtest from local sources" OFF)
OPTION(FS_BUILD_BENCHMARKS "Build fastscapelib benchmark suite" OFF)
OPTION(FS_DOWNLOAD_GBENCHMARK "Build gbenchmark from downloaded sources" OFF)
OPTION(FS_GBENCHMARK_SRC_DIR "Build gbenchmark from local sources" OFF)
OPTION(FS_WITH_HEALPIX "Turn on support of Healpix grid" ON)

if(WIN32)
set(FS_WITH_HEALPIX OFF CACHE BOOL "Healpix grid not supported on Windows" FORCE)
endif()

set(CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/cmake
${CMAKE_SOURCE_DIR}/cmake/modules
${CMAKE_MODULE_PATH})

# Dependencies
Expand Down Expand Up @@ -76,6 +81,11 @@ endif()

find_package(Threads REQUIRED)

if(FS_WITH_HEALPIX)
find_package(healpix REQUIRED)
message(STATUS "Found healpix: ${healpix_INCLUDE_DIRS}/healpix_cxx")
endif()

# Installation directories
# ========================

Expand Down Expand Up @@ -131,6 +141,10 @@ set(FASTSCAPELIB_HEADERS
version.hpp
)

if(FS_WITH_HEALPIX)
list(APPEND FASTSCAPELIB_HEADERS grid/healpix_grid.hpp)
endif()

set(FASTSCAPELIB_TARGET fastscapelib)

add_library(${FASTSCAPELIB_TARGET} INTERFACE)
Expand All @@ -143,6 +157,10 @@ target_include_directories(${FASTSCAPELIB_TARGET}

target_link_libraries(${FASTSCAPELIB_TARGET} INTERFACE xtensor Threads::Threads)

if(FS_WITH_HEALPIX)
target_link_libraries(${FASTSCAPELIB_TARGET} INTERFACE healpix)
endif()

target_compile_features(${FASTSCAPELIB_TARGET} INTERFACE cxx_std_17)

# -- optional subdirectories
Expand Down
11 changes: 7 additions & 4 deletions benchmark/benchmark_raster_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,18 @@ namespace fastscapelib
auto n = static_cast<size_type>(state.range(0));
std::array<size_type, 2> shape{ { n, n } };

const short d8_row_offsets[9] = { 0, -1, -1, 0, 1, 1, 1, 0, -1 };
const short d8_col_offsets[9] = { 0, 0, -1, -1, -1, 0, 1, 1, 1 };

neighbors_offsets_type offsets(grid_type::n_neighbors_max());

auto get_neighbors_indices
= [&shape, &offsets](auto& r, auto& c) -> neighbors_offsets_type
auto get_neighbors_indices = [&shape, &offsets, &d8_row_offsets, &d8_col_offsets](
auto& r, auto& c) -> neighbors_offsets_type
{
for (std::size_t k = 1; k <= grid_type::n_neighbors_max(); ++k)
{
const index_t kr = r + fs::consts::d8_row_offsets[k];
const index_t kc = c + fs::consts::d8_col_offsets[k];
const index_t kr = r + d8_row_offsets[k];
const index_t kc = c + d8_col_offsets[k];

offsets[k - 1] = std::array<std::ptrdiff_t, 2>({ kr, kc });

Expand Down
77 changes: 77 additions & 0 deletions cmake/modules/Findhealpix.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# The MIT License (MIT)
#
# Copyright (c) 2024 Benoit Bovy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

#
# FindHealpix
# -----------
#
# Find Healpix include directories and libraries.
#
# This module will set the following variables:
#
# healpix_FOUND - System has Healpix
# healpix_INCLUDE_DIRS - The Healpix include directories
# healpix_LIBRARIES - The libraries needed to use Healpix
#

include(FindPackageHandleStandardArgs)

find_path(healpix_INCLUDE_DIR healpix_cxx
HINTS
ENV healpix_ROOT
ENV healpix_DIR
ENV CONDA_PREFIX
${healpix_ROOT_DIR}
PATH_SUFFIXES
include
)

find_library(healpix_LIBRARY
NAMES healpix_cxx
HINTS
ENV healpix_ROOT
ENV healpix_DIR
ENV CONDA_PREFIX
${healpix_ROOT_DIR}
PATH_SUFFIXES
lib
libs
Library
)

find_package_handle_standard_args(healpix
REQUIRED_VARS healpix_INCLUDE_DIR healpix_LIBRARY
)

if(healpix_FOUND)
set(healpix_INCLUDE_DIRS ${healpix_INCLUDE_DIR})
set(healpix_LIBRARIES ${healpix_LIBRARY})

add_library(healpix SHARED IMPORTED)
set_target_properties(healpix PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${healpix_INCLUDE_DIRS}
IMPORTED_LOCATION ${healpix_LIBRARIES}
IMPORTED_IMPLIB ${healpix_LIBRARIES}
)

mark_as_advanced(healpix_INCLUDE_DIRS healpix_LIBRARIES)
endif()
1 change: 1 addition & 0 deletions doc/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dependencies:
- python=3.11
- breathe
- cmake
- healpix_cxx
- xtensor-python
- pybind11
- scikit-build-core
Expand Down
2 changes: 0 additions & 2 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ channels:
dependencies:
- xtensor
- cmake
- gtest
- benchmark
3 changes: 2 additions & 1 deletion include/fastscapelib/grid/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ namespace fastscapelib
core = 0, /**< Inner grid node */
fixed_value = 1, /**< Dirichlet boundary condition */
fixed_gradient = 2, /**< Neumann boundary condition */
looped = 3 /**< Reflective boundaries */
looped = 3, /**< Reflective boundaries */
ghost = 4 /**< Inactive grid node (outisde the domain) */
};

namespace detail
Expand Down
Loading
Loading