Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align raw ephys timestamps #93

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions src/ibl_to_nwb/_scripts/convert_brainwide_map_raw_only.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand Down
Loading