rex.utilities.regridder.CachedRegridder

class CachedRegridder(cache_pattern, min_distance=1e-12)[source]

Bases: _InterpolationMixin

Interpolate from one grid to another using cached dists and inds.

Parameters:
  • cache_pattern (str) – Filepath pattern for cached distances and indices to load. Should be of the form './{array_name}.pkl' where array_name will internally be replaced with either 'distances' or 'indices'.’

  • min_distance (float, optional) – Minimum distance to use for inverse-weighted distances calculation to avoid diving by 0. By default, 1e-12.

Methods

build_cache(cache_pattern, *args, **kwargs)

Cache distances and indices from ball tree query.

load_cache(cache_pattern)

Load cached indices and distances from ball tree query.

Attributes

weights

Weights used for regridding.

static load_cache(cache_pattern)[source]

Load cached indices and distances from ball tree query.

Parameters:

cache_pattern (str) – Filepath pattern for cached distances and indices to load. Should be of the form './{array_name}.pkl' where array_name will internally be replaced with either 'distances' or 'indices'.

Returns:

distances, indices (ndarray) – Arrays of distances and indices output by the ball tree.

classmethod build_cache(cache_pattern, *args, **kwargs)[source]

Cache distances and indices from ball tree query.

Parameters:
  • cache_pattern (str) – Filepath pattern used to cache distances and indices. Should be of the form './{array_name}.pkl' where array_name will internally be replaced with either 'distances' or 'indices'.

  • *args, **kwargs – Arguments followed by keyword arguments that can be used to initialize Regridder. The Regridder instance will generate the distance and index arrays to be cached.

__call__(data)

Regrid given spatiotemporal data over entire grid.

Parameters:

data (numpy.ndarray | dask.core.array.Array) – Spatiotemporal data to regrid to target_meta. Data can be flattened in the spatial dimension to match the target_meta or be in a 2D spatial grid, e.g.: (spatial, temporal) or (spatial_1, spatial_2, temporal)

Returns:

out (numpy.ndarray | dask.core.array.Array) – Flattened regridded spatiotemporal data (spatial, temporal)

property weights

Weights used for regridding.

Type:

ndarray