Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fancy indexing for electrical series with Zarr backend #283

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

alejoe91
Copy link
Contributor

@alejoe91 alejoe91 commented May 9, 2023

Turns out fancy indexing is not supported for zarr.Dataset objects and this was causing an issue in displaying timeseries correctly.

This small PR fixes it by changing the behavior of the timeseries.py and:

  • use direct slicing when possible (consecutive indices)
  • slice first in time and then in channels otherwise

Not that for NWBwidgets in all cases we can slice directly, because of the channel slider.

@codecov
Copy link

codecov bot commented May 9, 2023

Codecov Report

Attention: Patch coverage is 80.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 66.24%. Comparing base (fdc0309) to head (03a598a).

Files Patch % Lines
nwbwidgets/timeseries.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #283   +/-   ##
=======================================
  Coverage   66.24%   66.24%           
=======================================
  Files          35       35           
  Lines        3478     3481    +3     
=======================================
+ Hits         2304     2306    +2     
- Misses       1174     1175    +1     
Flag Coverage Δ
unittests 66.24% <80.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bendichter
Copy link
Collaborator

@alejoe91 it looks like Zarr does actually support fancy indexing, though the syntax is different from numpy

https://zarr.readthedocs.io/en/stable/tutorial.html#advanced-indexing

@alejoe91
Copy link
Contributor Author

@bendichter should we use the Zarr fancy indexing functions when the dataset is a Zarr object then?

@bendichter
Copy link
Collaborator

Yes that would be an immediate fix. But this issue is going to come up for anything downstream of pynwb so maybe it makes sense to fix on the pynwb level. Maybe we could wrap all arrays in xarray?

unique_sorted_order = slice(unique_sorted_order[0], unique_sorted_order[-1] + 1)
mini_data = time_series.data[t_ind_start:t_ind_stop, unique_sorted_order][:, inverse_sort]
else:
mini_data = np.array(time_series.data[t_ind_start:t_ind_stop])[:, unique_sorted_order][:, inverse_sort]
Copy link
Collaborator

@bendichter bendichter Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a check here and have this work differently only for Zarr dataset objects? I'd prefer to use the simultaneous indexing approach for h5py datasets where we can so we don't load data into memory when we don't need to. I also think this could and probably should be refactored into a data utility function that can be used in other places

@bendichter bendichter self-requested a review August 16, 2023 17:58
Copy link
Collaborator

@bendichter bendichter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alejoe91 see comments

@bendichter
Copy link
Collaborator

@alejoe91 can you also please add checks that this data indexing utility does indeed solve the problem for Zarr dataset objects?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants