pynapple-org / pynapple

PYthon Neural Analysis Package :pineapple:
https://pynapple-org.github.io/pynapple/
MIT License
243 stars 59 forks source link

IntervalSet creation from (start, end) pairs #304

Open eschombu opened 1 week ago

eschombu commented 1 week ago

It's a bit counter-intuitive sometimes to split up a sequence of intervals into the starts and ends, and easier sometimes to write a sequence of start-end pairs. This change allows the IntervalSet to accept such a sequence of pairs, or a single pair.

Example:

single_intvl = IntervalSet((0, 60))
several_intvls = IntervalSet([(0, 5), (5, 10), (40, 50)])

I also added the capability to pass a variable that can be used for IntervalSet creation to the time_support parameter during TsGroup initialization. Meaning, if time_support is not an IntervalSet instance, time_support = IntervalSet(time_support) will be attempted.

I added tests and updated the doc string. This is my first PR to the repo, so more than happy for feedback on:

gviejo commented 6 hours ago

I agree for the flexibility and I think the new argument for IntervalSet makes sense. For TsGroup, I would not do it as I can see it being hard to maintain on the long run. In this case, forcing to pass an IntervalSet is probably easier.