From d64df1120a5631cdf438cc57a15a977392710408 Mon Sep 17 00:00:00 2001 From: samuelbray32 Date: Fri, 11 Jul 2025 08:47:53 -0700 Subject: [PATCH 1/4] update for use of DeviceModel --- src/trodes_to_nwb/convert_yaml.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/trodes_to_nwb/convert_yaml.py b/src/trodes_to_nwb/convert_yaml.py index 044ee90..0940317 100644 --- a/src/trodes_to_nwb/convert_yaml.py +++ b/src/trodes_to_nwb/convert_yaml.py @@ -25,6 +25,12 @@ from pynwb import NWBFile from pynwb.file import ProcessingModule, Subject +try: + from pynwb.device import DeviceModel +except ImportError: + # Temporary error message to ensure existing users have the correct version of pynwb + raise ImportError("Please upgrade pynwb to 3.1.0 or later") + import trodes_to_nwb.metadata_validation from trodes_to_nwb import __version__ @@ -135,12 +141,17 @@ def add_cameras(nwbfile: NWBFile, metadata: dict) -> None: """ # add each camera device to the nwb for camera_metadata in metadata["cameras"]: + model = DeviceModel( + name=camera_metadata["model"], + manufacturer=camera_metadata["manufacturer"], + description="", + ) nwbfile.add_device( CameraDevice( name="camera_device " + str(camera_metadata["id"]), meters_per_pixel=camera_metadata["meters_per_pixel"], manufacturer=camera_metadata["manufacturer"], - model=camera_metadata["model"], + model=model, lens=camera_metadata["lens"], camera_name=camera_metadata["camera_name"], ) From e879fcf7b77833de7f9b1c70ad14ef1386a1489f Mon Sep 17 00:00:00 2001 From: samuelbray32 Date: Fri, 11 Jul 2025 08:49:00 -0700 Subject: [PATCH 2/4] update environment to pynwb 3.1.0 --- environment.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index 86c90e1..e2e1fda 100644 --- a/environment.yml +++ b/environment.yml @@ -7,7 +7,7 @@ dependencies: - numpy - scipy - pandas -- pynwb<=3.0.0 +- pynwb>=3.1.0 - nwbinspector>=0.5.0 - dask - ipython diff --git a/pyproject.toml b/pyproject.toml index 3b800e7..1377a4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ dependencies = [ "numpy", "scipy", "pandas", - "pynwb<=3.0.0", + "pynwb>=3.1.0", "nwbinspector>=0.5.0", "ndx_franklab_novela", "pyyaml", From 8a9439bcefee5226dc9ef97e3f28239945815d4a Mon Sep 17 00:00:00 2001 From: samuelbray32 Date: Fri, 11 Jul 2025 09:26:11 -0700 Subject: [PATCH 3/4] update camera test values --- src/trodes_to_nwb/tests/test_convert_yaml.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/trodes_to_nwb/tests/test_convert_yaml.py b/src/trodes_to_nwb/tests/test_convert_yaml.py index 7a8608c..d7feaf9 100644 --- a/src/trodes_to_nwb/tests/test_convert_yaml.py +++ b/src/trodes_to_nwb/tests/test_convert_yaml.py @@ -60,7 +60,8 @@ def test_camera_creation(): assert len(cameras) == 2 name = "camera_device " + str(metadata["cameras"][0]["id"]) assert cameras[name].meters_per_pixel == 0.001 - assert cameras[name].model == "model1" + assert cameras[name].model.name == "model1" + assert cameras[name].manufacturer == "Allied Vision" assert cameras[name].lens == "lens1" assert cameras[name].manufacturer == "Allied Vision" From 81c1227bf5c30b3f340d6ef8a5512047bbdb7290 Mon Sep 17 00:00:00 2001 From: samuelbray32 Date: Fri, 11 Jul 2025 09:27:09 -0700 Subject: [PATCH 4/4] correctly add camera device object to file --- src/trodes_to_nwb/convert_yaml.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/trodes_to_nwb/convert_yaml.py b/src/trodes_to_nwb/convert_yaml.py index 0940317..5082ae4 100644 --- a/src/trodes_to_nwb/convert_yaml.py +++ b/src/trodes_to_nwb/convert_yaml.py @@ -140,18 +140,20 @@ def add_cameras(nwbfile: NWBFile, metadata: dict) -> None: metadata from the yaml generator """ # add each camera device to the nwb + camera_devices = {} for camera_metadata in metadata["cameras"]: - model = DeviceModel( - name=camera_metadata["model"], - manufacturer=camera_metadata["manufacturer"], - description="", - ) + if (model_name := camera_metadata["model"]) not in camera_devices: + camera_devices[model_name] = nwbfile.create_device_model( + name=camera_metadata["model"], + manufacturer=camera_metadata["manufacturer"], + description="", + ) nwbfile.add_device( CameraDevice( name="camera_device " + str(camera_metadata["id"]), meters_per_pixel=camera_metadata["meters_per_pixel"], manufacturer=camera_metadata["manufacturer"], - model=model, + model=camera_devices[model_name], lens=camera_metadata["lens"], camera_name=camera_metadata["camera_name"], )