flatironinstitute / neurosift

Browser-based NWB visualization and DANDI exploration
Apache License 2.0
42 stars 5 forks source link

Extend trial-aligned view to TimeSeries #190

Open weiglszonja opened 1 month ago

weiglszonja commented 1 month ago

Can you extend the TimeAlignedSeries view mentioned here to work on this dataset?

We would like to see trial-aligned view for fiber photometry data (added as FiberPhotometryResponseSeries from ndx-fiber-photometry which extends TimeSeries), light and tone stimulus times stored in TimeIntervals.

trial-aligned DF/F in figure B:

https://www.sciencedirect.com/science/article/pii/S0896627323009704#fig4

Screenshot 2024-07-15 at 15 35 27 (2)
magland commented 1 month ago

I have now enabled this for FiberPhotometryResponseSeries

https://neurosift.app/?p=/nwb&url=https://api.dandiarchive.org/api/assets/deb6b7b3-47cb-421e-a600-72a73ae4bad3/download/&dandisetId=001084&dandisetVersion=draft&tab=view:TrialAlignedSeries|/processing/behavior/TimeIntervals^/processing/ophys/DfOverFFiberPhotometryResponseSeriesGreen

You need to click checkboxes to select /processing/behavior/TimeIntervals and /processing/ophys/DfOverFFiberPhotometryResponseSeriesGreen and then the button/link will appear at the bottom of the left panel.

Will need to think about how to make this view more discoverable, because a user will not know to do this.

As a side note, there was an error when I tried to do this with /processing/ophys/BaselineFiberPhotometryResponseSeriesGreen

After doing some investigation, I'm pretty sure that the content of the .nwb file is corrupted for this dataset. It's a large file so I didn't download locally, but for reference the following produces an error.

import remfile
import h5py

url = 'https://api.dandiarchive.org/api/assets/deb6b7b3-47cb-421e-a600-72a73ae4bad3/download/'

rf = remfile.File(url)
f = h5py.File(rf, 'r')

X = f['/processing/ophys/BaselineFiberPhotometryResponseSeriesGreen']
timestamps = X['timestamps']
data = X['data']

print(f'timestamps shape: {timestamps.shape}')
print(f'data shape: {data.shape}')

print(data[30, 30])
print(data[30000, 30])
print(data[30000, 100])

# this is the one that produces the error.
# it seems the chunk is not valid gzip data
print(data[30, 100])
weiglszonja commented 1 month ago

Thank you @magland!

It would be also useful if the TimeAlignedSeries could group by "event_type" or other columns in the table and then align to "start_time" or "stop_time". Do you think this filtering option could be added to this view?

Will need to think about how to make this view more discoverable, because a user will not know to do this.

How about having a third box showing up here:

Screenshot 2024-07-16 at 11 55 23 (2)

And then the TimeSeries can be selected for which the TimeAlignedSeries view will be triggered?

After doing some investigation, I'm pretty sure that the content of the .nwb file is corrupted for this dataset. It's a large file so I didn't download locally, but for reference the following produces an error.

Thank you for letting me know, I'm looking into it now. Not sure how this dataset became corrupted in the first place, as the other two fiber photometry series data looks fine. But I managed to replicate this error with NWBHDF5IO as well, I'll try to figure out and fix it.

magland commented 11 hours ago

@weiglszonja I have updated the above link that I had shared.

To trigger this view, you can go to the TimeIntervals object and click on TrialAlignedSeries