Skip to content

module regrid

Group of functions to regrid GRIDs to other variations.


function make_subset_and_mask

make_subset_and_mask(source_grid, destination_grid)

Create a subset of the source grid that matches the area of the destination grid.

Args:

  • source_grid (GRID): The source grid instance.
  • destination_grid (GRID): The destination grid instance.

function subset_mask

subset_mask(source_grid, destination_grid, return_masks=False)

Create a mask for the source grid that covers the same area as the destination grid.

Args:

  • source_grid (GRID): The source grid instance.
  • destination_grid (GRID): The destination grid instance.
  • return_masks (bool): If True, return the masks for longitude and latitude.

Returns:

  • tuple: Longitude and latitude masks if return_masks is True.

function make_subset

make_subset(source_grid, subset_lon_bool=None, subset_lat_bool=None)

Create a subset of the source grid based on the provided longitude and latitude masks.

Args:

  • source_grid (GRID): The source grid instance.
  • subset_lon_bool (array-like, optional): Boolean mask for longitude.
  • subset_lat_bool (array-like, optional): Boolean mask for latitude.

Returns:

  • xarray.Dataset: The subsetted dataset.

function is_superset_of

is_superset_of(source_grid, destination_grid, return_indices=False, tolerance=0)

Check if the source grid is a superset of the destination grid.

Args:

  • source_grid (GRID): The source grid instance.
  • destination_grid (GRID): The destination grid instance.
  • return_indices (bool): If True, return indices of the source grid for insetting.
  • tolerance (float): Tolerance for checking bounds.

Returns:

  • tuple: Indices of the source grid if return_indices is True.

Raises:

  • Exception: If the source grid is not a superset of the destination grid.

function make_regridder

make_regridder(
    source_grid,
    destination_grid,
    landsea_mask=None,
    regrid_algorithm="bilinear",
    save_weights=None,
    reload_weights=None,
    periodic=True,
    ignore_degenerate=True,
    unmapped_to_nan=True,
    force=False,
    check_superset=True,
    use_inset=False,
    parallel=False,
)

Create a regridder to transform the source grid onto the destination grid.

Args:

  • source_grid (GRID): The source grid instance.
  • destination_grid (GRID): The destination grid instance.
  • landsea_mask (str): variable name of the landsea mask.
  • regrid_algorithm (str): The regridding method to use (e.g., "bilinear", "conservative").
  • save_weights (str, optional): Path to save the regridding weights.
  • reload_weights (str, optional): Path to load existing regridding weights.
  • periodic (bool): If True, allows periodic boundaries in the regridding process.
  • ignore_degenerate (bool): If True, ignores degenerate grid cells during regridding.
  • unmapped_to_nan (bool): If True, sets unmapped values to NaN in the output.
  • force (bool): If True, skip superset checks and force regridding (equivalent to setting both check_superset and use_inset to False).
  • check_superset (bool): If True, check source is a superset of destination.
  • use_inset (bool): If True, make inset of source. Sometimes results in a type error.

Returns:

  • xesmf.Regridder: The regridder object for transforming data.

function vertical_regrid

vertical_regrid(dataset, vertical_coord, levels, method="linear", kwargs={})

Vertically regrid the dataset.

Regrid onto specified levels using preferred method of regridding (wraps xarray.Dataset.interp). https://docs.xarray.dev/en/stable/generated/xarray.Dataset.interp.html

Args:

  • dataset (xarray.Dataset): object to be verticaly regridded
  • vertical_coord (str): coordinate name of the vertical.
  • levels (array_like): levels to interpolate Dataset onto.
  • method (str): interpolation method (see xr documentation for more info).
  • kwargs (dict): other arguments to pass to xarray.Dataset.interp.

Returns: regridded xarray.Dataset object.


function infill

infill(arr_in, n_iter=None, bathy=None)

Floodfill missing data.

Returns data with any NaNs replaced by iteratively taking the geometric mean of surrounding points until all NaNs are removed or n_inter-ations have been performed. Input data must be 2D and can include a bathymetry array as to provide land barriers to the infilling.

Args:

  • arr_in (ndarray): data array 2D
  • n_iter (int): number of smoothing iterations
  • bathy (ndarray): bathymetry array (land set to zero)

Returns:

  • arr_mod (ndarray): modified data array

function test_wet_points_populated

test_wet_points_populated(regridded_ds, dest_mask)

Test that wet points have been populated after regridding.

Args:

  • regridded_ds (xarray.Dataset): regridded dataset object
  • dest_mask (ndarray): landsea mask for destination grid

Returns:

  • regridded_ds (xarray.Dataset): regridded dataset object, infill function used if data are missing.

function regrid_data

regrid_data(
    source_data,
    dest_grid=None,
    regridder=None,
    regrid_vertically=False,
    vertical_kwargs={},
    dest_grid_mask=None,
)

Regrid the source data onto the destination grid using the specified regridder.

One of dest_grid or regridder must be provided. If no regridder provided then one is made using the dest_grid.

Args:

  • source_data (GRID): The source data instance.
  • dest_grid (GRID, optional): The destination grid instance.
  • regridder (xesmf.Regridder, optional): The regridder object to use.
  • regrid_vertically (bool,optional): whether to regrid vertically
  • vertical_kwargs (dict, optional): dict containing arguments for vertical_regrid function. Must contain "vertical_coord" and "levels" as a minimum.

Returns:

  • xarray.Dataset: The regridded data.

Raises:

  • Exception: If neither dest_grid nor regridder is provided.

This file was automatically generated via lazydocs.