xugrid.OverlapRegridder#

class xugrid.OverlapRegridder(source: UgridDataArray, target: UgridDataArray, method: str | Callable = 'mean')[source]#

The OverlapRegridder regrids by computing which target faces overlap with which source faces. It stores the area of overlap, which can be used in multiple ways to aggregate the values associated with the source faces.

Currently supported aggregation methods are:

  • "mean"

  • "harmonic_mean"

  • "geometric_mean"

  • "sum"

  • "minimum"

  • "maximum"

  • "mode"

  • "median"

  • "max_overlap"

  • percentiles 5, 10, 25, 50, 75, 90, 95: as "p5", "p10", etc.

Custom aggregation functions are also supported, if they can be compiled by Numba. See the User Guide.

Any percentile method can be created via: method = OverlapRegridder.create_percentile_methode(percentile) See the examples.

Parameters:

Examples

Create an OverlapRegridder to regrid with mean:

>>> regridder = OverlapRegridder(source_grid, target_grid, method="mean")
>>> regridder.regrid(source_data)

Setup a custom percentile method and apply it:

>>> p33_3 = OverlapRegridder.create_percentile_method(33.3)
>>> regridder = OverlapRegridder(source_grid, target_grid, method=p33_3)
>>> regridder.regrid(source_data)
__init__(source: UgridDataArray, target: UgridDataArray, method: str | Callable = 'mean')[source]#

Methods

__init__(source, target[, method])

create_percentile_method(percentile)

from_dataset(dataset)

Reconstruct the regridder from a dataset with source, target indices and weights.

from_weights(weights, target[, method])

regrid(object)

Regrid the data from a DataArray from its old grid topology to the new target topology.

regrid_dataarray(source, source_dims)

to_dataset()

Store the computed weights and target in a dataset for re-use.

weights_as_dataframe()

Return the weights as a three column dataframe:

Attributes

weights