英文:
Recent Pygrib fail to retrieve ecmwf grib2 data within latitude and longitude
问题
之前,我没有问题地使用以下命令从实时预测ecmwf中检索降雨数据:
import pygrib
import numpy as np
source = './10-Download-ECMWF/'
grbs = pygrib.open(source + '10-data.grib2')
grb2 = grbs.message(1) # 消息从1开始,消息1=降雨,消息2=温度
data, lats, lons = grb2.data(lat1=-10, lat2=20, lon1=90, lon2=130)
我的旧数据存档中下载的数据仍然可以使用,但从2023年6月起重新下载后出现了问题,并显示以下消息:
RuntimeError: b'Function not yet implemented' #### 问题在第7行提到
有人有想法吗?提前感谢。
英文:
Previously I had no problem to retrieve rainfall data from real-time forecast ecmwf using this command;
1 import pygrib
2 import numpy as np
3
4 source='./10-Download-ECMWF/'
5 grbs = pygrib.open(source+'10-data.grib2')
6 grb2 = grbs.message(1) ### message start from 1, message 1=rainfall, mesage2=temp
7 data, lats, lons = grb2.data(lat1=-10, lat2=20, lon1=90, lon2=130)
Old data downloaded in my archive still can be used but after new download in June 2023 onwards the problem begins and showing this messages;
RuntimeError: b'Function not yet implemented' #### the problem mentioned at line 7
Anyone got ideas?. Thanks in advance.
答案1
得分: 1
首先尝试升级您的 pygrib
:
pip install --upgrade pygrib
如果问题仍然存在,您可以尝试另一个替代库称为 pygrib2
,首先安装它:
pip install ecmwf-api-client
然后:
from ecmwfapi import ECMWFDataServer
import pygrib2
# ECMWF API凭据
server = ECMWFDataServer(url="https://api.ecmwf.int/v1")
# 数据检索的参数
dataset = "cams_gfas"
date = "2023-06-01/to/2023-06-30"
time = "00:00/06:00/12:00/18:00"
area = "10/-10/20/130"
target = "output.grib"
# 检索GRIB文件
server.retrieve({
"dataset": dataset,
"date": date,
"time": time,
"area": area,
"target": target,
"format": "grib"
})
# 打开下载的GRIB文件并检索降雨数据、纬度和经度值
grbs = pygrib2.open("output.grib")
grb = grbs[1] # 假设降雨数据在第一条消息中
data = grb.values
lats, lons = grb.latlons()
# 根据需要使用检索到的数据
print(data)
print(lats)
print(lons)
祝好运!
英文:
first of all try to upgrade your pygrib
pip install --upgrade pygrib
and if the issue persists,
you can try another alternative library called pygrib2
, so first install this :
pip install ecmwf-api-client
and now
from ecmwfapi import ECMWFDataServer
import pygrib2
# ECMWF API credentials
server = ECMWFDataServer(url="https://api.ecmwf.int/v1")
# parameters for data retrieval
dataset = "cams_gfas"
date = "2023-06-01/to/2023-06-30"
time = "00:00/06:00/12:00/18:00"
area = "10/-10/20/130"
target = "output.grib"
# retrieve the GRIB file
server.retrieve({
"dataset": dataset,
"date": date,
"time": time,
"area": area,
"target": target,
"format": "grib"
})
#open the downloaded GRIB file and retrieve the rainfall data, latitude, and longitude values
grbs = pygrib2.open("output.grib")
grb = grbs[1] # Assuming rainfall is in the first message
data = grb.values
lats, lons = grb.latlons()
#use the retrieved data as needed
print(data)
print(lats)
print(lons)
good luck !
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论