Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/CSET/operators/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from typing import Literal

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import iris
import iris.coords
import iris.cube
Expand Down Expand Up @@ -354,7 +355,7 @@ def _setup_spatial_map(
grid_size: int | None = None,
subplot: int | None = None,
):
"""Define map projections, extent and add coastlines for spatial plots.
"""Define map projections, extent and add coastlines and borderlines for spatial plots.

For spatial map plots, a relevant map projection for rotated or non-rotated inputs
is specified, and map extent defined based on the input data.
Expand Down Expand Up @@ -435,13 +436,14 @@ def _setup_spatial_map(
else:
axes = figure.add_subplot(projection=projection)

# Add coastlines if cube contains x and y map coordinates.
# Add coastlines and borderlines if cube contains x and y map coordinates.
if cmap.name in ["viridis", "Greys"]:
coastcol = "magenta"
else:
coastcol = "black"
logging.debug("Plotting coastlines in colour %s.", coastcol)
logging.debug("Plotting coastlines and borderlines in colour %s.", coastcol)
axes.coastlines(resolution="10m", color=coastcol)
axes.add_feature(cfeature.BORDERS, edgecolor=coastcol)

# If is lat/lon spatial map, fix extent to keep plot tight.
# Specifying crs within set_extent helps ensure only data region is shown.
Expand Down Expand Up @@ -577,7 +579,7 @@ def _plot_and_save_spatial_plot(
if contour_cube:
cntr_cmap, cntr_levels, cntr_norm = _colorbar_map_levels(contour_cube)

# Setup plot map projection, extent and coastlines.
# Setup plot map projection, extent and coastlines and borderlines.
axes = _setup_spatial_map(cube, fig, cmap)

# Plot the field.
Expand Down Expand Up @@ -753,7 +755,7 @@ def _plot_and_save_postage_stamp_spatial_plot(
for member, subplot in zip(
cube.slices_over(stamp_coordinate), range(1, grid_size**2 + 1), strict=False
):
# Setup subplot map projection, extent and coastlines.
# Setup subplot map projection, extent and coastlines and borderlines.
axes = _setup_spatial_map(
member, fig, cmap, grid_size=grid_size, subplot=subplot
)
Expand Down Expand Up @@ -1186,7 +1188,7 @@ def _plot_and_save_vector_plot(
# Specify the color bar
cmap, levels, norm = _colorbar_map_levels(cube_vec_mag)

# Setup plot map projection, extent and coastlines.
# Setup plot map projection, extent and coastlines and borderlines.
axes = _setup_spatial_map(cube_vec_mag, fig, cmap)

if method == "contourf":
Expand Down Expand Up @@ -1517,9 +1519,10 @@ def _plot_and_save_scattermap_plot(
edgecolors="k",
)

# Add coastlines.
# Add coastlines and borderlines.
try:
axes.coastlines(resolution="10m")
axes.add_feature(cfeature.BORDERS)
except AttributeError:
pass

Expand Down
8 changes: 4 additions & 4 deletions tests/operators/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,25 +690,25 @@ def test_postage_stamp_pcolormesh_plot_sequence_coord_check(cube, tmp_working_di


def test_pcolormesh_coastline(cube, caplog, tmp_working_dir):
"""Check coastlines plotted in black for air_temperature colormap."""
"""Check coastlines and borderlines plotted in black for air_temperature colormap."""
with caplog.at_level(logging.DEBUG):
plot.spatial_pcolormesh_plot(cube)
message_match = False
for _, _, message in caplog.record_tuples:
if message == "Plotting coastlines in colour black.":
if message == "Plotting coastlines and borderlines in colour black.":
message_match = True
assert message_match


def test_pcolormesh_coastline_m(cube, caplog, tmp_working_dir):
"""Check coastlines plotted in magenta for viridis colormap."""
"""Check coastlines and borderlines plotted in magenta for viridis colormap."""
with caplog.at_level(logging.DEBUG):
# Set cube name to unknown to trigger viridis default cmap
cube.rename("unknown_var_name")
plot.spatial_pcolormesh_plot(cube)
message_match = False
for _, _, message in caplog.record_tuples:
if message == "Plotting coastlines in colour magenta.":
if message == "Plotting coastlines and borderlines in colour magenta.":
message_match = True
assert message_match

Expand Down
Loading