我正在尝试从 THREDDS 服务器加载 netcdf,但在某个时间步后遇到无法识别的错误。
def list_dates(start, end):
num_days = (end - start).days
return [start + dt.timedelta(days=x) for x in range(num_days)]
start_date = dt.date(2017, 3, 1)
end_date = dt.date(2017, 3, 31)
date_list = list_dates(start_date, end_date)
window = dt.timedelta(days=5)
url = 'https://www.ncei.noaa.gov/thredds/dodsC/OisstBase/NetCDF/V2.0/AVHRR/{0:%Y%m}/avhrr-only-v2.{0:%Y%m%d}.nc'
#url2= 'https://www.ncei.noaa.gov/thredds/dodsC/Datasets/noaa.oisst.v2.highres/icec.day.mean.{0:%Y}.v2.nc'
data = []
cur_date = start_date
for cur_date in date_list:
print(cur_date)
date_window = list_dates(cur_date - window, cur_date + window)
url_list = [url.format(x) for x in date_window]
window_data=xr.open_mfdataset(url_list).sst
data.append(window_data.mean('time'))
print(data[-1])
dataf=xr.concat(data, dim=pd.DatetimeIndex(date_list, name='time'))
print (dataf)
这些数据的加载一直很顺利,直到 3 月 22 日,这是失败的日期。我尝试过更改月份和年份,每次脚本在第 22 个时间步失败时。我将在下面提供两个错误代码。任何有关这里发生的事情的信息将不胜感激。作为参考,我正在运行最新版本的 python 和 netCDF4,以及 xarray。
错误:
错误一:KeyError: [<class 'netCDF4._netCDF4.Dataset'>, ('https://www.ncei.noaa.gov/thredds/dodsC/OisstBase/NetCDF/V2.0/AVHRR/201703/avhrr-only-v2.20170322.nc',), 'r', (('clobber', True), ('diskless', False), ('format', 'NETCDF4'), ('persist', False))]
错误2:OSError: [Errno -37] NetCDF: Write to read only: b'https://www.ncei.noaa.gov/thredds/dodsC/OisstBase/NetCDF/V2.0/AVHRR/201703/avhrr-only-v2.20170322.nc'