Skip to content

Commit eaff45a

Browse files
committed
dev
1 parent 7055117 commit eaff45a

4 files changed

Lines changed: 42 additions & 29 deletions

File tree

cf/data/data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,8 @@ def _regrid(
23832383
23842384
{{max_masked: `int`, optional}}
23852385
2386+
.. versionadded:: NEXVERSION
2387+
23862388
:Returns:
23872389
23882390
`Data`

cf/docstring/docstring.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@
411411
The maximum allow number of masked source cells which
412412
are allowed to be ignored when calculating a
413413
non-masked destination cell. When masked source cells
414-
are ignored, the weights of non-masked source cells i
415-
are adjusted so that they sum to 1.
414+
are ignored, the weights of the non-masked source
415+
cells are adjusted so that they sum to 1.
416416
417417
Define ``w_ji`` as the multiplicative weight that
418418
defines how much of ``Vs_i`` (the value in source grid
@@ -424,9 +424,7 @@
424424
i is masked and ``w_ji >= min_weight``. If set to
425425
``N``, then destination grid cell j will be masked if
426426
more than ``N`` source cells i are masked with ``w_ji
427-
>= min_weight``.
428-
429-
.. versionadded:: NEXTVERSION""",
427+
>= min_weight``.""",
430428
# weights_file
431429
"{{weights_file: `str` or `None`, optional}}": """weights_file: `str` or `None`, optional
432430
Provide a netCDF file that contains, or will contain,

cf/regrid/regrid.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,12 @@ def regrid(
399399
"""
400400
debug = is_log_level_debug(logger)
401401

402+
if not isinstance(max_masked, int) or max_masked < 0:
403+
raise ValueError(
404+
"The max_masked keyword must be a non-negative integer. "
405+
f"Got: {max_masked!r}"
406+
)
407+
402408
if not inplace:
403409
src = src.copy()
404410

cf/test/test_regrid.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -914,18 +914,24 @@ def test_regrids_max_masked(self):
914914
)
915915
)
916916

917-
x = s.regrids(d, method="linear", use_dst_mask=False, max_masked=3)
918-
self.assertTrue(
919-
np.array_equal(
920-
x.data.mask,
921-
[
922-
[False, False, True, True, True, True, True, True],
923-
[False, False, False, True, True, True, True, True],
924-
[False, False, False, False, True, True, True, True],
925-
[False, False, False, False, False, True, True, True],
926-
],
917+
for n in (3, 4, 5):
918+
x = s.regrids(d, method="linear", use_dst_mask=False, max_masked=n)
919+
self.assertTrue(
920+
np.array_equal(
921+
x.data.mask,
922+
[
923+
[False, False, True, True, True, True, True, True],
924+
[False, False, False, True, True, True, True, True],
925+
[False, False, False, False, True, True, True, True],
926+
[False, False, False, False, False, True, True, True],
927+
],
928+
)
927929
)
928-
)
930+
931+
# Check bad values of max_masked
932+
for n in (-1, 3.14, "string", None):
933+
with self.assertRaises(ValueError):
934+
x = s.regrids(d, method="linear", max_masked=n)
929935

930936
def test_regridc_max_masked(self):
931937
"""Test max_masked keyword to regridc."""
@@ -1011,20 +1017,21 @@ def test_regridc_max_masked(self):
10111017
)
10121018
)
10131019

1014-
x = s.regridc(
1015-
d, axes=axes, method="linear", use_dst_mask=False, max_masked=3
1016-
)
1017-
self.assertTrue(
1018-
np.array_equal(
1019-
x.data.mask,
1020-
[
1021-
[True, False, True, True, True, True, True, True],
1022-
[True, False, False, True, True, True, True, True],
1023-
[True, False, False, False, True, True, True, True],
1024-
[True, False, False, False, False, True, True, True],
1025-
],
1020+
for n in (3, 4, 5):
1021+
x = s.regridc(
1022+
d, axes=axes, method="linear", use_dst_mask=False, max_masked=n
1023+
)
1024+
self.assertTrue(
1025+
np.array_equal(
1026+
x.data.mask,
1027+
[
1028+
[True, False, True, True, True, True, True, True],
1029+
[True, False, False, True, True, True, True, True],
1030+
[True, False, False, False, True, True, True, True],
1031+
[True, False, False, False, False, True, True, True],
1032+
],
1033+
)
10261034
)
1027-
)
10281035

10291036

10301037
if __name__ == "__main__":

0 commit comments

Comments
 (0)