GRIB: missing values

We read a GRIB file containing 2 messages with missing values. 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]:
fs = ekd.from_source("file", "missing.grib")
[3]:
fs.ls()
[3]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType
0 ecmf 2t surface 0 20200513 1200 0 an 0 regular_ll
1 ecmf msl surface 0 20200513 1200 0 an 0 regular_ll

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

[4]:
fs.metadata("bitmapPresent")
[4]:
[1, 1]
[5]:
fs.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 fs:
    v = f.values
    print(f"Number of nans={np.count_nonzero(np.isnan(v))}")
Number of nans=142
Number of nans=13