Prepare project_grid for the future grid method in Verde gridders
See original GitHub issueDescription
Since Verde v2.0.0 the grid
method of every gridder in Verde will not take the spacing
, shape
or region
arguments.
They will not create the desired grid, but will be able to take the coordinates of a predefined regular grid (see #326 for more details).
Currently the verde.project_grid
makes use of the Chain.grid
method to produce the projected and interpolated grid. During this step, the output grid is generated by passing the soon-to-be-deprecated region
and spacing
arguments. This raises a FutureWarning
when calling project_grid
that isn’t due to any misuse from the user.
Here I copy a working example that reproduces this problem:
import pyproj
import ensaio
import xarray as xr
import verde as vd
# Download the data using ensaio
fname = ensaio.fetch_earth_topography(version=1)
# Load it with xarray
grid = xr.load_dataarray(fname)
# Crop it to a smaller region
region = (-70, -67, -45, -40)
grid = grid.sel(longitude=slice(*region[:2]), latitude=slice(*region[2:]))
# Define a projection
projection = pyproj.Proj(proj="merc", lat_ts=grid.latitude.values.mean())
# Project the grid
grid_proj = vd.project_grid(grid, projection)
/home/santi/git/verde/verde/base/base_classes.py:463: FutureWarning: The 'spacing', 'shape' and 'region' arguments will be removed in Verde v2.0.0. Please use the 'verde.grid_coordinates' function to define grid coordinates and pass them as the 'coordinates' argument.
warnings.warn(
How to solve this?
We need verde.project_grid
to predefine the output grid through the verde.grid_coordinates
and use the Chain.grid
method by passing the coordinates
argument with the coordinates of this predefined grid.
This change wouldn’t need significant tests, just one that checks that no FutureWarning
is raised after using it. We can do so with pytest.warns
(see Warnings Capture for further details and examples).
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
You’re right! The
interpolator.grid
method creates the xarray object, so grid coordinates can be 2D arrays obtained directly fromgrid_coordinates
. Editing the issue description…👍🏽 will do