Skip to content

Drawing of certain paths breaks in cartopy 0.25.0 #2590

@andrewdnolan

Description

@andrewdnolan

Hello! I’m a developer of mosaic, a python package for unstructured mesh visualization which is heavily reliant on cartopy.

We’ve noticed an issue drawing certain paths when switching from cartopy 0.24.0 to 0.25.0. See E3SM-Project/mosaic/#42 for the original issue where this was brought to our attention. Here’s a minimum working example:

import cartopy
import cartopy.crs as ccrs
import numpy as np
import matplotlib.pyplot as plt

from matplotlib.collections import PolyCollection

# https://wktmap.com/?fae129b6
patch = np.array([[
    [-180.00020734,  -63.5383884 ],
    [-179.93611911,  -63.61745971],
    [-179.77001049,  -63.62512738],
    [-179.67109735,  -63.55616224],
    [-179.74190981,  -63.49385818],
    [-179.91362571,  -63.48807984],
    [-180.00020734,  -63.5383884 ],
    [-180.00020734,  -63.5383884 ],
]])

fig, ax = plt.subplots(
    constrained_layout=True, subplot_kw={"projection": ccrs.PlateCarree()}
)

collection = PolyCollection(patch, array=[1.], ec='k', alpha=0.5)

collection.set_transform(ccrs.PlateCarree())

ax.add_collection(collection)
ax.autoscale_view()

ax.set_title(f"cartopy v{cartopy.__version__}")
ax.gridlines(draw_labels=True)

plt.show() 

Here's what the patch looks like in cartopy 0.24.0:

conda create -n cartopy_0.24.0 python=3.13 cartopy=0.24.0
Image

And, here's what the patch looks like in cartopy 0.25.0:

conda create -n cartopy_0.25.0 python=3.13 cartopy=0.25.0
Image

My hunch is that the issue arises because the first/last index lies outside of the projection boundary (i.e. -180 deg). But, I haven't had time to through and test that hunch.

For some context, in mosaic we repeat the first index as the last to ensure the polygons are closed. Because we have variable resolution meshes, the polygons can have variable number of sides. To support ragged array likes this, we further repeat the first/last index as many times as needed to fill in up to the max number of sides.

cc'ing @xylar @cbegeman

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions