Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Using BUFR

earthkit-data-logo

Using BUFR

In this notebook you will see how to:

  • inspect BUFR data

  • extract BUFR data into a Pandas dataframe

Getting the data

First we read some BUFR data from disk with from_source.

import earthkit.data as ekd

d = ekd.from_source("sample", "synop_10.bufr")
d

Featurelists and BUFR messages

To inspect BUFR data we need to convert it into a featureslist. It is a similar object to a fieldList, but it is an iterable of “features”, where a “feature” can be anything. In a BUFR featurelist each feature is a BUFR message.

fl = d.to_featurelist()

The file contains 10 messages.

len(fl)

With the ls() method we can get a summary of the messages (using header keys).

fl.ls()

BUFR messages

# f is the first message in the featurelist
f = fl[0]
f

To dump the contents of a message (as a tree view) use describe().

f.describe()

Subsetting

With sel() we can select the messages matching the given metadata conditions.

fl1 = fl.sel(dataSubCategory=1, ident=[60545, 48352])
fl1.ls()

Converting to pandas

BUFR data can be extracted into a Pandas dataframe using to_pandas(), which passes all the arguments to the read_bufr() method from pdbufr.

df = fl.to_pandas(columns=["latitude", "longitude",
                           "heightOfStation","airTemperatureAt2M"])
df
df = fl.to_pandas(reader="synop")
df

Please note it is also possible to call to_pandas() on the input data object “d”. It this case, first the data is converted to a featurelist under the hood, then to_pandas() is called on the featurelist.

df = d.to_pandas(columns=["latitude", "longitude",
                           "heightOfStation","airTemperatureAt2M"])
df

Extra work

Get the “temp_10.bufr” radiosonde BUFR file as a sample and extract the latitude-longitude and the pressure-temperature profile from it for station “01415”.

Hints:

  • use the “indent” key for the station ID

  • use the “filters” kwarg in to_pandas() (for details about the format see here)

  • use the “pressure” and “airTemperature” keys (use describe() to inspect the radiosonde message structure)