我正在尝试使用Python GLBy0.08-latest
包从Navy HYCOM海洋数据集xarray
(请参阅目录here)中加载数据。根据一天中的时间而定,但没有明显的原因,它会失败并显示错误消息
packages/xarray/backends/common.py", line 55, in robust_getitem
return array[key]
File "netCDF4/_netCDF4.pyx", line 4119, in netCDF4._netCDF4.Variable.__getitem__
File "netCDF4/_netCDF4.pyx", line 5036, in netCDF4._netCDF4.Variable._get
File "netCDF4/_netCDF4.pyx", line 1754, in netCDF4._netCDF4._ensure_nc_success
RuntimeError: NetCDF: file not found
回溯不是很有用,因为它可能在较低级别的C库中引发。如果我排除过去的时间戳(即未预测),则查询成功。这是Python 3中的一个最低限度的工作示例,有时会成功,有时会因上述错误而失败:
from datetime import datetime, time
import pytz
import pandas as pd
import xarray as xr
# Use coordinates on the supported data grid
lat, lon = -42.68000030517578, 286.96002197265625
# Open the GLBy0.08-latest + forecast data set
ds = xr.open_dataset(
'http://tds.hycom.org/thredds/dodsC/GLBy0.08/latest',
decode_times=False)[dict(tau_0=0)]
# Set time interval of interest to be all times today in UTC
today = datetime.now().date()
t_i = datetime.combine(today, time(0, 0, 0)).astimezone(pytz.utc)
t_f = datetime.combine(today, time(23, 0, 0)).astimezone(pytz.utc)
print(f'Querying for time interval: ({t_i}, {t_f})')
# Figure out the starting timestamp of the time coordinate
t_ds_start = pd.Timestamp(ds.time.attrs['units'][12:]).to_pydatetime()
print('Dataset start time:', t_ds_start)
assert t_i > t_ds_start
# Convert these timestamps to hour offsets from dataset start time
t_i_val = (t_i-t_ds_start).total_seconds() / 3600.
t_f_val = (t_f-t_ds_start).total_seconds() / 3600.
print(f'Querying for hour offsets: ({t_i_val}, {t_f_val})')
# Get data subset
ds_sub = ds.sel(lat=lat,
lon=lon,
depth=slice(0., 25., None),
time=slice(t_i_val, t_f_val, None))
# Start actual data acquisition by converting to data frame
df = ds_sub.to_dataframe()
感谢您提供有关如何解决此问题或其原因的帮助!如果有兴趣的话,这是我的安装中pd.show_versions()
的输出:
------------------
commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Linux
OS-release: 5.0.0-27-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.23.4
pytest: 4.1.1
pip: 19.3
setuptools: 40.8.0
Cython: 0.29.5
numpy: 1.16.1
scipy: 1.2.0
pyarrow: None
xarray: 0.11.3
IPython: 7.2.0
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2015.7
blosc: None
bottleneck: None
tables: 3.4.4
numexpr: 2.6.9
feather: None
matplotlib: 3.0.2
openpyxl: 2.6.2
xlrd: 1.2.0
xlwt: None
xlsxwriter: None
lxml: 4.3.1
bs4: None
html5lib: None
sqlalchemy: 1.2.16
pymysql: None
psycopg2: 2.7.6.1 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: 0.9.0
pandas_datareader: None```
Thanks.