From 606de7eeb68312cab878447a6c7ab7711639ab99 Mon Sep 17 00:00:00 2001 From: Nina Raoult Date: Fri, 20 Dec 2024 10:51:41 +0000 Subject: [PATCH] added plotting options --- src/anemoi/utils/devtools.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/anemoi/utils/devtools.py b/src/anemoi/utils/devtools.py index 53e8ea2..e79b486 100644 --- a/src/anemoi/utils/devtools.py +++ b/src/anemoi/utils/devtools.py @@ -27,7 +27,9 @@ def fix(lons): return np.where(lons > 180, lons - 360, lons) -def plot_values(values, latitudes, longitudes, title=None, **kwargs): +def plot_values( + values, latitudes, longitudes, title=None, missing_value=None, min_value=None, max_value=None, **kwargs +): _, ax = plt.subplots(subplot_kw={"projection": ccrs.PlateCarree()}) ax.coastlines() @@ -35,9 +37,19 @@ def plot_values(values, latitudes, longitudes, title=None, **kwargs): missing_values = np.isnan(values) - values = values[~missing_values] - longitudes = longitudes[~missing_values] - latitudes = latitudes[~missing_values] + if missing_value is None: + values = values[~missing_values] + longitudes = longitudes[~missing_values] + latitudes = latitudes[~missing_values] + else: + values = np.where(missing_values, missing_value, values) + + if max_value is not None: + values = np.where(values > max_value, max_value, values) + + if min_value is not None: + values = np.where(values < min_value, min_value, values) + triangulation = tri.Triangulation(fix(longitudes), latitudes) levels = kwargs.pop("levels", 10)