Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mollweide projection for polygons that intersect a pole #724

Closed
xylar opened this issue Feb 10, 2016 · 2 comments · Fixed by #1146
Closed

Mollweide projection for polygons that intersect a pole #724

xylar opened this issue Feb 10, 2016 · 2 comments · Fixed by #1146

Comments

@xylar
Copy link
Contributor

xylar commented Feb 10, 2016

First let me say that I'm very happy with cartopy. Most projections I have tried handle polygons that that intersect a pole surprisingly well. The one exception I've encountered is the Mollweide projection, which seems to get confused when when the polygon is closer to the pole than 89.0 N. Below is a script that reproduces the issue with a polygon representing the Arctic Ocean basin.

A plot with a PlateCarree projection behaves as expected:
platecarree

Mollweide produces the following glitch with a polygon that intersects the pole

mollweide

but behaves as expected if the polygon doesn't quite reach the pole (maxLat = 89 in the script).

mollweide_89

import numpy
import matplotlib.pyplot as plt
import cartopy.crs
import cartopy.feature

#maxLat = 89.
maxLat = 90.

points = [
    [ -114.848345, 77.854709],
    [ -120.812209, 76.737200],
    [ -180.000000, 71.535845],
    [ -180.000000, maxLat],
    [ 0.000000, maxLat],
    [ 180.000000, maxLat],
    [ 180.000000, 73.187262],
    [ 173.916445, 73.187262],
    [ 88.445563, 81.255838],
    [ 44.860000, 80.613455],
    [ 24.365000, 80.289982],
    [ 21.798055, 80.146945],
    [ 18.443464, 80.181091],
    [ -28.773336, 83.513609],
    [ -36.783487, 83.573498],
    [ -72.648900, 82.746645],
    [ -76.102782, 82.470536],
    [ -78.843609, 82.664991],
    [ -80.909164, 82.156645],
    [ -83.001955, 82.089155],
    [ -85.405836, 82.042209],
    [ -88.113618, 82.090545],
    [ -93.687500, 81.210264],
    [ -94.093609, 80.593318],
    [ -114.848345, 77.854709]]

points = numpy.asarray(points)


for projection in [cartopy.crs.PlateCarree(), cartopy.crs.Mollweide()]:
    plt.figure()

    ax = plt.axes(projection=projection)
    resolution = '50m'
    ax.add_feature(cartopy.feature.NaturalEarthFeature('physical', 'land', resolution,
                   edgecolor='face', facecolor=cartopy.feature.COLORS['land']), zorder=1)
    ax.add_feature(cartopy.feature.NaturalEarthFeature('physical', 'coastline', resolution,
                   edgecolor='black', facecolor='none'), zorder=2)


    plt.tight_layout()

    ax.fill(points[:,0], points[:,1], transform=cartopy.crs.PlateCarree(), color='green', alpha=0.4, linewidth=2.0, zorder=3)

plt.show()
@QuLogic
Copy link
Member

QuLogic commented Feb 10, 2016

For future reference, the downstream ticket shows that decreasing the threshold had no effect.

@xylar
Copy link
Contributor Author

xylar commented Feb 10, 2016

@QuLogic, that's correct. It might be easiest if I repeat the snippet I tried here for clarity. At @pelson's suggestion, I made a new child class of Mollweide with a threshold smaller than the default value (1e5). I used a threshold of 1e4 and then 1e3 but the poles still seem to give the Mollweide plot the same difficulty.

class BetterMollweide(cartopy.crs.Mollweide):
    def __init__(self, *args, **kwargs):
        cartopy.crs.Mollweide.__init__(self, *args, **kwargs)
        self._threshold = 1e3

    @property
    def threshold(self):
        return self._threshold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants