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.

test_pickleio.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests of the neo.io.pickleio.PickleIO class
  4. """
  5. # needed for python 3 compatibility
  6. from __future__ import absolute_import, division
  7. import os
  8. try:
  9. import unittest2 as unittest
  10. except ImportError:
  11. import unittest
  12. import numpy as np
  13. import quantities as pq
  14. from neo.core import Block, Segment, AnalogSignal, SpikeTrain, Unit, Epoch, Event, ChannelIndex, IrregularlySampledSignal
  15. from neo.io import PickleIO
  16. from numpy.testing import assert_array_equal
  17. from neo.test.tools import assert_arrays_equal, assert_file_contents_equal
  18. from neo.test.iotest.common_io_test import BaseTestIO
  19. NCELLS = 5
  20. class CommonTestPickleIO(BaseTestIO, unittest.TestCase):
  21. ioclass = PickleIO
  22. def test_readed_with_cascade_is_compliant(self):
  23. pass
  24. test_readed_with_cascade_is_compliant.__test__ = False # PickleIO does not support lazy loading
  25. def test_readed_with_lazy_is_compliant(self):
  26. pass
  27. test_readed_with_lazy_is_compliant.__test__ = False
  28. class TestPickleIO(unittest.TestCase):
  29. def test__issue_285(self):
  30. ##Spiketrain
  31. train = SpikeTrain([3, 4, 5] * pq.s, t_stop=10.0)
  32. unit = Unit()
  33. train.unit = unit
  34. unit.spiketrains.append(train)
  35. epoch = Epoch([0, 10, 20], [2, 2, 2], ["a", "b", "c"], units="ms")
  36. blk = Block()
  37. seg = Segment()
  38. seg.spiketrains.append(train)
  39. seg.epochs.append(epoch)
  40. epoch.segment = seg
  41. blk.segments.append(seg)
  42. reader = PickleIO(filename="blk.pkl")
  43. reader.write(blk)
  44. reader = PickleIO(filename="blk.pkl")
  45. r_blk = reader.read_block()
  46. r_seg = r_blk.segments[0]
  47. self.assertIsInstance(r_seg.spiketrains[0].unit, Unit)
  48. self.assertIsInstance(r_seg.epochs[0], Epoch)
  49. os.remove('blk.pkl')
  50. ##Epoch
  51. train = Epoch(times=np.arange(0, 30, 10)*pq.s,durations=[10, 5, 7]*pq.ms,labels=np.array(['btn0', 'btn1', 'btn2'], dtype='S'))
  52. train.segment = Segment()
  53. unit = Unit()
  54. unit.spiketrains.append(train)
  55. blk = Block()
  56. seg = Segment()
  57. seg.spiketrains.append(train)
  58. blk.segments.append(seg)
  59. reader = PickleIO(filename="blk.pkl")
  60. reader.write(blk)
  61. reader = PickleIO(filename="blk.pkl")
  62. r_blk = reader.read_block()
  63. r_seg = r_blk.segments[0]
  64. self.assertIsInstance(r_seg.spiketrains[0].segment, Segment)
  65. os.remove('blk.pkl')
  66. ##Event
  67. train = Event(np.arange(0, 30, 10)*pq.s,labels=np.array(['trig0', 'trig1', 'trig2'],dtype='S'))
  68. train.segment = Segment()
  69. unit = Unit()
  70. unit.spiketrains.append(train)
  71. blk = Block()
  72. seg = Segment()
  73. seg.spiketrains.append(train)
  74. blk.segments.append(seg)
  75. reader = PickleIO(filename="blk.pkl")
  76. reader.write(blk)
  77. reader = PickleIO(filename="blk.pkl")
  78. r_blk = reader.read_block()
  79. r_seg = r_blk.segments[0]
  80. self.assertIsInstance(r_seg.spiketrains[0].segment, Segment)
  81. os.remove('blk.pkl')
  82. ##IrregularlySampledSignal
  83. train = IrregularlySampledSignal([0.0, 1.23, 6.78], [1, 2, 3],units='mV', time_units='ms')
  84. train.segment = Segment()
  85. unit = Unit()
  86. train.channel_index = ChannelIndex(1)
  87. unit.spiketrains.append(train)
  88. blk = Block()
  89. seg = Segment()
  90. seg.spiketrains.append(train)
  91. blk.segments.append(seg)
  92. blk.segments[0].block = blk
  93. reader = PickleIO(filename="blk.pkl")
  94. reader.write(blk)
  95. reader = PickleIO(filename="blk.pkl")
  96. r_blk = reader.read_block()
  97. r_seg = r_blk.segments[0]
  98. self.assertIsInstance(r_seg.spiketrains[0].segment, Segment)
  99. self.assertIsInstance(r_seg.spiketrains[0].channel_index, ChannelIndex)
  100. os.remove('blk.pkl')
  101. if __name__ == '__main__':
  102. unittest.main()