Skip to content

Commit dac02a7

Browse files
authored
Prepare ophys metadata for dict-based format (#1680)
1 parent 63713b7 commit dac02a7

File tree

8 files changed

+116
-588
lines changed

8 files changed

+116
-588
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# v0.9.4 (Upcoming)
22

33
## Removals, Deprecations and Changes
4+
* Removed deprecated wrapper functions from `roiextractors_pending_deprecation.py` (March 2026 deadline): `add_imaging_plane_to_nwbfile`, `add_image_segmentation_to_nwbfile`, `add_photon_series_to_nwbfile`, `add_plane_segmentation_to_nwbfile`, `add_background_plane_segmentation_to_nwbfile`, `add_background_fluorescence_traces_to_nwbfile`, `add_summary_images_to_nwbfile`. [PR #1680](https://github.com/catalystneuro/neuroconv/pull/1680)
5+
* Added `*args` positional argument deprecation to `add_imaging_to_nwbfile` to enforce keyword-only arguments. Will be enforced on or after September 2026. [PR #1680](https://github.com/catalystneuro/neuroconv/pull/1680)
46
* Removed the deprecated `staging` parameter from `automatic_dandi_upload`. Use `sandbox` instead. [PR #1678](https://github.com/catalystneuro/neuroconv/pull/1678)
57
* Removed the deprecated `container_name` parameter from `ImageInterface.add_to_nwbfile` and `DeepLabCutInterface.add_to_nwbfile`. Use `metadata_key` in `__init__` instead. [PR #1678](https://github.com/catalystneuro/neuroconv/pull/1678)
68
* Removed the deprecated `time_series_name` parameter from `add_recording_as_time_series_to_nwbfile`. Use `metadata_key` instead. [PR #1678](https://github.com/catalystneuro/neuroconv/pull/1678)

src/neuroconv/datainterfaces/ophys/basesegmentationextractorinterface.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,14 @@ def get_metadata_schema(self) -> dict:
118118
return metadata_schema
119119

120120
def get_metadata(self) -> DeepDict:
121-
from ...tools.roiextractors.roiextractors import _get_default_ophys_metadata
121+
from ...tools.roiextractors.roiextractors import (
122+
_get_default_ophys_metadata_old_metadata_list,
123+
)
122124

123125
metadata = super().get_metadata()
124126

125127
# Get the default ophys metadata (single source of truth)
126-
ophys_defaults = _get_default_ophys_metadata()
128+
ophys_defaults = _get_default_ophys_metadata_old_metadata_list()
127129

128130
# Only include the fields relevant to segmentation (not imaging series)
129131
metadata["Ophys"] = {

src/neuroconv/datainterfaces/ophys/miniscope/miniscopeconverter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,10 @@ def _align_session_start_times(self):
378378

379379
def get_metadata(self):
380380
from neuroconv.tools.roiextractors.roiextractors import (
381-
_get_default_ophys_metadata,
381+
_get_default_ophys_metadata_old_metadata_list,
382382
)
383383

384-
default_ophys_metadata = _get_default_ophys_metadata()
384+
default_ophys_metadata = _get_default_ophys_metadata_old_metadata_list()
385385
metadata = super().get_metadata()
386386

387387
# Use the minimum session start time if it was calculated during alignment

src/neuroconv/datainterfaces/ophys/miniscope/miniscopeimagingdatainterface.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ def add_to_nwbfile(
178178
"""
179179
from ndx_miniscope.utils import add_miniscope_device
180180

181-
from ....tools.roiextractors import add_photon_series_to_nwbfile
181+
from ....tools.roiextractors.roiextractors import (
182+
_add_photon_series_to_nwbfile_old_list_format,
183+
)
182184

183185
miniscope_timestamps = self.get_original_timestamps()
184186
imaging_extractor = self.imaging_extractor
@@ -193,7 +195,7 @@ def add_to_nwbfile(
193195
device_metadata = metadata["Ophys"]["Device"][0]
194196
add_miniscope_device(nwbfile=nwbfile, device_metadata=device_metadata)
195197

196-
add_photon_series_to_nwbfile(
198+
_add_photon_series_to_nwbfile_old_list_format(
197199
imaging=imaging_extractor,
198200
nwbfile=nwbfile,
199201
metadata=metadata,

src/neuroconv/tools/roiextractors/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,5 @@
99
write_segmentation_to_nwbfile,
1010
)
1111
from .roiextractors_pending_deprecation import (
12-
add_background_fluorescence_traces_to_nwbfile,
13-
add_background_plane_segmentation_to_nwbfile,
1412
add_fluorescence_traces_to_nwbfile,
15-
add_image_segmentation_to_nwbfile,
16-
add_imaging_plane_to_nwbfile,
17-
add_photon_series_to_nwbfile,
18-
add_plane_segmentation_to_nwbfile,
19-
add_summary_images_to_nwbfile,
2013
)

src/neuroconv/tools/roiextractors/roiextractors.py

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
from ...utils.str_utils import human_readable_size
5555

5656

57-
def _get_default_ophys_metadata():
57+
def _get_default_ophys_metadata_old_metadata_list():
5858
"""
5959
Returns fresh ophys default metadata dictionary.
6060
@@ -151,7 +151,7 @@ def _get_default_segmentation_metadata() -> DeepDict:
151151
metadata = get_default_nwbfile_metadata()
152152

153153
# Get fresh ophys defaults and add to metadata
154-
ophys_defaults = _get_default_ophys_metadata()
154+
ophys_defaults = _get_default_ophys_metadata_old_metadata_list()
155155
metadata["Ophys"] = {
156156
"Device": ophys_defaults["Ophys"]["Device"],
157157
"ImagingPlane": ophys_defaults["Ophys"]["ImagingPlane"],
@@ -185,7 +185,7 @@ def get_nwb_imaging_metadata(
185185
specific to the imaging data.
186186
"""
187187
# Get fresh ophys defaults
188-
metadata = _get_default_ophys_metadata()
188+
metadata = _get_default_ophys_metadata_old_metadata_list()
189189

190190
# TODO: get_num_channels is deprecated, remove
191191
channel_name_list = imgextractor.get_channel_names() or ["OpticalChannel"]
@@ -232,7 +232,7 @@ def add_devices_to_nwbfile(nwbfile: NWBFile, metadata: dict | None = None) -> NW
232232
device_metadata = metadata.get("Ophys", {}).get("Device")
233233

234234
if device_metadata is None:
235-
default_metadata = _get_default_ophys_metadata()
235+
default_metadata = _get_default_ophys_metadata_old_metadata_list()
236236
device_metadata = default_metadata["Ophys"]["Device"]
237237

238238
for device in device_metadata:
@@ -251,7 +251,7 @@ def add_devices_to_nwbfile(nwbfile: NWBFile, metadata: dict | None = None) -> NW
251251
return nwbfile
252252

253253

254-
def _add_imaging_plane_to_nwbfile(
254+
def _add_imaging_plane_to_nwbfile_old_list_format(
255255
nwbfile: NWBFile,
256256
metadata: dict,
257257
imaging_plane_name: str | None = None,
@@ -275,7 +275,7 @@ def _add_imaging_plane_to_nwbfile(
275275
NWBFile
276276
The nwbfile passed as an input with the imaging plane added.
277277
"""
278-
default_metadata = _get_default_ophys_metadata()
278+
default_metadata = _get_default_ophys_metadata_old_metadata_list()
279279
default_imaging_plane = default_metadata["Ophys"]["ImagingPlane"][0]
280280

281281
# Track whether user explicitly provided a name
@@ -359,7 +359,7 @@ def _add_image_segmentation_to_nwbfile(nwbfile: NWBFile, metadata: dict) -> NWBF
359359
return nwbfile
360360

361361

362-
def _add_photon_series_to_nwbfile(
362+
def _add_photon_series_to_nwbfile_old_list_format(
363363
imaging: ImagingExtractor,
364364
nwbfile: NWBFile,
365365
metadata: dict | None = None,
@@ -422,7 +422,7 @@ def _add_photon_series_to_nwbfile(
422422
], "'parent_container' must be either 'acquisition' or 'processing/ophys'."
423423

424424
# Get defaults from single source of truth
425-
default_metadata = _get_default_ophys_metadata()
425+
default_metadata = _get_default_ophys_metadata_old_metadata_list()
426426
default_photon_series = default_metadata["Ophys"][photon_series_type][0]
427427

428428
# Extract photon series metadata from user or use defaults
@@ -451,7 +451,7 @@ def _add_photon_series_to_nwbfile(
451451
imaging_plane_name = None # Will create default imaging plane
452452

453453
# Add imaging plane (None signals to create default imaging plane)
454-
_add_imaging_plane_to_nwbfile(
454+
_add_imaging_plane_to_nwbfile_old_list_format(
455455
nwbfile=nwbfile,
456456
metadata=metadata,
457457
imaging_plane_name=imaging_plane_name,
@@ -602,6 +602,7 @@ def add_imaging_to_nwbfile(
602602
imaging: ImagingExtractor,
603603
nwbfile: NWBFile,
604604
metadata: dict | None = None,
605+
*args, # TODO: change to * (keyword only) on or after September 2026
605606
photon_series_type: Literal["TwoPhotonSeries", "OnePhotonSeries"] = "TwoPhotonSeries",
606607
photon_series_index: int = 0,
607608
iterator_type: str | None = "v2",
@@ -643,8 +644,42 @@ def add_imaging_to_nwbfile(
643644
The NWB file with the imaging data added
644645
645646
"""
647+
# TODO: Remove this block in September 2026 or after when positional arguments are no longer supported.
648+
if args:
649+
parameter_names = [
650+
"photon_series_type",
651+
"photon_series_index",
652+
"iterator_type",
653+
"iterator_options",
654+
"parent_container",
655+
"always_write_timestamps",
656+
]
657+
num_positional_args_before_args = 3 # imaging, nwbfile, metadata
658+
if len(args) > len(parameter_names):
659+
raise TypeError(
660+
f"add_imaging_to_nwbfile() takes at most {len(parameter_names) + num_positional_args_before_args} positional arguments but "
661+
f"{len(args) + num_positional_args_before_args} were given. "
662+
"Note: Positional arguments are deprecated and will be removed in September 2026 or after. Please use keyword arguments."
663+
)
664+
positional_values = dict(zip(parameter_names, args))
665+
passed_as_positional = list(positional_values.keys())
666+
warnings.warn(
667+
f"Passing arguments positionally to add_imaging_to_nwbfile is deprecated "
668+
f"and will be removed in September 2026 or after. "
669+
f"The following arguments were passed positionally: {passed_as_positional}. "
670+
"Please use keyword arguments instead.",
671+
FutureWarning,
672+
stacklevel=2,
673+
)
674+
photon_series_type = positional_values.get("photon_series_type", photon_series_type)
675+
photon_series_index = positional_values.get("photon_series_index", photon_series_index)
676+
iterator_type = positional_values.get("iterator_type", iterator_type)
677+
iterator_options = positional_values.get("iterator_options", iterator_options)
678+
parent_container = positional_values.get("parent_container", parent_container)
679+
always_write_timestamps = positional_values.get("always_write_timestamps", always_write_timestamps)
680+
646681
add_devices_to_nwbfile(nwbfile=nwbfile, metadata=metadata)
647-
nwbfile = _add_photon_series_to_nwbfile(
682+
nwbfile = _add_photon_series_to_nwbfile_old_list_format(
648683
imaging=imaging,
649684
nwbfile=nwbfile,
650685
metadata=metadata,
@@ -1014,7 +1049,7 @@ def _add_plane_segmentation(
10141049
iterator_options = iterator_options or dict()
10151050

10161051
# Get defaults from single source of truth
1017-
default_metadata = _get_default_ophys_metadata()
1052+
default_metadata = _get_default_ophys_metadata_old_metadata_list()
10181053
default_plane_segmentation = default_metadata["Ophys"]["ImageSegmentation"]["plane_segmentations"][
10191054
default_plane_segmentation_index
10201055
]
@@ -1065,7 +1100,9 @@ def _add_plane_segmentation(
10651100
)
10661101

10671102
imaging_plane_name_to_add = imaging_plane_name_from_plane_seg if user_has_imaging_plane else None
1068-
_add_imaging_plane_to_nwbfile(nwbfile=nwbfile, metadata=metadata, imaging_plane_name=imaging_plane_name_to_add)
1103+
_add_imaging_plane_to_nwbfile_old_list_format(
1104+
nwbfile=nwbfile, metadata=metadata, imaging_plane_name=imaging_plane_name_to_add
1105+
)
10691106

10701107
if plane_segmentation_name in image_segmentation.plane_segmentations:
10711108
# At the moment, we don't support extending an existing PlaneSegmentation.
@@ -1219,7 +1256,7 @@ def _add_fluorescence_traces_to_nwbfile(
12191256
iterator_options = iterator_options or dict()
12201257

12211258
# Get defaults from single source of truth
1222-
default_metadata = _get_default_ophys_metadata()
1259+
default_metadata = _get_default_ophys_metadata_old_metadata_list()
12231260
default_plane_segmentation_name = default_metadata["Ophys"]["ImageSegmentation"]["plane_segmentations"][
12241261
default_plane_segmentation_index
12251262
]["name"]
@@ -1375,7 +1412,7 @@ def _create_roi_table_region(
13751412
The name of the plane segmentation that identifies which plane to add the ROI table region to.
13761413
"""
13771414
# Get ImageSegmentation name from user metadata or use default
1378-
default_metadata = _get_default_ophys_metadata()
1415+
default_metadata = _get_default_ophys_metadata_old_metadata_list()
13791416

13801417
_add_plane_segmentation_to_nwbfile(
13811418
segmentation_extractor=segmentation_extractor,
@@ -1461,7 +1498,7 @@ def _add_summary_images_to_nwbfile(
14611498
metadata = metadata or dict()
14621499

14631500
# Get defaults from single source of truth
1464-
default_metadata = _get_default_ophys_metadata()
1501+
default_metadata = _get_default_ophys_metadata_old_metadata_list()
14651502
default_segmentation_images = default_metadata["Ophys"]["SegmentationImages"]
14661503

14671504
# Extract SegmentationImages metadata from user or use defaults

0 commit comments

Comments
 (0)