Reading multiple files

First we prepare the data.

[1]:
import earthkit.data as ekd
ekd.download_example_file(["test.grib", "test4.grib"])
[2]:
!test -d _grib_dir_no_sql || (mkdir -p _grib_dir_no_sql; cp -f test.grib test4.grib _grib_dir_no_sql/)

Multiple GRIB files can be read in various ways:

Option 1: using wildcards

[3]:
fs = ekd.from_source("file", "test*.grib")
[4]:
len(fs)
[4]:
12
[5]:
fs
[5]:
GribMultiFieldList(GRIBReader(test.grib),GRIBReader(test4.grib),GRIBReader(test6.grib))

Option 2: using a list

[6]:
fs = ekd.from_source("file", ["test.grib", "test4.grib"])
[7]:
len(fs)
[7]:
6
[8]:
fs
[8]:
GribMultiFieldList(GRIBReader(test.grib),GRIBReader(test4.grib))

Option 3: reading all files in a directory

[9]:
fs = ekd.from_source("file", "./_grib_dir_no_sql")
[10]:
len(fs)
[10]:
6
[11]:
fs
[11]:
GribMultiFieldList(GRIBReader(./_grib_dir_no_sql/test.grib),GRIBReader(./_grib_dir_no_sql/test4.grib))

Working with the object

The resulting GRIB object behaves in the same way as if it was created from a single file:

[12]:
fs.ls()
[12]:
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
2 ecmf t isobaricInhPa 500 20070101 1200 0 an 0 regular_ll
3 ecmf z isobaricInhPa 500 20070101 1200 0 an 0 regular_ll
4 ecmf t isobaricInhPa 850 20070101 1200 0 an 0 regular_ll
5 ecmf z isobaricInhPa 850 20070101 1200 0 an 0 regular_ll
[13]:
fs[2]
[13]:
GribField(t,500,20070101,1200,0,0)
[14]:
g = fs[1:6]
g.ls()
[14]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType
0 ecmf msl surface 0 20200513 1200 0 an 0 regular_ll
1 ecmf t isobaricInhPa 500 20070101 1200 0 an 0 regular_ll
2 ecmf z isobaricInhPa 500 20070101 1200 0 an 0 regular_ll
3 ecmf t isobaricInhPa 850 20070101 1200 0 an 0 regular_ll
4 ecmf z isobaricInhPa 850 20070101 1200 0 an 0 regular_ll
[15]:
g = fs[3:6].sel(param="z").order_by("level")
g.ls()
[15]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType
0 ecmf z isobaricInhPa 500 20070101 1200 0 an 0 regular_ll
1 ecmf z isobaricInhPa 850 20070101 1200 0 an 0 regular_ll