neo_utils.py 1015 B

1234567891011121314151617181920212223242526272829303132
  1. from neo.io.proxyobjects import BaseProxy
  2. from neo import Segment
  3. import copy
  4. def load_segment(segment, *args, **kwargs):
  5. """
  6. Utility function to load data of all child data object
  7. """
  8. new_segment = Segment(segment.name)
  9. def load_data(obj, *args, **kwargs):
  10. if isinstance(obj, BaseProxy):
  11. return obj.load(*args, **kwargs)
  12. else:
  13. return copy.deepcopy(obj)
  14. for st in segment.spiketrains:
  15. new_segment.spiketrains.append(load_data(st, load_waveforms=True))
  16. for event in segment.events:
  17. new_segment.events.append(load_data(event))
  18. for epoch in segment.epochs:
  19. new_segment.epochs.append(load_data(epoch))
  20. for anasig in segment.analogsignals:
  21. new_segment.analogsignals.append(load_data(anasig))
  22. for irrsig in segment.irregularlysampledsignals:
  23. new_segment.irregularlysampledsignals.append(load_data(irrsig))
  24. for c in new_segment.children:
  25. c.segment = new_segment
  26. return new_segment