Introduction
Some users are interested on geopotential (z) of the different model levels (ml). This Python script computes the geopotential on model levels, using as inputs NetCDF files containing geopotential and the pressure (z and lnsp) on the surface, and creating as output a NetCDF file containing the geopotential in m^2/s^2 for each level. Note that you can get the height in meters if you divide the geopotential by the gravity of Earth (9.80665 m/s^2).
- This script is intended only as a workaround for users who can not work with the ECMWF GRIB API. If you can use the GRIB API, use the script available here.
- The script requires Python and the ECMWF WebAPI to access ECMWF public datasets
The script only works correctly for ECMWF ERA-Interim data, do not use it with other datasets
Input data has to be gridded, not spectral
Get input data
For this use case, you need both temperature (t) and Specific humidity (q) for each model level. You also need both surface geopotential (z) and logarithm of surface pressure (lnsp) for model level = 1. Input files have to be synchronized using the same date, date, time, step and gridType. Afterwards the calculation of geopotential will iterate through the date/time/step parameters, allowing you to get the values for multiple times.
First get temperature (t) and Specific humidity (q), using the ECMWF Web API:
Get surface logarithm of surface pressure (lnsp) for model level = 1:
#!/usr/bin/env python
from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()
server.retrieve({
"class": "ei",
"dataset": "interim",
"date": "2016-12-01",
"expver": "1",
"grid": "0.75/0.75",
"levelist": "1",
"levtype": "ml",
"param": "lnsp",
"step": "0",
"stream": "oper",
"time": "0",
"type": "an",
"format": "netcdf"
"target": "lnsp_ml_20150801_00.nc",
})
Get the geopotential (z):
#!/usr/bin/env python
from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()
server.retrieve({
"class": "ei",
"dataset": "interim",
"date": "1989-01-01",
"expver": "1",
"grid": "0.75/0.75",
"levtype": "sfc",
"param": "z",
"step": "0",
"stream": "oper",
"time": "12:00:00",
"type": "an",
"format": "netcdf"
"target": "zlnsp_ml_20150801_00.nc",
})
Compute geopotential on model levels
- The script is based on the Metview macro mvl_geopotential_on_ml, code from Nils Wedi, IFS documentation:
- CY41R1 Official IFS Documentation
- part III. Dynamics and numerical procedures
- CY41R1 Official IFS Documentation
Download
Python program | compute_geopotential_on_ml.py |
Wrapper script | compute_geopotential_on_ml.ksh |
Examples
This example will compute the geopotential on the 2015-10-08 time 00 operational analysis model levels (137). Below you can see the MARS user documentation request used to retrive both files. You can set a different class/stream/type for the input data. The gribType and resolution can also be changed.
python compute_geopotential_on_ml.py tq_ml_20151008_00.grib zlnsp_ml_20151008_00.grib python compute_geopotential_on_ml.py tq_ml_20151008_00.grib zlnsp_ml_20151008_00.grib -o my_grib.grib |
tq_ml_20151008_00.grib
zlnsp_ml_20151008_00.grib