Skip to content

Commit

Permalink
Merge pull request #5 from catalystneuro/fix_identifier
Browse files Browse the repository at this point in the history
Fix duplicated file identifiers from sharing metadata
  • Loading branch information
CodyCBakerPhD authored Sep 28, 2023
2 parents ad6eb70 + 2708ebe commit e45bf47
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
neuroconv==0.4.3
neuroconv==0.4.4
spikeinterface==0.98.2
nwbwidgets
nwbinspector
Expand Down
17 changes: 12 additions & 5 deletions src/jazayeri_lab_to_nwb/watters/watters_convert_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/jazayeri_lab_to_nwb/watters/watters_metadata.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions src/jazayeri_lab_to_nwb/watters/watterstrialsinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit e45bf47

Please sign in to comment.