Skip to content

Commit

Permalink
Dev icenet-ai#279: Partial plotting regression fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bnubald committed Jul 3, 2024
1 parent d7f4b09 commit 62e4baa
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
15 changes: 10 additions & 5 deletions icenet/plotting/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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],
Expand All @@ -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)
Expand Down
34 changes: 25 additions & 9 deletions icenet/plotting/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 62e4baa

Please sign in to comment.