Skip to content

Commit 4ff55fa

Browse files
authored
GeogCS.as_cartopy_projection handling non-Earth planets (#4497)
* GeogCS passes itself as a globe to ccrs.PlateCarree * Test that fails before change * Bug or feature? * Update as_projection test to use .srs * Fix failing test * Bug fix in test * Capitalise Earth to bump tests * Fix test_project to map between equal-sized planets * Fix test
1 parent e3df0a0 commit 4ff55fa

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

docs/src/whatsnew/latest.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ This document explains the changes made to Iris for this release
153153
instead of one latitude and one longitude.
154154
(:issue:`4460`, :pull:`4470`)
155155

156+
#. `@wjbenfold`_ stopped :meth:`iris.coord_systems.GeogCS.as_cartopy_projection`
157+
from assuming the globe to be the Earth (:issue:`4408`, :pull:`4497`)
158+
156159

157160
💣 Incompatible Changes
158161
=======================

lib/iris/coord_systems.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ def as_cartopy_crs(self):
297297
return ccrs.Geodetic(self.as_cartopy_globe())
298298

299299
def as_cartopy_projection(self):
300-
return ccrs.PlateCarree()
300+
return ccrs.PlateCarree(
301+
central_longitude=self.longitude_of_prime_meridian,
302+
globe=self.as_cartopy_globe(),
303+
)
301304

302305
def as_cartopy_globe(self):
303306
# Explicitly set `ellipse` to None as a workaround for

lib/iris/tests/test_coordsystem.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,29 @@ def test_as_cartopy_globe(self):
188188
self.assertEqual(res, expected)
189189

190190

191+
class Test_GeogCS_as_cartopy_projection(tests.IrisTest):
192+
def test_as_cartopy_projection(self):
193+
geogcs_args = {
194+
"semi_major_axis": 6543210,
195+
"semi_minor_axis": 6500000,
196+
"longitude_of_prime_meridian": 30,
197+
}
198+
cs = GeogCS(**geogcs_args)
199+
res = cs.as_cartopy_projection()
200+
201+
globe = ccrs.Globe(
202+
semimajor_axis=geogcs_args["semi_major_axis"],
203+
semiminor_axis=geogcs_args["semi_minor_axis"],
204+
ellipse=None,
205+
)
206+
expected = ccrs.PlateCarree(
207+
globe=globe,
208+
central_longitude=geogcs_args["longitude_of_prime_meridian"],
209+
)
210+
211+
self.assertEqual(res, expected)
212+
213+
191214
class Test_GeogCS_as_cartopy_crs(tests.IrisTest):
192215
def test_as_cartopy_crs(self):
193216
cs = GeogCS(6543210, 6500000)

lib/iris/tests/test_mapping.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ def test_grid(self):
211211

212212
def test_default_projection_and_extent(self):
213213
self.assertEqual(
214-
iplt.default_projection(self.cube), ccrs.PlateCarree()
214+
iplt.default_projection(self.cube),
215+
ccrs.PlateCarree(
216+
globe=self.cube.coord_system("CoordSystem").as_cartopy_globe()
217+
),
215218
)
216219
np_testing.assert_array_almost_equal(
217220
iplt.default_projection_extent(self.cube),

lib/iris/tests/unit/analysis/cartography/test_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def setUp(self):
5252
1,
5353
)
5454

55-
self.tcs = iris.coord_systems.GeogCS(6000000)
55+
self.tcs = iris.coord_systems.GeogCS(6371229)
5656

5757
def test_is_iris_coord_system(self):
5858
res, _ = project(self.cube, self.tcs)

0 commit comments

Comments
 (0)