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

Fix duplicated file identifiers from sharing metadata #5

Merged
merged 8 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
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
16 changes: 10 additions & 6 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,13 @@ 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
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:
print("Session start time not auto-detected. Setting to 2022-06-01...")
date = datetime.datetime(year=2022, month=6, day=1, tzinfo=ZoneInfo("US/Eastern"))
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
metadata["NWBFile"]["session_start_time"] = date
metadata["NWBFile"]["session_id"] = session_id

# Subject name
Expand Down Expand Up @@ -147,6 +150,7 @@ def session_to_nwb(data_dir_path: Union[str, Path], output_dir_path: Union[str,
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 All @@ -159,7 +163,7 @@ def session_to_nwb(data_dir_path: Union[str, Path], output_dir_path: Union[str,
data_dir_path = Path("/shared/catalystneuro/JazLab/monkey0/2022-06-01/")
# data_dir_path = Path("/shared/catalystneuro/JazLab/monkey1/2022-06-05/")
output_dir_path = Path("~/conversion_nwb/jazayeri-lab-to-nwb/watters_perle_combined/").expanduser()
stub_test = True
stub_test = False

session_to_nwb(
data_dir_path=data_dir_path,
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
3 changes: 3 additions & 0 deletions src/jazayeri_lab_to_nwb/watters/watterstrialsinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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):
print(f"Start time for trial {i} is NaN. Dropping this trial.")
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
continue

# map response object index to id
response_object = data_dict["behavior/trials.response.object.json"][i]
Expand Down