From 62dc7fcb0f7d9682fb86673c0bfe2d94dd6e1b23 Mon Sep 17 00:00:00 2001 From: huziy Date: Sat, 3 Sep 2022 23:40:29 -0400 Subject: [PATCH 1/3] Calculate vertical coord, even if not explicitely requested assume it is 0 --- lib/cartopy/crs.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/cartopy/crs.py b/lib/cartopy/crs.py index 8175fea78..5efe9ef2f 100644 --- a/lib/cartopy/crs.py +++ b/lib/cartopy/crs.py @@ -47,13 +47,12 @@ def _get_transformer_from_crs(src_crs, tgt_crs): def _safe_pj_transform(src_crs, tgt_crs, x, y, z=None, trap=True): transformer = _get_transformer_from_crs(src_crs, tgt_crs) - transformed_coords = transformer.transform(x, y, z, errcheck=trap) + + # if a projection is essentially 2d there should be no harm in setting its z to 0 if z is None: - xx, yy = transformed_coords - zz = 0 - else: - xx, yy, zz = transformed_coords - return xx, yy, zz + z = np.zeros_like(x) + + return transformer.transform(x, y, z, errcheck=trap) class Globe: From af2ad55e51f150e826d2e75fc6ad294dbd0f1b83 Mon Sep 17 00:00:00 2001 From: huziy Date: Sat, 3 Sep 2022 23:56:32 -0400 Subject: [PATCH 2/3] Split a comment into 2 lines --- lib/cartopy/crs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cartopy/crs.py b/lib/cartopy/crs.py index 5efe9ef2f..082dd8930 100644 --- a/lib/cartopy/crs.py +++ b/lib/cartopy/crs.py @@ -48,7 +48,8 @@ def _get_transformer_from_crs(src_crs, tgt_crs): def _safe_pj_transform(src_crs, tgt_crs, x, y, z=None, trap=True): transformer = _get_transformer_from_crs(src_crs, tgt_crs) - # if a projection is essentially 2d there should be no harm in setting its z to 0 + # if a projection is essentially 2d there + # should be no harm in setting its z to 0 if z is None: z = np.zeros_like(x) From 71c4f7b72e023f67bdeb59dd312e5ab43878c601 Mon Sep 17 00:00:00 2001 From: huziy Date: Sun, 4 Sep 2022 00:32:26 -0400 Subject: [PATCH 3/3] Adjust test_crs assuming z is computed z is not set to 0, but computed --- lib/cartopy/tests/test_crs.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/cartopy/tests/test_crs.py b/lib/cartopy/tests/test_crs.py index 977494f58..0cc64ddf5 100644 --- a/lib/cartopy/tests/test_crs.py +++ b/lib/cartopy/tests/test_crs.py @@ -303,8 +303,7 @@ def test_transform_points_outside_domain(): crs = ccrs.Orthographic() result = crs.transform_points(ccrs.PlateCarree(), np.array([-120]), np.array([80])) - assert np.all(np.isnan(result[..., :2])) - assert result[..., -1] == 0 + assert np.all(np.isnan(result)) result = crs.transform_points(ccrs.PlateCarree(), np.array([-120]), np.array([80]), trap=True)