NeurodataWithoutBorders / nwbwidgets

Explore the hierarchical structure of NWB 2.0 files and visualize data with Jupyter widgets.
https://nwb-widgets.readthedocs.io/en/latest/
Other
48 stars 21 forks source link

Show SpatialSeries when the second axis of the data is 1 #206

Open weiglszonja opened 2 years ago

weiglszonja commented 2 years ago

Rendering SpatialSeries data with nwbwidgets is not possible when spatial_series.data.shape[1] == 1. I noticed this issue when when trying to visualise SpatialSeries data for a dandi dataset : "animal_direction" which is a SpatialSeries with a shape of (90050, 1) (see below steps to reproduce).

We discussed with @CodyCBakerPhD that this should be handled on the widgets side, as this data was created with pynwb without complains. Currently, this case gets handled as:

https://github.com/NeurodataWithoutBorders/nwb-jupyter-widgets/blob/c891978d74a2e52a3ccbf65949f5b8192858e1dc/nwbwidgets/behavior.py#L93-L94

If you agree this should be handled on the widgets side as well, I'll try to create a PR for this as well.

Steps to reproduce with the real data:

from pynwb import NWBHDF5IO
from nwbinspector.tools import get_s3_urls_and_dandi_paths
from nwbwidgets import nwb2widget

s3_path = list(get_s3_urls_and_dandi_paths(dandiset_id="000230", n_jobs=-1))[0]

io = NWBHDF5IO(
    path=s3_path,
    mode="r",
    load_namespaces=True,
    driver="ros3")

nwbfile = io.read()

print(nwbfile.processing["animal_behaviour"].data_interfaces["animal_direction"].data[:].shape)

nwb2widget(nwbfile)
CodyCBakerPhD commented 2 years ago

My main point is just that the data access through the actual NWBFile is 'fine' - has no issues and is clear what dims represent. Error stems from how the widgets code expects the output shape to be, which I think ought to be able to handle this case.