问题描述
我有一个带有时间变量的 netcdf 文件,它表示为“proleptic_gregorian”。我想使用 num2date
函数将其转换为公历日期。
我正在尝试这个
import netCDF4 as nc
from netCDF4 import num2date,date2num
#read in the file
ncfile_o = Dataset(input_netcdf_file,'r',format="NETCDF4")
这有变量:
odict_keys(['time','time_bnds','lon','lat','landCoverFrac'])
我现在将获取时间信息:
#time dimension
nctime = ncfile_o.variables['time'][:]
t_unit = ncfile_o.variables['time'].units
t_cal = ncfile_o.variables['time'].calendar
此处 t_cal
是 'proleptic_gregorian' 而 t_unit
是'years since 1860-1-15 00:00:00'。 nctime
看起来像这样:
array([1.45698925,2.45698925,151.45698925,152.45698925)]
然后我试着把它变成这样的日期:
datevar = []
datevar.append(num2date(nctime,units = t_unit,calendar = t_cal))
但这失败了:
ValueError: unsupported time units
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)