因此,我使用this website中的函数(尝试)制作一些 netCDF4
数据的简图。下面有我的代码的摘录。我从here获得了数据。
stick_plot(time,u,v)
功能完全正如我所链接的网站中显示的那样,这就是为什么我没有在下面显示该功能的副本。
当我运行我的代码时,我收到以下错误。有关如何绕过这个的任何想法?
AttributeError: 'numpy.float64' object has no attribute 'toordinal'
netCDF4
文件中的时间描述:
<type 'netCDF4._netCDF4.Variable'>
float64 time(time)
long_name: time
standard_name: time
units: days since 1900-01-01 00:00:00Z
axis: T
ancillary_variables: time_quality_flag
data_min: 2447443.375
data_max: 2448005.16667
unlimited dimensions:
current shape = (13484,)
filling off
以下是我的代码的摘录:
进口:
import matplotlib.pyplot as plot
import numpy as np
from netCDF4 import Dataset
import os
from matplotlib.dates import date2num
from datetime import datetime
尝试生成图表:
path = '/Users/Kyle/Documents/Summer_Research/east_coast_currents/'
currents = [x for x in os.listdir('%s' %(path)) if '.DS' not in x]
for datum in currents:
working_data = Dataset('%s' %(path+datum), 'r', format = 'NETCDF4')
u = working_data.variables['u'][:][:100]
v = working_data.variables['v'][:][:100]
time = working_data.variables['time'][:][:100]
q = stick_plot(time,u,v)
ref = 1
qk = plot.quiverkey(q, 0.1, 0.85, ref,
"%s N m$^{-2}$" % ref,
labelpos='N', coordinates='axes')
_ = plot.xticks(rotation=70)
答案 0 :(得分:1)
datetime
对象读取。我所要做的就是用date2num(time)
替换time
来修复所有内容。