Skip to content

[Bug] Heatmap CLI fails on time‑stacked NetCDFs (3D arrays) #219

@jphpme

Description

@jphpme

Title: visualize heatmap fails on time‑stacked NetCDFs (3D arrays) — Invalid shape (48, 721, 1440)

Description:
zyra visualize heatmap fails when the NetCDF variable contains a time dimension (3D array). The CLI passes the full (time, lat, lon) array into matplotlib.imshow, which raises a shape error.

Exact error

Warning: Input CRS unknown; assuming EPSG:4326.
Traceback (most recent call last):
File "/opt/venv/bin/zyra", line 8, in
sys.exit(main())
File "/opt/venv/lib/python3.10/site-packages/zyra/cli.py", line 1164, in main
return args.func(args)
File "/opt/venv/lib/python3.10/site-packages/zyra/visualization/cli_heatmap.py", line 84, in handle_heatmap
mgr.render(
File "/opt/venv/lib/python3.10/site-packages/zyra/visualization/heatmap_manager.py", line 165, in render
im = ax.imshow(
File "/opt/venv/lib/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 291, in wrapper
return func(self, *args, **kwargs)
File "/opt/venv/lib/python3.10/site-packages/cartopy/mpl/geoaxes.py", line 1275, in imshow
result = super().imshow(img, *args, **kwargs)
File "/opt/venv/lib/python3.10/site-packages/matplotlib/init.py", line 1524, in inner
return func(
File "/opt/venv/lib/python3.10/site-packages/matplotlib/axes/_axes.py", line 5982, in imshow
im.set_data(X)
File "/opt/venv/lib/python3.10/site-packages/matplotlib/image.py", line 685, in set_data
self._A = self._normalize_image_array(A)
File "/opt/venv/lib/python3.10/site-packages/matplotlib/image.py", line 653, in _normalize_image_array
raise TypeError(f"Invalid shape {A.shape} for image data")
TypeError: Invalid shape (48, 721, 1440) for image data
Dataset context
ERA5 NetCDF with variables:

['number', 'valid_time', 'latitude', 'longitude', 'expver', 't2m']

Expected behavior
If a time dimension exists and no explicit index is provided, render one frame per timestep (output directory), or
Allow a --time-index / --time flag for a single timestep, and error clearly if not provided.
Also consider handling extra dims like expver/number by defaulting to the first slice or supporting a selector.

Actual behavior
Zyra tries to render the full 3D array with imshow, causing a shape error.

Environment

Zyra CLI invoked inside Docker (Python 3.10)
Cartopy + Matplotlib
NetCDF input with time dimension (ERA5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions