1

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.

Azam
  • 165
  • 14

1 Answers1

1

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 !

Freeman
  • 9,464
  • 7
  • 35
  • 58
  • Thanks for the answer. I tried the second option but to no avail as the result shows " GribInternalError: ('Function not yet implemented (-4).', -4)". I am not sure the meaning of it. I am on my way to upgrade pygrib as adviced for option 1. Currently, I am using conda-forge for installing pygrib so when to upgrade it takes quite awhile. Will provide you feedback when it is done..thanks – Azam Jul 11 '23 at 07:14
  • @Azam I updated again, please check it out. – Freeman Jul 11 '23 at 11:01
  • Thanks for the input. Will come back to you soon. I am updating my python version but now facing another problem while updating the pygrib. I guess need to update to new version python 3.8 – Azam Jul 12 '23 at 11:08
  • Now I know what is going on with the situation. It happened to be that ECMWF decommissioning the public datasets that affects S2S and TIGGE dataset beginning 1st June 2023. Datasets before the date is working so well. Some grib2 datasets like ERA5 or ERA5-Land stay as what it is and no problem arise when dealing with python. You can have a read from this link : https://confluence.ecmwf.int/display/WEBAPI/Accessing+ECMWF+data+servers+in+batch – Azam Jul 13 '23 at 10:46
  • 1
    Yes I have tried to solution provided by you above unfortunately, I don't have permission to engage the data "cams_gfas" and required to reregister before downloading. Now my machine is already updated to Python 3.9 and other libraries working well. I will keep the beautiful solution for future use. Many thanks. – Azam Jul 13 '23 at 10:49
  • @Azam you're welcome, it was my pleasure! It's clear from your name that you are a Muslim, and I would be grateful if you could also pray for me! good luck, my dear brother! – Freeman Jul 13 '23 at 10:58
  • Sure will pray for your career success in future and always in good health. – Azam Jul 13 '23 at 11:08