def __init__(self, dirname, use_cache=False, cache_path='same_as_resource', keep_original_times=False): """ Initialise IO instance Parameters ---------- dirname : str Directory containing data files use_cache : bool, optional Cache results of initial file scans for faster loading in subsequent runs. Default: False cache_path : str, optional Folder path to use for cache files. Default: 'same_as_resource' keep_original_times : bool Preserve original time stamps as in data files. By default datasets are shifted to begin at t_start = 0*pq.second. Default: False """ NeuralynxRawIO.__init__(self, dirname=dirname, use_cache=use_cache, cache_path=cache_path, keep_original_times=keep_original_times) BaseFromRaw.__init__(self, dirname)
def test_single_file_mode(self): """ Tests reading of single files. """ # test single analog signal channel fname = self.get_filename_path('Cheetah_v5.6.3/original_data/CSC1.ncs') rawio = NeuralynxRawIO(filename=fname) rawio.parse_header() self.assertEqual(rawio._nb_segment, 2) self.assertEqual(len(rawio.ncs_filenames), 1) self.assertEqual(len(rawio.nev_filenames), 0) sigHdrs = rawio.header['signal_channels'] self.assertEqual(sigHdrs.size, 1) self.assertEqual(sigHdrs[0][0], 'CSC1') self.assertEqual(sigHdrs[0][1], '58') self.assertEqual(len(rawio.header['spike_channels']), 0) self.assertEqual(len(rawio.header['event_channels']), 0) # test one single electrode channel fname = self.get_filename_path( 'Cheetah_v5.5.1/original_data/STet3a.nse') rawio = NeuralynxRawIO(filename=fname) rawio.parse_header() self.assertEqual(rawio._nb_segment, 1) self.assertEqual(len(rawio.ncs_filenames), 0) self.assertEqual(len(rawio.nev_filenames), 0) seHdrs = rawio.header['spike_channels'] self.assertEqual(len(seHdrs), 1) self.assertEqual(seHdrs[0][0], 'chSTet3a#8#0') self.assertEqual(seHdrs[0][1], '0') self.assertEqual(len(rawio.header['signal_channels']), 0) self.assertEqual(len(rawio.header['event_channels']), 0)
def test_exclude_filenames(self): # exclude single ncs file from session dname = self.get_local_path('neuralynx/Cheetah_v5.6.3/original_data/') rawio = NeuralynxRawIO(dirname=dname, exclude_filename='CSC2.ncs') rawio.parse_header() self.assertEqual(rawio._nb_segment, 2) self.assertEqual(len(rawio.ncs_filenames), 1) self.assertEqual(len(rawio.nev_filenames), 1) sigHdrs = rawio.header['signal_channels'] self.assertEqual(sigHdrs.size, 1) self.assertEqual(sigHdrs[0][0], 'CSC1') self.assertEqual(sigHdrs[0][1], '58') self.assertEqual(len(rawio.header['spike_channels']), 8) self.assertEqual(len(rawio.header['event_channels']), 2) # exclude multiple files from session rawio = NeuralynxRawIO(dirname=dname, exclude_filename=['Events.nev', 'CSC2.ncs']) rawio.parse_header() self.assertEqual(rawio._nb_segment, 2) self.assertEqual(len(rawio.ncs_filenames), 1) self.assertEqual(len(rawio.nev_filenames), 0) sigHdrs = rawio.header['signal_channels'] self.assertEqual(sigHdrs.size, 1) self.assertEqual(sigHdrs[0][0], 'CSC1') self.assertEqual(sigHdrs[0][1], '58') self.assertEqual(len(rawio.header['spike_channels']), 8) self.assertEqual(len(rawio.header['event_channels']), 0)
def __init__(self, dirname='', filename='', use_cache=False, cache_path='same_as_resource', exclude_filename=None, keep_original_times=False): """ Initialise IO instance Parameters ---------- dirname : str Directory containing data files use_cache : bool, optional Cache results of initial file scans for faster loading in subsequent runs. Default: False cache_path : str, optional Folder path to use for cache files. Default: 'same_as_resource' exclude_filename: str or list Filename or list of filenames to be excluded. Expects base filenames without directory path. keep_original_times : bool Preserve original time stamps as in data files. By default datasets are shifted to begin at t_start = 0*pq.second. Default: False """ NeuralynxRawIO.__init__(self, dirname=dirname, filename=filename, use_cache=use_cache, cache_path=cache_path, exclude_filename=exclude_filename, keep_original_times=keep_original_times) if self.rawmode == 'one-file': BaseFromRaw.__init__(self, filename) elif self.rawmode == 'one-dir': BaseFromRaw.__init__(self, dirname)
def test_scan_ncs_files(self): # Test BML style of Ncs files, similar to PRE4 but with fractional frequency # in the header and fractional microsPerSamp, which is then rounded as appropriate # in each record. rawio = NeuralynxRawIO(self.get_filename_path('BML/original_data')) rawio.parse_header() # test values here from direct inspection of .ncs files self.assertEqual(rawio._nb_segment, 1) self.assertListEqual(rawio._timestamp_limits, [(0, 192000)]) self.assertEqual(rawio._sigs_length[0], 4608) self.assertEqual(rawio._sigs_t_start[0], 0) self.assertEqual(rawio._sigs_t_stop[0], 0.192) self.assertEqual(len(rawio._sigs_memmaps), 1) # Test Cheetah 4.0.2, which is PRE4 type with frequency in header and # no microsPerSamp. Number of microseconds per sample in file is inverse of # sampling frequency in header trucated to microseconds. rawio = NeuralynxRawIO( self.get_filename_path('Cheetah_v4.0.2/original_data')) rawio.parse_header() # test values here from direct inspection of .ncs files self.assertEqual(rawio._nb_segment, 1) self.assertListEqual(rawio._timestamp_limits, [(266982936, 267162136)]) self.assertEqual(rawio._sigs_length[0], 5120) self.assertEqual(rawio._sigs_t_start[0], 266.982936) self.assertEqual(rawio._sigs_t_stop[0], 267.162136) self.assertEqual(len(rawio._sigs_memmaps), 1) # Test Cheetah 5.5.1, which is DigitalLynxSX and has two blocks of records # with a fairly large gap. rawio = NeuralynxRawIO( self.get_filename_path('Cheetah_v5.5.1/original_data')) rawio.parse_header() # test values here from direct inspection of .ncs files self.assertEqual(rawio._nb_segment, 2) self.assertListEqual(rawio._timestamp_limits, [(26122557633, 26162525633), (26366360633, 26379704633)]) self.assertListEqual(rawio._sigs_length, [1278976, 427008]) self.assertListEqual(rawio._sigs_t_stop, [26162.525633, 26379.704633]) self.assertListEqual(rawio._sigs_t_start, [26122.557633, 26366.360633]) self.assertEqual(len(rawio._sigs_memmaps), 2) # check only that there are 2 memmaps # Test Cheetah 6.3.2, the incomplete_blocks test. This is a DigitalLynxSX with # three blocks of records. Gaps are on the order of 60 microseconds or so. rawio = NeuralynxRawIO( self.get_filename_path('Cheetah_v6.3.2/incomplete_blocks')) rawio.parse_header() # test values here from direct inspection of .ncs file, except for 3rd block # t_stop, which is extended due to events past the last block of ncs records. self.assertEqual(rawio._nb_segment, 3) self.assertListEqual(rawio._timestamp_limits, [(8408806811, 8427831990), (8427832053, 8487768498), (8487768561, 8515816549)]) self.assertListEqual(rawio._sigs_length, [608806, 1917967, 897536]) self.assertListEqual(rawio._sigs_t_stop, [8427.831990, 8487.768498, 8515.816549]) self.assertListEqual(rawio._sigs_t_start, [8408.806811, 8427.832053, 8487.768561]) self.assertEqual(len(rawio._sigs_memmaps), 3) # check only that there are 3 memmaps