test_tdtio.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """
  2. Tests of neo.io.tdtio
  3. """
  4. import unittest
  5. from neo.io import TdtIO
  6. from neo.test.iotest.common_io_test import BaseTestIO
  7. from neo.test.iotest.tools import get_test_file_full_path
  8. import numpy as np
  9. class TestTdtIO(BaseTestIO, unittest.TestCase, ):
  10. ioclass = TdtIO
  11. files_to_test = ['aep_05']
  12. files_to_download = ['aep_05/Block-1/aep_05_Block-1.Tbk',
  13. 'aep_05/Block-1/aep_05_Block-1.Tdx',
  14. 'aep_05/Block-1/aep_05_Block-1.tev',
  15. 'aep_05/Block-1/aep_05_Block-1.tsq',
  16. 'aep_05/Block-2/aep_05_Block-2.Tbk',
  17. 'aep_05/Block-2/aep_05_Block-2.Tdx',
  18. 'aep_05/Block-2/aep_05_Block-2.tev',
  19. 'aep_05/Block-2/aep_05_Block-2.tsq',
  20. # ~ 'aep_05/Block-3/aep_05_Block-3.Tbk',
  21. # ~ 'aep_05/Block-3/aep_05_Block-3.Tdx',
  22. # ~ 'aep_05/Block-3/aep_05_Block-3.tev',
  23. # ~ 'aep_05/Block-3/aep_05_Block-3.tsq',
  24. ]
  25. def test_signal_group_mode(self):
  26. dirname = get_test_file_full_path(ioclass=TdtIO,
  27. filename='aep_05', directory=self.local_test_dir,
  28. clean=False)
  29. # TdtIO is a hard case they are 3 groups at rawio level
  30. # there are 3 groups of signals
  31. nb_sigs_by_group = [1, 16, 16]
  32. signal_group_mode = 'group-by-same-units'
  33. reader = TdtIO(dirname=dirname)
  34. bl = reader.read_block(signal_group_mode=signal_group_mode)
  35. for seg in bl.segments:
  36. assert len(seg.analogsignals) == 3
  37. i = 0
  38. for anasig in seg.analogsignals:
  39. # print(anasig.shape, anasig.sampling_rate)
  40. assert anasig.shape[1] == nb_sigs_by_group[i]
  41. i += 1
  42. signal_group_mode = 'split-all'
  43. reader = TdtIO(dirname=dirname)
  44. bl = reader.read_block(signal_group_mode=signal_group_mode)
  45. for seg in bl.segments:
  46. assert len(seg.analogsignals) == np.sum(nb_sigs_by_group)
  47. for anasig in seg.analogsignals:
  48. # print(anasig.shape, anasig.sampling_rate)
  49. assert anasig.shape[1] == 1
  50. if __name__ == "__main__":
  51. unittest.main()