Skip to content

Commit ad28892

Browse files
committed
Support for oceanic InterruptedGoodeHomolosine
- The ocean emphasis for the Interrupted Goode Homolosine projection (imh_o) requires proj version 7.1.0 or later. - Option to select 'land' or 'ocean' emphasis - Increaed n resolution from 31 points to 91 points - Added docstring for class - Added images of both land and ocean views
1 parent efd15f1 commit ad28892

3 files changed

Lines changed: 81 additions & 10 deletions

File tree

docs/make_projection.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ def plate_carree_plot():
4141
ax.gridlines()
4242

4343

44+
def igh_plot():
45+
import matplotlib.pyplot as plt
46+
import cartopy.crs as ccrs
47+
48+
fig = plt.figure(figsize=(6.9228, 6))
49+
50+
ax1 = fig.add_subplot(2, 1, 1,
51+
projection=ccrs.InterruptedGoodeHomolosine(
52+
emphasis='land'))
53+
ax1.coastlines(resolution='110m')
54+
ax1.gridlines()
55+
56+
ax2 = fig.add_subplot(2, 1, 2,
57+
projection=ccrs.InterruptedGoodeHomolosine(
58+
central_longitude=-160, emphasis='ocean'))
59+
ax2.coastlines(resolution='110m')
60+
ax2.gridlines()
61+
62+
4463
def utm_plot():
4564
import matplotlib.pyplot as plt
4665
import cartopy.crs as ccrs
@@ -59,6 +78,7 @@ def utm_plot():
5978

6079
MULTI_PLOT_CASES = {
6180
ccrs.PlateCarree: plate_carree_plot,
81+
ccrs.InterruptedGoodeHomolosine: igh_plot,
6282
ccrs.UTM: utm_plot,
6383
}
6484

docs/source/crs/projections.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,19 @@ InterruptedGoodeHomolosine
274274
import matplotlib.pyplot as plt
275275
import cartopy.crs as ccrs
276276

277-
plt.figure(figsize=(6.9228, 3))
278-
ax = plt.axes(projection=ccrs.InterruptedGoodeHomolosine())
279-
ax.coastlines(resolution='110m')
280-
ax.gridlines()
277+
fig = plt.figure(figsize=(6.9228, 6))
278+
279+
ax1 = fig.add_subplot(2, 1, 1,
280+
projection=ccrs.InterruptedGoodeHomolosine(
281+
emphasis='land'))
282+
ax1.coastlines(resolution='110m')
283+
ax1.gridlines()
284+
285+
ax2 = fig.add_subplot(2, 1, 2,
286+
projection=ccrs.InterruptedGoodeHomolosine(
287+
central_longitude=-160, emphasis='ocean'))
288+
ax2.coastlines(resolution='110m')
289+
ax2.gridlines()
281290

282291

283292
RotatedPole

lib/cartopy/crs.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,17 +1930,59 @@ def transform_points(self, src_crs, x, y, z=None):
19301930

19311931

19321932
class InterruptedGoodeHomolosine(Projection):
1933-
def __init__(self, central_longitude=0, globe=None):
1934-
proj4_params = [('proj', 'igh'), ('lon_0', central_longitude)]
1935-
super().__init__(proj4_params, globe=globe)
1933+
"""
1934+
Composite equal-area projection empahsizing either land or
1935+
ocean features.
1936+
1937+
Original Reference:
1938+
Goode, J. P., 1925: The Homolosine Projection: A new device for
1939+
portraying the Earth's surface entire. Annals of the
1940+
Association of American Geographers, 15:3, 119-125,
1941+
DOI: 10.1080/00045602509356949
1942+
1943+
A central_longitude value of -160 is recommended for the oceanic view.
1944+
1945+
"""
1946+
def __init__(self, central_longitude=0, globe=None, emphasis='land'):
1947+
"""
1948+
Parameters
1949+
----------
1950+
central_longitude: optional
1951+
The central longitude. Defaults to 0.
1952+
globe: :class:`cartopy.crs.Globe`, optional
1953+
If omitted, a default globe is created.
1954+
emphasis: optional
1955+
Options "land" and "ocean" are available. Defaults to "land"
1956+
1957+
"""
1958+
if emphasis == 'land':
1959+
proj4_params = [('proj', 'igh'), ('lon_0', central_longitude)]
1960+
super().__init__(proj4_params,globe=globe)
1961+
1962+
elif emphasis == 'ocean':
1963+
if PROJ4_VERSION < (7, 1, 0):
1964+
_proj_ver = '.'.join(str(v) for v in PROJ4_VERSION)
1965+
raise ValueError('The Interrupted Goode Homolosine ocean '
1966+
'projection requires Proj version 7.1.0, '
1967+
'but you are using ' + _proj_ver)
1968+
proj4_params = [('proj', 'igh_o'), ('lon_0', central_longitude)]
1969+
super().__init__(proj4_params,globe=globe)
1970+
1971+
else:
1972+
msg = '`emphasis` needs to be either \'land\' or \'ocean\''
1973+
raise ValueError(msg)
19361974

19371975
minlon, maxlon = self._determine_longitude_bounds(central_longitude)
19381976
epsilon = 1e-10
19391977

19401978
# Obtain boundary points
1941-
n = 31
1942-
top_interrupted_lons = (-40.0,)
1943-
bottom_interrupted_lons = (80.0, -20.0, -100.0)
1979+
n = 91
1980+
if emphasis == 'land':
1981+
top_interrupted_lons = (-40.0,)
1982+
bottom_interrupted_lons = (80.0, -20.0, -100.0)
1983+
elif emphasis == 'ocean':
1984+
top_interrupted_lons = (-90.0, 60.0)
1985+
bottom_interrupted_lons = (90.0, -60.0)
19441986
lons = np.empty(
19451987
(2 + 2 * len(top_interrupted_lons + bottom_interrupted_lons)) * n +
19461988
1)

0 commit comments

Comments
 (0)