Versions Compared

Key

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

...

  1. Download 2m temperature from the Copernicus Climate Change Service (C3S)'s Climate Data Store (CDS) and save the data as file t2m_20000801.grib. In this example, selections are set as below:
    1. Dataset: ERA5 hourly data on single levels from 2000 to 2017 (you may see different years as new data is released)
    2. Parameter    : 2m temperature
    3. Product type: Reanalysis
    4. Year                  : 2000
    5. Month              : August
    6. Day                    : 01
    7. Time                 : 06:00, 12:00 and 18:00
    8. Format             : GRIB
  2. Check the GRIB file by issuing command grib_ls -P time t2m_20000801.grib, you should see three GRIB messages in the file at three different times: 600, 1200, 1800 as shown below. Remember three time values were selected in step 1. Option -P time shows key "time", typing grib_ls for help.

    Code Block
    languagebashtext
    t2m_20000801.grib
    time         edition      centre       typeOfLevel  level        dataDate     stepRange    dataType     shortName    packingType  gridType     
    600          1            ecmf         surface      0            20000801     0            an           2t           grid_simple  regular_ll  
    1200         1            ecmf         surface      0            20000801     0            an           2t           grid_simple  regular_ll  
    1800         1            ecmf         surface      0            20000801     0            an           2t           grid_simple  regular_ll  
    3 of 3 messages in t2m_20000801.grib
    
    3 of 3 total messages in 1 files


  3. Say I want to extract lat, lon, 2t (2m temperature) at time = 12:00 from the GRIB file. Run command grib_get_data -w time=1200 t2m_20000801.grib > temp.csv and you will get a file containing data like below. Option -w time=1200 filters data for time = 12:00 only, typing grib_get_data for help.

    Code Block
    languagebashtext
    Latitude, Longitude, Value
       90.000    0.000 2.7346786499e+02
       90.000    0.250 2.7346786499e+02
       90.000    0.500 2.7346786499e+02
       90.000    0.750 2.7346786499e+02
    ...


  4. Format the CSV file. You may use script below.

    Code Block
    languagebashpy
    #!/usr/bin/env python
    """
    Save as format.py, then run "python format.py".
     
    Input file : temp.csv
    Output file: t2m_20000801.csv
    """
    with open('temp.csv', 'r') as f_in, open('t2m_20000801.csv', 'w') as f_out:
        f_out.write(next(f_in))
        [f_out.write(','.join(line.split()) + '\n') for line in f_in]


  5. You have a CSV file t2m_20000801.csv, which is ready to be imported in Excel. Notice there are over 1 million records in the file! You may now want to extract data for time=600 and 1800.

    Code Block
    languagebash
    Latitude, Longitude, Value
    90.000,0.000,2.7346786499e+02
    90.000,0.250,2.7346786499e+02
    90.000,0.500,2.7346786499e+02
    90.000,0.750,2.7346786499e+02
    ...


...