toad.regridding.base

Classes

BaseRegridder()

Abstract base class for spatial regridders in TOAD.

class toad.regridding.base.BaseRegridder

Bases: ABC

Abstract base class for spatial regridders in TOAD.

Every regridder must provide:
  • regrid(): forward mapping from original grid to regridded coordinates

  • regrid_clusters_back(): inverse mapping from regridded labels to original grid

  • map_orig_to_regrid(): direct spatial index mapping without resampling

The mapping method is lightweight and required for consensus-based workflows.

abstractmethod map_orig_to_regrid(coords_2d)

Lightweight mapping from original spatial points → regridded index.

This must not modify the data or allocate giant grids. Only spatial coordinates (e.g. lat/lon or x/y) are required.

Parameters:

coords_2d (ndarray) – Array (N, 2) containing spatial coord pairs.

Returns:

Array (N,) of integer indices into the regridded space.

Return type:

ndarray

Example

hp_idx = map_orig_to_regrid(np.column_stack([lat, lon]))

abstractmethod regrid(coords, weights, space_dims_size)

Regrid per-point values into a new coordinate system.

Parameters:
  • coords (ndarray) – Array (N, 3) containing (time, lat, lon) or similar spatial coords.

  • weights (ndarray) – Array (N,) containing scalar values to aggregate/interpolate.

  • space_dims_size (tuple[int, int]) – Original grid shape as (ny, nx).

Returns:

Array (N’, 3) of regridded (time, lat, lon) coordinates. weights_regrid: Array (N’,) of aggregated/interpolated weights.

Return type:

coords_regrid

abstractmethod regrid_clusters_back(cluster_labels)

Project cluster labels from regridded space back to original grid.

Parameters:

cluster_labels (ndarray) – Array (N’,) of labels corresponding to regridded coords.

Returns:

Array (N,) of labels aligned with original grid points.

Return type:

ndarray