Skip to content

Commit

Permalink
Add option to initialise from mesh (#289)
Browse files Browse the repository at this point in the history
* add mesh initialisation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* clarify and test tgt_location defaults

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
stephenworsley and pre-commit-ci[bot] authored Aug 22, 2023
1 parent 5ebf2bc commit 29b63fb
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 77 deletions.
16 changes: 12 additions & 4 deletions esmf_regrid/experimental/unstructured_scheme.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Provides an iris interface for unstructured regridding."""

from iris.experimental.ugrid import Mesh

from esmf_regrid.schemes import (
_ESMFRegridder,
_get_mask,
Expand Down Expand Up @@ -281,16 +283,18 @@ def __init__(
src_resolution=None,
use_src_mask=False,
use_tgt_mask=False,
tgt_location=None,
):
"""
Create regridder for conversions between source grid and target mesh.
Parameters
----------
src_grid_cube : :class:`iris.cube.Cube`
src : :class:`iris.cube.Cube`
The rectilinear :class:`~iris.cube.Cube` cube providing the source grid.
target_mesh_cube : :class:`iris.cube.Cube`
The unstructured :class:`~iris.cube.Cube` providing the target mesh.
tgt : :class:`iris.cube.Cube` or :class:`iris.experimental.ugrid.Mesh`
The unstructured :class:`~iris.cube.Cube`or
:class:`~iris.experimental.ugrid.Mesh` providing 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
Expand Down Expand Up @@ -322,6 +326,9 @@ def __init__(
a boolean value. If True, this array is taken from the mask on the data
in ``tgt``. 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 :class:`~iris.cube.Cube`.
Raises
------
Expand All @@ -330,7 +337,7 @@ def __init__(
or ``tgt`` respectively are not constant over non-horizontal dimensions.
"""
if tgt.mesh is None:
if not isinstance(tgt, Mesh) and tgt.mesh is None:
raise ValueError("tgt has no mesh.")
super().__init__(
src,
Expand All @@ -341,6 +348,7 @@ def __init__(
src_resolution=src_resolution,
use_src_mask=use_src_mask,
use_tgt_mask=use_tgt_mask,
tgt_location=tgt_location,
)
self.resolution = src_resolution
self.mesh, self.location = self._tgt
Expand Down
Loading

0 comments on commit 29b63fb

Please sign in to comment.