Esempio n. 1
0
 def test_save_NS_efile_with_header(self):
     fp = self.resdir + 'NS2_withheader.ev2'
     fp2 = fp.replace('.ev2', '_recoded.ev2')
     efile = load_efile(fp)
     save_efile(efile)
     efile2 = load_efile(fp2)
     pattern = '[\s]+'
     self.assertEqual(len(efile.raw), len(efile2.raw))
     raw1 = [list(filter(bool, re.split(pattern, l))) for l in efile.raw]
     raw2 = [list(filter(bool, re.split(pattern, l))) for l in efile2.raw]
     self.assertEqual(raw1, raw2)
Esempio n. 2
0
 def test_mod_code(self):
     # v0.2.2 expects str's as codes
     # v0.3+ should fail but doesn't
     efile = load_efile(self.NSfile)
     efile.mod_code(5, 12)
     self.assertEqual(efile.events[5].code, 12)
     efile = load_efile(self.BESAfile)
     efile.mod_code(5, 12)
     self.assertEqual(efile.events[5].code, 12)
     efile.events[4].code = 3
     self.assertEqual(efile.events[4].code, 3)
Esempio n. 3
0
 def test_save_BESA(self):
     # BESA evt files seem to have spurious whitespace
     fp = self.resdir + 'BESA_minimal.evt'
     fp2 = fp.replace('.evt', '_recoded.evt')
     efile = load_efile(fp)
     save_efile(efile)
     efile2 = load_efile(fp2)
     pattern = '[\s,]+'
     self.assertEqual(len(efile.raw), len(efile2.raw))
     raw1 = [list(filter(bool, re.split(pattern, l))) for l in efile.raw]
     raw2 = [list(filter(bool, re.split(pattern, l))) for l in efile2.raw]
     self.assertEqual(raw1, raw2)
Esempio n. 4
0
def load_pair(lf, ef):
    pfile = load(lf)
    efile = load_efile(ef)
    # load codes
    pcodes = [e.code for e in pfile.events]
    ecodes = [d.code for d in efile.events]
    for c in pcodes[:]:
        try:
            int(c)
        except ValueError:
            print('Warning: Non-number code found, cannot plot', c)
            pcodes.remove(c)
    codereport(pcodes, ecodes)
    # load time differences between events
    ptimes = [e.time for e in pfile.events]
    etimes = [float(d.time) for d in efile.events]
    pdiffs = [t - ptimes[i] for i, t in enumerate(ptimes[1:])]
    ediffs = [(t - etimes[i])*1000 for i, t in enumerate(etimes[1:])]
    # Return report
    return dict(codes=(pcodes, ecodes), diffs=(pdiffs, ediffs),
                times=(ptimes, etimes))
Esempio n. 5
0
 def test_save_Neuroscan(self):
     fp = self.resdir + 'NS2_minimal.ev2'
     fp2 = fp.replace('.ev2', '_recoded.ev2')
     efile = load_efile(fp)
     save_efile(efile)
     self.assertTrue(filecmp.cmp(fp, fp2, shallow=False))
Esempio n. 6
0
 def test_malformed_line(self):
     with self.assertRaises(TypeError):
         load_efile(self.resdir + 'malformedline.ev2')
Esempio n. 7
0
 def test_malformed_BESA_header(self):
     with self.assertRaises(ValueError):
         load_efile(self.resdir + 'BESAheaderbad.evt')
Esempio n. 8
0
 def test_nonexistent_file(self):
     with self.assertRaises(FileNotFoundError):
         load_efile(self.resdir + 'NotAFile.evt')
Esempio n. 9
0
 def test_unknown_ext(self):
     with self.assertRaises(ValueError):
         load_efile(self.resdir + 'BadExt.err')
Esempio n. 10
0
 def test_load_NS_efile_with_header(self):
     efile = load_efile(self.resdir + 'NS2_withheader.ev2')
     self.assertEqual(efile.events[-1].code, 1)
     self.assertEqual(len(efile.events), 7)
Esempio n. 11
0
 def test_load_NS_efile(self):
     efile = load_efile(self.NSfile)
     self.assertEqual(efile.events[-1].code, 1)
     self.assertEqual(len(efile.events), 35)
Esempio n. 12
0
 def test_load_BESA_noextra(self):
     efile = load_efile(self.resdir + 'BESA_noextra.evt')
     self.assertEqual(efile.events[-2].time, 5744629)
     self.assertEqual(len(efile.events), 4)
Esempio n. 13
0
 def test_load_BESA_efile(self):
     efile = load_efile(self.BESAfile)
     self.assertEqual(efile.events[-1].code, 2)
     self.assertEqual(len(efile.events), 33)
Esempio n. 14
0
 def test_mod_and_save(self):
     efile = load_efile(self.NSfile)
     efile.events[4].code = 247
     save_efile(efile)
     ef2 = load_efile(self.resdir + 'NS2_recoded.ev2')
     self.assertEqual(ef2.events[4].code, 247)