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

concatenating Tsd #366

Open
samdeoxys1 opened this issue Nov 14, 2024 · 1 comment
Open

concatenating Tsd #366

samdeoxys1 opened this issue Nov 14, 2024 · 1 comment

Comments

@samdeoxys1
Copy link

In concatenating the Tsd, why having the restriction that
image
?
Maybe this is an unlikely use case:
I'm trying to do something like: doing some shuffle of spike times for spikes that happen during the small window of the ripple, but keep spikes outside of that small window (within an extended window) unchanged. I then form a Tsd for the shuffled spikes, as well as a Tsd for the non-shuffled spikes outside of the small window. The second Tsd include before and after the small window, so the two Tsds cannot be concatenated. But it would be nice it they could be, and pynapple just sort the final time automatically. What do you think?

@sjvenditto
Copy link
Collaborator

Concatenating Tsd objects inherits functionality from numpy, which doesn't do any sorting; therefore, to match numpy's definition, we also don't do any sorting. This means we have to restrict concatenating Tsd objects with out-of-order or overlapping time indexes so that the output is sensible. We can theoretically extend it to allow post-concatenation sorting, but it's unclear how complex it may turn out under-the-hood with added edge cases (like duplicate time indices, for example). But we'll definitely consider it in future development!

In the meantime for your case, you can solve your concatenation issue by splitting the large window into two Tsd objects, one for before the small window and one for after. Then you can concatenate the three Tsd objects. For example:

tsd1 = nap.Tsd(t=[3, 4], d=[1, 1]) # middle
tsd2 = nap.Tsd(t=[1, 2, 5, 6], d=[2, 2, 2, 2]) # edges

np.concatenate((tsd1, tsd2))  # error

tsd2_1, tsd2_2 = tsd2.split([2])  # split at index 2
np.concatenate((tsd2_1, tsd1, tsd2_2))  # no error

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

No branches or pull requests

2 participants