From 62e4baa136844eeed5d01da19c677c164ccf0739 Mon Sep 17 00:00:00 2001 From: "Bryn N. Ubald" <55503826+bnubald@users.noreply.github.com> Date: Wed, 3 Jul 2024 13:17:29 +0100 Subject: [PATCH] Dev #279: Partial plotting regression fix --- icenet/plotting/forecast.py | 15 ++++++++++----- icenet/plotting/video.py | 34 +++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/icenet/plotting/forecast.py b/icenet/plotting/forecast.py index 6d5942a..db73fa3 100644 --- a/icenet/plotting/forecast.py +++ b/icenet/plotting/forecast.py @@ -27,11 +27,13 @@ from icenet import __version__ as icenet_version from icenet.data.cli import date_arg from icenet.data.sic.mask import Masks -from icenet.plotting.utils import (filter_ds_by_obs, get_forecast_ds, +from icenet.plotting.utils import (calculate_extents, filter_ds_by_obs, + get_forecast_ds, get_obs_da, get_seas_forecast_da, - get_seas_forecast_init_dates, show_img, + get_seas_forecast_init_dates, + lat_lon_box, show_img, get_plot_axes, process_probes, - process_regions, lat_lon_box) + process_regions) from icenet.plotting.video import xarray_to_video @@ -1639,8 +1641,8 @@ def plot_forecast(show_plot=False): bound_args = dict(north=args.hemisphere == "north", south=args.hemisphere == "south") + method = "pixel" if args.region is not None: - method = "pixel" bound_args.update(x1=args.region[0], x2=args.region[2], y1=args.region[1], @@ -1652,7 +1654,10 @@ def plot_forecast(show_plot=False): y1=args.region_lat_lon[1], y2=args.region_lat_lon[3]) - extent = (bound_args["x1"], bound_args["x2"], bound_args["y1"], bound_args["y2"]) + if args.region is not None or args.region_lat_lon is not None: + extent = (bound_args["x1"], bound_args["x2"], bound_args["y1"], bound_args["y2"]) + else: + extent = None if args.format == "mp4": pred_da = fc.isel(time=0).sel(leadtime=leadtimes) diff --git a/icenet/plotting/video.py b/icenet/plotting/video.py index 316ae58..bd6d506 100644 --- a/icenet/plotting/video.py +++ b/icenet/plotting/video.py @@ -18,6 +18,7 @@ from icenet.process.predict import get_refcube from icenet.utils import setup_logging +from icenet.plotting.utils import calculate_extents # TODO: This can be a plotting or analysis util function elsewhere @@ -194,25 +195,40 @@ def update(date, north_facing): date = pd.Timestamp(da.time.values[0]).to_pydatetime() - cmap.set_bad("dimgrey", alpha=0) + # cmap.set_bad("dimgrey", alpha=0) ax.add_feature(cfeature.LAND, facecolor="dimgrey") - # ax.add_feature(cfeature.COASTLINE) + ax.add_feature(cfeature.COASTLINE) + + if gridlines: + gl = ax.gridlines(crs=source_crs) + + data = da.sel(time=date) + lon, lat = da.lon.values, da.lat.values + + if method == "pixel": + if extent is None: + extent = (0, 432, 0, 432) + extent = calculate_extents(*extent) # TODO: Tidy up, and cover all argument options if not north_facing: - image = ax.imshow(da.sel(time=date), + image = ax.imshow(data, cmap=cmap, + transform=source_crs, clim=(n_min, n_max), animated=True, zorder=1, + extent = extent, **imshow_kwargs if imshow_kwargs is not None else {}) + # image = ax.pcolormesh(lon, lat, data, + # transform=target_crs, + # cmap=cmap, + # clim=(n_min, n_max), + # animated=True, + # zorder=1, + # **imshow_kwargs if imshow_kwargs is not None else {} + # ) else: - lon, lat = da.lon.values, da.lat.values - data = da.sel(time=date) - - if gridlines: - gl = ax.gridlines(crs=source_crs) - if extent and method == "lat_lon": ax.set_extent(extent, crs=target_crs)