test_asciiimageio.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """
  2. Test of neo.io.asciiimageio
  3. """
  4. import os
  5. import unittest
  6. import quantities as pq
  7. from neo.io import AsciiImageIO
  8. import numpy as np
  9. class TestAsciiImageIO(unittest.TestCase):
  10. def test_read_txt(self):
  11. img = ''
  12. img_list = []
  13. for frame in range(20):
  14. img_list.append([])
  15. for y in range(50):
  16. img_list[frame].append([])
  17. for x in range(50):
  18. img += str(x)
  19. img += '\t'
  20. img_list[frame][y].append(x)
  21. img_list = np.array(img_list)
  22. file_name = "txt_test_file.txt"
  23. file = open(file_name, mode="w")
  24. file.write(str(img))
  25. file.close()
  26. object = AsciiImageIO(file_name='txt_test_file.txt',
  27. nb_frame=20, nb_row=50, nb_column=50, units='V',
  28. sampling_rate=1 * pq.Hz, spatial_scale=1 * pq.micrometer)
  29. block = object.read_block()
  30. self.assertEqual(len(block.segments), 1)
  31. self.assertEqual(len(block.segments[0].imagesequences), 1)
  32. self.assertEqual(block.segments[0].imagesequences[0].shape, (20, 50, 50))
  33. self.assertEqual(block.segments[0].imagesequences[0].any(), img_list.any())
  34. file.close()
  35. os.remove(file_name)
  36. if __name__ == "__main__":
  37. unittest.main()