diff --git a/requirements.txt b/requirements.txt index dc321c0..e411ef3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -neuroconv==0.4.3 +neuroconv==0.4.4 spikeinterface==0.98.2 nwbwidgets nwbinspector diff --git a/src/jazayeri_lab_to_nwb/watters/watters_convert_session.py b/src/jazayeri_lab_to_nwb/watters/watters_convert_session.py index e4e54f6..ec9eafb 100644 --- a/src/jazayeri_lab_to_nwb/watters/watters_convert_session.py +++ b/src/jazayeri_lab_to_nwb/watters/watters_convert_session.py @@ -5,6 +5,7 @@ import glob import json from zoneinfo import ZoneInfo +from uuid import uuid4 from neuroconv.utils import load_dict_from_file, dict_deep_update @@ -110,11 +111,6 @@ def session_to_nwb(data_dir_path: Union[str, Path], output_dir_path: Union[str, # Add datetime to conversion metadata = processed_converter.get_metadata() # use processed b/c it has everything - try: - date = datetime.datetime.strptime(data_dir_path.name, "%Y-%m-%d").replace(tzinfo=ZoneInfo("US/Eastern")) - except: - date = datetime.datetime(year=2022, month=6, day=1, tzinfo=ZoneInfo("US/Eastern")) - metadata["NWBFile"]["session_start_time"] = date metadata["NWBFile"]["session_id"] = session_id # Subject name @@ -142,11 +138,22 @@ def session_to_nwb(data_dir_path: Union[str, Path], output_dir_path: Union[str, editable_metadata = load_dict_from_file(editable_metadata_path) metadata = dict_deep_update(metadata, editable_metadata) + # check if session_start_time was found/set + if "session_start_time" not in metadata["NWBFile"]: + try: + date = datetime.datetime.strptime(data_dir_path.name, "%Y-%m-%d").replace(tzinfo=ZoneInfo("US/Eastern")) + except: + raise AssertionError( + "Session start time was not auto-detected. Please provide it in `watters_metadata.yaml`" + ) + metadata["NWBFile"]["session_start_time"] = date + # Run conversion processed_converter.run_conversion( metadata=metadata, nwbfile_path=processed_nwbfile_path, conversion_options=processed_conversion_options ) + metadata["NWBFile"]["identifier"] = str(uuid4()) raw_converter = WattersNWBConverter(source_data=raw_source_data, sync_dir=str(data_dir_path / "sync_pulses")) raw_converter.run_conversion( metadata=metadata, nwbfile_path=raw_nwbfile_path, conversion_options=raw_conversion_options diff --git a/src/jazayeri_lab_to_nwb/watters/watters_metadata.yaml b/src/jazayeri_lab_to_nwb/watters/watters_metadata.yaml index db7e745..8207f76 100644 --- a/src/jazayeri_lab_to_nwb/watters/watters_metadata.yaml +++ b/src/jazayeri_lab_to_nwb/watters/watters_metadata.yaml @@ -1,14 +1,16 @@ NWBFile: - # related_publications: + # related_publications: # no pubs yet # - https://doi.org/12345 session_description: - A rich text description of the experiment. Can also just be the abstract of the publication. + Data from macaque performing working memory task. Subject is presented with multiple objects at different locations + on a screen. After a delay, the subject is then cued with one of the objects, now displayed at the center of the + screen. Subject should respond by saccading to the location of the cued object at its initial presentation. institution: MIT lab: Jazayeri experimenter: - Watters, Nicholas Subject: species: Macaca mulatta - # subject_id: monkey0 + # subject_id: Elgar # currently auto-detected from session path, but can be overridden here age: P6Y # in ISO 8601, such as "P1W2D" sex: U # One of M, F, U, or O diff --git a/src/jazayeri_lab_to_nwb/watters/watterstrialsinterface.py b/src/jazayeri_lab_to_nwb/watters/watterstrialsinterface.py index 922ee77..fe13f50 100644 --- a/src/jazayeri_lab_to_nwb/watters/watterstrialsinterface.py +++ b/src/jazayeri_lab_to_nwb/watters/watterstrialsinterface.py @@ -2,6 +2,7 @@ import json import numpy as np import pandas as pd +import warnings from pathlib import Path from pynwb import NWBFile from typing import Optional @@ -61,6 +62,9 @@ def _read_file(self, file_path: FolderPathType): for i in range(n_trials): # get trial start time start_time = data_dict["task/trials.start_times.json"][i] + if np.isnan(start_time): + warnings.warn(f"Start time for trial {i} is NaN. Dropping this trial.", stacklevel=2) + continue # map response object index to id response_object = data_dict["behavior/trials.response.object.json"][i]