Skip to content

Commit

Permalink
Merge pull request #74 from djhoese/build-np2rc1
Browse files Browse the repository at this point in the history
Build wheels with numpy 2.0rc1 and fix scipy 1.13.0 compatibility
  • Loading branch information
djhoese authored Apr 16, 2024
2 parents 8f12127 + c248ff4 commit 3172085
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,23 @@ jobs:
if: matrix.experimental == true
shell: bash -l {0}
run: |
python -m pip install versioneer pkgconfig setuptools-scm; \
conda uninstall --force-remove -y scipy h5py pyresample pykdtree pandas xarray; \
python -m pip install \
-f https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/ \
--trusted-host pypi.anaconda.org \
--no-deps --pre --upgrade \
matplotlib \
numpy \
pandas \
scipy; \
python -m pip install \
--no-deps --upgrade \
--no-deps --upgrade --pre --no-build-isolation \
git+https://github.com/dask/dask \
git+https://github.com/dask/distributed \
git+https://github.com/h5py/h5py \
git+https://github.com/storpipfugl/pykdtree \
git+https://github.com/pytroll/pyresample \
git+https://github.com/zarr-developers/zarr \
git+https://github.com/pydata/bottleneck \
git+https://github.com/pydata/xarray;
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ jobs:
CIBW_SKIP: "cp36-* cp37-* cp38-* pp* *-manylinux_i686 *-musllinux_i686 *-musllinux_aarch64 *-win32"
CIBW_ARCHS: "${{ matrix.cibw_archs }}"
CIBW_TEST_SKIP: "*_arm64 *_universal2:arm64"
# below only for building against unstable numpy
CIBW_BUILD_FRONTEND: "pip; args: --no-build-isolation"
CIBW_BEFORE_BUILD: "pip install --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy cython setuptools versioneer"

- uses: actions/upload-artifact@v4
with:
Expand Down
12 changes: 6 additions & 6 deletions geotiepoints/multilinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def mlinspace(smin, smax, orders):
else:
meshes = np.meshgrid(
*[np.linspace(smin[i], smax[i], orders[i]) for i in range(len(orders))], indexing='ij')
return np.row_stack([l.flatten() for l in meshes])
return np.vstack([l.flatten() for l in meshes])


class MultilinearInterpolator:
Expand Down Expand Up @@ -44,8 +44,8 @@ class MultilinearInterpolator:
smax = [1,1]
orders = [5,5]
f = lambda x: np.row_stack([np.sqrt( x[0,:]**2 + x[1,:]**2 ),
np.power( x[0,:]**3 + x[1,:]**3, 1.0/3.0 )])
f = lambda x: np.vstack([np.sqrt( x[0,:]**2 + x[1,:]**2 ),
np.power( x[0,:]**3 + x[1,:]**3, 1.0/3.0 )])
interp = MultilinearInterpolator(smin,smax,orders)
interp.set_values( f(interp.grid) )
Expand All @@ -59,9 +59,9 @@ class MultilinearInterpolator:
__grid__ = None

def __init__(self, smin, smax, orders, values=None, dtype=np.float64):
self.smin = np.array(smin, dtype=dtype, copy=False)
self.smax = np.array(smax, dtype=dtype, copy=False)
self.orders = np.array(orders, dtype=np.int_, copy=False)
self.smin = np.asarray(smin, dtype=dtype)
self.smax = np.asarray(smax, dtype=dtype)
self.orders = np.asarray(orders, dtype=np.int_)
self.d = len(orders)
self.dtype = dtype
if values is not None:
Expand Down
8 changes: 4 additions & 4 deletions geotiepoints/tests/test_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ def test_interpolate(self, grid_interpolator):
fine_x = np.arange(16)
fine_y = np.arange(32)

res = grid_interpolator.interpolate((fine_y, fine_x), method="cubic")
res = grid_interpolator.interpolate((fine_y, fine_x), method="cubic_legacy")
np.testing.assert_allclose(res, self.expected, atol=2e-9)

def test_interpolate_slices(self, grid_interpolator):
"""Test that interpolation from slices is working."""
res = grid_interpolator.interpolate_slices((slice(0, 32), slice(0, 16)), method="cubic")
res = grid_interpolator.interpolate_slices((slice(0, 32), slice(0, 16)), method="cubic_legacy")
np.testing.assert_allclose(res, self.expected, atol=2e-9)

@pytest.mark.parametrize("chunks, expected_chunks", [(10, (10, 10)),
Expand All @@ -369,7 +369,7 @@ def test_interpolate_dask(self, grid_interpolator, chunks, expected_chunks):
with mock.patch.object(grid_interpolator,
"interpolate_numpy",
wraps=grid_interpolator.interpolate_numpy) as interpolate:
res = grid_interpolator.interpolate((fine_y, fine_x), method="cubic", chunks=chunks)
res = grid_interpolator.interpolate((fine_y, fine_x), method="cubic_legacy", chunks=chunks)
assert not interpolate.called

assert isinstance(res, da.Array)
Expand All @@ -395,5 +395,5 @@ def test_interpolate_preserves_dtype(self):
fine_x = np.arange(16)
fine_y = np.arange(32)

res = grid_interpolator.interpolate((fine_y, fine_x), method="cubic")
res = grid_interpolator.interpolate((fine_y, fine_x), method="cubic_legacy")
assert res.dtype == data.dtype
15 changes: 9 additions & 6 deletions geotiepoints/tests/test_modis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import h5py
import os

import pytest

FILENAME_250M_RESULT = os.path.join(
os.path.dirname(__file__), '../../testdata/250m_lonlat_section_result.h5')
FILENAME_250M_INPUT = os.path.join(
Expand Down Expand Up @@ -68,8 +70,12 @@ def test_5_to_1(self):
np.testing.assert_allclose(tlons, glons, atol=0.05)
np.testing.assert_allclose(tlats, glats, atol=0.05)

def test_1000m_to_250m(self):
@pytest.mark.parametrize("ncores", [None, 4])
def test_1000m_to_250m(self, ncores):
"""Test the 1 km to 250 meter interpolation facility."""
if ncores:
import multiprocessing as mp
mp.set_start_method("spawn", force=True)

with h5py.File(FILENAME_250M_RESULT) as h5f:
glons = h5f['longitude'][:] / 1000.
Expand All @@ -79,10 +85,7 @@ def test_1000m_to_250m(self):
lons = h5f['longitude'][:] / 1000.
lats = h5f['latitude'][:] / 1000.

tlons, tlats = modis1kmto250m(lons, lats)
np.testing.assert_allclose(tlons, glons, atol=0.05)
np.testing.assert_allclose(tlats, glats, atol=0.05)

tlons, tlats = modis1kmto250m(lons, lats, cores=4)
kwargs = {"cores": ncores} if ncores is not None else {}
tlons, tlats = modis1kmto250m(lons, lats, **kwargs)
np.testing.assert_allclose(tlons, glons, atol=0.05)
np.testing.assert_allclose(tlats, glats, atol=0.05)
2 changes: 1 addition & 1 deletion geotiepoints/tests/test_multilinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_multilinear_interp(self):
smax = [1, 1]
orders = [5, 5]

f = lambda x: np.row_stack([
f = lambda x: np.vstack([
np.sqrt(x[0, :]**2 + x[1, :]**2),
np.power(x[0, :]**3 + x[1, :]**3, 1.0 / 3.0)
])
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "wheel", "oldest-supported-numpy", "Cython>=3", "versioneer"]
requires = ["setuptools", "wheel", "numpy>=2.0.0rc1,<3", "Cython>=3", "versioneer"]
build-backend = "setuptools.build_meta"

[tool.coverage.run]
Expand Down

0 comments on commit 3172085

Please sign in to comment.