Skip to content

Commit

Permalink
Remove coord discontinuity check in regrid (#2119)
Browse files Browse the repository at this point in the history
  • Loading branch information
sloosvel authored Jul 3, 2023
1 parent f5aef4a commit 276c56c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 88 deletions.
7 changes: 0 additions & 7 deletions doc/recipe/preprocessor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1015,13 +1015,6 @@ scheme available in :doc:`iris-esmf-regrid:index`:
reference: esmf_regrid.schemes:regrid_rectilinear_to_rectilinear
mdtol: 0.7
Since version 0.6 of :doc:`iris-esmf-regrid:index`, the regridder is able
to ignore discontinuities in the source grids if the data defined in the
discontiguous points is masked.
The :func:`~esmvalcore.preprocessor.regrid` preprocessor automatically detects
if discontinuities are present, and configures the regridding scheme in order to take
into account the mask of the source grid to ignore them.

.. _ensemble statistics:

Ensemble statistics
Expand Down
23 changes: 0 additions & 23 deletions esmvalcore/preprocessor/_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,21 +384,6 @@ def extract_location(cube, location, scheme):
scheme)


def _check_grid_discontiguities(cube, scheme):
"""Check if there are grid discontiguities and set use_src_mask to True."""
scheme = dict(scheme)
try:
discontiguities = iris.util.find_discontiguities(cube)
except NotImplementedError:
pass
else:
if discontiguities.any():
scheme['use_src_mask'] = True
logger.debug('Grid discontinuities were found in the source grid. '
'Setting scheme argument `use_src_mask` to True.')
return scheme


def extract_point(cube, latitude, longitude, scheme):
"""Extract a point, with interpolation.
Expand Down Expand Up @@ -577,12 +562,6 @@ def regrid(cube, target_grid, scheme, lat_offset=True, lon_offset=True):
scheme:
reference: esmf_regrid.schemes:ESMFAreaWeighted
Since version 0.6 of :doc:`iris-esmf-regrid:index`, the regridder is able
to ignore discontinuities in the source grids if the data defined in the
discontiguous points is masked.
The preprocessor automatically detects if discontinuities are present,
and configures the regridding scheme in order to take into account
the mask of the source grid to ignore them.
"""
if is_dataset(target_grid):
target_grid = target_grid.copy()
Expand Down Expand Up @@ -637,8 +616,6 @@ def regrid(cube, target_grid, scheme, lat_offset=True, lon_offset=True):
scheme['src_cube'] = cube
if 'grid_cube' in scheme_args:
scheme['grid_cube'] = target_grid
if 'use_src_mask' in scheme_args:
scheme = _check_grid_discontiguities(cube, scheme)

loaded_scheme = obj(**scheme)
else:
Expand Down
58 changes: 0 additions & 58 deletions tests/unit/preprocessor/_regrid/test_regrid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Unit tests for the :func:`esmvalcore.preprocessor.regrid.regrid`
function."""

import logging
import unittest
from unittest import mock

Expand All @@ -16,7 +15,6 @@
from esmvalcore.preprocessor._regrid import (
_CACHE,
HORIZONTAL_SCHEMES,
_check_grid_discontiguities,
_horizontal_grid_is_close,
_rechunk,
)
Expand Down Expand Up @@ -269,62 +267,6 @@ def test_regrid_is_skipped_if_grids_are_the_same():
assert expected_different_cube is not cube


def test_no_discontiguities_in_coords():
"""Test that no mask is used if there are no discontinuities in coords."""
cube = _make_cube(lat=LAT_SPEC1, lon=LON_SPEC1)
scheme = {}
scheme = _check_grid_discontiguities(cube, scheme)
assert scheme == {}


def test_use_mask_if_discontiguities_in_coords(caplog):
"""Test use_src_mask is added to the scheme."""
lat_bounds = np.array(
[[[-43.48076211, -34.01923789, -22.00961894, -31.47114317],
[-34.01923789, -10.0, 2.00961894, -22.00961894],
[-10.0, -0.53847577, 11.47114317, 2.00961894]],
[[-31.47114317, -22.00961894, -10.0, -19.46152423],
[-22.00961894, 2.00961894, 14.01923789, -10.0],
[2.00961894, 11.47114317, 23.48076211, 14.01923789]]])
lat_coord = iris.coords.AuxCoord(
[[-40.0, -20.0, 0.0], [-20.0, 0.0, 20.0]],
var_name='lat',
standard_name='latitude',
units='degrees_north',
bounds=lat_bounds,
)
lon_bounds = np.array([[[140.625, 99.375, 99.375, 140.625],
[99.375, 140.625, 140.625, 99.375],
[140.625, 99.375, 99.375, 140.625]],
[[140., 99.375, 99.375, 140.],
[99.375, 140.625, 140.625, 99.375],
[140., 99.375, 99.375, 140.]]])
lon_coord = iris.coords.AuxCoord(
[[100.0, 140.0, 180.0], [80.0, 100.0, 120.0]],
var_name='lon',
standard_name='longitude',
units='degrees_east',
bounds=lon_bounds,
)
data = np.ma.array(
[[-40.0, -20.0, 0.0], [-20.0, 0.0, 20.0]],
mask=[[True, False, True], [False, True, False]],
)
cube = iris.cube.Cube(
data,
aux_coords_and_dims=[(lat_coord, (0, 1)), (lon_coord, (0, 1))],
)

scheme = {}
with caplog.at_level(logging.DEBUG):
scheme = _check_grid_discontiguities(cube, scheme)
assert scheme == {'use_src_mask': True}

msg = ('Grid discontinuities were found in the source grid. '
'Setting scheme argument `use_src_mask` to True.')
assert msg in caplog.text


def make_test_cube(shape):
data = da.empty(shape, dtype=np.float32)
cube = iris.cube.Cube(data)
Expand Down

0 comments on commit 276c56c

Please sign in to comment.