Description of the desired feature:
The function fetch.resample_grid is heavily used in PolarToolkit for changing a grid's region, spacing, or registration (pixel vs. gridline), or all of the above. During fetch calls of very large grids (e.g. BedMap3, Antarctic-wide and 500m resolution), this resampling is slow, and prone to crashing (maybe a separate issue). Here I'll try and lay out the possible options, and our current implementation, to see if there is a better option.
Current (PyGMT)
- extract grid spacing, region, and registration
- if only changing spacing
- if spacing is being reduced, use
pygmt.grdsample
- if spacing is increasing, first filter grid and new spacing with
pygmt.grdfilter, then use pygmt.grdsample.
- if only changing region
- change region to be nearest multiple of spacing
- cut grid with
pygmt.grdcut
- if only registration changes
- manually change registration with
GMT grdedit
- if changing multiple things
- first cut grid to new region with
pygmt.grdcut
- then change spacing with
pygmt.grdsample with pygmt.grdfilterer if reducing spacing
- set registration during
pygmt.grdsample call.
- updates 1 dataarray/dataset to match to spacing, region, and projection of another
- how do know which is the grid to change?
Rioxarray
- use
rio.clip_box, rio.reproject(resolution=<<spacing>> in a scheme simial to the current PyGMT version.
- lots of useful looking functions and grid attributes
- check reference, region, and spacing of grid:
grid.pixel_ref, grid.extent, grid.dx, grid.dy
- change resolution (by setting shape not spacing):
grid.regrid
- change region:
grid.subset
- reproject a grid to match another and as variable:
transform_and_add
- reproject a grid:
map_gridded_data
- data accessor make code easy to implement
- need to make grid to set the desired resolution with
xarray_regrid.Grid
- handle both finer and coarser resolutions
- similar to xarray-regrid, need to first create a grid with the desired region/spacing
- auto-loops over variables of dataset
- can save the regridder weights as a netcdf for future use! make regridding very fast
- seems a bit heavy on boilerplate code, but if it's in the backend of PolarToolkit then that is fine.
Description of the desired feature:
The function
fetch.resample_gridis heavily used in PolarToolkit for changing a grid's region, spacing, or registration (pixel vs. gridline), or all of the above. During fetch calls of very large grids (e.g. BedMap3, Antarctic-wide and 500m resolution), this resampling is slow, and prone to crashing (maybe a separate issue). Here I'll try and lay out the possible options, and our current implementation, to see if there is a better option.Current (PyGMT)
pygmt.grdsamplepygmt.grdfilter, then usepygmt.grdsample.pygmt.grdcutGMT grdeditpygmt.grdcutpygmt.grdsamplewithpygmt.grdfiltererif reducing spacingpygmt.grdsamplecall.Rioxarray
rio.reproject_matchRioxarray
rio.clip_box,rio.reproject(resolution=<<spacing>>in a scheme simial to the current PyGMT version.Salem
grid.pixel_ref,grid.extent,grid.dx,grid.dygrid.regridgrid.subsettransform_and_addmap_gridded_dataxarray-regrid
xarray_regrid.GridxESMF
Pyresample