Initializing the WRF model with ERA5 (pressure level)

Note

This is the tutorial of using WRF with ERA5 pressure level (38 vertical levels) data.

If you prefer model level (138 vertical levels), please check another tutorial.

I recommend the pressure level data, because the download speed is much faster.

If you don’t have cdsapi, please check this official tutorial.

Required Fields

WRF requires a number of fields as input.

  • 3D Data (e.g. data on pressure levels)

    • Temperature
    • U and V components of Wind
    • Geopotential Height
    • Relative Humidity (the code can calculate RH if Specific Humidity is available;this is controlled in the Vtable)
  • 2D Data

    • Surface Pressure
    • Mean Sea Level Pressure
    • Skin Temperature/SST
    • 2-meter Temperature
    • 2-meter Relative or Specific Humidity
    • 10-meter U and V components of wind
    • Soil data (temperature and moisture) and soil height

If any masked field is ingested, then a LANDSEA field is recommended

Water equivalent snow depth (SNOW) is a nice field to have, but not required.

SEAICE is good to have for a high latitude winter case, but it is not required.

Single level data (GetERA5-sl.py)

import cdsapi

c = cdsapi.Client()

c.retrieve(
    'reanalysis-era5-single-levels',
    {
        'product_type':'reanalysis',
        'format':'grib',
        'variable':[
            '10m_u_component_of_wind','10m_v_component_of_wind','2m_dewpoint_temperature',
            '2m_temperature','land_sea_mask','mean_sea_level_pressure',
            'sea_ice_cover','sea_surface_temperature','skin_temperature',
            'snow_depth','soil_temperature_level_1','soil_temperature_level_2',
            'soil_temperature_level_3','soil_temperature_level_4','surface_pressure',
            'volumetric_soil_water_layer_1','volumetric_soil_water_layer_2','volumetric_soil_water_layer_3',
            'volumetric_soil_water_layer_4'
        ],
        'date':'DATE1/DATE2',
        'area':'Nort/West/Sout/East',
        'time':'00/to/23/by/1',
    },
    'ERA5-DATE1-DATE2-sl.grib')

Pressure level data (GetERA5-pl.py)

import cdsapi

c = cdsapi.Client()

c.retrieve(
    'reanalysis-era5-pressure-levels',
    {
        'product_type':'reanalysis',
        'format':'grib',
        'pressure_level':[
            '1','2','3',
            '5','7','10',
            '20','30','50',
            '70','100','125',
            '150','175','200',
            '225','250','300',
            '350','400','450',
            '500','550','600',
            '650','700','750',
            '775','800','825',
            '850','875','900',
            '925','950','975',
            '1000'
        ],
        'date':'DATE1/DATE2',
        'area':'Nort/West/Sout/East',
        'time':'00/to/23/by/1',
        'variable':[
            'geopotential','relative_humidity','specific_humidity',
            'temperature','u_component_of_wind','v_component_of_wind'
        ]
    },
    'ERA5-DATE1-DATE2-pl.grib')

Automation script (Download)

You can automate the script rather than change elements one by one.

#!/bin/bash -l

CODEDIR=/nuist/u/home/yinyan/xin/scratch/data/ERA5/code
DATADIR=/nuist/u/home/yinyan/xin/scratch/data/ERA5/data

# Set your python environment
export PATH=~/xin/work/anaconda3/bin:$PATH
source activate root
cd $CODEDIR

DATE1=20170419
DATE2=20170420
YY1=`echo $DATE1 | cut -c1-4`
MM1=`echo $DATE1 | cut -c5-6`
DD1=`echo $DATE1 | cut -c7-8`
YY2=`echo $DATE2 | cut -c1-4`
MM2=`echo $DATE2 | cut -c5-6`
DD2=`echo $DATE2 | cut -c7-8`
Nort=60
West=80
Sout=15
East=150

sed -e "s/DATE1/${DATE1}/g;s/DATE2/${DATE2}/g;s/Nort/${Nort}/g;s/West/${West}/g;s/Sout/${Sout}/g;s/East/${East}/g;" GetERA5-sl.py > GetERA5-${DATE1}-${DATE2}-sl.py

python GetERA5-${DATE1}-${DATE2}-sl.py

sed -e "s/DATE1/${DATE1}/g;s/DATE2/${DATE2}/g;s/Nort/${Nort}/g;s/West/${West}/g;s/Sout/${Sout}/g;s/East/${East}/g;" GetERA5-pl.py > GetERA5-${DATE1}-${DATE2}-pl.py

python GetERA5-${DATE1}-${DATE2}-pl.py

mkdir -p ${DATADIR}/$YY1

mv ERA5-${DATE1}-${DATE2}-sl.grib ERA5-${DATE1}-${DATE2}-pl.grib ${DATADIR}/$YY1/


exit 0

geogrid

Run geogrid.exe as usual.

If you’re not familiar with WRF, please check the online tutorial in detail.

ungrib

Run ungrib.exe by using the Vtable.ERA-interim.pl table:

$ ln -s ./ungrib/Variable_Tables/Vtable.ERA-interim.pl Vtable

metgrid

Run metgrid.exe as usual.

References

  1. How to run the WRF model using ERA5 (on model levels) as initial and boundary conditions
  2. Grib to Netcdf conversion
  3. Download ERA-Interim data
  4. UNGRIB: Required Fields

Version control

Version Action Time
1.0 Init 2019-10-03
1.1 Add support of selecting area 2019-10-04
1.2 Update the method of assigning ‘time’ 2020-03-27

Comments (30)

Sam
Tuesday, Mar 24, 2020

Do I need to merge both dataset before running ungrib? If not what name I should give to each? GRIBFILE.AAA and GRIBFILE.AAB?

Xin Zhang
In reply to Sam
Tuesday, Mar 24, 2020

Hi, Sam!

You don’t have to merge both datasets.

You can just use ./link_grib.csh ERF5* to link all files.

Then ungrib.exe will read all GRIBFILE.*.

Xin

Zhenning Li
Thursday, Mar 26, 2020

Hi Xin,

Thanks for your great post. Very helpful! Just one question, in your downloading py script, the specific time ranges from 00Z to 12Z, I am just wondering why 13-23Z were not selected? Thanks

Zhenning

Xin Zhang
In reply to Zhenning Li
Thursday, Mar 26, 2020

Hi Zhenning,

Thanks!

That’s just an example which downloads 12 hours data.

You can choose any time interval you like, even unequally spaced intervals.

Xin

Xin Zhang
In reply to Zhenning Li
Friday, Mar 27, 2020

Hi Zhenning,

You can use a simpler method to choose the time like this:

'time':'00/to/23/by/1',

I’ve updated that part in the blog. Thank you for your question ;)

Xin

Prerita Agarwal
Tuesday, Apr 7, 2020

Hi Xin,

What is the exact difference between using model and pressure level data?

Also, does linking the grib files to folder like ./link_grib.csh ../DATA/ERA5 links both pressure and single-level data and does not need to be done separately?

Thanks, Prerita

Xin Zhang
In reply to Prerita Agarwal
Tuesday, Apr 7, 2020

Hi Prerita,

A1:

The pressure levels are interpolated from model levels. You can check the ERA5 document in detail. Also, the definition of 137 model levels is here and the diagram.

A2: Yes, you can link both kinds of data. That’s easier to do ungrib.exe and metgrid.exe.

Cheers, Xin

Yasmin
Sunday, Apr 12, 2020

Hi Xin, With the older dataset (Era-Interim), between the steps ungrib.exe and metgrid.exe, you had to apply the calc_ecmwf_p.exe (https://metclim.ucd.ie/2018/03/wrfv3-9-1-with-era-interim-data-on-orr2/). Is that not necessary anymore?

Thank you.

Xin Zhang
In reply to Yasmin
Sunday, Apr 12, 2020

Hi Yasmin,

That step is related to the ERA5 model level data. For the pressure level data, you don’t have to calculate data manually again.

Of course, I’ve written another tutorial for the model level data. Feel free to check that ;)

Xin

Yasmin
In reply to Yasmin
Thursday, Apr 16, 2020

Ahhh.. I see Xin, Thank you for the elucidation. Which one do you recommend? Model or Pressure level data?

I am downloading the pressure data + surface data. Hopefully I can run successfully the WRF. Let’s see. Yasmin

Xin Zhang
In reply to Yasmin
Sunday, Apr 19, 2020

Hi Yasmin,

In my opinion, the pressure level data is enough. But, if you want the higher vertical resolution, such as >100 levels, or focus on upper atmosphere, you can try the model data.

Looking forward to your test ;)

Xin

Yasmin
Sunday, Apr 19, 2020

Hi again Xin, So I just downloaded my data and performed a test, however I got the error relate to the Pressure levels, I guess I need to use the calc_ecmwf_p.exe Do you know where I can find the ecmwf_coeffs table for 38 pressure levels?

WARNING: Couldn’t open file PRES:2019-11-02_00 for input. Processing 2019-11-02_06 FILE PRES

Xin Zhang
In reply to Yasmin
Monday, Apr 20, 2020

Hi Yasmin,

I’ve used the ERA5 pressure level data several times and it always works well. So, I suppose there’s something wrong in your step of ./link_grib.csh or ungrib.exe. You need to check files (GRIBFILE.AAA ……) and logs (ungrib.log) related to these two command. If these steps are successful, then you should see the FILE:** files which cover the simulation time duration.

The most possible cause is the namelist.wps, you don’t need PRES. Here’s an example:

&ungrib
 out_format                         = 'WPS',
 prefix                             = 'FILE',
 /

&metgrid
 fg_name                            = 'FILE',
 io_form_metgrid                    = 2,
 /

Xin

Yasmin
Monday, Apr 20, 2020

Hey Xin, You were right, The problem was in the namelist.wps, which I didnt remove the fg_nam = ‘PRES’ (I’ve copied it from past simulations that I did using ERA-Interim). My simulations are already running. Thank you very much. Hopefully this dataset will provide results as good as the Era-Interim =)

Xin Zhang
In reply to Yasmin
Tuesday, Apr 21, 2020

Great! Looking forward to your new results ;)

Xin

Guilherme
Tuesday, Apr 21, 2020

Hi Xin, After i run the command “calc_ecmwf_p.exe”, the following error appears:

ERROR: Error opening ecmwf_coeffs Reading from FILE at time 2016-10-17_00 Found PSFC field in FILE:2016-10-17_00 WARNING: Either TT or SPECHUMD not found. No RH will be computed… … … … Any idea? Thank you!

Xin Zhang
In reply to Guilherme
Tuesday, Apr 21, 2020

Hi,

Note that the step of calc_ecmwf_p.exe is necessary for model level data, not pressure data.

If you’re using model level data, you need to create ecmwf_coeffs by yourself. Please check my another tutorial.

Xin

Stefan Rahimi
Friday, Jun 26, 2020

Dear Xin,

Thank you for this wonderful tutorial. I just have one question.

Where are you downloading these data from? ERA5 data are on the CISL RDA (https://rda.ucar.edu/datasets/ds630.0/), but the data are not in discrete time slices as required by ungrib.exe. I am planning to downscale ERA5 for a 40-year period, so I am trying to find grb files that are date-time specific…

It looks like the above scripts nicely subset the data and pull relevant variables into new grb files?

Thanks, -Stefan Rahimi, UCLA

Xin Zhang
In reply to Stefan Rahimi
Saturday, Jun 27, 2020

Dear Stefan,

The resource is from CDS which contains ERA5 Pressure level data and Single level data.

Since you need 40-year data, you can choose either method: using the above scripts or just clicking the boxes on the CDS web page.

Regards, Xin

bara
Friday, Jun 26, 2020

Hi Xin Thank you for your nice tutorial. I have followed all steps ,but I did not get the verticale levels for 4-dimensional variables like relative humidity (RH) and temperature (TT)) in my met file ( met_em.d01.2018-06-28_18:00:00.nc example)

How to solve this problem?

bara

Xin Zhang
In reply to bara
Saturday, Jun 27, 2020

Hi Bara,

That’s strange …

Could you check whether RH and TT exist in the pressure level grib files you have downloaded?

BTW, it;s better to make sure there’s no error in the log files (ungrib.log and metgrid.log).

Xin

Bara
In reply to bara
Saturday, Jun 27, 2020

Hi Xin! Thank you for your quick reply I checked the downloaded files but they contain pressure levels for UU, TT …. But the problem in coming from ungrib.exe and metgrid.exe. Files created by these both executables have not pressure levels. Do you have any idea please

Xin Zhang
In reply to bara
Sunday, Jun 28, 2020

Hi Bara,

Could you send the log files to my email? (If the generated files aren’t big, you can send them too) So, I can check the details …

Xin

Bara
Tuesday, Jun 30, 2020

Hi Xin, I really appreciated your collaboration. Finally, I have solved the problem by adding the following code to the 38 pressure levels:

echo ‘write “[centre][dataDate][dataType][levelType][step].grib[edition]“;’ > split.rule grib_filter split.rule ERA5-${DATE1}-${DATE2}-sfc.grb grib_set -s deletePV=1,edition=1 ERA5-${DATE1}-${DATE2}-ml.grb ERA5-${DATE1}-${DATE2}-ml.grib1 grib_filter split.rule ERA5-${DATE1}-${DATE2}-ml.grib1

This code is the last step for bash program for your 138 model levels tutorial.

Bara

Xin Zhang
In reply to Bara
Tuesday, Jun 30, 2020

Ha, nice!

I thought that step was optional for pressure level data and never used that before …

Anyway, I’m glad you solved it ;)

Xin

Chi
Friday, Jul 3, 2020

Hi Xin, thanks for your tutorial, and I have some questions. I’m ungribbing ERA-Interim data(pressure level), can I use SH, 2m T and 2m dewpoint T to calculate RH by adding SPECHUMD to the Vtable.ECMWF? I noticed this RH data are different from ungribbing it directly with ERA-Interim RH data in met files, what could be the problem?

Chi

Xin Zhang
In reply to Chi
Friday, Jul 3, 2020

Hi Chi,

This post is for ERA5 dataset.

If you’re using ERA-Interim data, please check my another post.

Xin

Bart Brashers
Sunday, Jul 5, 2020

Would it be beneficial to add ‘geopotential’ to the GetERA5-sl.py part of the code? That would download GRIB code=129, level code=1 (surface), which WRF uses to construct SOILGEO and SOILHGT. [url]https://confluence.ecmwf.int/pages/viewpage.action?pageId=82870405#ERA5:datadocumentation-Table1[/url] says it’s available.

Back when I first stated using ERA-Interim for WRF I constructed an invariant SOILGEO file, so why not for ERA5?

Xin Zhang
In reply to Bart Brashers
Monday, Jul 6, 2020

Thanks, Bart. Nice question!

I can’t find the soil height variable in the ERA5 dataset …

Have you found it on the CDS website?

Regards,

Xin

Du Xin-guan
Monday, Jul 6, 2020

Dear Xin,

When i do ungrib.exe, I can ungrib pressure-level ERA5 data, but I can not ungrib surface ERA5 data. It was said that ‘was expecting a Grib1 file , but this is a Grib2 file. It is possible this is because your GRIBFILE.XXX files are not all of the same type. ‘

I will appreciate your any suggestions.

Du

Say something

Thank you

Your comment has been submitted and will be published once it has been approved.

Click here to see the pull request you generated.

OOPS!

Your comment has not been submitted. Please go back and try again. Thank You!

If this error persists, please open an issue by clicking here.