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).
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
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:
#!/usr/bin/env python from ecmwfapi import ECMWFDataServer server = ECMWFDataServer() server.retrieve({ "class": "ei", "dataset": "interim", "date": "2015-08-01", "expver": "1", "grid": "0.75/0.75", "levtype": "ml", "levelist": "all", "param": "t/q", "step": "0", "stream": "oper", "time": "0", "type": "an", "format": "netcdf" "target": "tq_ml_20150801_00.nc" }) |
#!/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": "z/lnsp", "step": "0", "stream": "oper", "time": "0", "type": "an", "format": "netcdf" "target": "zlnsp_ml_20150801_00.nc", }) |
Python program | compute_geopotential_on_ml.py |
Wrapper script | compute_geopotential_on_ml.ksh |
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