Skip to content
Closed
Changes from all commits
Commits
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 weatherbench2/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ def _get_output_path(

def _to_netcdf(dataset: xr.Dataset, filename: str) -> None:
with fsspec.open(filename, 'wb', auto_mkdir=True) as f:
for coord in dataset.coords:
if dataset[coord].dtype == 'timedelta64[ns]':
# Make sure to also override all other existing encodings.
dataset[coord].encoding = {'dtype': 'int32'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend also adding:

if "_FillValue" in dataset[coord].encoding:
  # Let NetCDF pick a default that works for int32
  del dataset[coord].encoding["_FillValue"]

f.write(dataset.to_netcdf())


Expand Down
Loading