Gridlocator

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
 1import os
 2import xarray as xr
 3
 4def get_grid(ds):
 5    uri = ds.grid_file_uri
 6    downloads_prefix = "http://icon-downloads.mpimet.mpg.de/grids/public/"
 7    if uri.startswith(downloads_prefix):
 8        local_grid_path = os.path.join("/pool/data/ICON/grids/public", uri[len(downloads_prefix):])
 9    else:
10        raise NotImplementedError(f"no idea about how to get {uri}")
11    return xr.open_dataset(local_grid_path)
12
13def merge_grid(data_ds):
14    return xr.merge([data_ds.rename({"ncells": "cell"}), get_grid(data_ds)])