将所选GFS集成的openDAP数据加载到内存(Python)

时间:2018-09-19 13:19:23

标签: python python-xarray netcdf4 opendap

我想通过netCDF和xarray从OpenDAP服务器从GFS集成数据中下载子选择。但是,当尝试将子选择加载到内存中时,程序在返回RuntimeError(netCDF:I / O故障)后不久便崩溃了。

我希望获取的数据点数量为13650,因此数据大小应易于在Python中处理。

奇怪的是,下载GFS数据或NCEP重新分析数据时,我没有遇到此问题。这使我相信该问题可能与数据维度的数量有关,因为集合数据具有5个维度,而Reanalysis and Operational(GFS)数据仅具有4个维度。

我也曾尝试仅在使用netCDF4模块时下载数据,但这导致了相同的错误。因此,我认为问题不在于xarray。

以下是下载数据所需的代码:

from netCDF4 import Dataset
import numpy as np
import pandas as pd
import xarray as xr
import time as tm

# Set time to download data from (this is always the 00UTC run of the present day)
time_year = str(tm.localtime()[0])
time_month = str(tm.localtime()[1])
time_day = str(tm.localtime()[2])

if len(time_month)== 1:
    time_month = '0' + time_month
datestr = time_year + time_month + time_day
print('The run chosen is the 00 UTC run of ' + time_day + '-' + time_month + '-' + time_year)

# Define server information
serverstring='http://nomads.ncep.noaa.gov:9090/dods/gens_bc/gens' + datestr + '/gep_all_00z'
print(serverstring)

# Load data 
dataset = xr.open_dataset(serverstring)
time = dataset.variables['time']  
lat = dataset.variables['lat'][:]
lon = dataset.variables['lon'][:]
lev = dataset.variables['lev'][:]
ens = dataset.variables['ens'][:]

# Select user settings to plot (in this case all timesteps for all (20) members for a box around the Netherlands near the surface)
time_toplot = time  # select all available timesteps
lat_toplot = np.arange(50, 55, 0.5)
lon_toplot = np.arange(2, 8, 0.5)
lev_toplot = np.array([1000])
ens_toplot = ens  # select all available ensemble members

# Select required data via xarray
dataset = dataset.sel(ens=ens_toplot, time=time_toplot, lev=lev_toplot, lon=lon_toplot, lat=lat_toplot)

# Loading the data into memory finally results in the error
u = dataset.variables["ugrdprs"].values

谢谢!

0 个答案:

没有答案