esmf_regrid.experimental.unstructured_scheme module#
Provides an iris interface for unstructured regridding.
- class esmf_regrid.experimental.unstructured_scheme.GridToMeshESMFRegridder(src, tgt, mdtol=None, method=Method.CONSERVATIVE, precomputed_weights=None, src_resolution=None, use_src_mask=False, use_tgt_mask=False, tgt_location=None, esmf_args=None)[source]#
Bases:
_ESMFRegridderRegridder class for rectilinear to unstructured
Cube\ s.Create regridder for conversions between source grid and target mesh.
- Parameters:
src (
iris.cube.Cube) – The rectilinearCubecube providing the source grid.tgt (
iris.cube.Cubeoriris.mesh.MeshXY) – The unstructuredMeshXYproviding the target mesh.mdtol (float, optional) – Tolerance of missing data. The value returned in each element of the returned array will be masked if the fraction of masked data exceeds
mdtol.mdtol=0means no missing data is tolerated whilemdtol=1will mean the resulting element will be masked if and only if all the contributing elements of data are masked. Defaults to 1 for conservative regregridding and 0 for bilinear regridding.method (
Constants.Method, default=Constants.Method.CONSERVATIVE) – The method used to calculate weights.precomputed_weights (
scipy.sparse.spmatrix, optional) – IfNone,esmpywill be used to calculate regridding weights. Otherwise,esmpywill be bypassed andprecomputed_weightswill be used as the regridding weights.src_resolution (int, optional) – If present, represents the amount of latitude slices per cell given to ESMF for calculation. If
src_resolutionis set,srcmust have strictly increasing bounds (bounds may be transposed plus or minus 360 degrees to make the bounds strictly increasing).use_src_mask (
ArrayLikeor bool, default=False) – Either an array representing the cells in the source to ignore, or else a boolean value. If True, this array is taken from the mask on the data insrc. If False, no mask will be taken and all points will be used in weights calculation.use_tgt_mask (
ArrayLikeor bool, default=False) – Either an array representing the cells in the target to ignore, or else a boolean value. If True, this array is taken from the mask on the data intgt. If False, no mask will be taken and all points will be used in weights calculation.tgt_location (str or None, default=None) – Either “face” or “node”. Describes the location for data on the mesh if the target is not a
Cube.esmf_args (dict, optional) – A dictionary of arguments to pass to ESMF.
- Raises:
ValueError – If
use_src_maskoruse_tgt_maskare True while the masks onsrcortgtrespectively are not constant over non-horizontal dimensions.
- class esmf_regrid.experimental.unstructured_scheme.MeshToGridESMFRegridder(src, tgt, mdtol=None, method=Method.CONSERVATIVE, precomputed_weights=None, tgt_resolution=None, use_src_mask=False, use_tgt_mask=False, esmf_args=None)[source]#
Bases:
_ESMFRegridderRegridder class for unstructured to rectilinear
Cube\ s.Create regridder for conversions between source mesh and target grid.
- Parameters:
src_mesh_cube (
iris.cube.Cube) – The unstructuredCubeproviding the source mesh.target_grid_cube (
iris.cube.Cube) – TheCubeproviding the target grid.mdtol (float, optional) – Tolerance of missing data. The value returned in each element of the returned array will be masked if the fraction of masked data exceeds
mdtol.mdtol=0means no missing data is tolerated whilemdtol=1will mean the resulting element will be masked if and only if all the contributing elements of data are masked. Defaults to 1 for conservative regregridding and 0 for bilinear regridding.method (
Constants.Method, default=Constants.Method.CONSERVATIVE) – The method used to calculate weights.precomputed_weights (
scipy.sparse.spmatrix, optional) – IfNone,esmpywill be used to calculate regridding weights. Otherwise,esmpywill be bypassed andprecomputed_weightswill be used as the regridding weights.tgt_resolution (int, optional) – If present, represents the amount of latitude slices per cell given to ESMF for calculation. If
tgt_resolutionis set,tgtmust have strictly increasing bounds (bounds may be transposed plus or minus 360 degrees to make the bounds strictly increasing).use_src_mask (
ArrayLikeor bool, default=False) – Either an array representing the cells in the source to ignore, or else a boolean value. If True, this array is taken from the mask on the data insrc. If False, no mask will be taken and all points will be used in weights calculation.use_tgt_mask (
ArrayLikeor bool, default=False) – Either an array representing the cells in the target to ignore, or else a boolean value. If True, this array is taken from the mask on the data intgt. If False, no mask will be taken and all points will be used in weights calculation.esmf_args (dict, optional) – A dictionary of arguments to pass to ESMF.
- Raises:
ValueError – If
use_src_maskoruse_tgt_maskare True while the masks onsrcortgtrespectively are not constant over non-horizontal dimensions.
- esmf_regrid.experimental.unstructured_scheme.regrid_rectilinear_to_unstructured(src_cube, mesh_cube, mdtol=0, method=Method.CONSERVATIVE, src_resolution=None, use_src_mask=False, use_tgt_mask=False)[source]#
Regrid rectilinear
Cubeonto unstructured mesh.Return a new
Cubewithdatavalues calculated using weights generated byesmpyto give the weighted mean ofdatavalues fromsrc_cuberegridded onto the horizontal mesh ofmesh_cube. The dimensions on theCubeassociated with the grid will be replaced by a dimension associated with themesh. That dimension will be the first of the grid dimensions, whether it is associated with thexorycoordinate. Since two dimensions are being replaced by one, coordinates associated with dimensions after the grid will become associated with dimensions one lower. This function requires that the horizontal dimension ofmesh_cubeis described by a 2D mesh with data located on the faces of that mesh for conservative regridding and located on either faces or nodes for bilinear regridding. This function allows the horizontal grid ofgrid_cubeto be either rectilinear or curvilinear (i.e. expressed in terms of two orthogonal 1D coordinates or via a pair of 2D coordinates). This function also requires that theCoord\ s describing the horizontal grid havebounds.- Parameters:
src_cube (
iris.cube.Cube) – A rectilinear instance ofCubethat supplies the data, metadata and coordinates.mesh_cube (
iris.cube.Cube) – An unstructured instance ofCubethat supplies the desired horizontal mesh definition.mdtol (float, default=0) – Tolerance of missing data. The value returned in each element of the returned
Cube\ ‘sdataarray will be masked if the fraction of masked data in the overlapping cells of the source cube exceedsmdtol. This fraction is calculated based on the area of masked cells within each target cell.mdtol=0means no missing data is tolerated whilemdtol=1will mean the resulting element will be masked if and only if all the overlapping cells of thesrc_cubeare masked.method (
Constants.Method, default=Constants.Method.CONSERVATIVE) – The method used to calculate weights.src_resolution (int, optional) – If present, represents the amount of latitude slices per cell given to ESMF for calculation.
use_src_mask (
ArrayLikeor bool, default=False) – Either an array representing the cells in the source to ignore, or else a boolean value. If True, this array is taken from the mask on the data insrc_cube. If False, no mask will be taken and all points will be used in weights calculation.use_tgt_mask (
ArrayLikeor bool, default=False) – Either an array representing the cells in the target to ignore, or else a boolean value. If True, this array is taken from the mask on the data ingrid_cube. If False, no mask will be taken and all points will be used in weights calculation.
- Returns:
A new
Cubeinstance.- Return type:
- esmf_regrid.experimental.unstructured_scheme.regrid_unstructured_to_rectilinear(src_cube, grid_cube, mdtol=0, method=Method.CONSERVATIVE, tgt_resolution=None, use_src_mask=False, use_tgt_mask=False)[source]#
Regrid unstructured
Cubeonto rectilinear grid.Return a new
Cubewithdatavalues calculated using weights generated byesmpyto give the weighted mean ofdatavalues fromsrc_cuberegridded onto the horizontal grid ofgrid_cube. The dimension on theCubebelonging to themeshwill be replaced by the two dimensions associated with the grid. This function requires that the horizontal dimension ofsrc_cubeis described by a 2D mesh with data located on the faces of that mesh for conservative regridding and located on either faces or nodes for bilinear regridding. This function allows the horizontal grid ofgrid_cubeto be either rectilinear or curvilinear (i.e. expressed in terms of two orthogonal 1D coordinates or via a pair of 2D coordinates). This function also requires that theCoord\ s describing the horizontal grid havebounds.- Parameters:
src_cube (
iris.cube.Cube) – An unstructured instance ofCubethat supplies the data, metadata and coordinates.grid_cube (
iris.cube.Cube) – An instance ofCubethat supplies the desired horizontal grid definition.mdtol (float, default=0) – Tolerance of missing data. The value returned in each element of the returned
Cube\ ‘sdataarray will be masked if the fraction of masked data in the overlapping cells ofsrc_cubeexceedsmdtol. This fraction is calculated based on the area of masked cells within each target cell.mdtol=0means no missing data is tolerated whilemdtol=1will mean the resulting element will be masked if and only if all the overlapping cells ofsrc_cubeare masked.method (
Constants.Method, default=Constants.Method.CONSERVATIVE) – The method used to calculate weights.tgt_resolution (int, optional) – If present, represents the amount of latitude slices per cell given to ESMF for calculation.
use_src_mask (
ArrayLikeor bool, default=False) – Either an array representing the cells in the source to ignore, or else a boolean value. If True, this array is taken from the mask on the data insrc_cube. If False, no mask will be taken and all points will be used in weights calculation.use_tgt_mask (
ArrayLikeor bool, default=False) – Either an array representing the cells in the target to ignore, or else a boolean value. If True, this array is taken from the mask on the data ingrid_cube. If False, no mask will be taken and all points will be used in weights calculation.
- Returns:
A new
Cubeinstance.- Return type:
- esmf_regrid.experimental.unstructured_scheme.regrid_unstructured_to_unstructured(src_mesh_cube, tgt_mesh_cube, mdtol=0, method=Method.CONSERVATIVE, use_src_mask=False, use_tgt_mask=False)[source]#
Regrid rectilinear
Cubeonto unstructured mesh.Return a new
Cubewithdatavalues calculated using weights generated byesmpyto give the weighted mean ofdatavalues fromsrc_mesh_cuberegridded onto the horizontal mesh oftgt_mesh_cube. The resulting cube will have the samemesh_dimassrc_mesh_cube.- Parameters:
src_mesh_cube (
iris.cube.Cube) – A unstructured instance ofCubethat supplies the data, metadata and coordinates.tgt_mesh_cube (
iris.cube.Cube) – An unstructured instance ofCubethat supplies the desired horizontal mesh definition.mdtol (float, default=0) – Tolerance of missing data. The value returned in each element of the returned
Cube\ ‘sdataarray will be masked if the fraction of masked data in the overlapping cells of the source cube exceedsmdtol. This fraction is calculated based on the area of masked cells within each target cell.mdtol=0means no missing data is tolerated whilemdtol=1will mean the resulting element will be masked if and only if all the overlapping cells of thesrc_cubeare masked.method (
Constants.Method, default=Constants.Method.CONSERVATIVE) – The method used to calculate weights.use_src_mask (
ArrayLikeor bool, default=False) – Either an array representing the cells in the source to ignore, or else a boolean value. If True, this array is taken from the mask on the data insrc_cube. If False, no mask will be taken and all points will be used in weights calculation.use_tgt_mask (
ArrayLikeor bool, default=False) – Either an array representing the cells in the target to ignore, or else a boolean value. If True, this array is taken from the mask on the data ingrid_cube. If False, no mask will be taken and all points will be used in weights calculation.
- Returns:
A new
Cubeinstance.- Return type: