test_spike2io.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. """
  2. Tests of neo.io.spike2io
  3. """
  4. import unittest
  5. import quantities as pq
  6. from neo.io import Spike2IO
  7. from neo.test.iotest.common_io_test import BaseTestIO
  8. class TestSpike2IO(BaseTestIO, unittest.TestCase, ):
  9. ioclass = Spike2IO
  10. files_to_test = [
  11. 'File_spike2_1.smr',
  12. 'File_spike2_2.smr',
  13. 'File_spike2_3.smr',
  14. '130322-1LY.smr', # this is for bug 182
  15. 'multi_sampling.smr', # this is for bug 466
  16. 'Two-mice-bigfile-test000.smr', # SONv9 file
  17. ]
  18. files_to_download = files_to_test
  19. def test_multi_sampling_no_grouping(self):
  20. """
  21. Some file can have several sampling_rate.
  22. This one contain 3 differents signals sampling rate
  23. """
  24. filename = self.get_filename_path('multi_sampling.smr')
  25. reader = Spike2IO(filename=filename, try_signal_grouping=False)
  26. bl = reader.read_block(signal_group_mode='group-by-same-units')
  27. assert len(bl.segments) == 10
  28. seg = bl.segments[0]
  29. # 7 group_id one per channel
  30. assert len(seg.analogsignals) == 7
  31. # 1 channel for 1kHz
  32. assert seg.analogsignals[0].shape == (14296, 1)
  33. assert seg.analogsignals[0].sampling_rate == 1000 * pq.Hz
  34. # 4 channel for 2kHz
  35. for c in range(1, 5):
  36. assert seg.analogsignals[c].shape == (28632, 1)
  37. assert seg.analogsignals[c].sampling_rate == 2000 * pq.Hz
  38. # 2 channel for 10kHz
  39. for c in range(5, 7):
  40. assert seg.analogsignals[c].shape == (114618, 1)
  41. assert seg.analogsignals[c].sampling_rate == 10000 * pq.Hz
  42. def test_multi_sampling_no_grouping(self):
  43. """
  44. Some files can contain multiple sampling rates.
  45. This file contains three signals with different sampling rates.
  46. """
  47. filename = self.get_filename_path('multi_sampling.smr')
  48. reader = Spike2IO(filename=filename, try_signal_grouping=True)
  49. bl = reader.read_block(signal_group_mode='group-by-same-units')
  50. assert len(bl.segments) == 10
  51. seg = bl.segments[0]
  52. # 3 groups
  53. assert len(seg.analogsignals) == 3
  54. # 1 channel for 1kHz
  55. assert seg.analogsignals[0].shape == (14296, 1)
  56. assert seg.analogsignals[0].sampling_rate == 1000 * pq.Hz
  57. # 4 channel for 2kHz
  58. assert seg.analogsignals[1].shape == (28632, 4)
  59. assert seg.analogsignals[1].sampling_rate == 2000 * pq.Hz
  60. # 2 channel for 10kHz
  61. assert seg.analogsignals[2].shape == (114618, 2)
  62. assert seg.analogsignals[2].sampling_rate == 10000 * pq.Hz
  63. if __name__ == "__main__":
  64. unittest.main()