Skip to content

Commit 883a2a4

Browse files
Implement addition of optogenetic metadata (#118)
* add optogenetics extension dependency * implement opto metadata addition * move probe_metadata to device_metadata * update virus addition for yaml format * update excitation source addition for yaml format * update optic fiber addition for yaml format * specificity update * add optogenetic devices in main conversion function * add demo opto device files * add opto devices to test metadata yaml * tests for optogenetics devices * updates for device metadata generalization * update test to device metadata * linting * epoch optogenetic protocol info * link to dio src in optogenetics table * update metadata * fix condition id search * parse track geometry files * add fsgui cameras to table * tests for optogenetics epochs table * generalize for statescript-defined protocols * add device yamls * fix tests and naming * fix bad unix character * update named attributes from ndx novela review * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * logging and docstrings * change to np docstring format * pin pynwb version * pin pynwb version in pyproject.toml --------- Co-authored-by: Copilot <[email protected]>
1 parent 6145f12 commit 883a2a4

29 files changed

+1300
-44
lines changed

environment.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dependencies:
77
- numpy
88
- scipy
99
- pandas
10-
- pynwb
10+
- pynwb<=3.0.0
1111
- nwbinspector>=0.5.0
1212
- dask
1313
- ipython
@@ -20,4 +20,5 @@ dependencies:
2020
- pip
2121
- pip:
2222
- ndx-franklab-novela
23+
- ndx-optogenetics
2324
- neo>=0.13.4

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies = [
2424
"numpy",
2525
"scipy",
2626
"pandas",
27-
"pynwb",
27+
"pynwb<=3.0.0",
2828
"nwbinspector>=0.5.0",
2929
"ndx_franklab_novela",
3030
"pyyaml",

src/trodes_to_nwb/convert.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""
77

88
import logging
9-
import os
109
from pathlib import Path
1110

1211
import nwbinspector
@@ -18,6 +17,7 @@
1817
from trodes_to_nwb.convert_dios import add_dios
1918
from trodes_to_nwb.convert_ephys import RecFileDataChunkIterator, add_raw_ephys
2019
from trodes_to_nwb.convert_intervals import add_epochs, add_sample_count
20+
from trodes_to_nwb.convert_optogenetics import add_optogenetics
2121
from trodes_to_nwb.convert_position import add_associated_video_files, add_position
2222
from trodes_to_nwb.convert_rec_header import (
2323
add_header_device,
@@ -72,18 +72,16 @@ def setup_logger(name_logfile: str, path_logfile: str) -> logging.Logger:
7272
return logger
7373

7474

75-
def get_included_probe_metadata_paths() -> list[Path]:
75+
def get_included_device_metadata_paths() -> list[Path]:
7676
"""Get the included probe metadata paths
7777
Returns
7878
-------
79-
probe_metadata_paths : list[Path]
79+
device_metadata_paths : list[Path]
8080
List of probe metadata paths
8181
"""
8282
package_dir = Path(__file__).parent.resolve()
83-
probe_folder = package_dir / "probe_metadata"
84-
return [
85-
probe_folder / file for file in probe_folder.iterdir() if file.suffix == ".yml"
86-
]
83+
device_folder = package_dir / "device_metadata"
84+
return device_folder.rglob("*.yml")
8785

8886

8987
def _get_file_paths(df: pd.DataFrame, file_extension: str) -> list[str]:
@@ -107,7 +105,7 @@ def _get_file_paths(df: pd.DataFrame, file_extension: str) -> list[str]:
107105
def create_nwbs(
108106
path: Path,
109107
header_reconfig_path: Path | None = None,
110-
probe_metadata_paths: list[Path] | None = None,
108+
device_metadata_paths: list[Path] | None = None,
111109
output_dir: str = "/stelmo/nwb/raw",
112110
video_directory: str = "",
113111
convert_video: bool = False,
@@ -124,8 +122,8 @@ def create_nwbs(
124122
Path to the SpikeGadgets data file.
125123
header_reconfig_path : Path, optional
126124
Path to the header reconfiguration file, by default None.
127-
probe_metadata_paths : list[Path], optional
128-
List of paths to the probe metadata files, by default None.
125+
device_metadata_paths : list[Path], optional
126+
List of paths to the device metadata files, by default None.
129127
output_dir : str, optional
130128
Output directory for the NWB files, by default "/stelmo/nwb/raw".
131129
video_directory : str, optional
@@ -147,8 +145,8 @@ def create_nwbs(
147145
path = Path(path)
148146

149147
# provide the included probe metadata files if none are provided
150-
if probe_metadata_paths is None:
151-
probe_metadata_paths = get_included_probe_metadata_paths()
148+
if device_metadata_paths is None:
149+
device_metadata_paths = get_included_device_metadata_paths()
152150

153151
file_info = get_file_info(path)
154152

@@ -164,7 +162,7 @@ def pass_func(args):
164162
session,
165163
session_df,
166164
header_reconfig_path,
167-
probe_metadata_paths,
165+
device_metadata_paths,
168166
output_dir,
169167
video_directory,
170168
convert_video,
@@ -191,7 +189,7 @@ def pass_func(args):
191189
session,
192190
session_df,
193191
header_reconfig_path,
194-
probe_metadata_paths,
192+
device_metadata_paths,
195193
output_dir,
196194
video_directory,
197195
convert_video,
@@ -203,7 +201,7 @@ def _create_nwb(
203201
session: tuple[str, str, str],
204202
session_df: pd.DataFrame,
205203
header_reconfig_path: Path | None = None,
206-
probe_metadata_paths: list[Path] | None = None,
204+
device_metadata_paths: list[Path] | None = None,
207205
output_dir: str = "/stelmo/nwb/raw",
208206
video_directory: str = "",
209207
convert_video: bool = False,
@@ -241,8 +239,8 @@ def _create_nwb(
241239
metadata_filepaths = metadata_filepaths[0]
242240
logger.info(f"\tmetadata_filepath: {metadata_filepaths}")
243241

244-
metadata, probe_metadata = load_metadata(
245-
metadata_filepaths, probe_metadata_paths=probe_metadata_paths
242+
metadata, device_metadata = load_metadata(
243+
metadata_filepaths, device_metadata_paths=device_metadata_paths
246244
)
247245

248246
logger.info("CREATING HARDWARE MAPS")
@@ -266,15 +264,16 @@ def _create_nwb(
266264
add_tasks(nwb_file, metadata)
267265
add_associated_files(nwb_file, metadata)
268266
add_electrode_groups(
269-
nwb_file, metadata, probe_metadata, hw_channel_map, ref_electrode_map
267+
nwb_file, metadata, device_metadata, hw_channel_map, ref_electrode_map
270268
)
271269
add_header_device(nwb_file, rec_header)
272270
add_associated_video_files(
273271
nwb_file, metadata, session_df, video_directory, convert_video
274272
)
273+
add_optogenetics(nwb_file, metadata, device_metadata)
275274

276275
logger.info("ADDING EPHYS DATA")
277-
### add rec file data ###
276+
# add rec file data
278277
map_row_ephys_data_to_row_electrodes_table = list(
279278
range(len(nwb_file.electrodes))
280279
) # TODO: Double check this
@@ -297,7 +296,7 @@ def _create_nwb(
297296
neo_io=rec_dci.neo_io,
298297
)
299298
logger.info("ADDING POSITION")
300-
### add position ###
299+
# add position
301300
if disable_ptp:
302301
ptp_enabled = False
303302
else:

0 commit comments

Comments
 (0)