Skip to content

Commit

Permalink
Dev icenet-ai#279: icenet-ai#100 Switch from imshow to pcolormesh, fi…
Browse files Browse the repository at this point in the history
…x overlap w/ northfacing
  • Loading branch information
bnubald committed Jul 3, 2024
1 parent 62e4baa commit ee17344
Showing 1 changed file with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions icenet/plotting/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

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 @@ -124,12 +123,9 @@ def xarray_to_video(
source_crs = ccrs.LambertAzimuthalEqualArea(central_latitude=pole*90, central_longitude=0)
target_crs = ccrs.PlateCarree()

def update(date, north_facing):
def update(date):
logging.debug("Plotting {}".format(date.strftime("%D")))
if north_facing:
image.set_array(da.sel(time=date))
else:
image.set_data(da.sel(time=date))
image.set_array(da.sel(time=date))

image_title.set_text("{:04d}/{:02d}/{:02d}".format(
date.year, date.month, date.day))
Expand Down Expand Up @@ -195,7 +191,12 @@ def update(date, north_facing):

date = pd.Timestamp(da.time.values[0]).to_pydatetime()

# cmap.set_bad("dimgrey", alpha=0)
# pcolormesh requires set_bad to be transparent for wraparound.
if method == "lat_lon" and north_facing:
alpha = 0.0
else:
alpha = 1.0
cmap.set_bad("dimgrey", alpha=alpha)
ax.add_feature(cfeature.LAND, facecolor="dimgrey")
ax.add_feature(cfeature.COASTLINE)

Expand All @@ -205,35 +206,26 @@ def update(date, north_facing):
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(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 {}
# )
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:
if extent and method == "lat_lon":
ax.set_extent(extent, crs=target_crs)

image = ax.pcolormesh(lon, lat, data,
transform=target_crs,
transformed_coords = source_crs.transform_points(target_crs, lon, lat)

x = transformed_coords[:, :, 0]
y = transformed_coords[:, :, 1]
image = ax.pcolormesh(x, y, data,
transform=source_crs,
cmap=cmap,
clim=(n_min, n_max),
animated=True,
Expand All @@ -259,7 +251,7 @@ def update(date, north_facing):
logging.info("Animating")

# Investigated blitting, but it causes a few problems with masks/titles.
animation = FuncAnimation(fig, update, video_dates, fargs=(north_facing,),
animation = FuncAnimation(fig, update, video_dates,
interval=1000 / fps)

plt.close()
Expand Down

0 comments on commit ee17344

Please sign in to comment.