MedPC data conversion#

Deprecated since version 0.10.1: MedPCInterface is deprecated and will be removed in v0.12.0. Use MedPC Events data conversion, which reads the same files and writes their events as native pynwb.event.EventsTable objects into nwbfile.events rather than as ndx-events objects and IntervalSeries into the behavior processing module.

MedPC output files contain information about operant behavior such as nose pokes and rewards. Install NeuroConv with the additional dependencies necessary for writing medpc behavioral data.

pip install "neuroconv[medpc_legacy]"

Convert MedPC output data to NWB using MedPCInterface.

>>> from datetime import datetime
>>> from zoneinfo import ZoneInfo
>>> from neuroconv.datainterfaces import MedPCInterface
>>>
>>> # For this data interface we need to pass the output file from MedPC
>>> file_path = f"{BEHAVIOR_DATA_PATH}/medpc/example_medpc_file_06_06_2024.txt"
>>> # Change the folder_path to the appropriate location in your system
>>> session_conditions = {"Start Date": "04/09/19", "Start Time": "10:34:30"}
>>> start_variable = "Start Date"
>>> metadata_medpc_name_to_info_dict = {
...     "Start Date": {"name": "start_date", "is_array": False},
...     "Start Time": {"name": "start_time", "is_array": False},
...     "Subject": {"name": "subject", "is_array": False},
...     "Box": {"name": "box", "is_array": False},
...     "MSN": {"name": "MSN", "is_array": False},
... }
>>> interface = MedPCInterface(
...     file_path=file_path,
...     session_conditions=session_conditions,
...     start_variable=start_variable,
...     metadata_medpc_name_to_info_dict=metadata_medpc_name_to_info_dict
... )
>>>
>>> # Extract what metadata we can from the source file
>>> metadata = interface.get_metadata()
>>> # We add the time zone information, which is required by NWB
>>> session_start_time = datetime(2019, 4, 9, 10, 34, 30).replace(tzinfo=ZoneInfo("US/Pacific"))
>>> metadata["NWBFile"].update(session_start_time=session_start_time)
>>> metadata["MedPC"]["medpc_name_to_info_dict"] = {
...         "A": {"name": "left_nose_poke_times", "is_array": True},
...         "B": {"name": "left_reward_times", "is_array": True},
...         "C": {"name": "right_nose_poke_times", "is_array": True},
...         "D": {"name": "right_reward_times", "is_array": True},
...         "E": {"name": "duration_of_port_entry", "is_array": True},
...         "G": {"name": "port_entry_times", "is_array": True},
...         "H": {"name": "footshock_times", "is_array": True},
... }
>>> metadata["MedPC"]["Events"] = [
...     {
...         "name": "left_nose_poke_times",
...         "description": "Left nose poke times.",
...     },
...     {
...         "name": "left_reward_times",
...         "description": "Left reward times.",
...     },
...     {
...         "name": "right_nose_poke_times",
...         "description": "Right nose poke times.",
...     },
...     {
...         "name": "right_reward_times",
...         "description": "Right reward times.",
...     },
...     {
...         "name": "footshock_times",
...         "description": "Footshock times.",
...     },
... ]
>>> metadata["MedPC"]["IntervalSeries"] = [
...     {
...         "name": "reward_port_intervals",
...         "description": "Interval of time spent in reward port (1 is entry, -1 is exit).",
...         "onset_name": "port_entry_times",
...         "duration_name": "duration_of_port_entry",
...     },
... ]
>>> # Add subject information (required for DANDI upload)
>>> metadata["Subject"] = dict(subject_id="subject1", species="Mus musculus", sex="M", age="P30D")
>>>
>>> # 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)