Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* 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)

## Features
* 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)

## Improvements
* 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)
Expand Down
1 change: 1 addition & 0 deletions src/neuroconv/tools/nwb_helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ._configure_backend import configure_backend
from ._dataset_configuration import get_default_dataset_io_configurations, get_existing_dataset_io_configurations
from ._metadata_and_file_helpers import (
_add_device_to_nwbfile,
add_device_from_metadata,
configure_and_write_nwbfile,
get_default_nwbfile_metadata,
Expand Down
31 changes: 31 additions & 0 deletions src/neuroconv/tools/nwb_helpers/_metadata_and_file_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,37 @@ def add_device_from_metadata(nwbfile: NWBFile, modality: str = "Ecephys", metada
nwbfile.create_device(**dict(defaults, **device_metadata))


def _add_device_to_nwbfile(
nwbfile: NWBFile,
device_metadata: dict,
):
"""
Add a device to an NWBFile.

If a device with the same name already exists, the existing device is
returned without creating a duplicate.

Parameters
----------
nwbfile : NWBFile
The NWB file to add the device to.
device_metadata : dict
Dictionary describing the device. Must contain at least a ``"name"`` key.

Returns
-------
Device
The Device object (either newly created or existing).
"""
device_name = device_metadata["name"]

if device_name in nwbfile.devices:
return nwbfile.devices[device_name]

device = nwbfile.create_device(**device_metadata)
return device


def _attempt_cleanup_of_existing_nwbfile(nwbfile_path: Path) -> None:
if not nwbfile_path.exists():
return
Expand Down
Loading
Loading