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")
dFeaturelists 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)10With 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]
fBUFRMessage(type=0,subType=1,subsets=1,20230602,120000)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"])
dfdf = fl.to_pandas(reader="synop")
dfPlease 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"])
dfExtra 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)
fl = ekd.from_source("sample", "temp_10.bufr").to_featurelist()
fl.ls()fl[0].describe()df = fl.to_pandas(columns=["latitude", "longitude",
"pressure","airTemperature"],
filters={"ident": "01415"})
df