Skip to content

Commit b630a43

Browse files
authored
Add dict-based metadata pipeline for imaging (#1677)
1 parent dac02a7 commit b630a43

File tree

5 files changed

+879
-27
lines changed

5 files changed

+879
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Fixed `get_json_schema_from_method_signature` to resolve PEP 563 string annotations (from `from __future__ import annotations`) before passing them to pydantic. This affected any interface defined in a module with deferred annotations (e.g. `MiniscopeConverter`, or external subclasses from SpikeInterface). [PR #1670](https://github.com/catalystneuro/neuroconv/pull/1670)
1212

1313
## Features
14+
* Added dict-based metadata pipeline for imaging in `roiextractors.py`, supporting the new `MicroscopySeries`, `ImagingPlanes`, and `Devices` metadata format keyed by `metadata_key`. Old list-based functions are preserved (renamed with `_old_list_format` suffix) and dispatched automatically when `metadata_key` is not provided. [PR #1677](https://github.com/catalystneuro/neuroconv/pull/1677)
1415

1516
## Improvements
1617
* Added column-first fast path for writing Units tables when the table is new (no append/merge). Uses `id.extend()` + `add_column()` instead of per-row `add_unit()` calls, reducing Python overhead for large sortings. [PR #1669](https://github.com/catalystneuro/neuroconv/pull/1669)

src/neuroconv/tools/nwb_helpers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from ._configure_backend import configure_backend
2626
from ._dataset_configuration import get_default_dataset_io_configurations, get_existing_dataset_io_configurations
2727
from ._metadata_and_file_helpers import (
28+
_add_device_to_nwbfile,
2829
add_device_from_metadata,
2930
configure_and_write_nwbfile,
3031
get_default_nwbfile_metadata,

src/neuroconv/tools/nwb_helpers/_metadata_and_file_helpers.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,37 @@ def add_device_from_metadata(nwbfile: NWBFile, modality: str = "Ecephys", metada
189189
nwbfile.create_device(**dict(defaults, **device_metadata))
190190

191191

192+
def _add_device_to_nwbfile(
193+
nwbfile: NWBFile,
194+
device_metadata: dict,
195+
):
196+
"""
197+
Add a device to an NWBFile.
198+
199+
If a device with the same name already exists, the existing device is
200+
returned without creating a duplicate.
201+
202+
Parameters
203+
----------
204+
nwbfile : NWBFile
205+
The NWB file to add the device to.
206+
device_metadata : dict
207+
Dictionary describing the device. Must contain at least a ``"name"`` key.
208+
209+
Returns
210+
-------
211+
Device
212+
The Device object (either newly created or existing).
213+
"""
214+
device_name = device_metadata["name"]
215+
216+
if device_name in nwbfile.devices:
217+
return nwbfile.devices[device_name]
218+
219+
device = nwbfile.create_device(**device_metadata)
220+
return device
221+
222+
192223
def _attempt_cleanup_of_existing_nwbfile(nwbfile_path: Path) -> None:
193224
if not nwbfile_path.exists():
194225
return

0 commit comments

Comments
 (0)