Skip to content

Grib / Kerchunk recipe? #267

@rabernat

Description

@rabernat

The new ECMWF forecast dataset in Azure is a perfect chance for us develop a close but not quite functional type of recipe: indexing and combing a bunch of grib files with Kerchunk.

The current HDFReferenceRecipe class almost does what we need; it just needs to be generalized to permit grib inputs. The kerchunk HRRR example shows how to open grib with kerchunk.

Here is some code to kick things off. cc @cisaacstern, @lsterzinger, @martindurant, @TomAugspurger

from kerchunk.grib2 import scan_grib
from fsspec.implementations.reference import ReferenceFileSystem
import zarr
import xarray as xr

ROOT = 'https://ai4edataeuwest.blob.core.windows.net/ecmwf/'
path = '20220122/18z/0p4-beta/scda/20220122180000-36h-scda-fc.grib2'
url = ROOT + path

storage_options = {}
common = ['time', 'latitude', 'longitude']
%time scan = scan_grib(url, common, storage_options)

rfs = ReferenceFileSystem(scan)
zg = zarr.open_group(rfs.get_mapper(""))
zg.info

%time _ = zg['q'][:]

import xarray as xr
ds = xr.open_zarr(rfs.get_mapper(""), consolidated=False)
print(ds)
<xarray.Dataset>
Dimensions:    (latitude: 451, longitude: 900)
Coordinates:
  * latitude   (latitude) float64 90.0 89.6 89.2 88.8 ... -89.2 -89.6 -90.0
  * longitude  (longitude) float64 -180.0 -179.6 -179.2 ... 178.8 179.2 179.6
Data variables: (12/18)
    d          (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
    gh         (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
    msl        (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
    q          (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
    r          (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
    skt        (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
    ...         ...
    u          (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
    u10        (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
    unknown    (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
    v          (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
    v10        (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
    vo         (latitude, longitude) float32 dask.array<chunksize=(451, 900), meta=np.ndarray>
Attributes:
    Conventions:             CF-1.7
    GRIB_centre:             ecmf
    GRIB_centreDescription:  European Centre for Medium-Range Weather Forecasts
    GRIB_edition:            2
    GRIB_subCentre:          0
    history:                 2022-01-26T04:08 GRIB to CDM+CF via cfgrib-0.9.9...
    institution:             European Centre for Medium-Range Weather Forecasts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions