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_nixio_fr.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # -*- coding: utf-8 -*-
  2. """
  3. Tests of neo.io.nixio_fr
  4. """
  5. from __future__ import absolute_import
  6. import numpy as np
  7. import unittest
  8. from neo.io.nixio_fr import NixIO as NixIOfr
  9. import quantities as pq
  10. from neo.io.nixio import NixIO
  11. from neo.test.iotest.common_io_test import BaseTestIO
  12. from neo.test.iotest.tools import get_test_file_full_path
  13. try:
  14. import nixio as nix
  15. HAVE_NIX = True
  16. except ImportError:
  17. HAVE_NIX = False
  18. @unittest.skipUnless(HAVE_NIX, "Requires NIX")
  19. class TestNixfr(BaseTestIO, unittest.TestCase, ):
  20. ioclass = NixIOfr
  21. files_to_test = ['nixio_fr.nix']
  22. files_to_download = ['nixio_fr.nix']
  23. def setUp(self):
  24. super(TestNixfr, self).setUp()
  25. self.testfilename = self.get_filename_path('nixio_fr.nix')
  26. self.reader_fr = NixIOfr(filename=self.testfilename)
  27. self.reader_norm = NixIO(filename=self.testfilename, mode='ro')
  28. self.blk = self.reader_fr.read_block(block_index=1, load_waveforms=True)
  29. # read block with NixIOfr
  30. self.blk1 = self.reader_norm.read_block(index=1) # read same block with NixIO
  31. def tearDown(self):
  32. self.reader_fr.file.close()
  33. self.reader_norm.close()
  34. def test_check_same_neo_structure(self):
  35. self.assertEqual(len(self.blk.segments), len(self.blk1.segments))
  36. for seg1, seg2 in zip(self.blk.segments, self.blk1.segments):
  37. self.assertEqual(len(seg1.analogsignals), len(seg2.analogsignals))
  38. self.assertEqual(len(seg1.spiketrains), len(seg2.spiketrains))
  39. self.assertEqual(len(seg1.events), len(seg2.events))
  40. self.assertEqual(len(seg1.epochs), len(seg2.epochs))
  41. def test_check_same_data_content(self):
  42. for seg1, seg2 in zip(self.blk.segments, self.blk1.segments):
  43. for asig1, asig2 in zip(seg1.analogsignals, seg2.analogsignals):
  44. np.testing.assert_almost_equal(asig1.magnitude, asig2.magnitude)
  45. # not completely equal
  46. for st1, st2 in zip(seg1.spiketrains, seg2.spiketrains):
  47. np.testing.assert_array_equal(st1.magnitude, st2.times)
  48. for wf1, wf2 in zip(st1.waveforms, st2.waveforms):
  49. np.testing.assert_array_equal(wf1.shape, wf2.shape)
  50. np.testing.assert_almost_equal(wf1.magnitude, wf2.magnitude)
  51. for ev1, ev2 in zip(seg1.events, seg2.events):
  52. np.testing.assert_almost_equal(ev1.times, ev2.times)
  53. assert np.all(ev1.labels == ev2.labels)
  54. for ep1, ep2 in zip(seg1.epochs, seg2.epochs):
  55. assert len(ep1.durations) == len(ep2.times)
  56. np.testing.assert_almost_equal(ep1.times, ep2.times)
  57. np.testing.assert_array_equal(ep1.durations, ep2.durations)
  58. np.testing.assert_array_equal(ep1.labels, ep2.labels)
  59. # Not testing for channel_index as rawio always read from seg
  60. for chid1, chid2 in zip(self.blk.channel_indexes, self.blk1.channel_indexes):
  61. for asig1, asig2 in zip(chid1.analogsignals, chid2.analogsignals):
  62. np.testing.assert_almost_equal(asig1.magnitude, asig2.magnitude)
  63. def test_analog_signal(self):
  64. seg1 = self.blk.segments[0]
  65. an_sig1 = seg1.analogsignals[0]
  66. assert len(an_sig1) == 30
  67. an_sig2 = seg1.analogsignals[1]
  68. assert an_sig2.shape == (50, 3)
  69. def test_spike_train(self):
  70. st1 = self.blk.segments[0].spiketrains[0]
  71. assert np.all(st1.times == np.cumsum(np.arange(0, 1, 0.1)).tolist() * pq.s + 10 * pq.s)
  72. def test_event(self):
  73. seg1 = self.blk.segments[0]
  74. event1 = seg1.events[0]
  75. raw_time = 10 + np.cumsum(np.array([0, 1, 2, 3, 4]))
  76. assert np.all(event1.times == np.array(raw_time * pq.s / 1000))
  77. assert np.all(event1.labels == np.array([b'A', b'B', b'C', b'D', b'E']))
  78. assert len(seg1.events) == 1
  79. def test_epoch(self):
  80. seg1 = self.blk.segments[1]
  81. seg2 = self.blk1.segments[1]
  82. epoch1 = seg1.epochs[0]
  83. epoch2 = seg2.epochs[0]
  84. assert len(epoch1.durations) == len(epoch1.times)
  85. assert np.all(epoch1.durations == epoch2.durations)
  86. assert np.all(epoch1.labels == epoch2.labels)
  87. if __name__ == '__main__':
  88. unittest.main()