Skip to content

Commit

Permalink
Replace workaround by a new xarray lower bound
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Hoersch committed Nov 9, 2024
1 parent 9bd3014 commit 332a5d1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
13 changes: 0 additions & 13 deletions atlite/datasets/era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import os
import warnings
import weakref
from importlib.metadata import version
from tempfile import mkstemp

import cdsapi
Expand All @@ -22,7 +21,6 @@
from dask import compute, delayed
from dask.array import arctan2, sqrt
from numpy import atleast_1d
from packaging.version import parse

from atlite.gis import maybe_swap_spatial_dims
from atlite.pv.solar_position import SolarPosition
Expand Down Expand Up @@ -363,17 +361,6 @@ def retrieve_data(product, chunks=None, tmpdir=None, lock=None, **updates):
logger.debug(f"Adding finalizer for {target}")
weakref.finalize(ds._file_obj._manager, noisy_unlink, target)

# Remove default encoding we get from CDSAPI, which can lead to NaN values after loading with subsequent
# saving due to how xarray handles netcdf compression (only float encoded as short int seem affected)
# Fixes issue by keeping "float32" encoded as "float32" instead of internally saving as "short int", see:
# https://stackoverflow.com/questions/75755441/why-does-saving-to-netcdf-without-encoding-change-some-values-to-nan
# see https://github.com/pydata/xarray/issues/7691 and https://github.com/pydata/xarray/pull/8713
# Fix was included in v2024.03.0
if parse(version("xarray")) < parse("2024.03.0"):
for v in ds.data_vars:
if ds[v].encoding["dtype"] == "int16":
ds[v].encoding.clear()

return ds


Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies = [
"pandas>=0.25",
"bottleneck",
"numexpr",
"xarray>=0.20",
"xarray>=2024.03.0",
"netcdf4",
"dask>=2021.10.0",
"toolz",
Expand Down Expand Up @@ -116,4 +116,4 @@ ignore = [
'D415', # First line should end with a period, question mark, or exclamation point
'D417', # Missing argument descriptions in the docstring

]
]

0 comments on commit 332a5d1

Please sign in to comment.