pynapple-org / pynapple

PYthon Neural Analysis Package :pineapple:
https://pynapple.org/
MIT License
281 stars 64 forks source link

[ENH] Merge TsGroup? #251

Closed qian-chu closed 6 months ago

qian-chu commented 7 months ago

In quite a few scenarios one may want to merge some TsGroup (e.g. adding new neurons, merging PETH from different runs, etc.) but currently TsGroup is non-mutable: https://github.com/pynapple-org/pynapple/blob/ea603577767e2117c7afdaac4edf800fae4bf6ce/pynapple/core/ts_group.py#L149-L151 Maybe we can add a method that takes two TsGroups and returns a new TsGroup when the following conditions are met:

  1. Non-overlapping indices
  2. Same meta-info columns
  3. Same time support (if none specified, infer from start and end of the merged Ts/Tsd

Happy to initiate a pull request if people see a need for this.

gviejo commented 7 months ago

Hi Qian Chu, I think it's doable with the condition you just listed. Maybe a class method that does something like this

tsgroup = nap.TsGroup.join_group_set([tsgroup1, tsgroup2, tsgroup3])

Maybe this class method can be called by a simple method of TsGroup like this as well.

tsgroup = tsgroup1.join(tsgroup2)

In general I like to provide multiple ways of doing the same thing in pynapple. I noticed people have different intuition about how the package should behave.

Happy to review a PR.

gviejo commented 6 months ago

Solved in #275