Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

1
0

pickleio.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. """
  3. Module for reading/writing data from/to Python pickle format.
  4. Class:
  5. PickleIO
  6. Supported: Read/Write
  7. Authors: Andrew Davison
  8. """
  9. try:
  10. import cPickle as pickle # Python 2
  11. except ImportError:
  12. import pickle # Python 3
  13. from neo.io.baseio import BaseIO
  14. from neo.core import (Block, Segment,
  15. AnalogSignal, SpikeTrain)
  16. class PickleIO(BaseIO):
  17. """
  18. A class for reading and writing Neo data from/to the Python "pickle" format.
  19. Note that files in this format may not be readable if using a different version
  20. of Neo to that used to create the file. It should therefore not be used for
  21. long-term storage, but rather for intermediate results in a pipeline.
  22. """
  23. is_readable = True
  24. is_writable = True
  25. has_header = False
  26. is_streameable = False # TODO - correct spelling to "is_streamable"
  27. # should extend to other classes.
  28. supported_objects = [Block, Segment, AnalogSignal, SpikeTrain]
  29. readable_objects = supported_objects
  30. writeable_objects = supported_objects
  31. mode = 'file'
  32. name = "Python pickle file"
  33. extensions = ['pkl', 'pickle']
  34. def read_block(self, lazy=False):
  35. assert not lazy, 'Do not support lazy'
  36. with open(self.filename, "rb") as fp:
  37. block = pickle.load(fp)
  38. return block
  39. def write_block(self, block):
  40. with open(self.filename, "wb") as fp:
  41. pickle.dump(block, fp)