GeoscienceAustralia / dea-sandbox

Digital Earth Australia Sandbox config and planning
Apache License 2.0
13 stars 6 forks source link

"Loading widget..." error when running Matplotlib widget on latest Sandbox image #244

Closed robbibt closed 1 year ago

robbibt commented 1 year ago

Describe the bug The Land Cover Pixel drill notebook here uses Matplotlib widgets to allow users to click on the map and return Land cover pixel drill data: https://docs.dea.ga.gov.au/notebooks/Frequently_used_code/Land_cover_pixel_drill.html

However, this notebook as broken on the latest Sandbox image: when a user runs the cell to create the widget, they see a "Loading widget..." message but the widget does not load:

image

This works correctly on the current "default" Sandbox images.

To Reproduce Run code on "Unstable" prod Sandbox server:

%matplotlib widget

import datacube
import matplotlib.pyplot as plt

dc = datacube.Datacube(app="Land_cover_pixel_drill")

def click_for_coords(event):
    """
    Define behaviour widget to enable extraction of x,y values for point 
    manually selected with mouse click on interactive plot.
    For use with Matplotlib Imshow.
    The x and y returned are the coordinate positions of the pixel in 
    the x and y axis, rather than latitude/longitude values of the point.
    The coordinate positions of the pixel this is what you need later 
    to conduct a pixel drill.
    Returns: ix, iy = position of selected pixel in the x and y 
    coordinates of the array.
    """
    global ix, iy
    ix, iy = event.xdata, event.ydata
    global coords
    coords.append((ix, iy))

    fig.canvas.mpl_disconnect(cid)
    return

# Load DEA Land Cover data from the datacube
all_data = dc.load(
    product="ga_ls_landcover_class_cyear_2",
    y=(-35.2064, -35.0064),
    x=(149.3248, 149.5248),
    time=("1988", "2020"),
    output_crs="EPSG:3577",
    measurements=["level3"],
    resolution=(-25, 25)
)

# Create interactive plot
fig, ax = plt.subplots(figsize=(6, 6))
ax = plt.imshow(
    all_data.level3.sel(time="2020", method="nearest").squeeze(),
    interpolation="nearest",
)
cid = fig.canvas.mpl_connect("button_press_event", click_for_coords)
plt.title("Interactive Plot")

Expected behavior Users can successfully run Matplotlib widgets using latest Sandbox image

robbibt commented 1 year ago

I think this is fixed now, thanks @emmaai!