From 78183dab6fb3e11d86dd3b91e888de7209f17505 Mon Sep 17 00:00:00 2001 From: "Bryn N. Ubald" <55503826+bnubald@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:58:03 +0000 Subject: [PATCH] Dev #279: Minor plotting overlay updates Use more aggressive AdaptiveScaler for land and coastline plotting features --- icenet/plotting/forecast.py | 1 - icenet/plotting/utils.py | 14 +++++++++----- icenet/plotting/video.py | 1 - 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/icenet/plotting/forecast.py b/icenet/plotting/forecast.py index 9c29bf8..a562c19 100644 --- a/icenet/plotting/forecast.py +++ b/icenet/plotting/forecast.py @@ -1792,7 +1792,6 @@ def plot_forecast(): extent=extent, coastlines=coastlines, gridlines=args.gridlines, - transform_crs=data_crs_geo, ) # Convert from km to m fc = fc.assign_coords(xc=fc.xc.data * 1000, yc=fc.yc.data * 1000) diff --git a/icenet/plotting/utils.py b/icenet/plotting/utils.py index 8521d09..92b4c6c 100644 --- a/icenet/plotting/utils.py +++ b/icenet/plotting/utils.py @@ -427,7 +427,6 @@ def set_plot_geoaxes(ax, extent: list = None, coastlines: str = None, gridlines: bool = False, - transform_crs: object = ccrs.PlateCarree(), ): plt.tight_layout(pad=4.0) @@ -441,30 +440,35 @@ def set_plot_geoaxes(ax, if extent: lon_min, lon_max, lat_min, lat_max = extent + # With some projections like Mercator, it doesn't like having exact boundary longitude + if lon_min == -180: + lon_min = -179.99 + elif lon_max == 180: + lon_max = 179.99 ax.set_extent([lon_min, lon_max, lat_min, lat_max], crs=ccrs.PlateCarree()) clipping_polygon = Polygon(get_geoextent_polygon(extent)) path = Path(np.array(clipping_polygon.exterior.coords)) if coastlines: - land = NaturalEarthFeature("physical", "land", scale="10m", facecolor="dimgrey") + auto_scaler = AdaptiveScaler("110m", (("50m", 150), ("10m", 50))) + land = NaturalEarthFeature("physical", "land", scale=auto_scaler, facecolor="dimgrey", edgecolor="black") if extent: clipped_land = ShapelyFeature([clipping_polygon.intersection(geom) for geom in land.geometries()], ccrs.PlateCarree(), facecolor="dimgrey") ax.add_feature(clipped_land, zorder=100) # Draw coastlines explicitly within the clipping region - ax.add_geometries([clipping_polygon], ccrs.PlateCarree(), edgecolor="black", facecolor="none", linewidth=0.8, zorder=2) + ax.add_geometries([clipping_polygon], ccrs.PlateCarree(), edgecolor="red", facecolor="none", linewidth=1, linestyle="dashed", zorder=100) else: ax.add_feature(land, zorder=100) # Add OSMnx GeoDataFrame of coastlines #gdf = ox.features_from_place("Antarctica", tags={"natural": "coastline"}) #gdf.plot(ax=ax, facecolor='none', edgecolor='black', linewidth=0.5) - auto_scaler = AdaptiveScaler("110m", (("50m", 150), ("10m", 50))) ax.coastlines(resolution=auto_scaler, zorder=100) if gridlines: - gl = ax.gridlines(crs=transform_crs, draw_labels=True) + gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True) # Prevent generating labels beneath the colourbar gl.top_labels = False diff --git a/icenet/plotting/video.py b/icenet/plotting/video.py index ab5e13b..ee11087 100644 --- a/icenet/plotting/video.py +++ b/icenet/plotting/video.py @@ -188,7 +188,6 @@ def update(date): extent=extent, coastlines=coastlines, gridlines=gridlines, - transform_crs=transform_crs, ) else: ax = ax_init