def test_glob_ephys(self): def dict_equals(d1, d2): return all([x in d1 for x in d2]) and all([x in d2 for x in d1]) ef3b = spikeglx.glob_ephys_files(self.dir3b) ef3a = spikeglx.glob_ephys_files(self.dir3a) ef3b_ch = spikeglx.glob_ephys_files(self.dir3b, ext='ch') # test glob self.assertTrue(dict_equals(self.dict3a, ef3a)) self.assertTrue(dict_equals(self.dict3b, ef3b)) self.assertTrue(dict_equals(self.dict3b_ch, ef3b_ch)) # test the version from glob self.assertTrue( spikeglx.get_neuropixel_version_from_files(ef3a) == '3A') self.assertTrue( spikeglx.get_neuropixel_version_from_files(ef3b) == '3B') # test the version from paths self.assertTrue( spikeglx.get_neuropixel_version_from_folder(self.dir3a) == '3A') self.assertTrue( spikeglx.get_neuropixel_version_from_folder(self.dir3b) == '3B') self.dir3b.joinpath('imec1', 'sync_testing_g0_t0.imec1.ap.bin').unlink() self.assertEqual( spikeglx.glob_ephys_files(self.dir3b.joinpath('imec1')), [])
def _get_all_probes_sync(session_path, bin_exists=True): # round-up of all bin ephys files in the session, infer revision and get sync map ephys_files = spikeglx.glob_ephys_files(session_path, bin_exists=bin_exists) version = spikeglx.get_neuropixel_version_from_files(ephys_files) # attach the sync information to each binary file found for ef in ephys_files: ef['sync'] = alfio.load_object(ef.path, 'sync', namespace='spikeglx', short_keys=True) ef['sync_map'] = get_ibl_sync_map(ef, version) return ephys_files
def _get_all_probes_sync(session_path): # round-up of all bin ephys files in the session, infer revision and get sync map ephys_files = glob_ephys_files(session_path) version = get_neuropixel_version_from_files(ephys_files) extract_sync(session_path, save=True) # attach the sync information to each binary file found for ef in ephys_files: ef['sync'] = alf.io.load_object(ef.path, '_spikeglx_sync', short_keys=True) ef['sync_map'] = get_ibl_sync_map(ef, version) return ephys_files
def _get_main_probe_sync(session_path, bin_exists=True): """ From 3A or 3B multiprobe session, returns the main probe (3A) or nidq sync pulses with the attached channel map (default chmap if none) :param session_path: :return: """ ephys_files = _get_all_probes_sync(session_path, bin_exists=bin_exists) if not ephys_files: raise FileNotFoundError(f"No ephys files found in {session_path}") version = get_neuropixel_version_from_files(ephys_files) if version == '3A': # the sync master is the probe with the most sync pulses sync_box_ind = np.argmax([ef.sync.times.size for ef in ephys_files]) elif version == '3B': # the sync master is the nidq breakout box sync_box_ind = np.argmax([1 if ef.get('nidq') else 0 for ef in ephys_files]) sync = ephys_files[sync_box_ind].sync sync_chmap = ephys_files[sync_box_ind].sync_map return sync, sync_chmap