55import pathlib
66import unittest
77
8+ import quantities as pq
9+ import numpy as np
10+
811from neo .io .medio import MedIO
912from neo .test .iotest .common_io_test import BaseTestIO
10- from neo .test .iotest .tools import get_test_file_full_path
11- from neo .io .proxyobjects import (AnalogSignalProxy ,
12- SpikeTrainProxy , EventProxy , EpochProxy )
13- from neo import (AnalogSignal , SpikeTrain )
1413
15- import quantities as pq
16- import numpy as np
14+ try :
15+ import dhn_med_py
16+ HAVE_DHN_MED = True
17+ except ImportError :
18+ HAVE_DHN_MED = False
1719
1820
19- # This run standard tests, this is mandatory for all IOs
21+ # This runs standard tests, this is mandatory for all IOs
22+ @unittest .skipUnless (HAVE_DHN_MED , "requires dhn_med_py package and all its dependencies" )
2023class TestMedIO (BaseTestIO , unittest .TestCase , ):
2124 ioclass = MedIO
2225 entities_to_download = ['med' ]
@@ -31,22 +34,22 @@ def setUp(self):
3134 self .dirname = self .get_local_path ('med/sine_waves.medd' )
3235 self .dirname2 = self .get_local_path ('med/test.medd' )
3336 self .password = 'L2_password'
34-
37+
3538 def test_read_segment_lazy (self ):
36-
39+
3740 r = MedIO (self .dirname , self .password )
3841 seg = r .read_segment (lazy = False )
39-
42+
4043 # There will only be one analogsignal in this reading
4144 self .assertEqual (len (seg .analogsignals ), 1 )
4245 # Test that the correct number of samples are read, 5760000 samps for 3 channels
4346 self .assertEqual (seg .analogsignals [0 ].shape [0 ], 5760000 )
4447 self .assertEqual (seg .analogsignals [0 ].shape [1 ], 3 )
45-
48+
4649 # Test the first sample value of all 3 channels, which are
4750 # known to be [-1, -4, -4]
4851 np .testing .assert_array_equal (seg .analogsignals [0 ][0 ][:3 ], [- 1 , - 4 , - 4 ])
49-
52+
5053 for anasig in seg .analogsignals :
5154 self .assertNotEqual (anasig .size , 0 )
5255 for st in seg .spiketrains :
@@ -61,61 +64,61 @@ def test_read_segment_lazy(self):
6164 assert ev .name is not None
6265 for ep in seg .epochs :
6366 assert ep .name is not None
64-
67+
6568 r .close ()
6669
6770 def test_read_block (self ):
68-
71+
6972 r = MedIO (self .dirname , self .password )
7073 bl = r .read_block (lazy = True )
7174 self .assertTrue (bl .annotations )
72-
75+
7376 for count , seg in enumerate (bl .segments ):
7477 assert seg .name == 'Seg #' + str (count ) + ' Block #0'
75-
78+
7679 for anasig in seg .analogsignals :
7780 assert anasig .name is not None
78-
81+
7982 # Verify that the block annotations from the MED session are
8083 # read properly. There are a lot of annotations, so we'll just
8184 # spot-check a couple of them.
8285 assert (bl .annotations ['metadata' ]['recording_country' ] == 'United States' )
8386 assert (bl .annotations ['metadata' ]['AC_line_frequency' ] == 60.0 )
84-
87+
8588 r .close ()
86-
89+
8790 def test_read_segment_with_time_slice (self ):
8891 """
8992 Test loading of a time slice and check resulting times
9093 """
9194 r = MedIO (self .dirname , self .password )
9295 seg = r .read_segment (time_slice = None )
93-
96+
9497 # spike and epoch timestamps are not being read
9598 self .assertEqual (len (seg .spiketrains ), 0 )
9699 self .assertEqual (len (seg .epochs ), 1 )
97100 self .assertEqual (len (seg .epochs [0 ]), 0 )
98-
101+
99102 # Test for 180 events (1 per second for 3 minute recording)
100103 self .assertEqual (len (seg .events ), 1 )
101104 self .assertEqual (len (seg .events [0 ]), 180 )
102-
105+
103106 for asig in seg .analogsignals :
104107 self .assertEqual (asig .shape [0 ], 5760000 )
105108 n_channels = sum (a .shape [- 1 ] for a in seg .analogsignals )
106109 self .assertEqual (n_channels , 3 )
107-
110+
108111 t_start , t_stop = 500 * pq .ms , 800 * pq .ms
109112 seg = r .read_segment (time_slice = (t_start , t_stop ))
110-
113+
111114 # Test that 300 ms were read, which at 32 kHz, is 9600 samples
112115 self .assertAlmostEqual (seg .analogsignals [0 ].shape [0 ], 9600 , delta = 1. )
113116 # Test that it read from 3 channels
114117 self .assertEqual (seg .analogsignals [0 ].shape [1 ], 3 )
115-
118+
116119 self .assertAlmostEqual (seg .t_start .rescale (t_start .units ), t_start , delta = 5. )
117120 self .assertAlmostEqual (seg .t_stop .rescale (t_stop .units ), t_stop , delta = 5. )
118-
121+
119122 r .close ()
120123
121124
0 commit comments