diff --git a/CHANGELOG.md b/CHANGELOG.md index 38924c48..27972c72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ All notable changes to this library are documented in this file. ### Bug Fixes +- Ensure geometries going into masking helper are CCW, to mask outside of. + ## **1.21.0** (6 Sep 2024) ### API Changes diff --git a/src/pyiem/plot/util.py b/src/pyiem/plot/util.py index d5f0f08c..d3c0134b 100644 --- a/src/pyiem/plot/util.py +++ b/src/pyiem/plot/util.py @@ -756,7 +756,9 @@ def mask_outside_geom(gp, geom): geom = MultiPolygon([geom]) trans = Transformer.from_crs(LATLON, gp.crs, always_xy=True) for geo in geom.geoms: - ccw = np.asarray(geo.exterior.coords)[::-1] + ccw = np.asarray(geo.exterior.coords) + if not geo.exterior.is_ccw: + ccw = ccw[::-1] points = trans.transform(ccw[:, 0], ccw[:, 1]) # pylint: disable=unsubscriptable-object ar = np.column_stack([*points])[:-1] diff --git a/tests/plot/baseline/test_fema_region_pcolormesh.png b/tests/plot/baseline/test_fema_region_pcolormesh.png new file mode 100644 index 00000000..ff84eff6 Binary files /dev/null and b/tests/plot/baseline/test_fema_region_pcolormesh.png differ diff --git a/tests/plot/test_geoplot.py b/tests/plot/test_geoplot.py index c366840a..aae9bc04 100644 --- a/tests/plot/test_geoplot.py +++ b/tests/plot/test_geoplot.py @@ -239,6 +239,28 @@ def test_fema_region6(): return mp.fig +@pytest.mark.mpl_image_compare(tolerance=PAIN) +def test_fema_region_pcolormesh(): + """Test problem found in production.""" + mp = MapPlot( + figsize=(8, 6), + nocaption=True, + fema_region=7, + sector="fema_region", + title="FEMA Region 7", + nostates=True, + ) + lons = np.arange(-100, -80, 0.25) + lats = np.arange(40, 50, 0.25) + vals = np.linspace(0, 1, lats.shape[0] * lons.shape[0]).reshape( + [lats.shape[0], lons.shape[0]] + ) + lons, lats = np.meshgrid(lons, lats) + res = mp.pcolormesh(lons, lats, vals, np.arange(0, 1, 0.1)) + res.set_rasterized(True) + return mp.fig + + @pytest.mark.mpl_image_compare(tolerance=PAIN) def test_nashville(): """Test that Benton County, TNC005 does not show for OHX."""