Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ESadek-MO committed Nov 24, 2023
2 parents 091b11b + be33a81 commit 4f5ba2d
Show file tree
Hide file tree
Showing 26 changed files with 926 additions and 243 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:

steps:
- name: "checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- if: ${{ github.event_name == 'pull_request' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ concurrency:
jobs:
manifest:
name: "check-manifest"
uses: scitools/workflows/.github/workflows/ci-manifest.yml@2023.05.0
uses: scitools/workflows/.github/workflows/ci-manifest.yml@2023.09.0
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:

steps:
- name: "checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Nox
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:

steps:
- name: "checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/refresh-lockfiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
gen_lockfiles:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: install nox
run: |
source $CONDA/bin/activate base
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
- uses: actions/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: '@SciTools-incubator/esmf-regrid-devs This issue is stale due to a lack of activity in the last 90 days. Remove stale label or comment, otherwise this issue will close automatically in 7 days time.'
stale-pr-message: '@SciTools-incubator/esmf-regrid-devs This pull-request is stale due to a lack of activity in the last 90 days. Remove stale label or comment, otherwise this pull-request will close automatically in 7 days time.'
stale-issue-message: '@SciTools-incubator/esmf-regrid-devs This issue is stale due to a lack of activity in the last 180 days. Remove stale label or comment, otherwise this issue will close automatically in 14 days time.'
stale-pr-message: '@SciTools-incubator/esmf-regrid-devs This pull-request is stale due to a lack of activity in the last 180 days. Remove stale label or comment, otherwise this pull-request will close automatically in 14 days time.'
stale-issue-label: 'Stale: Closure warning'
stale-pr-label: 'Stale: Closure warning'
close-issue-message: '@SciTools-incubator/esmf-regrid-devs This stale issue has been automatically closed due to no community activity'
Expand All @@ -23,5 +23,5 @@ jobs:
close-pr-label: 'Stale: Closed'
exempt-issue-labels: 'Status: Blocked,Status: Decision needed,Status: Needs info,Status: Stalled,Status: Will not fix,Status: Work in progress'
exempt-pr-labels: 'Status: Blocked,Status: Decision needed,Status: Needs info,Status: Stalled,Status: Will not fix,Status: Work in progress'
days-before-stale: 90
days-before-close: 7
days-before-stale: 180
days-before-close: 14
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.9] - 2023-11-03

### Added

- [PR#178](https://github.com/SciTools-incubator/iris-esmf-regrid/pull/178)
Added support for coordinate systems with non-degree type units.
[@stephenworsley](https://github.com/stephenworsley)

- [PR#311](https://github.com/SciTools-incubator/iris-esmf-regrid/pull/311)
Added support for Mesh to Mesh regridding.
[@HGWright](https://github.com/HGWright)

### Fixed

- [PR#301](https://github.com/SciTools-incubator/iris-esmf-regrid/pull/301)
Fixed a bug which caused errors when regridding with the node locations
of a mesh whose face_node_connectivity had non-zero start_index.
[@stephenworsley](https://github.com/stephenworsley)

## [0.8] - 2023-08-22

### Added

- [PR#289](https://github.com/SciTools-incubator/iris-esmf-regrid/pull/289)
Added the ability to regrid onto a Mesh as a target instead of a Cube.
[@stephenworsley](https://github.com/stephenworsley)

## [0.7] - 2023-05-23

### Added
Expand Down
3 changes: 2 additions & 1 deletion esmf_regrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
from .constants import Constants, check_method, check_norm
from .schemes import *

__version__ = "0.8.dev0"

__version__ = "0.10.dev0"
4 changes: 3 additions & 1 deletion esmf_regrid/experimental/unstructured_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,19 @@ def __init__(
if location == "face":
field_kwargs = {"meshloc": esmpy.MeshLoc.ELEMENT}
shape = (len(face_node_connectivity),)
index_offset = self.esi
elif location == "node":
field_kwargs = {"meshloc": esmpy.MeshLoc.NODE}
shape = (len(node_coords),)
index_offset = self.nsi
else:
raise ValueError(
f"The mesh location '{location}' is not supported, only "
f"'face' and 'node' are supported."
)
super().__init__(
shape=shape,
index_offset=self.esi,
index_offset=index_offset,
field_kwargs=field_kwargs,
mask=mask,
)
Expand Down
93 changes: 89 additions & 4 deletions esmf_regrid/experimental/unstructured_scheme.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Provides an iris interface for unstructured regridding."""

from iris.experimental.ugrid import Mesh

from esmf_regrid import Constants, check_method
from esmf_regrid.schemes import (
_ESMFRegridder,
Expand All @@ -7,6 +10,8 @@
_regrid_rectilinear_to_unstructured__prepare,
_regrid_unstructured_to_rectilinear__perform,
_regrid_unstructured_to_rectilinear__prepare,
_regrid_unstructured_to_unstructured__perform,
_regrid_unstructured_to_unstructured__prepare,
)


Expand Down Expand Up @@ -274,16 +279,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 @@ -312,6 +319,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 @@ -320,7 +330,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 @@ -331,7 +341,82 @@ 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
self.grid_x, self.grid_y = self._src


def regrid_unstructured_to_unstructured(
src_mesh_cube,
tgt_mesh_cube,
mdtol=0,
method="conservative",
use_src_mask=False,
use_tgt_mask=False,
):
r"""
Regrid rectilinear :class:`~iris.cube.Cube` onto unstructured mesh.
Return a new :class:`~iris.cube.Cube` with :attr:`~iris.cube.Cube.data`
values calculated using weights generated by :mod:`esmpy` to give the weighted
mean of :attr:`~iris.cube.Cube.data` values from ``src_mesh_cube`` regridded onto the
horizontal mesh of ``tgt_mesh_cube``. The resulting cube will have the same
``mesh_dim`` as ``src_mesh_cube``.
Parameters
----------
src_mesh_cube : :class:`iris.cube.Cube`
A unstructured instance of :class:`~iris.cube.Cube` that supplies the data,
metadata and coordinates.
tgt_mesh_cube : :class:`iris.cube.Cube`
An unstructured instance of :class:`~iris.cube.Cube` that supplies the desired
horizontal mesh definition.
mdtol : float, default=0
Tolerance of missing data. The value returned in each element of the
returned :class:`~iris.cube.Cube`\\ 's :attr:`~iris.cube.Cube.data` array
will be masked if the fraction of masked
data in the overlapping cells of the source cube exceeds ``mdtol``. This
fraction is calculated based on the area of masked cells within each
target cell. ``mdtol=0`` means no missing data is tolerated while ``mdtol=1``
will mean the resulting element will be masked if and only if all the
overlapping cells of the ``src_cube`` are masked.
method : str, default="conservative"
Either "conservative", "bilinear" or "nearest". Corresponds to the :mod:`esmpy` methods
:attr:`~esmpy.api.constants.RegridMethod.CONSERVE` or
:attr:`~esmpy.api.constants.RegridMethod.BILINEAR` or
:attr:`~esmpy.api.constants.RegridMethod.NEAREST` used to calculate weights.
use_src_mask : :obj:`~numpy.typing.ArrayLike` or 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
in ``src_cube``. If False, no mask will be taken and all points will
be used in weights calculation.
use_tgt_mask : :obj:`~numpy.typing.ArrayLike` or 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
in ``grid_cube``. If False, no mask will be taken and all points
will be used in weights calculation.
Returns
-------
:class:`iris.cube.Cube`
A new :class:`~iris.cube.Cube` instance.
"""
if tgt_mesh_cube.mesh is None:
raise ValueError("mesh_cube has no mesh.")
src_mask = _get_mask(src_mesh_cube, use_src_mask)
tgt_mask = _get_mask(tgt_mesh_cube, use_tgt_mask)

regrid_info = _regrid_unstructured_to_unstructured__prepare(
src_mesh_cube,
tgt_mesh_cube,
method=method,
src_mask=src_mask,
tgt_mask=tgt_mask,
)
result = _regrid_unstructured_to_unstructured__perform(
src_mesh_cube, regrid_info, mdtol
)
return result
Loading

0 comments on commit 4f5ba2d

Please sign in to comment.