NeurodataWithoutBorders / pynwb

A Python API for working with Neurodata stored in the NWB Format
https://pynwb.readthedocs.io
Other
178 stars 84 forks source link

method for TimeSeries: get_values #540

Open bendichter opened 6 years ago

bendichter commented 6 years ago

I'd like a function for TimeSeries that gets me the data values that correspond to a specific start and end time. I'd like this to work whether the time is stored as starting_time and rate or as timestamps. Does this already exist?

ajtritt commented 6 years ago

No, it doesn’t exist yet, but we’ve done a little work on internal infrastructure needed for doing this.

oruebel commented 6 years ago

In addition to what Andrew mentioned. As a bit of a side-project, I started experimenting with how this might look in the special case of a TimeSeries on a branch but it's experimental at this point and I think the final solution will likely look different and will use some more of the general infrastructure that Andrew mentioned. I.e., I would not recommend to rely on what I'm describing next as it is experimental and will very likely change. I just wanted to mention it in case you need something quick-and-dirty for some time-critical task.

If you want, you can have a look at the class TimeSeriesHelper on the branch enh/select_timeseries. The class just wraps an existing TimeSeries to provide additional functions. In particular, have a look at the function subset_series which can take a time_range and/or an index_select (e.g., numpy.s_[:,1:10]) to select data from the TimeSeries and creates a new TimeSeries for the corresponding data subset. I have not tested it extensively, but it should in principle work with any TimeSeries, i.e., subset_series should create a new series of the same derived type as the input TimeSeries and all fields should be copied over. Here is a simple test case which shows how it should work. The TimeSeriesHelper class also has a number of other experimental functions to deal with the timestamps issued, e.g., to convert between stamps and index or to convert the timestamps (which are relative to the session_start_time) into absolute timestamps. There are also some functions to convert a TimeSeries to an xarray or pandas series

I don't want to merge this stuff back right now because a) it introduces a bunch of heavy dependencies (xarray, pandas), b) its not well tested, c) the interface is not really how it should look in PyNWB (it's really just me playing with it).

bendichter commented 6 years ago

analogous to https://github.com/NeurodataWithoutBorders/matnwb/pull/52