Skip to content

Commit

Permalink
Only set fill value as nan for floating point arrays (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrjones authored Mar 13, 2024
1 parent 0c1c734 commit 8e56c02
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ndpyramid/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import xarray as xr

from .common import Projection
from .utils import add_metadata_and_zarr_encoding, get_levels, get_version, multiscales_template
from .utils import (
add_metadata_and_zarr_encoding,
get_levels,
get_version,
multiscales_template,
)


def pyramid_coarsen(
Expand Down Expand Up @@ -132,7 +137,10 @@ def pyramid_reproject(
dst_transform = projection_model.transform(dim=dim)

def reproject(da, var):
da.encoding['_FillValue'] = np.nan
# Set float FillValue that rasterio will use to initialize array
if da.encoding.get('_FillValue') is None and np.issubdtype(da.dtype, np.floating):
da.encoding['_FillValue'] = np.nan

da = da.rio.reproject(
projection_model._crs,
resampling=Resampling[resampling_dict[var]],
Expand Down

0 comments on commit 8e56c02

Please sign in to comment.