diff --git a/ndpyramid/core.py b/ndpyramid/core.py index 0252f06..34e2463 100644 --- a/ndpyramid/core.py +++ b/ndpyramid/core.py @@ -1,10 +1,10 @@ from __future__ import annotations # noqa: F401 -import contextlib import typing from collections import defaultdict import datatree as dt +import numpy as np import xarray as xr from .common import Projection @@ -132,16 +132,13 @@ def pyramid_reproject( dst_transform = projection_model.transform(dim=dim) def reproject(da, var): + da.encoding['_FillValue'] = np.nan da = da.rio.reproject( projection_model._crs, resampling=Resampling[resampling_dict[var]], shape=(dim, dim), transform=dst_transform, ) - da = da.where(da != da.rio.nodata) - with contextlib.suppress(KeyError): - del da.attrs['_FillValue'] - del da.encoding['_FillValue'] return da # create the data array for each level diff --git a/tests/test_pyramids.py b/tests/test_pyramids.py index bd54fdf..e5f60be 100644 --- a/tests/test_pyramids.py +++ b/tests/test_pyramids.py @@ -41,7 +41,7 @@ def test_reprojected_pyramid_fill(temperature, benchmark): """ pytest.importorskip('rioxarray') temperature = temperature.rio.write_crs('EPSG:4326') - pyramid = benchmark(lambda: pyramid_reproject(temperature, levels=2)) + pyramid = benchmark(lambda: pyramid_reproject(temperature, levels=1)) assert np.isnan(pyramid['0'].air.isel(time=0, x=0, y=0).values)