issues: 558293655
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
558293655 | MDU6SXNzdWU1NTgyOTM2NTU= | 3739 | ValueError when trying to encode time variable in a NetCDF file with CF convensions | 33062222 | closed | 0 | 7 | 2020-01-31T18:22:36Z | 2023-09-13T13:45:47Z | 2023-09-13T13:45:46Z | NONE | ```python Importsimport numpy as np import xarray as xr import pandas as pd from glob import glob files to be concatenatedfiles = sorted(glob(path + str(1988) + '/V250*')) corrected datesdates = pd.date_range(start=str(yr), end=str(yr+1), freq='6H', closed='left') ds_test = xr.open_mfdataset(files[:10], combine='nested', concat_dim='time', decode_cf=False) correcting timeds_test.time.values=dates[:10] fixing encodingds_test.time.attrs['units'] = "Seconds since 1970-01-01 00:00:00" preview of the time variableprint(ds_test.time)
ds_test.to_netcdf(path+'test.nc')
``` Expected OutputCorrectly encode Problem DescriptionI'm trying to concatenate ```python More diagnostics on the encodingprint(ds_test.encoding)
checking any existing timeprint(ds_test.time.encoding)
another try on setting time encodingds_test.time.encoding['units'] = "Seconds since 1970-01-01 00:00:00" writing the file gives the same ValueError as aboveds_test.to_netcdf(path+'test.nc') ncdump output of one of the files
// global attributes: :Conventions = "CF" ; :constants_file_name = "P19880101_06" ; :institution = "IACETH" ; :lonmin = -180.f ; :lonmax = 179.5f ; :latmin = -90.f ; :latmax = 90.f ; :levmin = 250.f ; :levmax = 250.f ; :history = "Fri Sep 6 15:59:17 2019: ncatted -a units,time,o,c,hours since 1988-01-01 06:00:00 -a standard_name,time,o,c,time V250_19880101_06" ; :NCO = "4.7.2" ; data: time = 6 ; } ``` Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/3739/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |