Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Much of the data provided by the Copernicus Atmosphere Monitoring Service (CAMS), the Copernicus Climate Change Service (C3S), and by meteorological centres like ECMWF comes in GRIB or NetCDF format.  This article gives examples how to extract data for a specific location and/or time from a GRIB or NetCDF file.

In this example we work with  ERA5 data, hourly surface pressure (sp) for the month 2010-08, as specified in this data retrieval script:

Code Block
languagepy
collapsetrue
#!/usr/bin/env python
from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()
server.retrieve({
    "class": "ea",
    "dataset": "era5",
    "date": "2010-08-01/to/2010-08-31",
    "expver": "1",
    "levtype": "sfc",
    "param": "134.128",
    "stream": "oper",
    "time": "00/to/23/by/1",
    "type": "an",
    "target": "e5-sp-201008xx.grib",
})
server.retrieve({
    "class": "ea",
    "dataset": "era5",
    "date": "2010-08-01/to/2010-08-31",
    "expver": "1",
    "levtype": "sfc",
    "param": "134.128",
    "stream": "oper",
    "time": "00/to/23/by/1",
    "type": "an",
    "grid": "0.5/0.5",
    "format": "netcdf",
    "target": "e5-sp-201008xx.nc",
})

This script retrives a GRIB file 'e5-sp-201008xx.grib' and a NetCDF file 'e5-sp-201008xx.nc'.

Looking up data values in GRIB

We want to look up the surface pressure (sp) data value for 2010-08-05 00:00, at the model point closest to our target location lon=7.36 lat=43.89

Install ECMWF ecCodes, then look up the data value with the grib_ls command:

Code Block
grib_ls -l 43.89,7.36,1 -w dataDate=20100805,dataTime=0000 -p shortName e5-sp-201008xx.grib

Output:

Code Block
...
shortName    value 
sp          88510       
...
Input Point: latitude=43.89  longitude=7.36
Grid Point chosen #3 index=84109 latitude=43.98 longitude=7.50 distance=15.11 (Km)
...

Looking up data values in NetCDF

We want to look up the surface pressure (sp) data value for 2010-08-05 00:00, at the model point closest to our target location lon=7.36 lat=43.89

Install CDO, then look up the data value:

Code Block
cdo -outputtab,lon,lat,date,time,value -selyear,2010 -selmonth,08 -selday,05 -seltime,00:00 -remapnn,lon=7.36_lat=43.89 e5-sp-201008xx.nc

Output:

Code Block
#   lon    lat       date     time    value 
...
  7.36  43.89  2010-08-05 00:00:00  88360.6 
...