5454from ...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