verde.project_grid#
- verde.project_grid(grid, projection, method='linear', antialias=True, **kwargs)[source]#
Apply the given map projection to a grid and re-sample it.
Creates a new grid in the projected coordinates by interpolating the original values using the chosen method (linear by default). Before interpolation, apply a blocked mean operation (
BlockReduce
) to avoid aliasing when the projected coordinates become oversampled in some regions (which would cause the interpolation to down-sample the original data). For example, applying a polar projection results in oversampled data close to the pole.Points that fall outside the convex hull of the original data will be masked (see
convexhull_mask
) since they are not constrained by any data points.Any arguments that can be passed to the
grid
method of Verde gridders can be passed to this function as well. Use this to set a region and spacing (or shape) for the projected grid. The region and spacing must be in projected coordinates.If no region is provided, the bounding box of the projected data will be used. If no spacing or shape is provided, the shape of the input grid will be used for the projected grid.
By default, the
data_names
argument will be set to the name of the data variable of the input grid (if it has been set).Note
The interpolation methods are limited to what is available in Verde and there is only support for single 2D grids. For more sophisticated use cases, you might want to try pyresample instead.
- Parameters:
- grid
xarray.DataArray
A single 2D grid of values. The first dimension is assumed to be the northing/latitude dimension while the second is assumed to be the easting/longitude dimension.
- projection
callable
Should be a callable object (like a function)
projection(easting, northing) -> (proj_easting, proj_northing)
that takes in easting and northing coordinate arrays and returns projected northing and easting coordinate arrays.- method
str
orVerde
gridder
If a string, will use it to create
KNeighbors
,Linear
, orCubic
("nearest"
,"linear"
, or"cubic"
). Otherwise, should be a gridder/estimator object, likeSpline
. Default is"linear"
.- antialiasbool
If True, will run a
BlockReduce
with a mean function to avoid aliasing when the projection results in oversampling of the data in some areas (for example, in polar projections). If False, will not run the blocked mean.
- grid
- Returns:
- projected_grid
xarray.DataArray
The projected grid, interpolated with the given parameters.
- projected_grid