GRIB: inspecting contents

We will work with a GRIB file containing 6 messages. First we ensure the example file is available, then read the file with from_source().

[1]:
import earthkit.data as ekd
ekd.download_example_file("test6.grib")
[2]:
fs = ekd.from_source("file", "test6.grib")

Using head(), tail() and ls()

All these methods (head(), tail() and ls()) take the same set of keyword arguments:

  • n: number of messages to list

  • keys: the metadata keys to dump

  • extra_keys: extra keys of top of the default set of keys

  • namespace: the ecCodes namespace to use

head()

head() displays the first 5 messages by default:

[3]:
fs.head()
[3]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType
0 ecmf t isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
1 ecmf u isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
2 ecmf v isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
3 ecmf t isobaricInhPa 850 20180801 1200 0 an 0 regular_ll
4 ecmf u isobaricInhPa 850 20180801 1200 0 an 0 regular_ll

The number of fields can be passed as an argument:

[4]:
fs.head(2)
[4]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType
0 ecmf t isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
1 ecmf u isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
[5]:
fs.head(n=2)
[5]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType
0 ecmf t isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
1 ecmf u isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll

The keys can be taken from an ecCodes GRIB namespace:

[6]:
fs.head(namespace="statistics")
[6]:
max min avg sd skew kurt const
0 320.564178 240.564178 279.707036 19.674217 -0.731230 -0.169046 0.0
1 17.713120 -6.286880 -0.382119 5.605310 1.139004 1.018780 0.0
2 11.833481 -16.166519 -0.071281 6.140457 -0.217654 -0.839983 0.0
3 304.539169 232.539169 272.729646 19.241867 -0.998189 0.135718 0.0
4 27.101624 -12.898376 0.339719 8.141047 1.542573 1.864089 0.0
[7]:
fs.head(namespace="parameter")
[7]:
centre paramId units name shortName
0 ecmf 130 K Temperature t
1 ecmf 131 m s**-1 U component of wind u
2 ecmf 132 m s**-1 V component of wind v
3 ecmf 130 K Temperature t
4 ecmf 131 m s**-1 U component of wind u

The list of keys can be prescribed:

[8]:
fs.head(n=2, keys=["bitsPerValue", "packingType"])
[8]:
bitsPerValue packingType
0 4 grid_simple
1 4 grid_simple

The list of keys can also be extended:

[9]:
fs.head(extra_keys="paramId")
[9]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType paramId
0 ecmf t isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll 130
1 ecmf u isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll 131
2 ecmf v isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll 132
3 ecmf t isobaricInhPa 850 20180801 1200 0 an 0 regular_ll 130
4 ecmf u isobaricInhPa 850 20180801 1200 0 an 0 regular_ll 131

tail()

tail() displays the last 5 messages by default:

[10]:
fs.tail(5)
[10]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType
0 ecmf u isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
1 ecmf v isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
2 ecmf t isobaricInhPa 850 20180801 1200 0 an 0 regular_ll
3 ecmf u isobaricInhPa 850 20180801 1200 0 an 0 regular_ll
4 ecmf v isobaricInhPa 850 20180801 1200 0 an 0 regular_ll

ls()

By default ls() lists all the fields:

[11]:
fs.ls()
[11]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType
0 ecmf t isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
1 ecmf u isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
2 ecmf v isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
3 ecmf t isobaricInhPa 850 20180801 1200 0 an 0 regular_ll
4 ecmf u isobaricInhPa 850 20180801 1200 0 an 0 regular_ll
5 ecmf v isobaricInhPa 850 20180801 1200 0 an 0 regular_ll

The number of fields to list can also be specified:

[12]:
fs.ls(2)
[12]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType
0 ecmf t isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
1 ecmf u isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
[13]:
fs.ls(-2)
[13]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType
0 ecmf u isobaricInhPa 850 20180801 1200 0 an 0 regular_ll
1 ecmf v isobaricInhPa 850 20180801 1200 0 an 0 regular_ll

Using describe

We can describe() the whole object:

[14]:
fs.describe()
[14]:
    level date time step paramId class stream type experimentVersionNumber
shortName typeOfLevel                  
t isobaricInhPa 1000,850 20180801 1200 0 130 od oper an 0001
u isobaricInhPa 1000,850 20180801 1200 0 131 od oper an 0001
v isobaricInhPa 1000,850 20180801 1200 0 132 od oper an 0001

We can also describe() a given parameter (defined by shortName or paramId):

[15]:
fs.describe("t")
[15]:
shortName t
typeOfLevel isobaricInhPa
level 1000,850
date 20180801
time 1200
step 0
paramId 130
class od
stream oper
type an
experimentVersionNumber 0001
[16]:
fs.describe(131)
[16]:
shortName u
typeOfLevel isobaricInhPa
level 1000,850
date 20180801
time 1200
step 0
paramId 131
class od
stream oper
type an
experimentVersionNumber 0001

Accessing metadata

metadata() with positional arguments works for both for a field and a fieldlist. Key type qualifiers are allowed to be used.

[17]:
fs.metadata("typeOfLevel")
[17]:
['isobaricInhPa',
 'isobaricInhPa',
 'isobaricInhPa',
 'isobaricInhPa',
 'isobaricInhPa',
 'isobaricInhPa']
[18]:
fs[0].metadata(["typeOfLevel", "level", "centre", "centre"], astype=(None, None, str, int))
[18]:
['isobaricInhPa', 1000, 'ecmf', 98]

For single fields the bracket operator can also be used:

[19]:
fs[0]["param"]
[19]:
't'

Namespace keys can be fetched as a dict for single fields:

[20]:
fs[0].metadata(namespace="parameter")
[20]:
{'centre': 'ecmf',
 'paramId': 130,
 'units': 'K',
 'name': 'Temperature',
 'shortName': 't'}

Inspecting all the namespace keys for a message

dump() gives a tabbed interface to inspect the various namespaces:

[21]:
fs[0].dump()
[21]:
GribFieldMetadata
globalDomaing
GRIBEditionNumber1
eps0
offsetSection00
section0Length8
totalLength150
editionNumber1
WMO0
productionStatusOfProcessedData0
section1Length52
wrongPadding0
table2Version128
centreecmf
centreDescriptionEuropean Centre for Medium-Range Weather Forecasts
generatingProcessIdentifier254
gridDefinition255
indicatorOfParameter130
parameterNameTemperature
parameterUnitsK
indicatorOfTypeOfLevelpl
pressureUnitshPa
typeOfLevelECMFisobaricInhPa
typeOfLevelisobaricInhPa
level1000
yearOfCentury18
month8
day1
hour12
minute0
second0
unitOfTimeRange1
P10
P20
timeRangeIndicator0
numberIncludedInAverage0
numberMissingFromAveragesOrAccumulations0
centuryOfReferenceTimeOfData21
subCentre0
paramIdECMF130
paramId130
cfNameECMFair_temperature
cfNameair_temperature
unitsECMFK
unitsK
nameECMFTemperature
nameTemperature
decimalScaleFactor0
setLocalDefinition0
optimizeScaleFactor0
dataDate20180801
year2018
dataTime1200
julianDay2458332.0
stepUnits1
stepTypeinstant
stepRange0
startStep0
endStep0
marsParam130.128
validityDate20180801
validityTime1200
validityDateTime2458331.5083333333
deleteLocalDefinition0
localUsePresent1
reservedNeedNotBePresent['']
localDefinitionNumber1
GRIBEXSection1Problem0
marsClassod
marsTypean
marsStreamoper
experimentVersionNumber0001
perturbationNumber0
numberOfForecastsInEnsemble0
padding_local1_100
grib2LocalSectionNumber1
localExtensionPadding
_xNone
section1Padding
shortNameECMFt
shortNamet
cfVarNameECMFt
cfVarNamet
ifsParam130
stepTypeForConversionunknown
md5Section13ae6b1f6f34f431c6134c40ec42f27fa
md5Product54697e1d910c88b76a8759b67e5c7a9c
paramIdForConversion0
gridDescriptionSectionPresent1
bitmapPresent0
angleSubdivisions1000
section2Length32
radius6367470
numberOfVerticalCoordinateValues0
neitherPresent255
pvlLocation255
dataRepresentationType0
gridDefinitionDescriptionLatitude/Longitude Grid
gridDefinitionTemplateNumber0
Ni12
Nj7
latitudeOfFirstGridPoint90000
latitudeOfFirstGridPointInDegrees90.0
longitudeOfFirstGridPoint0
longitudeOfFirstGridPointInDegrees0.0
resolutionAndComponentFlags128
ijDirectionIncrementGiven1
earthIsOblate0
resolutionAndComponentFlags30
resolutionAndComponentFlags40
uvRelativeToGrid0
resolutionAndComponentFlags60
resolutionAndComponentFlags70
resolutionAndComponentFlags80
latitudeOfLastGridPoint-90000
latitudeOfLastGridPointInDegrees-90.0
longitudeOfLastGridPoint330000
longitudeOfLastGridPointInDegrees330.0
iDirectionIncrement30000
jDirectionIncrement30000
isGridded1
scanningMode0
iScansNegatively0
jScansPositively0
jPointsAreConsecutive0
alternativeRowScanning0
iScansPositively1
jScansNegatively1
scanningMode40
scanningMode50
scanningMode60
scanningMode70
scanningMode80
swapScanningAlternativeRows0
jDirectionIncrementInDegrees30.0
iDirectionIncrementInDegrees30.0
numberOfDataPoints84
numberOfValues84
zeros
PVPresent0
padding_sec2_2
PLPresent0
padding_sec2_1
deletePV1
padding_sec2_3
md5Section2e09e4d6171c0ac85da1d256b2f8acf88
isSpectral0
lengthOfHeaders85
md5Headers9160fb809a9d7b1efc95163bf36e6b51
missingValue9999
tableReference0
section4Length54
halfByte8
dataFlag8
binaryScaleFactor3
referenceValue240.56417846679688
referenceValueError1.52587890625e-05
sphericalHarmonics0
complexPacking0
integerPointValues0
additionalFlagPresent0
orderOfSPD2
boustrophedonic0
hideThis0
packingTypegrid_simple
bitsPerValue4
constantFieldHalfByte8
bitMapIndicator255
numberOfCodedValues84
packingError4.000007629394531
unpackedError1.52587890625e-05
maximum320.5641784667969
minimum240.56417846679688
average279.70703560965404
standardDeviation19.67421739058438
skewness-0.7312302105044429
kurtosis-0.16904561574741717
isConstant0.0
numberOfMissing0
dataLength5
changeDecimalPrecision0
decimalPrecision0
bitsPerValueAndRepack4
setPackingTypegrid_simple
scaleValuesBy1.0
offsetValuesBy0.0
gridTyperegular_ll
getNumberOfValues84
padding_sec4_1
md5Section47ea3331d80a962b5dc99276b76451eac
section5Length4
77777777
edition1
centreecmf
typeOfLevelisobaricInhPa
level1000
dataDate20180801
stepRange0
dataTypean
shortNamet
packingTypegrid_simple
gridTyperegular_ll
bitmapPresent0
Ni12
Nj7
latitudeOfFirstGridPointInDegrees90.0
longitudeOfFirstGridPointInDegrees0.0
latitudeOfLastGridPointInDegrees-90.0
longitudeOfLastGridPointInDegrees330.0
iScansNegatively0
jScansPositively0
jPointsAreConsecutive0
jDirectionIncrementInDegrees30.0
iDirectionIncrementInDegrees30.0
gridTyperegular_ll
domaing
levtypepl
levelist1000
date20180801
time1200
step0
paramt
classod
typean
streamoper
expver0001
centreecmf
paramId130
unitsK
nameTemperature
shortNamet
max320.5641784667969
min240.56417846679688
avg279.70703560965404
sd19.67421739058438
skew-0.7312302105044429
kurt-0.16904561574741717
const0.0
dataDate20180801
dataTime1200
stepUnits1
stepTypeinstant
stepRange0
startStep0
endStep0
validityDate20180801
validityTime1200
typeOfLevelisobaricInhPa
level1000