Look into ndpyramid#

import xarray as xr
from dask.distributed import Client, LocalCluster
import rioxarray
from ndpyramid import pyramid_coarsen, pyramid_reproject, pyramid_regrid
import matplotlib.pyplot as plt
cluster = LocalCluster()
client = Client(cluster)
client
2022-04-28 08:25:36,270 - distributed.diskutils - INFO - Found stale lock file and directory '/Users/matthewiannucci/Developer/restful-grids/pyramid/dask-worker-space/worker-p6iu6q93', purging
2022-04-28 08:25:36,270 - distributed.diskutils - INFO - Found stale lock file and directory '/Users/matthewiannucci/Developer/restful-grids/pyramid/dask-worker-space/worker-031c5o2j', purging
2022-04-28 08:25:36,271 - distributed.diskutils - INFO - Found stale lock file and directory '/Users/matthewiannucci/Developer/restful-grids/pyramid/dask-worker-space/worker-2wr270ul', purging
2022-04-28 08:25:36,271 - distributed.diskutils - INFO - Found stale lock file and directory '/Users/matthewiannucci/Developer/restful-grids/pyramid/dask-worker-space/worker-lu43oi4d', purging

Client

Client-b07232e0-c6f6-11ec-af44-acde48001122

Connection method: Cluster object Cluster type: distributed.LocalCluster
Dashboard: http://127.0.0.1:8787/status

Cluster Info

Load the gfs wave dataset#

ds = xr.open_dataset("s3://ioos-code-sprint-2022/gfs-wave.zarr",
                     engine='zarr',
                     storage_options={"anon":True})
#ds.rio.write_crs(4326)

Coarsen the dataset, and access via ndpyramid#

# make a coarsened pyramid]
#pyramid = pyramid_coarsen(ds, factors=[16, 8, 4, 3, 2, 1], dims=['latitude', 'longitude'], boundary='trim')

# make a reprojected (EPSG:4326) pyramid
ds = ds.rio.write_crs('EPSG:4326')
pyramid = pyramid_reproject(ds['hs'], levels=2)


# write the pyramid to zarr
pyramid.to_zarr('gfs-wave-resampled')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/matthewiannucci/Developer/restful-grids/pyramid/test-ndpyramid.ipynb Cell 7' in <cell line: 6>()
      <a href='vscode-notebook-cell:/Users/matthewiannucci/Developer/restful-grids/pyramid/test-ndpyramid.ipynb#ch0000006?line=0'>1</a> # make a coarsened pyramid]
      <a href='vscode-notebook-cell:/Users/matthewiannucci/Developer/restful-grids/pyramid/test-ndpyramid.ipynb#ch0000006?line=1'>2</a> #pyramid = pyramid_coarsen(ds, factors=[16, 8, 4, 3, 2, 1], dims=['latitude', 'longitude'], boundary='trim')
      <a href='vscode-notebook-cell:/Users/matthewiannucci/Developer/restful-grids/pyramid/test-ndpyramid.ipynb#ch0000006?line=2'>3</a> 
      <a href='vscode-notebook-cell:/Users/matthewiannucci/Developer/restful-grids/pyramid/test-ndpyramid.ipynb#ch0000006?line=3'>4</a> # make a reprojected (EPSG:4326) pyramid
      <a href='vscode-notebook-cell:/Users/matthewiannucci/Developer/restful-grids/pyramid/test-ndpyramid.ipynb#ch0000006?line=4'>5</a> ds = ds.rio.write_crs('EPSG:4326')
----> <a href='vscode-notebook-cell:/Users/matthewiannucci/Developer/restful-grids/pyramid/test-ndpyramid.ipynb#ch0000006?line=5'>6</a> pyramid = pyramid_reproject(ds, levels=2)
      <a href='vscode-notebook-cell:/Users/matthewiannucci/Developer/restful-grids/pyramid/test-ndpyramid.ipynb#ch0000006?line=8'>9</a> # write the pyramid to zarr
     <a href='vscode-notebook-cell:/Users/matthewiannucci/Developer/restful-grids/pyramid/test-ndpyramid.ipynb#ch0000006?line=9'>10</a> pyramid.to_zarr('gfs-wave-resampled')

File ~/Developer/restful-grids/env/lib/python3.9/site-packages/ndpyramid/core.py:135, in pyramid_reproject(ds, levels, pixels_per_tile, other_chunks, resampling, extra_dim)
    <a href='file:///Users/matthewiannucci/Developer/restful-grids/env/lib/python3.9/site-packages/ndpyramid/core.py?line=132'>133</a> if len(da.shape) == 4:
    <a href='file:///Users/matthewiannucci/Developer/restful-grids/env/lib/python3.9/site-packages/ndpyramid/core.py?line=133'>134</a>     if extra_dim is None:
--> <a href='file:///Users/matthewiannucci/Developer/restful-grids/env/lib/python3.9/site-packages/ndpyramid/core.py?line=134'>135</a>         raise ValueError("must specify 'extra_dim' to iterate over 4d data")
    <a href='file:///Users/matthewiannucci/Developer/restful-grids/env/lib/python3.9/site-packages/ndpyramid/core.py?line=135'>136</a>     da_all = []
    <a href='file:///Users/matthewiannucci/Developer/restful-grids/env/lib/python3.9/site-packages/ndpyramid/core.py?line=136'>137</a>     for index in ds[extra_dim]:

ValueError: must specify 'extra_dim' to iterate over 4d data

Visualize the Pyramid#

for child in pyramid.children:
    child.ds.u.isel(time=0).plot()
    plt.show()
    plt.close()
../_images/test-ndpyramid_8_0.png ../_images/test-ndpyramid_8_1.png ../_images/test-ndpyramid_8_2.png ../_images/test-ndpyramid_8_3.png ../_images/test-ndpyramid_8_4.png ../_images/test-ndpyramid_8_5.png