carbonplan/ndpyramid

Standardize metadata between pyramid generation methods

Closed this issue · 0 comments

There are some differences between the metadata produced by pyramid_reproject, pyramid_coarsen, and pyramid_regrid. It would be good to align the metadata between these functions and check for agreement with the current ndpyramid metadata schema. For example, pyramid_coarsen adds local variables to the recorded kwargs, whereas pyramid_coarsen and pyramid_reproject do not. pyramid_coarsen also lacks the multiscales.datasets.pixels_per_tile attribute.

pyramid_coarsen

import xarray as xr
import rioxarray
from ndpyramid import pyramid_coarsen, pyramid_reproject, pyramid_regrid

# load a sample xarray.Dataset
ds = xr.tutorial.load_dataset('air_temperature')
# make a coarsened pyramid
coarsened = pyramid_coarsen(ds, factors=[16, 8, 4, 3, 2, 1], dims=['lat', 'lon'], boundary='trim')
coarsened.attrs
{'multiscales': [{'datasets': [{'path': '0'},
    {'path': '1'},
    {'path': '2'},
    {'path': '3'},
    {'path': '4'},
    {'path': '5'}],
   'type': 'reduce',
   'metadata': {'method': 'pyramid_coarsen',
    'version': '0.1.0.post32+g56e0d0d.d20240319',
    'args': [],
    'kwargs': {'factors': [16, 8, 4, 3, 2, 1],
     'dims': ['lat', 'lon'],
     'kwargs': {'boundary': 'trim', 'lat': 1, 'lon': 1}}}}]}

pyramid_reproject

# make a reprojected (EPSG:3857) pyramid
ds = ds.rio.write_crs('EPSG:4326')
reprojected = pyramid_reproject(ds, levels=2)
reprojected.attrs
{'multiscales': [{'datasets': [{'path': '0',
     'pixels_per_tile': 128,
     'crs': 'EPSG:3857'},
    {'path': '1', 'pixels_per_tile': 128, 'crs': 'EPSG:3857'}],
   'type': 'reduce',
   'metadata': {'method': 'pyramid_reproject',
    'version': '0.1.0.post32+g56e0d0d.d20240319',
    'args': [],
    'kwargs': {'levels': 2, 'pixels_per_tile': 128}}}],
 'title': 'multiscale data pyramid',
 'version': '0.1.0.post32+g56e0d0d.d20240319'}

pyramid_regrid

regridded = pyramid_regrid(ds, levels=2)
regridded.attrs
{'multiscales': [{'datasets': [{'path': '0',
     'pixels_per_tile': 128,
     'crs': 'EPSG:3857'},
    {'path': '1', 'pixels_per_tile': 128, 'crs': 'EPSG:3857'}],
   'type': 'reduce',
   'metadata': {'method': 'pyramid_regrid',
    'version': '0.1.0.post32+g56e0d0d.d20240319',
    'args': [],
    'kwargs': {'projection': 'web-mercator',
     'levels': 2,
     'method': 'bilinear',
     'regridder_kws': {'periodic': True},
     'regridder_apply_kws': None,
     'other_chunks': None,
     'pixels_per_tile': 128}}}],
 'title': 'multiscale data pyramid',
 'version': '0.1.0.post32+g56e0d0d.d20240319'}