Conversion Gallery#
The examples here are guaranteed to be running correctly with our testing suite. Their aim is to be a showcase of the library capabilities and to get you to hit the ground running with your own conversion.
Extracellular electrophysiology#
Recording#
AlphaOmega#
Install NeuroConv with the additional dependencies necessary for reading AlphaOmega data.
pip install neuroconv[alphaomega]
Convert AlphaOmega data to NWB using AlphaOmegaRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import AlphaOmegaRecordingInterface
>>>
>>> folder_path = f"{ECEPHY_DATA_PATH}/alphaomega/mpx_map_version4/"
>>> # Change the file_path to the location in your system
>>> interface = AlphaOmegaRecordingInterface(folder_path=folder_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Axona#
Install NeuroConv with the additional dependencies necessary for reading Axona data.
pip install neuroconv[axona]
Convert axona data to NWB using AxonaRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import AxonaRecordingInterface
>>>
>>> # For this interface we need to pass the location of the ``.bin`` file
>>> file_path = f"{ECEPHY_DATA_PATH}/axona/axona_raw.bin"
>>> # Change the file_path to the location in your system
>>> interface = AxonaRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> tzinfo = tz.gettz("US/Pacific")
>>> session_start_time = metadata["NWBFile"]["session_start_time"]
>>> metadata["NWBFile"].update(session_start_time=session_start_time.replace(tzinfo=tzinfo))
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Biocam#
Install NeuroConv with the additional dependencies necessary for reading Biocam data.
pip install neuroconv[biocam]
Convert Biocam data to NWB using BiocamRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import BiocamRecordingInterface
>>>
>>> file_path = f"{ECEPHY_DATA_PATH}/biocam/biocam_hw3.0_fw1.6.brw"
>>> # Change the file_path to the location in your system
>>> interface = BiocamRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Blackrock recording#
Install NeuroConv with the additional dependencies necessary for reading Blackrock data.
pip install neuroconv[blackrock]
Convert Blackrock data to NWB using
BlackrockRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import BlackrockRecordingInterface
>>>
>>> # For this interface we need to pass the location of the ``.ns5`` file
>>> file_path = f"{ECEPHY_DATA_PATH}/blackrock/FileSpec2.3001.ns5"
>>> # Change the file_path to the location in your system
>>> interface = BlackrockRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = metadata["NWBFile"]["session_start_time"]
>>> session_start_time = session_start_time.replace(tzinfo=tz.gettz("US/Pacific")).isoformat()
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
European Data Format (EDF)#
Install NeuroConv with the additional dependencies necessary for reading EDF data.
pip install neuroconv[edf]
Convert edf data to NWB using EDFRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import EDFRecordingInterface
>>>
>>> file_path = f"{ECEPHY_DATA_PATH}/edf/edf+C.edf"
>>> # Change the file_path to the location in your system
>>> interface = EDFRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Intan#
Install NeuroConv with the additional dependencies necessary for reading Intan data.
pip install neuroconv[intan]
Convert Intan data to NWB using IntanRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import IntanRecordingInterface
>>>
>>> file_path = f"{ECEPHY_DATA_PATH}/intan/intan_rhd_test_1.rhd" # This can also be .rhs
>>> interface = IntanRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # session_start_time is required for conversion. If it cannot be inferred
>>> # automatically from the source files you must supply one.
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
MaxOne#
Install NeuroConv with the additional dependencies necessary for reading MaxOne data.
Note
Our interfaces for Maxwell are currently only supported on Linux systems.
pip install neuroconv[maxwell]
Convert MaxOne data to NWB using MaxOneRecordingInterface
.
import os
from datetime import datetime
from dateutil import tz
from pathlib import Path
from neuroconv.datainterfaces import MaxOneRecordingInterface
file_path = f"{ECEPHY_DATA_PATH}/maxwell/MaxOne_data/Record/000011/data.raw.h5"
# Change the file_path to the location in your system
interface = MaxOneRecordingInterface(file_path=file_path, verbose=False)
# Extract what metadata we can from the source files
metadata = interface.get_metadata()
# For data provenance we add the time zone information to the conversion
session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
metadata["NWBFile"].update(session_start_time=session_start_time)
# Choose a path for saving the nwb file and run the conversion
nwbfile_path = f"{path_to_save_nwbfile}"
interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
MCSRaw#
Install NeuroConv with the additional dependencies necessary for reading MCSRaw data.
pip install neuroconv[mcsraw]
Convert MCSRaw data to NWB using MCSRawRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import MCSRawRecordingInterface
>>>
>>> file_path = f"{ECEPHY_DATA_PATH}/rawmcs/raw_mcs_with_header_1.raw"
>>> # Change the file_path to the location in your system
>>> interface = MCSRawRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
MEArec#
Install NeuroConv with the additional dependencies necessary for reading MEArec data.
pip install neuroconv[mearec]
Convert MEArec data to NWB using MEArecRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import MEArecRecordingInterface
>>>
>>> file_path = f"{ECEPHY_DATA_PATH}/mearec/mearec_test_10s.h5"
>>> # Change the file_path to the location in your system
>>> interface = MEArecRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Neuralynx#
Install NeuroConv with the additional dependencies necessary for reading Neuralynx data.
pip install neuroconv[neuralynx]
Convert Neuralynx data to NWB using
NeuralynxRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import NeuralynxRecordingInterface
>>>
>>> # For this data interface we need to pass the folder where the data is
>>> folder_path = f"{ECEPHY_DATA_PATH}/neuralynx/Cheetah_v5.7.4/original_data"
>>> # Change the folder_path to the appropriate location in your system
>>> interface = NeuralynxRecordingInterface(folder_path=folder_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # session_start_time is required for conversion. If it cannot be inferred
>>> # automatically from the source files you must supply one.
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
NeuroScope#
Install NeuroConv with the additional dependencies necessary for reading NeuroScope data.
pip install neuroconv[neuroscope]
Convert NeuroScope data to NWB using
NeuroScopeRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import NeuroScopeRecordingInterface
>>>
>>> # For Neuroscope we need to pass the location of the `.dat` file
>>> file_path = f"{ECEPHY_DATA_PATH}/neuroscope/test1/test1.dat"
>>> # Change the file_path to the location in your system
>>> interface = NeuroScopeRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # session_start_time is required for conversion. If it cannot be inferred
>>> # automatically from the source files you must supply one.
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
OpenEphys#
Install NeuroConv with the additional dependencies necessary for reading OpenEphys data.
pip install neuroconv[openephys]
Convert OpenEphys data to NWB using OpenEphysRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>>
>>> from neuroconv.datainterfaces import OpenEphysRecordingInterface
>>>
>>> folder_path = f"{ECEPHY_DATA_PATH}/openephysbinary/v0.4.4.1_with_video_tracking"
>>> # Change the folder_path to the appropriate location in your system
>>> interface = OpenEphysRecordingInterface(folder_path=folder_path)
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # session_start_time is required for conversion. If it cannot be inferred
>>> # automatically from the source files you must supply one.
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
NWB file saved at ...
Plexon#
Install NeuroConv with the additional dependencies necessary for reading Plexon acquisition data.
pip install neuroconv[plexon]
Convert Plexon recording data to NWB using PlexonRecordingInterface
. Currently, only .plx is supported.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import PlexonRecordingInterface
>>>
>>> file_path = f"{ECEPHY_DATA_PATH}/plexon/File_plexon_3.plx"
>>> # Change the file_path to the location in your system
>>> interface = PlexonRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = metadata["NWBFile"]["session_start_time"].replace(tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Spike2#
Install NeuroConv with the additional dependencies necessary for reading Spike2 data by CED.
pip install neuroconv[spike2]
Convert Spike2 data to NWB using
Spike2RecordingInterface
.
from datetime import datetime
from dateutil import tz
from pathlib import Path
from neuroconv.datainterfaces import Spike2RecordingInterface
# For this interface we need to pass the specific path to the files.
file_path = f"{ECEPHY_DATA_PATH}/spike2/m365_1sec.smrx"
# Change the file_path to the location in your system
interface = Spike2RecordingInterface(file_path=file_path, verbose=False)
# Extract what metadata we can from the source files
metadata = interface.get_metadata()
# For data provenance we add the time zone information to the conversion
session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
metadata["NWBFile"].update(session_start_time=session_start_time)
# Choose a path for saving the nwb file and run the conversion
nwbfile_path = f"{path_to_save_nwbfile}"
interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Spikegadgets#
Install NeuroConv with the additional dependencies necessary for reading Spikegadgets data.
pip install neuroconv[spikegadgets]
Convert spikegadgets data to NWB using
SpikeGadgetsRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import SpikeGadgetsRecordingInterface
>>>
>>> # For this interface we need to pass the specific path to the files.
>>> file_path = f"{ECEPHY_DATA_PATH}/spikegadgets/20210225_em8_minirec2_ac.rec"
>>> # Change the file_path to the location in your system
>>> interface = SpikeGadgetsRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
SpikeGLX#
Install NeuroConv with the additional dependencies necessary for reading SpikeGLX data.
pip install neuroconv[spikeglx]
SpikeGLXConverter#
We can easily convert all data stored in the native SpikeGLX folder structure to NWB using
SpikeGLXConverterPipe
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.converters import SpikeGLXConverterPipe
>>>
>>> folder_path = f"{ECEPHY_DATA_PATH}/spikeglx/Noise4Sam_g0"
>>> converter = SpikeGLXConverterPipe(folder_path=folder_path)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = converter.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = metadata["NWBFile"]["session_start_time"].replace(tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = output_folder / "my_spikeglx_session.nwb"
>>> converter.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Single-stream#
Defining a ‘stream’ as a single band on a single NeuroPixels probe, we can convert either an AP or LF SpikeGLX stream to NWB using
SpikeGLXRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import SpikeGLXRecordingInterface
>>>
>>> # For this interface we need to pass the location of the ``.bin`` file
>>> file_path = f"{ECEPHY_DATA_PATH}/spikeglx/Noise4Sam_g0/Noise4Sam_g0_imec0/Noise4Sam_g0_t0.imec0.ap.bin"
>>> # Change the file_path to the location in your system
>>> interface = SpikeGLXRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = metadata["NWBFile"]["session_start_time"].replace(tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Tucker-Davis Technologies (TDT)#
Install NeuroConv with the additional dependencies necessary for reading TDT data.
pip install neuroconv[tdt]
Convert TDT data to NWB using TdtRecordingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import TdtRecordingInterface
>>>
>>> # For this data interface we need to pass the folder_path with the location of the data
>>> folder_path = f"{ECEPHY_DATA_PATH}/tdt/aep_05"
>>> # Change the folder_path to the location of the data in your system
>>> interface = TdtRecordingInterface(folder_path=folder_path, gain=1.0, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # session_start_time is required for conversion. If it cannot be inferred
>>> # automatically from the source files you must supply one.
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Sorting#
Blackrock sorting#
Install NeuroConv with the additional dependencies necessary for reading Blackrock sorting data.
pip install neuroconv[blackrock]
Convert Blackrock sorting data to NWB using
BlackrockSortingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import BlackrockSortingInterface
>>>
>>> file_path = f"{ECEPHY_DATA_PATH}/blackrock/FileSpec2.3001.nev"
>>> # Change the file_path to the location of the file in your system
>>> interface = BlackrockSortingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime.fromisoformat(metadata["NWBFile"]["session_start_time"])
>>> session_start_time = session_start_time.replace(tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
CellExplorer#
Install NeuroConv with the additional dependencies necessary for reading CellExplorer data.
pip install neuroconv[cellexplorer]
Convert CellExplorer sorting data to NWB using CellExplorerSortingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import CellExplorerSortingInterface
>>>
>>> # For this interface we need to pass the location of the ``cellinfo.mat`` file
>>> file_path = f"{ECEPHY_DATA_PATH}/cellexplorer/dataset_1/20170311_684um_2088um_170311_134350.spikes.cellinfo.mat"
>>> # Change the file_path to the location in your system
>>> interface = CellExplorerSortingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> tzinfo = tz.gettz("US/Pacific")
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific")).isoformat()
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
KiloSort#
Install NeuroConv with the additional dependencies necessary for reading kilosort data.
pip install neuroconv[kilosort]
Convert KiloSort data to NWB using
KiloSortSortingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>>
>>> from neuroconv.datainterfaces import KiloSortSortingInterface
>>>
>>> folder_path = f"{ECEPHY_DATA_PATH}/phy/phy_example_0"
>>> # Change the folder_path to the location of the data in your system
>>> interface = KiloSortSortingInterface(folder_path=folder_path, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Neuralynx sorting#
Install NeuroConv with the additional dependencies necessary for reading neuralynx data.
pip install neuroconv[neuralynx]
Convert Neuralynx data to NWB using
NeuralynxSortingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>>
>>> from neuroconv.datainterfaces import NeuralynxSortingInterface
>>>
>>> folder_path = f"{ECEPHY_DATA_PATH}/neuralynx/Cheetah_v5.5.1/original_data"
>>> # Change the folder_path to the location of the data in your system
>>> interface = NeuralynxSortingInterface(folder_path=folder_path, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific")).isoformat()
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./neuralynx_conversion.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
NeuroScope sorting#
Install NeuroConv with the additional dependencies necessary for reading neuroscope data.
pip install neuroconv[neuroscope]
Convert NeuroScope sorting data to NWB using
NeuroScopeSortingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import NeuroScopeSortingInterface
>>>
>>> folder_path = f"{ECEPHY_DATA_PATH}/neuroscope/dataset_1"
>>> xml_file_path = folder_path + "/YutaMouse42-151117.xml"
>>> # Neuroscope sorting requires both the folder_path (containing the .clu and .res files.)and the xml_file_path
>>> interface = NeuroScopeSortingInterface(folder_path=folder_path, xml_file_path=xml_file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # session_start_time is required for conversion. If it cannot be inferred
>>> # automatically from the source files you must supply one.
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Phy sorting#
Install NeuroConv with the additional dependencies necessary for reading Phy data.
pip install neuroconv[phy]
Convert Phy data to NWB using PhySortingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>>
>>> from neuroconv.datainterfaces import PhySortingInterface
>>>
>>> folder_path = f"{ECEPHY_DATA_PATH}/phy/phy_example_0"
>>> # Change the folder_path to the location of the data in your system
>>> interface = PhySortingInterface(folder_path=folder_path, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Plexon sorting#
Install NeuroConv with the additional dependencies necessary for reading Plexon data.
pip install neuroconv[plexon]
Convert Plexon spiking data (.plx) to NWB using PlexonSortingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import PlexonSortingInterface
>>>
>>> file_path = f"{ECEPHY_DATA_PATH}/plexon/File_plexon_2.plx"
>>> # Change the file_path to the location in your system
>>> interface = PlexonSortingInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> tzinfo = tz.gettz("US/Pacific")
>>> session_start_time = metadata["NWBFile"]["session_start_time"]
>>> metadata["NWBFile"].update(session_start_time=session_start_time.replace(tzinfo=tzinfo))
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Intracellular electrophysiology#
ABF#
Install NeuroConv with the additional dependencies necessary for reading ABF data.
pip install neuroconv[abf]
Convert ABF intracellular electrophysiology data to NWB using AbfInterface
.
>>> from neuroconv.datainterfaces import AbfInterface
>>>
>>> # Metadata info
>>> icephys_metadata = {
... "cell_id": "20220818001",
... "slice_id": "20220818001",
... "targeted_layer": "L2-3(medial)",
... "inferred_layer": "",
... "recording_sessions": [
... {
... "abf_file_name": "File_axon_5.abf",
... "stimulus_type": "long_square",
... "icephys_experiment_type": "voltage_clamp"
... }
... ]
... }
>>>
>>> # Instantiate data interface
>>> interface = AbfInterface(
... file_paths=[f"{ECEPHY_DATA_PATH}/axon/File_axon_5.abf"],
... icephys_metadata=icephys_metadata
... )
>>>
>>> # Get metadata from source data and modify any values you want
>>> metadata = interface.get_metadata()
>>> metadata['NWBFile'].update(
... identifier="ID1234",
... session_description="Intracellular electrophysiology experiment.",
... lab="my lab name", # <-- optional
... institution="My University", # <-- optional
... experimenter=["John Doe", "Jane Doe"], # <-- optional
... )
>>> metadata["Subject"] = dict(
... subject_id="subject_ID123",
... species="Mus musculus",
... sex="M",
... date_of_birth="2022-03-15T00:00:00"
... )
>>>
>>> # Run conversion
>>> interface.run_conversion(nwbfile_path=output_folder / "single_abf_conversion.nwb", metadata=metadata)
If you have multiple ABF files for the same experiment, one file per recording stimulus type, you can organize a multi-file conversion as such:
>>> from neuroconv.datainterfaces import AbfInterface
>>>
>>> # Metadata info
>>> icephys_metadata = {
... "cell_id": "20220818001",
... "slice_id": "20220818001",
... "targeted_layer": "L2-3(medial)",
... "inferred_layer": "",
... "recording_sessions": [
... {
... "abf_file_name": "File_axon_5.abf",
... "stimulus_type": "long_square",
... "icephys_experiment_type": "voltage_clamp"
... },
... {
... "abf_file_name": "File_axon_6.abf",
... "stimulus_type": "short_square",
... "icephys_experiment_type": "voltage_clamp"
... }
... ]
... }
>>>
>>> # Instantiate data interface
>>> interface = AbfInterface(
... file_paths=[
... f"{ECEPHY_DATA_PATH}/axon/File_axon_5.abf",
... f"{ECEPHY_DATA_PATH}/axon/File_axon_6.abf",
... ],
... icephys_metadata=icephys_metadata
... )
>>>
>>> # Get metadata from source data and modify any values you want
>>> metadata = interface.get_metadata()
>>> metadata['NWBFile'].update(
... identifier="ID1234",
... session_description="Intracellular electrophysiology experiment.",
... lab="my lab name", # <-- optional
... institution="My University", # <-- optional
... experimenter=["John Doe", "Jane Doe"], # <-- optional
... )
>>> metadata["Subject"] = dict(
... subject_id="subject_ID123",
... species="Mus musculus",
... sex="M",
... date_of_birth="2022-03-15T00:00:00"
... )
>>>
>>> # Run conversion
>>> interface.run_conversion(nwbfile_path=output_folder / "multiple_abf_conversion.nwb", metadata=metadata)
Optical physiology#
Imaging#
Bruker TIFF#
Install NeuroConv with the additional dependencies necessary for reading Bruker TIFF data.
pip install neuroconv[brukertiff]
Convert single imaging plane
Convert Bruker TIFF imaging data to NWB using
BrukerTiffSinglePlaneConverter
.
>>> from dateutil import tz
>>> from neuroconv.converters import BrukerTiffSinglePlaneConverter
>>>
>>> # The 'folder_path' is the path to the folder containing the OME-TIF image files and the XML configuration file.
>>> folder_path = OPHYS_DATA_PATH / "imaging_datasets" / "BrukerTif" / "NCCR32_2023_02_20_Into_the_void_t_series_baseline-000"
>>> converter = BrukerTiffSinglePlaneConverter(folder_path=folder_path)
>>>
>>> metadata = converter.get_metadata()
>>> # For data provenance we can add the time zone information to the conversion if missing
>>> session_start_time = metadata["NWBFile"]["session_start_time"]
>>> tzinfo = tz.gettz("US/Pacific")
>>> metadata["NWBFile"].update(session_start_time=session_start_time.replace(tzinfo=tzinfo))
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> converter.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Convert multiple imaging planes
Convert volumetric Bruker TIFF imaging data to NWB using
BrukerTiffMultiPlaneConverter
.
The plane_separation_type parameter defines how to load the imaging planes.
Use “contiguous” to create the volumetric two photon series, and “disjoint” to create separate imaging plane and two photon series for each plane.
>>> from dateutil import tz
>>> from neuroconv.converters import BrukerTiffMultiPlaneConverter
>>>
>>> # The 'folder_path' is the path to the folder containing the OME-TIF image files and the XML configuration file.
>>> folder_path = OPHYS_DATA_PATH / "imaging_datasets" / "BrukerTif" / "NCCR32_2022_11_03_IntoTheVoid_t_series-005"
>>> converter = BrukerTiffMultiPlaneConverter(folder_path=folder_path, plane_separation_type="contiguous")
>>>
>>> metadata = converter.get_metadata()
>>> # For data provenance we can add the time zone information to the conversion if missing
>>> session_start_time = metadata["NWBFile"]["session_start_time"]
>>> tzinfo = tz.gettz("US/Pacific")
>>> metadata["NWBFile"].update(session_start_time=session_start_time.replace(tzinfo=tzinfo))
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{output_folder}/test2.nwb"
>>> converter.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
HDF5 Imaging#
Install NeuroConv with the additional dependencies necessary for reading HDF5 data.
pip install neuroconv[hdf5]
Convert HDF5 imaging data to NWB using Hdf5ImagingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import Hdf5ImagingInterface
>>>
>>> file_path = OPHYS_DATA_PATH / "imaging_datasets" / "hdf5" / "demoMovie.hdf5"
>>> interface = Hdf5ImagingInterface(file_path=file_path, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Micro-Manager TIFF#
Install NeuroConv with the additional dependencies necessary for reading Micro-Manager TIFF data.
pip install neuroconv[micromanagertiff]
Convert Micro-Manager TIFF imaging data to NWB using
MicroManagerTiffImagingInterface
.
>>> from dateutil import tz
>>> from neuroconv.datainterfaces import MicroManagerTiffImagingInterface
>>>
>>> # The 'folder_path' is the path to the folder containing the OME-TIF image files and the 'DisplaySettings.json' file with the Micro-Manager properties.
>>> folder_path = OPHYS_DATA_PATH / "imaging_datasets" / "MicroManagerTif" / "TS12_20220407_20hz_noteasy_1"
>>> interface = MicroManagerTiffImagingInterface(folder_path=folder_path, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we can add the time zone information to the conversion if missing
>>> session_start_time = metadata["NWBFile"]["session_start_time"]
>>> if session_start_time.tzinfo is None:
... tzinfo = tz.gettz("US/Pacific")
... metadata["NWBFile"].update(session_start_time=session_start_time.replace(tzinfo=tzinfo))
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Miniscope#
Install NeuroConv with the additional dependencies necessary for reading Miniscope data.
pip install neuroconv[miniscope]
Miniscope simultaneously records optical physiology and behavior in the form of video data.
The MiniscopeConverter
combines the two data streams
into a single conversion.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.converters import MiniscopeConverter
>>>
>>> # The 'folder_path' is the path to the main Miniscope folder containing both the recording and behavioral data streams in separate subfolders.
>>> folder_path = str(OPHYS_DATA_PATH / "imaging_datasets" / "Miniscope" / "C6-J588_Disc5")
>>> converter = MiniscopeConverter(folder_path=folder_path, verbose=False)
>>>
>>> metadata = converter.get_metadata()
>>> # For data provenance we can add the time zone information to the conversion if missing
>>> session_start_time = metadata["NWBFile"]["session_start_time"]
>>> tzinfo = tz.gettz("US/Pacific")
>>> metadata["NWBFile"].update(session_start_time=session_start_time.replace(tzinfo=tzinfo))
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> converter.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Scanbox#
Install NeuroConv with the additional dependencies necessary for reading Scanbox data.
pip install neuroconv[scanbox]
Convert Scanbox imaging data to NWB using
SbxImagingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import SbxImagingInterface
>>>
>>> file_path = OPHYS_DATA_PATH / "imaging_datasets" / "Scanbox" / "sample.sbx"
>>> interface = SbxImagingInterface(file_path=file_path, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
ScanImage#
Install NeuroConv with the additional dependencies necessary for reading ScanImage data.
pip install neuroconv[scanimage]
Convert ScanImage imaging data to NWB using
ScanImageImagingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import ScanImageImagingInterface
>>>
>>> file_path = OPHYS_DATA_PATH / "imaging_datasets" / "Tif" / "sample_scanimage.tiff"
>>> interface = ScanImageImagingInterface(file_path=file_path, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = metadata["NWBFile"]["session_start_time"].replace(tzinfo=tz.gettz("US/Pacific")) if "session_start_time" in metadata["NWBFile"] else datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
TIFF#
Install NeuroConv with the additional dependencies necessary for reading TIFF data.
pip install neuroconv[tiff]
Convert TIFF imaging data to NWB using
TiffImagingInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import TiffImagingInterface
>>>
>>> file_path = OPHYS_DATA_PATH / "imaging_datasets" / "Tif" / "demoMovie.tif"
>>> interface = TiffImagingInterface(file_path=file_path, sampling_frequency=15.0, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Note
The TiffImagingInterface
is designed for
imaging data where all of the frames are in a multi-page TIFF file. It is not appropriate for datasets where the
TIFF data is distributed across many files, for example from Bruker acquisition software.
Segmentation#
CaImAn#
Install NeuroConv with the additional dependencies necessary for reading CaImAn data.
pip install neuroconv[caiman]
Convert CaImAn segmentation data to NWB using CaimanSegmentationInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import CaimanSegmentationInterface
>>>
>>> file_path = OPHYS_DATA_PATH / "segmentation_datasets" / "caiman" / "caiman_analysis.hdf5"
>>> interface = CaimanSegmentationInterface(file_path=file_path, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
CNMFE#
Install NeuroConv with the additional dependencies necessary for reading CNMF-E data.
pip install neuroconv[cnmfe]
Convert CNMFE segmentation data to NWB using CnmfeSegmentationInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import CnmfeSegmentationInterface
>>>
>>> file_path = OPHYS_DATA_PATH / "segmentation_datasets" / "cnmfe" / "2014_04_01_p203_m19_check01_cnmfeAnalysis.mat"
>>> interface = CnmfeSegmentationInterface(file_path=file_path, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
EXTRACT#
Install NeuroConv with the additional dependencies necessary for reading EXTRACT data.
pip install neuroconv[extract]
Convert EXTRACT segmentation data to NWB using ExtractSegmentationInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import ExtractSegmentationInterface
>>>
>>> file_path = OPHYS_DATA_PATH / "segmentation_datasets" / "extract"/ "2014_04_01_p203_m19_check01_extractAnalysis.mat"
>>> sampling_frequency = 20.0 # The sampling frequency in units of Hz
>>> interface = ExtractSegmentationInterface(file_path=file_path, sampling_frequency=sampling_frequency, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
suite2p#
Install NeuroConv with the additional dependencies necessary for reading suite2p data.
pip install neuroconv[suite2p]
Convert suite2p segmentation data to NWB using
Suite2pSegmentationInterface
.
Suite2p segmentation output is saved for each plane in a separate folder (e.g. “plane0”, “plane1”). To specify which plane to convert, use the plane_name argument (to see what planes are available use the Suite2pSegmentationInterface.get_available_planes(folder_path) method). For multichannel recordings, use the channel_name argument to specify the channel name (to see what channels are available use the Suite2pSegmentationInterface.get_channel_names(folder_path) method). When not specified, the first plane and channel are used.
The optional plane_segmentation_name argument specifies the name of the PlaneSegmentation
to be created.
When multiple planes and/or channels are present, the name should be unique for each plane and channel combination (e.g. “PlaneSegmentationChan1Plane0”).
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import Suite2pSegmentationInterface
>>>
>>> folder_path= OPHYS_DATA_PATH / "segmentation_datasets" / "suite2p"
>>> interface = Suite2pSegmentationInterface(folder_path=folder_path, verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Multi-plane example
This example shows how to convert multiple planes from the same dataset.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv import ConverterPipe
>>> from neuroconv.datainterfaces import Suite2pSegmentationInterface
>>>
>>> folder_path= OPHYS_DATA_PATH / "segmentation_datasets" / "suite2p"
>>> interface_first_plane = Suite2pSegmentationInterface(folder_path=folder_path, plane_name="plane0", verbose=False)
>>> interface_second_plane = Suite2pSegmentationInterface(folder_path=folder_path, plane_name="plane1", verbose=False)
>>>
>>> converter = ConverterPipe(data_interfaces=[interface_first_plane, interface_second_plane], verbose=False)
>>> metadata = converter.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{output_folder}/file2.nwb"
>>> converter.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Behavior#
Audio#
Install NeuroConv with the additional dependencies necessary for reading audio data.
pip install neuroconv[audio]
This interface can handle conversions from WAV format to NWB using the
AudioInterface
class.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>>
>>> from neuroconv.datainterfaces.behavior.audio.audiointerface import AudioInterface
>>>
>>> audio_file_path = BEHAVIOR_DATA_PATH / "audio" / "natural_audio_recording.wav"
>>> interface = AudioInterface(file_paths=[audio_file_path], verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> interface.run_conversion(nwbfile_path=path_to_save_nwbfile, metadata=metadata)
DeepLabCut#
Install NeuroConv with the additional dependencies necessary for reading DeepLabCut data.
pip install neuroconv[deeplabcut]
Convert DeepLabCut pose estimation data to NWB using DeepLabCutInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import DeepLabCutInterface
>>> file_path = BEHAVIOR_DATA_PATH / "DLC" / "m3v1mp4DLC_resnet50_openfieldAug20shuffle1_30000.h5"
>>> config_file_path = BEHAVIOR_DATA_PATH / "DLC" / "config.yaml"
>>> interface = DeepLabCutInterface(file_path=file_path, config_file_path=config_file_path, subject_name="ind1", verbose=False)
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>> # Choose a path for saving the nwb file and run the conversion
>>> interface.run_conversion(nwbfile_path=path_to_save_nwbfile, metadata=metadata)
FicTrac#
Install NeuroConv with the additional dependencies necessary for reading FicTrac data.
pip install neuroconv[fictrac]
Convert FicTrac spherical motion and fictive animal path data in a FicTrac .dat
file to NWB using FicTracDataInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import FicTracDataInterface
>>> file_path = BEHAVIOR_DATA_PATH / "FicTrac" / "sample" / "sample-20230724_113055.dat"
>>> radius = 0.035 # If you have the radius of the ball (in meters), you can pass it to the interface and the data will be saved in meters
>>> interface = FicTracDataInterface(file_path=file_path, radius=radius, verbose=False)
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = metadata["NWBFile"]["session_start_time"].replace(tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>> # For data provenance we add the time zone information to the conversion
>>> # Choose a path for saving the nwb file and run the conversion
>>> interface.run_conversion(nwbfile_path=path_to_save_nwbfile, metadata=metadata)
LightningPose#
Install NeuroConv with the additional dependencies necessary for reading LightningPose data.
pip install neuroconv[lightningpose]
Convert LightningPose pose estimation data to NWB using LightningPoseConverter
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.converters import LightningPoseConverter
>>> folder_path = BEHAVIOR_DATA_PATH / "lightningpose" / "outputs/2023-11-09/10-14-37/video_preds"
>>> file_path = str(folder_path / "test_vid.csv")
>>> original_video_file_path = str(folder_path / "test_vid.mp4")
>>> # The labeled video file path is optional
>>> labeled_video_file_path = str(folder_path / "labeled_videos/test_vid_labeled.mp4")
>>> converter = LightningPoseConverter(file_path=file_path, original_video_file_path=original_video_file_path, labeled_video_file_path=labeled_video_file_path, verbose=False)
>>> metadata = converter.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = metadata["NWBFile"]["session_start_time"]
>>> tzinfo = tz.gettz("US/Pacific")
>>> metadata["NWBFile"].update(session_start_time=session_start_time.replace(tzinfo=tzinfo))
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> converter.run_conversion(nwbfile_path=path_to_save_nwbfile, metadata=metadata)
SLEAP#
Install NeuroConv with the additional dependencies necessary for reading SLEAP data.
pip install neuroconv[sleap]
Convert SLEAP pose estimation data to NWB using SLEAPInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import SLEAPInterface
>>>
>>> # Change the file_path so it points to the slp file in your system
>>> file_path = BEHAVIOR_DATA_PATH / "sleap" / "predictions_1.2.7_provenance_and_tracking.slp"
>>> interface = SLEAPInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # session_start_time is required for conversion. If it cannot be inferred
>>> # automatically from the source files you must supply one.
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "saved_file.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Video (multimedia formats)#
Install NeuroConv with the additional dependencies necessary for reading multimedia data.
pip install neuroconv[video]
This interface can handle conversions from .avi, .mov, .mp4, .wmv, .flv and most FFmpeg-supported formats to NWB using the
VideoInterface
class.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>>
>>> from neuroconv.datainterfaces import VideoInterface
>>>
>>> video_file_path = BEHAVIOR_DATA_PATH / "videos" / "CFR" / "video_avi.avi"
>>> interface = VideoInterface(file_paths=[video_file_path], verbose=False)
>>>
>>> metadata = interface.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> interface.run_conversion(nwbfile_path=path_to_save_nwbfile, metadata=metadata)
Neuralynx NVT#
Neuralynx NVT files contain information about position tracking. This interface requires no additional dependencies, so you can install NeuroConv using:
pip install neuroconv
Convert Neuralynx NVT data to NWB using
NeuralynxNvtInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from neuroconv.datainterfaces import NeuralynxNvtInterface
>>>
>>> # For this data interface we need to pass the folder where the data is
>>> file_path = f"{BEHAVIOR_DATA_PATH}/neuralynx/test.nvt"
>>> # Change the folder_path to the appropriate location in your system
>>> interface = NeuralynxNvtInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # We add the time zone information, which is required by NWB
>>> session_start_time = metadata["NWBFile"]["session_start_time"].replace(tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Text#
Comma-Separated Values (CSV)#
Install NeuroConv. No extra dependencies are necessary for reading CSV.
pip install neuroconv
Convert CSV data to NWB using
CsvTimeIntervalsInterface
.
The CSV file must contain a header row that contains at least the column names “start_time” and “stop_time”. The CSV data will be saved as trials in the NWB file.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import CsvTimeIntervalsInterface
>>>
>>> file_path = f"{TEXT_DATA_PATH}/trials.csv"
>>> # Change the file_path to the location of the file in your system
>>> interface = CsvTimeIntervalsInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # Add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"] = dict(session_start_time=session_start_time)
>>>
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> nwbfile = interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Excel#
Install NeuroConv with the additional dependencies necessary for reading Excel data.
pip install neuroconv[excel]
Convert Excel files (.xls, .xlsx) to NWB using
ExcelTimeIntervalsInterface
.
The Excel file must contain a header row that contains at least the column names “start_time” and “stop_time”. The Excel data will be saved as trials in the NWB file.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv.datainterfaces import ExcelTimeIntervalsInterface
>>>
>>> file_path = f"{TEXT_DATA_PATH}/trials.xlsx"
>>> # Change the file_path to the location of the file in your system
>>> interface = ExcelTimeIntervalsInterface(file_path=file_path, verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = interface.get_metadata()
>>> # Add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"] = dict(session_start_time=session_start_time)
>>>
>>> nwbfile_path = f"{path_to_save_nwbfile}" # This should be something like: "./saved_file.nwb"
>>> nwbfile = interface.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Common interface combinations#
SpikeGLX & Phy#
A common workflow is to record electrophysiology data and then extract spiking units. The following is an example of
how to combine electrophysiology recordings and spike sorting data in the same conversion. For this specific example
were are combining a SpikeGLX recording with Phy sorting results using the
SpikeGLXRecordingInterface
and
PhySortingInterface
classes.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv import ConverterPipe
>>> from neuroconv.datainterfaces import SpikeGLXRecordingInterface, PhySortingInterface
>>>
>>> # For this interface we need to pass the location of the ``.bin`` file. Change the file_path to the location in your system
>>> file_path = f"{ECEPHY_DATA_PATH}/spikeglx/Noise4Sam_g0/Noise4Sam_g0_imec0/Noise4Sam_g0_t0.imec0.ap.bin"
>>> interface_spikeglx = SpikeGLXRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> folder_path = f"{ECEPHY_DATA_PATH}/phy/phy_example_0" # Change the folder_path to the location of the data in your system
>>> interface_phy = PhySortingInterface(folder_path=folder_path, verbose=False)
>>>
>>> # Now that we have defined the two interfaces we pass them to the ConverterPipe which will coordinate the
>>> # concurrent conversion of the data
>>> converter = ConverterPipe(data_interfaces=[interface_spikeglx, interface_phy], verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = converter.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = metadata["NWBFile"]["session_start_time"].replace(tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> converter.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Tiff & Suite2p#
A common workflow in optical physiology is to record images with a microscope (imaging) and then use a segmentation
algorithm to produce regions of interest and fluorescence traces. The following is an example of who to implement this
workflow in neuroconv for Tiff imaging files segmented using suite2p. This conversion uses the classes
TiffImagingInterface
and
Suite2pSegmentationInterface
.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv import ConverterPipe
>>> from neuroconv.datainterfaces import TiffImagingInterface, Suite2pSegmentationInterface
>>>
>>> file_path = OPHYS_DATA_PATH / "imaging_datasets" / "Tif" / "demoMovie.tif"
>>> interface_tiff = TiffImagingInterface(file_path=file_path, sampling_frequency=15.0, verbose=False)
>>>
>>> folder_path= OPHYS_DATA_PATH / "segmentation_datasets" / "suite2p"
>>> interface_suit2p = Suite2pSegmentationInterface(folder_path=folder_path, verbose=False)
>>>
>>> # Now that we have defined the two interfaces we pass them to the ConverterPipe which will coordinate the
>>> # concurrent conversion of the data
>>> converter = ConverterPipe(data_interfaces=[interface_tiff, interface_suit2p], verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = converter.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> converter.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Electrophysiology and Behavior#
This example showcases a conversion that combines two modalities of data electrophysiology and behavior in the form of pose estimation.
For this specific example were are combining a OpenEphys recording with KiloSort sorting results and PoseEstimation from sleap using the
BlackrockRecordingInterface
,
KiloSortSortingInterface
, and
SLEAPInterface
. classes.
>>> from datetime import datetime
>>> from dateutil import tz
>>> from pathlib import Path
>>> from neuroconv import ConverterPipe
>>> from neuroconv.datainterfaces import BlackrockRecordingInterface, KiloSortSortingInterface, SLEAPInterface
>>>
>>>
>>> file_path = f"{ECEPHY_DATA_PATH}/blackrock/FileSpec2.3001.ns5"
>>> # Change the file_path to the location in your system
>>> interface_blackrock = BlackrockRecordingInterface(file_path=file_path, verbose=False)
>>>
>>> folder_path = f"{ECEPHY_DATA_PATH}/phy/phy_example_0"
>>> # Change the folder_path to the location of the data in your system
>>> interface_kilosort = KiloSortSortingInterface(folder_path=folder_path, verbose=False)
>>>
>>> # Change the file_path so it points to the slp file in your system
>>> file_path = BEHAVIOR_DATA_PATH / "sleap" / "predictions_1.2.7_provenance_and_tracking.slp"
>>> interface_sleap = SLEAPInterface(file_path=file_path, verbose=False)
>>>
>>> # Now that we have defined the two interfaces we pass them to the ConverterPipe which will coordinate the
>>> # concurrent conversion of the data
>>> converter = ConverterPipe(data_interfaces=[interface_blackrock, interface_kilosort, interface_sleap], verbose=False)
>>>
>>> # Extract what metadata we can from the source files
>>> metadata = converter.get_metadata()
>>> # For data provenance we add the time zone information to the conversion
>>> session_start_time = datetime(2020, 1, 1, 12, 30, 0, tzinfo=tz.gettz("US/Pacific")).isoformat()
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>>
>>> # Choose a path for saving the nwb file and run the conversion
>>> nwbfile_path = f"{path_to_save_nwbfile}"
>>> converter.run_conversion(nwbfile_path=nwbfile_path, metadata=metadata)
Note
If you do not see the format you need, feel free to request it or Build a DataInterface.