python – 如何在ecmwf文件上读取日期和时间
发布时间:2020-12-20 11:52:24 所属栏目:Python 来源:网络整理
导读:我在netcdf文件中有全局数据集.数据文件的时间信息是: type 'netCDF4._netCDF4.Variable'int32 time(time) units: hours since 1900-01-01 00:00:0.0 long_name: time calendar: gregorianunlimited dimensions: timecurrent shape = (5875,)filling off 当
我在netcdf文件中有全局数据集.数据文件的时间信息是:
<type 'netCDF4._netCDF4.Variable'> int32 time(time) units: hours since 1900-01-01 00:00:0.0 long_name: time calendar: gregorian unlimited dimensions: time current shape = (5875,) filling off 当我从文件中提取时间时,我得到了这个数组: array([ 876600,876624,876648,...,1017528,1017552,1017576],dtype=int32) 我的问题是如何将此数组转换为正确的日期格式? 解决方法
这样做的理想方法是使用
netCDF4 num2date
import netCDF4 ncfile = netCDF4.Dataset('./foo.nc','r') time = ncfile.variables['time'] dates = netCDF4.num2date(time[:],time.units,time.calendar) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |