Gridlocator

The examples in this chapter use a little script (gridlocator.py) to find grid data associated with the opened model output dataset. This is likely not the final way of doing this, but should be regarded as a quick hack. In case you need to use it, here’s the code:

gridlocator.py
import os
import xarray as xr


def get_grid(ds):
    uri = ds.grid_file_uri
    downloads_prefix = "http://icon-downloads.mpimet.mpg.de/grids/public/"
    if uri.startswith(downloads_prefix):
        local_grid_path = os.path.join(
            "/pool/data/ICON/grids/public", uri[len(downloads_prefix) :]
        )
    else:
        raise NotImplementedError(f"no idea about how to get {uri}")
    return xr.open_dataset(local_grid_path)


def merge_grid(data_ds):
    return xr.merge([data_ds.rename({"ncells": "cell"}), get_grid(data_ds)])