将选择的 GFS-ensemble openDAP 数据加载到内存中 (Python)

2024-03-14

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

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

奇怪的是,我在下载 GFS-data 或 NCEP-Reanalysis 数据时没有遇到这个问题。这让我相信这个问题可能与数据维度的数量有关,因为集合数据有 5 个维度,而再分析和操作 (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

Thanks!


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将选择的 GFS-ensemble openDAP 数据加载到内存中 (Python) 的相关文章

随机推荐