From 159e056e359cf1540bbfd2c18d3b07a98b337b5d Mon Sep 17 00:00:00 2001 From: Matthias Cuntz Date: Sat, 10 Jun 2023 20:17:02 +0200 Subject: [PATCH] Added add_cyclic to API reference and What's new Version 0.21 --- docs/source/reference/transformations.rst | 2 ++ docs/source/whatsnew/v0.21.rst | 5 +++++ lib/cartopy/util.py | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/docs/source/reference/transformations.rst b/docs/source/reference/transformations.rst index db027ff92..286c3f467 100644 --- a/docs/source/reference/transformations.rst +++ b/docs/source/reference/transformations.rst @@ -34,6 +34,8 @@ Longitude wrapping :toctree: generated/ util.add_cyclic_point + util.add_cyclic + LinearRing/LineString projection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/whatsnew/v0.21.rst b/docs/source/whatsnew/v0.21.rst index a74d01c26..972cf657e 100644 --- a/docs/source/whatsnew/v0.21.rst +++ b/docs/source/whatsnew/v0.21.rst @@ -114,6 +114,11 @@ Features plt.show() +* Matthias Cuntz added a new convenience utility function + :func:~cartopy.util.add_cyclic. This is an extension of + :func:~cartopy.util.add_cyclic_point for 2-dimensional coordinates lat and + lon. (:pull:1753) + Deprecations ------------ diff --git a/lib/cartopy/util.py b/lib/cartopy/util.py index e93e190b9..e981c03f7 100644 --- a/lib/cartopy/util.py +++ b/lib/cartopy/util.py @@ -269,6 +269,7 @@ def add_cyclic(data, x=None, y=None, axis=-1, -------- Adding a cyclic point to a data array, where the cyclic dimension is the right-most dimension. + >>> import numpy as np >>> data = np.ones([5, 6]) * np.arange(6) >>> cyclic_data = add_cyclic(data) @@ -280,6 +281,7 @@ def add_cyclic(data, x=None, y=None, axis=-1, [0. 1. 2. 3. 4. 5. 0.]] Adding a cyclic point to a data array and an associated x-coordinate. + >>> lons = np.arange(0, 360, 60) >>> cyclic_data, cyclic_lons = add_cyclic(data, x=lons) >>> print(cyclic_data) # doctest: +NORMALIZE_WHITESPACE @@ -293,6 +295,7 @@ def add_cyclic(data, x=None, y=None, axis=-1, Adding a cyclic point to a data array and an associated 2-dimensional x-coordinate. + >>> lons = np.arange(0, 360, 60) >>> lats = np.arange(-90, 90, 180/5) >>> lon2d, lat2d = np.meshgrid(lons, lats) @@ -312,6 +315,7 @@ def add_cyclic(data, x=None, y=None, axis=-1, Adding a cyclic point to a data array and the associated 2-dimensional x- and y-coordinates. + >>> lons = np.arange(0, 360, 60) >>> lats = np.arange(-90, 90, 180/5) >>> lon2d, lat2d = np.meshgrid(lons, lats) @@ -337,6 +341,7 @@ def add_cyclic(data, x=None, y=None, axis=-1, [ 54. 54. 54. 54. 54. 54. 54.]] Not adding a cyclic point if cyclic point detected in x. + >>> lons = np.arange(0, 361, 72) >>> lats = np.arange(-90, 90, 180/5) >>> lon2d, lat2d = np.meshgrid(lons, lats)