-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from catalystneuro/add_fiber_photometry
Add fiber photometry interface
- Loading branch information
Showing
12 changed files
with
254 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,3 @@ jobs: | |
run: pip install -e . | ||
- name: Test module load | ||
run: python -c "import hnasko_lab_to_nwb" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,4 +146,4 @@ dmypy.json | |
.DS_Store | ||
|
||
# NWB files | ||
**.nwb | ||
**.nwb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
from .behaviorinterface import Embargo2025BehaviorInterface | ||
from .nwbconverter import Embargo2025NWBConverter | ||
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,101 @@ | ||
"""Primary script to run to convert an entire session for of data using the NWBConverter.""" | ||
|
||
from pathlib import Path | ||
from typing import Union | ||
import datetime | ||
from zoneinfo import ZoneInfo | ||
|
||
from neuroconv.utils import load_dict_from_file, dict_deep_update | ||
|
||
from .embargo_2025 import Embargo2025NWBConverter | ||
from nwbconverter import Embargo2025NWBConverter | ||
|
||
from neuroconv.utils import dict_deep_update, load_dict_from_file | ||
|
||
def session_to_nwb(data_dir_path: Union[str, Path], output_dir_path: Union[str, Path], stub_test: bool = False): | ||
|
||
data_dir_path = Path(data_dir_path) | ||
def session_to_nwb( | ||
output_dir_path: Union[str, Path], | ||
subject_id: str, | ||
session_id: str, | ||
tdt_folder_path: Union[str, Path], | ||
protocol_type: str, | ||
stub_test: bool = False, | ||
): | ||
output_dir_path = Path(output_dir_path) | ||
if stub_test: | ||
output_dir_path = output_dir_path / "nwb_stub" | ||
output_dir_path.mkdir(parents=True, exist_ok=True) | ||
|
||
session_id = "subject_identifier_usually" | ||
nwbfile_path = output_dir_path / f"{session_id}.nwb" | ||
|
||
nwbfile_path = output_dir_path / f"sub-{subject_id}_ses-{session_id}.nwb" | ||
|
||
valid_protocols = {"Varying durations", "Varying frequencies", "Shocks"} | ||
if protocol_type not in valid_protocols: | ||
raise ValueError(f"Invalid protocol_type: {protocol_type}. Must be one of {valid_protocols}.") | ||
if protocol_type == "Varying durations": | ||
session_description = ( | ||
"The subject is placed in a plastic tub and is recorded for 3.5 minutes. " | ||
"The subject receives a 40 Hz stimulation at various durations (i.e. 250ms, 1s and 4s) " | ||
"5 times for each duration) with an inter-stimulus interval (ISI) of 10s. " | ||
) | ||
elif protocol_type == "Varying frequencies": | ||
session_description = ( | ||
"The subject is placed in a plastic tub and undergoes 3 recording sessions corresponding " | ||
"to a fixed duration of stimulation (i.e., 250ms, 1s, and 4s). Each session lasted 8 minutes. " | ||
"The subject receives optogenetic stimulation at varying frequencies " | ||
"(5 Hz, 10 Hz , 20 Hz and 40 Hz) 5 times for each duration with an ISI of 10s. " | ||
) | ||
elif protocol_type == "Shocks": | ||
session_description = ( | ||
"The subject is placed in a shock chamber and recorded for 6 minutes. " | ||
"Uncued shocks (0.3 mA) at various durations (250ms, 1s and 4s, 5 times for each duration) " | ||
"are delivered in a randomized order and ISI." | ||
) | ||
source_data = dict() | ||
conversion_options = dict() | ||
|
||
# Add Recording | ||
source_data.update(dict(Recording=dict())) | ||
conversion_options.update(dict(Recording=dict(stub_test=stub_test))) | ||
|
||
# Add Sorting | ||
source_data.update(dict(Sorting=dict())) | ||
conversion_options.update(dict(Sorting=dict())) | ||
# Add FiberPhotometry | ||
|
||
# Add Behavior | ||
source_data.update(dict(Behavior=dict())) | ||
conversion_options.update(dict(Behavior=dict())) | ||
source_data.update(dict(FiberPhotometry=dict(folder_path=tdt_folder_path))) | ||
conversion_options.update(dict(FiberPhotometry=dict())) | ||
|
||
converter = Embargo2025NWBConverter(source_data=source_data) | ||
|
||
# Add datetime to conversion | ||
metadata = converter.get_metadata() | ||
date = datetime.datetime(year=2020, month=1, day=1, tzinfo=ZoneInfo("US/Eastern")) | ||
metadata["NWBFile"]["session_start_time"] = date | ||
|
||
# Update default metadata with the editable in the corresponding yaml file | ||
editable_metadata_path = Path(__file__).parent / "embargo_2025_metadata.yaml" | ||
metadata = converter.get_metadata() | ||
editable_metadata_path = Path(__file__).parent / "metadata.yaml" | ||
editable_metadata = load_dict_from_file(editable_metadata_path) | ||
metadata = dict_deep_update(metadata, editable_metadata) | ||
|
||
metadata["Subject"]["subject_id"] = "a_subject_id" # Modify here or in the yaml file | ||
metadata["Subject"]["subject_id"] = subject_id | ||
metadata["NWBFile"]["session_id"] = session_id | ||
metadata["NWBFile"]["session_description"] = session_description | ||
|
||
# Run conversion | ||
converter.run_conversion(metadata=metadata, nwbfile_path=nwbfile_path, conversion_options=conversion_options) | ||
converter.run_conversion( | ||
metadata=metadata, nwbfile_path=nwbfile_path, conversion_options=conversion_options, overwrite=True | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
# Parameters for conversion | ||
data_dir_path = Path("/Directory/With/Raw/Formats/") | ||
output_dir_path = Path("~/conversion_nwb/") | ||
stub_test = False | ||
|
||
<<<<<<< HEAD:hnasko-lab-to-nwb/src/hnasko_lab_to_nwb/embargo_2025/convert_session.py | ||
session_to_nwb(data_dir_path=data_dir_path, output_dir_path=output_dir_path, stub_test=stub_test) | ||
======= | ||
session_to_nwb(data_dir_path=data_dir_path, | ||
output_dir_path=output_dir_path, | ||
stub_test=stub_test, | ||
) | ||
>>>>>>> main:hnasko-lab-to-nwb/src/hnasko_lab_to_nwb/embargo_2025/embargo_2025_convert_session.py | ||
data_dir_path = Path("D:/Hnasko-CN-data-share/SN pan GABA recordings/PPN/") | ||
output_dir_path = Path("D:/hnasko_lab_conversion_nwb") | ||
from neuroconv.tools.path_expansion import LocalPathExpander | ||
|
||
data_dir_path = "D:/Hnasko-CN-data-share/SN pan GABA recordings/PPN/" | ||
# Specify source data | ||
source_data_spec = { | ||
"FiberPhotometry": { | ||
"base_directory": data_dir_path + "Fiber photometry_TDT", | ||
"folder_path": "{protocol_type}/{subject_id}-{session_id}", | ||
} | ||
} | ||
# Instantiate LocalPathExpander | ||
path_expander = LocalPathExpander() | ||
# Expand paths and extract metadata | ||
metadata_list = path_expander.expand_paths(source_data_spec) | ||
for metadata in metadata_list: | ||
session_to_nwb( | ||
output_dir_path=output_dir_path, | ||
subject_id=metadata["metadata"]["Subject"]["subject_id"], | ||
session_id=metadata["metadata"]["NWBFile"]["session_id"], | ||
tdt_folder_path=metadata["source_data"]["FiberPhotometry"]["folder_path"], | ||
protocol_type=metadata["metadata"]["extras"]["protocol_type"], | ||
stub_test=True, | ||
) |
Oops, something went wrong.