Mesh Transfer#

Sparse weight construction for transferring fields between meshes.

class sphedron.transfer.MeshTransfer(sender: Mesh, receiver: Mesh, method: str = 'local_rbf', k: int = 16, kernel: str = 'thin_plate_spline', degree: int = 1, max_dist: float = None)[source]#

Sparse regridder between two spherical meshes.

Builds a sparse weight matrix W of shape (receiver.num_nodes, sender.num_nodes) so that W @ data transfers values from the sender grid to the receiver grid.

Weights are computed lazily on the first transform() call, or explicitly via build_weights().

Parameters:
  • sender – Source mesh (any Mesh subclass).

  • receiver – Target mesh.

  • method

    Interpolation method.

    • "nearest": 1-nearest-neighbor.

    • "idw": Inverse-distance weighting.

    • "gaussian": Gaussian distance weighting.

    • "barycentric": Barycentric on triangulated faces.

    • "bilinear": Bilinear on quad faces (RectangularMesh sender only).

    • "local_rbf": Local RBF interpolation (default).

  • k – Number of neighbors for kNN-based methods.

  • kernel – RBF kernel name (for "local_rbf").

  • degree – Polynomial augmentation degree (for "local_rbf"). 0 = constant, 1 = linear, 2 = quadratic, etc.

  • max_dist – Maximum neighbor distance. Neighbors beyond this are pruned. Use "auto" for the 90th-percentile heuristic.

Example:

regridder = MeshTransfer(ocean_mesh, target_grid,
                         method="local_rbf", k=16, degree=0)
sst_regridded = regridder.transform(sst_ocean)

Example:

regridder = MeshTransfer(ocean_mesh, target_grid,
                         method="local_rbf", k=16, degree=0)
sst_regridded = regridder.transform(sst_ocean)

# Or use the @ operator
result = regridder @ data

# Access the sparse matrix directly
W = regridder.weights

Attributes

property weights: csr_matrix#

The sparse weight matrix. Built lazily on first access.

Methods

build_weights(method, k, kernel, degree, ...)

Build the sparse interpolation weight matrix.

transform(data)

Regrid data from sender mesh to receiver mesh.

__matmul__(data)

Allow regridder @ data as shorthand for transform().

build_weights(method: str = <object object>, k: int = <object object>, kernel: str = <object object>, degree: int = <object object>, max_dist: float = <object object>) csr_matrix[source]#

Build the sparse interpolation weight matrix.

When called with no arguments, uses the parameters stored on the instance. Any provided argument updates the stored configuration and triggers a rebuild.

Returns:

Sparse CSR matrix of shape shape.

transform(data: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Regrid data from sender mesh to receiver mesh.

Builds the weight matrix lazily on first call.

Parameters:

data – Values on the sender grid. Shape (N,) for a single field, (N, d) for d fields, or (N, ...) for batched data – where N is sender.num_nodes.

Returns:

Interpolated values on the receiver grid, same trailing dimensions as data.

__matmul__(data: ndarray[tuple[Any, ...], dtype[_ScalarT]]) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Allow regridder @ data as shorthand for transform().