You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
4.4 KiB

  1. """
  2. These tests require that you have a specific ND2 file created by the developer of nd2reader. You will never need to
  3. run them unless you're Jim Rybarski.
  4. """
  5. from nd2reader import Nd2
  6. from datetime import datetime
  7. import unittest
  8. class FunctionalTests(unittest.TestCase):
  9. def setUp(self):
  10. self.nd2 = Nd2("/var/nd2s/FYLM-141111-001.nd2")
  11. def tearDown(self):
  12. self.nd2.close()
  13. def test_shape(self):
  14. self.assertEqual(self.nd2.height, 1280)
  15. self.assertEqual(self.nd2.width, 800)
  16. def test_date(self):
  17. self.assertEqual(self.nd2.date, datetime(2014, 11, 11, 15, 59, 19))
  18. # def test_length(self):
  19. # # This will fail until we address issue #59
  20. # self.assertEqual(len(self.nd2), 17808)
  21. def test_frames(self):
  22. self.assertEqual(len(self.nd2.frames), 636)
  23. def test_fovs(self):
  24. self.assertEqual(len(self.nd2.fields_of_view), 8)
  25. def test_channels(self):
  26. self.assertTupleEqual(tuple(sorted(self.nd2.channels)), ('BF', 'GFP'))
  27. def test_z_levels(self):
  28. self.assertTupleEqual(tuple(self.nd2.z_levels), (0, 1, 2))
  29. def test_image(self):
  30. image = self.nd2[14]
  31. self.assertEqual(image.field_of_view, 2)
  32. self.assertEqual(image.frame_number, 0)
  33. self.assertAlmostEqual(image.timestamp, 19.0340758)
  34. self.assertEqual(image.channel, 'BF')
  35. self.assertEqual(image.z_level, 1)
  36. self.assertEqual(image.height, self.nd2.height)
  37. self.assertEqual(image.width, self.nd2.width)
  38. def test_last_image(self):
  39. image = self.nd2[30526]
  40. self.assertEqual(image.frame_number, 635)
  41. def test_bad_image(self):
  42. image = self.nd2[13]
  43. self.assertIsNone(image)
  44. def test_iteration(self):
  45. images = [image for image in self.nd2[:10]]
  46. self.assertEqual(len(images), 10)
  47. def test_iteration_step(self):
  48. images = [image for image in self.nd2[:10:2]]
  49. self.assertEqual(len(images), 5)
  50. def test_iteration_backwards(self):
  51. images = [image for image in self.nd2[:10:-1]]
  52. self.assertEqual(len(images), 10)
  53. def test_get_image_by_attribute_ok(self):
  54. image = self.nd2.get_image(4, 0, "GFP", 1)
  55. self.assertIsNotNone(image)
  56. image = self.nd2.get_image(4, 0, "BF", 0)
  57. self.assertIsNotNone(image)
  58. image = self.nd2.get_image(4, 0, "BF", 1)
  59. self.assertIsNotNone(image)
  60. def test_images(self):
  61. self.assertTupleEqual((self.nd2[0].z_level, self.nd2[0].channel), (0, 'BF'))
  62. self.assertIsNone(self.nd2[1])
  63. self.assertTupleEqual((self.nd2[2].z_level, self.nd2[2].channel), (1, 'BF'))
  64. self.assertTupleEqual((self.nd2[3].z_level, self.nd2[3].channel), (1, 'GFP'))
  65. self.assertTupleEqual((self.nd2[4].z_level, self.nd2[4].channel), (2, 'BF'))
  66. self.assertIsNone(self.nd2[5])
  67. self.assertTupleEqual((self.nd2[6].z_level, self.nd2[6].channel), (0, 'BF'))
  68. self.assertIsNone(self.nd2[7])
  69. self.assertTupleEqual((self.nd2[8].z_level, self.nd2[8].channel), (1, 'BF'))
  70. self.assertTupleEqual((self.nd2[9].z_level, self.nd2[9].channel), (1, 'GFP'))
  71. self.assertTupleEqual((self.nd2[10].z_level, self.nd2[10].channel), (2, 'BF'))
  72. self.assertIsNone(self.nd2[11])
  73. self.assertTupleEqual((self.nd2[12].z_level, self.nd2[12].channel), (0, 'BF'))
  74. self.assertIsNone(self.nd2[13])
  75. self.assertTupleEqual((self.nd2[14].z_level, self.nd2[14].channel), (1, 'BF'))
  76. self.assertTupleEqual((self.nd2[15].z_level, self.nd2[15].channel), (1, 'GFP'))
  77. self.assertTupleEqual((self.nd2[16].z_level, self.nd2[16].channel), (2, 'BF'))
  78. self.assertIsNone(self.nd2[17])
  79. self.assertTupleEqual((self.nd2[18].z_level, self.nd2[18].channel), (0, 'BF'))
  80. self.assertIsNone(self.nd2[19])
  81. self.assertIsNone(self.nd2[47])
  82. self.assertTupleEqual((self.nd2[48].z_level, self.nd2[48].channel), (0, 'BF'))
  83. self.assertIsNone(self.nd2[49])
  84. self.assertTupleEqual((self.nd2[50].z_level, self.nd2[50].channel), (1, 'BF'))
  85. self.assertIsNone(self.nd2[51])
  86. self.assertTupleEqual((self.nd2[52].z_level, self.nd2[52].channel), (2, 'BF'))
  87. self.assertIsNone(self.nd2[53])
  88. self.assertTupleEqual((self.nd2[54].z_level, self.nd2[54].channel), (0, 'BF'))
  89. def test_get_image_by_attribute_none(self):
  90. image = self.nd2.get_image(4, 0, "GFP", 0)
  91. self.assertIsNone(image)