Reading files

[1]:
import earthkit.data as ekd

First, we ensure the example files used for this notebook are avaliable.

[2]:
ekd.download_example_file(
    ["test.grib", "test4.grib", "test6.grib", "test.nc"])

Files can be read by from_source as a “file” source. The resulting object depends on the file type and chosen to best represent the the input data.

[3]:
# grib data
ds = ekd.from_source("file", "test.grib")
ds.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
[4]:
# netcdf data
ds = ekd.from_source("file", "test.nc")
ds.ls()
/Users/cgr/git/earthkit-data/src/earthkit/data/readers/netcdf/fieldlist.py:318: FutureWarning: In a future version of xarray decode_timedelta will default to False rather than None. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.
  return xr.open_dataset(self.path_or_url)
[4]:
variable level valid_datetime units
0 t2m None 2020-05-13T12:00:00 K
1 msl None 2020-05-13T12:00:00 Pa

See the other file related notebooks for more details:

Reading files using patterns

The file source can also be specified by using patterns. In the example below when pattern “id” is substituted it will match two files: test4.grib and test6.grib:

[5]:
ds = ekd.from_source("file-pattern", "./test{id}.grib",
                        {"id": [4, 6]})
ds.ls()
[5]:
centre shortName typeOfLevel level dataDate dataTime stepRange dataType number gridType
0 ecmf t isobaricInhPa 500 20070101 1200 0 an 0 regular_ll
1 ecmf z isobaricInhPa 500 20070101 1200 0 an 0 regular_ll
2 ecmf t isobaricInhPa 850 20070101 1200 0 an 0 regular_ll
3 ecmf z isobaricInhPa 850 20070101 1200 0 an 0 regular_ll
4 ecmf t isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
5 ecmf u isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
6 ecmf v isobaricInhPa 1000 20180801 1200 0 an 0 regular_ll
7 ecmf t isobaricInhPa 850 20180801 1200 0 an 0 regular_ll
8 ecmf u isobaricInhPa 850 20180801 1200 0 an 0 regular_ll
9 ecmf v isobaricInhPa 850 20180801 1200 0 an 0 regular_ll
[ ]: