diff --git a/src/ibl_to_nwb/_scripts/convert_brainwide_map_raw_only.py b/src/ibl_to_nwb/_scripts/convert_brainwide_map_raw_only.py index 496d930..f695968 100644 --- a/src/ibl_to_nwb/_scripts/convert_brainwide_map_raw_only.py +++ b/src/ibl_to_nwb/_scripts/convert_brainwide_map_raw_only.py @@ -1,5 +1,6 @@ from pathlib import Path +from brainbox.io.one import EphysSessionLoader, SpikeSortingLoader from neuroconv.datainterfaces import SpikeGLXRecordingInterface from one.api import ONE @@ -26,24 +27,38 @@ cache_dir=one_cache_folder_path, ) -# Specify the path to the SpikeGLX files on the server +# Specify the path to the SpikeGLX files on the server but use ONE API for timestamps probe_1_source_folder_path = Path("D:/example_data/ephy_testing_data/spikeglx/Noise4Sam_g0") probe_2_source_folder_path = Path( "D:/example_data/ephy_testing_data/spikeglx/multi_trigger_multi_gate/SpikeGLX/5-19-2022-CI0/5-19-2022-CI0_g0/" ) -ap_1_file_path = probe_1_source_folder_path / "Noise4Sam_g0_imec0/Noise4Sam_g0_t0.imec0.ap.bin" -ap_2_file_path = probe_2_source_folder_path / "5-19-2022-CI0_g0_imec0/5-19-2022-CI0_g0_t0.imec0.ap.bin" -lf_1_file_path = probe_1_source_folder_path / "Noise4Sam_g0_imec0/Noise4Sam_g0_t0.imec0.lf.bin" -lf_2_file_path = probe_2_source_folder_path / "5-19-2022-CI0_g0_imec0/5-19-2022-CI0_g0_t0.imec0.lf.bin" +# Initialize interfaces one probe at a time and properly align raw timestamps +ephys_session_loader = EphysSessionLoader(one=ibl_client, eid=session_id) + +probe_to_imec_map = { + "probe00": 0, + "probe01": 1, +} -# Initialize interfaces data_interfaces = list() -data_interfaces.append(SpikeGLXRecordingInterface(file_path=ap_1_file_path)) -data_interfaces.append(SpikeGLXRecordingInterface(file_path=ap_2_file_path)) -data_interfaces.append(SpikeGLXRecordingInterface(file_path=lf_1_file_path)) -data_interfaces.append(SpikeGLXRecordingInterface(file_path=lf_2_file_path)) +for probe_name, pid in ephys_session_loader.probes.items(): + spike_sorting_loader = SpikeSortingLoader(pid=pid, one=ibl_client) + + probe_index = probe_to_imec_map[probe_name] + for band in ["ap", "lf"]: + file_path = probe_1_source_folder_path / f"Noise4Sam_g0_imec0/Noise4Sam_g0_t0.imec{probe_index}.{band}.bin" + interface = SpikeGLXRecordingInterface(file_path=file_path) + + # This is the syntax for aligning the raw timestamps; I cannot test this without the actual data as stored + # on your end, so please work with Heberto if there are any problems after uncommenting + + # band_info = spike_sorting_loader.raw_electrophysiology(band=band, stream=True) + # aligned_timestamps = spike_sorting_loader.samples2times(numpy.arange(0, band_info.ns), direction='forward') + # interface.set_aligned_timestamps(aligned_timestamps=aligned_timestamps) + + data_interfaces.append(interface) # Raw video take some special handling metadata_retrieval = BrainwideMapConverter(one=ibl_client, session=session_id, data_interfaces=[], verbose=False)