Skip to content

Commit

Permalink
Dev icenet-ai#279: Minor plotting overlay updates
Browse files Browse the repository at this point in the history
Use more aggressive AdaptiveScaler for land and coastline plotting features
  • Loading branch information
bnubald committed Dec 18, 2024
1 parent 34c206e commit 78183da
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion icenet/plotting/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions icenet/plotting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion icenet/plotting/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def update(date):
extent=extent,
coastlines=coastlines,
gridlines=gridlines,
transform_crs=transform_crs,
)
else:
ax = ax_init
Expand Down

0 comments on commit 78183da

Please sign in to comment.