Versions Compared

Key

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

Encode BUFR SYNOP data provided in CVS format

This page aims to provide some detailed information and best practices to BUFR encode meteorological observations from an ascii file. As an example, we will BUFR encode SYNOP data provided in CVS format utilising BUFR template 307092 which is for sub-hourly observations.

1. Choosing the template

In order to encode meteorological observations in BUFR format, first thing to do is to decide which BUFR template we should use. This can be done by investigating WMO BUFR Table D which provides information on list of common sequences. For example, let’s assume we want to BUFR encode sub-hourly data from an automatic weather station. As you can see from the below given screenshot of Table D, the suitable template for this is 3 07 092 which is BUFR template for surface observations from n-minute period.

Expand
titleClick here to expand Table D screenshot...
Image Added

2. Investigating the template

Next thing to do is to investigate the template to have a better understanding what parameters we can encode with the template. For this, we need to refer to WMO tables which are

Table D defines sequence descriptors which are alias for a sequence of other descriptors. For example, one of the elements within the sequence 3 07 092 is Pressure having table reference value 0 07 004. As you can see from the Table B screenshot below, Table B provides detailed information on this element such as unit, scale, reference value and data width. 

Expand
titleClick here to expand Table B screenshot...

Image Added

This investigation is important to figure out what value to encode for a given key. ecCodes python interface allows us to encode values in the form below:

Code Block
codes_set(ibufr, 'key', value) (or codes_set_array(ibufr, 'key', values) for array of values)

where;

  • ibufr:   id of the message loaded in memory
  • key:     name of the variable key or shortName from Table B
  • value:  value to be encoded

Now let us get some help from ecCodes python interface and command line BUFR tools to investigate the chosen template in more details. Firstly, we can create a BUFR file without encoding data with the template of our choice. 

Code Block
titlecontent of create_bufr.py
#!/usr/bin/env python

# (C) Copyright 1996- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

from eccodes import *

ibufr = codes_bufr_new_from_samples('BUFR4')       # Creates a new valid message id from a BUFR sample
codes_set(ibufr, 'edition', 4)                     # BUFR edition number
codes_set(ibufr, 'masterTableNumber', 0)           # BUFR master table. Zero: standard WMO FM 94 BUFR tables
codes_set(ibufr, 'masterTablesVersionNumber', 31)  # Version number of master table used

ivalues = (307092)                                 # Template to be used 
codes_set(ibufr, 'unexpandedDescriptors', ivalues) # Key name to encode the sequence number is unexpandedDescriptors

fout = open('TM307092.bufr', 'w')                  # Open output file
codes_write(ibufr, fout)                           # Write the message to output file
codes_release(ibufr)                               # Release the BUFR message from memory
fout.close()                                       # Close the file

When the above given code is run (i.e., ./create_bufr.py), we expect to have a BUFR file named TM307092.bufr created.

Info

If the sample BUFR file cannot be found, please check the path used for samples (see the following command to be run for this, and example output):

Step-by-step guide

...

Content by Label
showLabelsfalse
max5
spacesUDOC
showSpacefalse
sortmodified
reversetrue
typepage
cqllabel in ("bufr","encode") and label = "bufr" and label = "encode" and type = "page" and space = "UDOC"
labelsbufr encode

...

Page properties
hiddentrue


Related issues