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
11 changes: 10 additions & 1 deletion packages/evaluate/src/weathergen/evaluate/plotting/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,16 @@ def scatter_plot(
if figsize is None and data.size >= 200_000:
figsize = (15, 7)

proj = ccrs.Robinson() if regionname == "global" else ccrs.PlateCarree()
proj = ccrs.PlateCarree()
if regionname:
try:
# This uses the method already available in RegionBoundingBox
bbox = RegionBoundingBox.from_region_name(regionname)
proj = bbox.projection
except ValueError:
# If regionname isn't in the library, fall back to PlateCarree
_logger.warning(f"Region '{regionname}' not found in library, using PlateCarree.")
proj = ccrs.PlateCarree()
fig = plt.figure(figsize=figsize, dpi=self.dpi_val)
ax = fig.add_subplot(1, 1, 1, projection=proj)
try:
Expand Down
23 changes: 13 additions & 10 deletions packages/evaluate/src/weathergen/evaluate/utils/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from dataclasses import dataclass
from typing import ClassVar

import cartopy.crs as ccrs
import xarray as xr

_logger = logging.getLogger(__name__)
Expand All @@ -22,16 +23,17 @@ class RegionLibrary:
Predefined bounding boxes for known regions.
"""

REGIONS: ClassVar[dict[str, tuple[float, float, float, float]]] = {
"global": (-90.0, 90.0, -180.0, 180.0),
"nhem": (0.0, 90.0, -180.0, 180.0),
"shem": (-90.0, 0.0, -180.0, 180.0),
"tropics": (-30.0, 30.0, -180.0, 180.0),
"belgium": (49, 52, 2, 7),
"europe": (35, 70, -10, 40),
"uwc-west": (39.0, 63.0, -26.0, 41.0),
"arome": (37.0, 56.0, -12.0, 16.0),
"icon": (42.0, 51.0, -1.0, 18.0),
REGIONS: ClassVar[dict[str, tuple[float, float, float, float, ccrs.Projection]]] = {
"global": (-90.0, 90.0, -180.0, 180.0, ccrs.Robinson()),
"nhem": (0.0, 90.0, -180.0, 180.0, ccrs.PlateCarree()),
"shem": (-90.0, 0.0, -180.0, 180.0, ccrs.PlateCarree()),
"tropics": (-30.0, 30.0, -180.0, 180.0, ccrs.PlateCarree()),
"belgium": (49, 52, 2, 7, ccrs.PlateCarree()),
"europe": (35, 70, -10, 40, ccrs.PlateCarree()),
"arctic": (50.0, 90.0, -180.0, 180.0, ccrs.Stereographic(central_longitude=0, central_latitude=90)),
"uwc-west": (39.0, 63.0, -26.0, 41.0, ccrs.PlateCarree()),
"arome": (37.0, 56.0, -12.0, 16.0, ccrs.PlateCarree()),
"icon": (42.0, 51.0, -1.0, 18.0, ccrs.PlateCarree()),
}


Expand All @@ -41,6 +43,7 @@ class RegionBoundingBox:
lat_max: float
lon_min: float
lon_max: float
projection: ccrs.Projection

def __post_init__(self):
"""Validate the bounding box coordinates."""
Expand Down
Loading