Interpolation API

enstools.interpolation.downsize(arr, fac)

Reduce resolution of an array by neighbourhood averaging - 2D averaging of fac x fac element

Parameters:
arrxarray.DataArray or np.ndarray

array to downsize by neighbourhood averaging

facint

factor of downsizing, 2D averaging of fac x fac element

Returns:
xarray.DataArray or np.ndarray
class enstools.interpolation.model2pressure(src_p, dst_p, vertical_dim=None)

Interpolator object for the interpolation from model to pressure level

Methods

__call__(data)

perform the actual interpolation

enstools.interpolation.nearest_neighbour(src_lon, src_lat, dst_lon, dst_lat, src_grid='regular', dst_grid='unstructured', npoints=1, method='mean')

Find the coordinates of station locations within gridded model data. Supported are 1d- and 2d-coordinates of regular grids (e.g. rotated lat-lon) or ‘unstructured’ grids like the ICON grid.

Parameters:
src_lonnp.ndarray or xarray.DataArray

1d or 2d coordinate in x-direction of the source grid

src_latnp.ndarray or xarray.DataArray

1d or 2d coordinate in y-direction of the source grid

dst_lonnp.ndarray or xarray.DataArray

1d coordinate in x-direction of the station locations

dst_latnp.ndarray or xarray.DataArray

1d coordinate in y-direction of the station locations

src_grid{‘regular’, ‘unstructured’}

Type of input grid. Possible values are: “regular”: a regular grid with 1d or 2d coordinates. 1d-coordinates are internally converted to 2d- coordinates using meshgrid. This selection is the default. “unstructured”: The grid is given as a 1d list of points (e.g., station data or ICON model output).

dst_grid{‘regular’, ‘unstructured’}

Type of output grid. Possible values are: “regular”: a regular grid with 1d coordinates. “unstructured”: The grid is given as a 1d list of points (e.g., station data or ICON model output). This selection is the default.

npointsint

Number of nearest points to be used in the interpolation. For a regular grid useful values are 4 or 12. For data on the ICON grid 3 or 6 might be used. The actual geometry of the grid is not taken into account. The points are selected based merely on distance.

method{‘mean’, ‘d-mean’}

“mean” : the mean value of the neighbour points is used with equal weight. “d-mean”: each point is weighted by the reciprocal of the squared distance. The minimum distance within this calculation is half of the mean grid spacing.

Returns:
NearestNeighbourInterpolator

callable interpolator object. Each call returns interpolated values

Examples

>>> import numpy
>>> if numpy.__version__ > "1.13.9": numpy.set_printoptions(legacy="1.13")      # numpy version independent printing
>>> lon = numpy.arange(10)
>>> lat = numpy.arange(15)
>>> gridded_data = numpy.zeros((15, 10))
>>> gridded_data[8, 4] = 3
>>> f = nearest_neighbour(lon, lat, 4.4, 7.6)
>>> f(gridded_data)
<xarray.DataArray 'interpolated' (cell: 1)>
array([ 3.])
Coordinates:
    lat      (cell) float64 7.6
    lon      (cell) float64 4.4
Dimensions without coordinates: cell
Attributes:
    grid_type:    unstructured_grid
    coordinates:  lon lat