GRIB: missing valuesΒΆ

We read a GRIB file containing 2 messages with missing values using from_source(). First we ensure the example file is available.

[1]:
import numpy as np

import earthkit.data as ekd

ekd.download_example_file("missing.grib")
[2]:
ds = ekd.from_source("file", "missing.grib").to_fieldlist()
[3]:
ds.ls()
[3]:
parameter.variable time.valid_datetime time.base_datetime time.step vertical.level vertical.level_type ensemble.member geography.grid_type
0 2t 2020-05-13 12:00:00 2020-05-13 12:00:00 0 days 0 surface 0 regular_ll
1 msl 2020-05-13 12:00:00 2020-05-13 12:00:00 0 days 0 surface 0 regular_ll

When can see how many missing values we have by inspecting the metadata:

[4]:
ds.metadata("bitmapPresent")
[4]:
[1, 1]
[5]:
ds.metadata("numberOfMissingValues")
[5]:
[142, 13]

When data values are extracted as numpy arrays missing values are automatically replaced by np.nan:

[6]:
for f in ds:
    v = f.values
    print(f"Number of nans={np.count_nonzero(np.isnan(v))}")
Number of nans=142
Number of nans=13