diff --git a/CHANGELOG.md b/CHANGELOG.md index 1de3166f3..efa5ef267 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v0.9.4 (Upcoming) ## Removals, Deprecations and Changes +* 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) +* 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) * Removed the deprecated `staging` parameter from `automatic_dandi_upload`. Use `sandbox` instead. [PR #1678](https://github.com/catalystneuro/neuroconv/pull/1678) * 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) * 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) diff --git a/src/neuroconv/datainterfaces/ophys/basesegmentationextractorinterface.py b/src/neuroconv/datainterfaces/ophys/basesegmentationextractorinterface.py index 7b45c779c..bfd48bd27 100644 --- a/src/neuroconv/datainterfaces/ophys/basesegmentationextractorinterface.py +++ b/src/neuroconv/datainterfaces/ophys/basesegmentationextractorinterface.py @@ -118,12 +118,14 @@ def get_metadata_schema(self) -> dict: return metadata_schema def get_metadata(self) -> DeepDict: - from ...tools.roiextractors.roiextractors import _get_default_ophys_metadata + from ...tools.roiextractors.roiextractors import ( + _get_default_ophys_metadata_old_metadata_list, + ) metadata = super().get_metadata() # Get the default ophys metadata (single source of truth) - ophys_defaults = _get_default_ophys_metadata() + ophys_defaults = _get_default_ophys_metadata_old_metadata_list() # Only include the fields relevant to segmentation (not imaging series) metadata["Ophys"] = { diff --git a/src/neuroconv/datainterfaces/ophys/miniscope/miniscopeconverter.py b/src/neuroconv/datainterfaces/ophys/miniscope/miniscopeconverter.py index bcc82cc90..2df3081e4 100644 --- a/src/neuroconv/datainterfaces/ophys/miniscope/miniscopeconverter.py +++ b/src/neuroconv/datainterfaces/ophys/miniscope/miniscopeconverter.py @@ -378,10 +378,10 @@ def _align_session_start_times(self): def get_metadata(self): from neuroconv.tools.roiextractors.roiextractors import ( - _get_default_ophys_metadata, + _get_default_ophys_metadata_old_metadata_list, ) - default_ophys_metadata = _get_default_ophys_metadata() + default_ophys_metadata = _get_default_ophys_metadata_old_metadata_list() metadata = super().get_metadata() # Use the minimum session start time if it was calculated during alignment diff --git a/src/neuroconv/datainterfaces/ophys/miniscope/miniscopeimagingdatainterface.py b/src/neuroconv/datainterfaces/ophys/miniscope/miniscopeimagingdatainterface.py index 04f563dd9..04d588baf 100644 --- a/src/neuroconv/datainterfaces/ophys/miniscope/miniscopeimagingdatainterface.py +++ b/src/neuroconv/datainterfaces/ophys/miniscope/miniscopeimagingdatainterface.py @@ -178,7 +178,9 @@ def add_to_nwbfile( """ from ndx_miniscope.utils import add_miniscope_device - from ....tools.roiextractors import add_photon_series_to_nwbfile + from ....tools.roiextractors.roiextractors import ( + _add_photon_series_to_nwbfile_old_list_format, + ) miniscope_timestamps = self.get_original_timestamps() imaging_extractor = self.imaging_extractor @@ -193,7 +195,7 @@ def add_to_nwbfile( device_metadata = metadata["Ophys"]["Device"][0] add_miniscope_device(nwbfile=nwbfile, device_metadata=device_metadata) - add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=imaging_extractor, nwbfile=nwbfile, metadata=metadata, diff --git a/src/neuroconv/tools/roiextractors/__init__.py b/src/neuroconv/tools/roiextractors/__init__.py index 406bedbdb..1565453ea 100644 --- a/src/neuroconv/tools/roiextractors/__init__.py +++ b/src/neuroconv/tools/roiextractors/__init__.py @@ -9,12 +9,5 @@ write_segmentation_to_nwbfile, ) from .roiextractors_pending_deprecation import ( - add_background_fluorescence_traces_to_nwbfile, - add_background_plane_segmentation_to_nwbfile, add_fluorescence_traces_to_nwbfile, - add_image_segmentation_to_nwbfile, - add_imaging_plane_to_nwbfile, - add_photon_series_to_nwbfile, - add_plane_segmentation_to_nwbfile, - add_summary_images_to_nwbfile, ) diff --git a/src/neuroconv/tools/roiextractors/roiextractors.py b/src/neuroconv/tools/roiextractors/roiextractors.py index 3f2cb6a6c..2dc7d6537 100644 --- a/src/neuroconv/tools/roiextractors/roiextractors.py +++ b/src/neuroconv/tools/roiextractors/roiextractors.py @@ -54,7 +54,7 @@ from ...utils.str_utils import human_readable_size -def _get_default_ophys_metadata(): +def _get_default_ophys_metadata_old_metadata_list(): """ Returns fresh ophys default metadata dictionary. @@ -151,7 +151,7 @@ def _get_default_segmentation_metadata() -> DeepDict: metadata = get_default_nwbfile_metadata() # Get fresh ophys defaults and add to metadata - ophys_defaults = _get_default_ophys_metadata() + ophys_defaults = _get_default_ophys_metadata_old_metadata_list() metadata["Ophys"] = { "Device": ophys_defaults["Ophys"]["Device"], "ImagingPlane": ophys_defaults["Ophys"]["ImagingPlane"], @@ -185,7 +185,7 @@ def get_nwb_imaging_metadata( specific to the imaging data. """ # Get fresh ophys defaults - metadata = _get_default_ophys_metadata() + metadata = _get_default_ophys_metadata_old_metadata_list() # TODO: get_num_channels is deprecated, remove 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 device_metadata = metadata.get("Ophys", {}).get("Device") if device_metadata is None: - default_metadata = _get_default_ophys_metadata() + default_metadata = _get_default_ophys_metadata_old_metadata_list() device_metadata = default_metadata["Ophys"]["Device"] for device in device_metadata: @@ -251,7 +251,7 @@ def add_devices_to_nwbfile(nwbfile: NWBFile, metadata: dict | None = None) -> NW return nwbfile -def _add_imaging_plane_to_nwbfile( +def _add_imaging_plane_to_nwbfile_old_list_format( nwbfile: NWBFile, metadata: dict, imaging_plane_name: str | None = None, @@ -275,7 +275,7 @@ def _add_imaging_plane_to_nwbfile( NWBFile The nwbfile passed as an input with the imaging plane added. """ - default_metadata = _get_default_ophys_metadata() + default_metadata = _get_default_ophys_metadata_old_metadata_list() default_imaging_plane = default_metadata["Ophys"]["ImagingPlane"][0] # Track whether user explicitly provided a name @@ -359,7 +359,7 @@ def _add_image_segmentation_to_nwbfile(nwbfile: NWBFile, metadata: dict) -> NWBF return nwbfile -def _add_photon_series_to_nwbfile( +def _add_photon_series_to_nwbfile_old_list_format( imaging: ImagingExtractor, nwbfile: NWBFile, metadata: dict | None = None, @@ -422,7 +422,7 @@ def _add_photon_series_to_nwbfile( ], "'parent_container' must be either 'acquisition' or 'processing/ophys'." # Get defaults from single source of truth - default_metadata = _get_default_ophys_metadata() + default_metadata = _get_default_ophys_metadata_old_metadata_list() default_photon_series = default_metadata["Ophys"][photon_series_type][0] # Extract photon series metadata from user or use defaults @@ -451,7 +451,7 @@ def _add_photon_series_to_nwbfile( imaging_plane_name = None # Will create default imaging plane # Add imaging plane (None signals to create default imaging plane) - _add_imaging_plane_to_nwbfile( + _add_imaging_plane_to_nwbfile_old_list_format( nwbfile=nwbfile, metadata=metadata, imaging_plane_name=imaging_plane_name, @@ -602,6 +602,7 @@ def add_imaging_to_nwbfile( imaging: ImagingExtractor, nwbfile: NWBFile, metadata: dict | None = None, + *args, # TODO: change to * (keyword only) on or after September 2026 photon_series_type: Literal["TwoPhotonSeries", "OnePhotonSeries"] = "TwoPhotonSeries", photon_series_index: int = 0, iterator_type: str | None = "v2", @@ -643,8 +644,42 @@ def add_imaging_to_nwbfile( The NWB file with the imaging data added """ + # TODO: Remove this block in September 2026 or after when positional arguments are no longer supported. + if args: + parameter_names = [ + "photon_series_type", + "photon_series_index", + "iterator_type", + "iterator_options", + "parent_container", + "always_write_timestamps", + ] + num_positional_args_before_args = 3 # imaging, nwbfile, metadata + if len(args) > len(parameter_names): + raise TypeError( + f"add_imaging_to_nwbfile() takes at most {len(parameter_names) + num_positional_args_before_args} positional arguments but " + f"{len(args) + num_positional_args_before_args} were given. " + "Note: Positional arguments are deprecated and will be removed in September 2026 or after. Please use keyword arguments." + ) + positional_values = dict(zip(parameter_names, args)) + passed_as_positional = list(positional_values.keys()) + warnings.warn( + f"Passing arguments positionally to add_imaging_to_nwbfile is deprecated " + f"and will be removed in September 2026 or after. " + f"The following arguments were passed positionally: {passed_as_positional}. " + "Please use keyword arguments instead.", + FutureWarning, + stacklevel=2, + ) + photon_series_type = positional_values.get("photon_series_type", photon_series_type) + photon_series_index = positional_values.get("photon_series_index", photon_series_index) + iterator_type = positional_values.get("iterator_type", iterator_type) + iterator_options = positional_values.get("iterator_options", iterator_options) + parent_container = positional_values.get("parent_container", parent_container) + always_write_timestamps = positional_values.get("always_write_timestamps", always_write_timestamps) + add_devices_to_nwbfile(nwbfile=nwbfile, metadata=metadata) - nwbfile = _add_photon_series_to_nwbfile( + nwbfile = _add_photon_series_to_nwbfile_old_list_format( imaging=imaging, nwbfile=nwbfile, metadata=metadata, @@ -1014,7 +1049,7 @@ def _add_plane_segmentation( iterator_options = iterator_options or dict() # Get defaults from single source of truth - default_metadata = _get_default_ophys_metadata() + default_metadata = _get_default_ophys_metadata_old_metadata_list() default_plane_segmentation = default_metadata["Ophys"]["ImageSegmentation"]["plane_segmentations"][ default_plane_segmentation_index ] @@ -1065,7 +1100,9 @@ def _add_plane_segmentation( ) imaging_plane_name_to_add = imaging_plane_name_from_plane_seg if user_has_imaging_plane else None - _add_imaging_plane_to_nwbfile(nwbfile=nwbfile, metadata=metadata, imaging_plane_name=imaging_plane_name_to_add) + _add_imaging_plane_to_nwbfile_old_list_format( + nwbfile=nwbfile, metadata=metadata, imaging_plane_name=imaging_plane_name_to_add + ) if plane_segmentation_name in image_segmentation.plane_segmentations: # At the moment, we don't support extending an existing PlaneSegmentation. @@ -1219,7 +1256,7 @@ def _add_fluorescence_traces_to_nwbfile( iterator_options = iterator_options or dict() # Get defaults from single source of truth - default_metadata = _get_default_ophys_metadata() + default_metadata = _get_default_ophys_metadata_old_metadata_list() default_plane_segmentation_name = default_metadata["Ophys"]["ImageSegmentation"]["plane_segmentations"][ default_plane_segmentation_index ]["name"] @@ -1375,7 +1412,7 @@ def _create_roi_table_region( The name of the plane segmentation that identifies which plane to add the ROI table region to. """ # Get ImageSegmentation name from user metadata or use default - default_metadata = _get_default_ophys_metadata() + default_metadata = _get_default_ophys_metadata_old_metadata_list() _add_plane_segmentation_to_nwbfile( segmentation_extractor=segmentation_extractor, @@ -1461,7 +1498,7 @@ def _add_summary_images_to_nwbfile( metadata = metadata or dict() # Get defaults from single source of truth - default_metadata = _get_default_ophys_metadata() + default_metadata = _get_default_ophys_metadata_old_metadata_list() default_segmentation_images = default_metadata["Ophys"]["SegmentationImages"] # Extract SegmentationImages metadata from user or use defaults diff --git a/src/neuroconv/tools/roiextractors/roiextractors_pending_deprecation.py b/src/neuroconv/tools/roiextractors/roiextractors_pending_deprecation.py index 9b34e9139..dadfc791f 100644 --- a/src/neuroconv/tools/roiextractors/roiextractors_pending_deprecation.py +++ b/src/neuroconv/tools/roiextractors/roiextractors_pending_deprecation.py @@ -1,395 +1,15 @@ -"""Deprecated roiextractors functions pending removal on or after March 2026. +"""Deprecated roiextractors functions pending removal. These functions are kept for backward compatibility only. Use high-level -interface methods (e.g., BaseImagingExtractorInterface.add_to_nwbfile() or -BaseSegmentationExtractorInterface.add_to_nwbfile()) instead. +interface methods (e.g., BaseSegmentationExtractorInterface.add_to_nwbfile()) instead. """ import warnings -from typing import Literal from pynwb import NWBFile -from pynwb.base import Images -from pynwb.image import GrayscaleImage -from pynwb.ophys import ( - ImageSegmentation, - ImagingPlane, - OnePhotonSeries, - OpticalChannel, - TwoPhotonSeries, -) -from roiextractors import ( - ImagingExtractor, - SegmentationExtractor, -) +from roiextractors import SegmentationExtractor -from .roiextractors import ( - _add_fluorescence_traces_to_nwbfile, - _add_imaging_plane_to_nwbfile, - _add_plane_segmentation, - _get_default_ophys_metadata, - _get_default_segmentation_metadata, - _imaging_frames_to_hdmf_iterator, - add_devices_to_nwbfile, -) -from ..nwb_helpers import get_module -from ...utils import calculate_regular_series_rate - - -def add_imaging_plane_to_nwbfile( - nwbfile: NWBFile, - metadata: dict, - imaging_plane_name: str | None = None, -) -> NWBFile: - """ - .. deprecated:: 0.8.2 - This function is deprecated and will be removed on or after March 2026. - It is kept as-is for backward compatibility. Use high-level interface methods instead. - """ - warnings.warn( - "The 'add_imaging_plane_to_nwbfile' function is deprecated and will be removed on or after March 2026. " - "This is a low-level function that should not be called directly. " - "Use high-level interface methods like BaseImagingExtractorInterface.add_to_nwbfile() instead.", - FutureWarning, - stacklevel=2, - ) - - # Duplicated implementation - kept verbatim for backward compatibility - default_metadata = _get_default_ophys_metadata() - default_imaging_plane = default_metadata["Ophys"]["ImagingPlane"][0] - - # Track whether user explicitly provided a name - user_provided_a_name = imaging_plane_name is not None - - imaging_plane_name = imaging_plane_name or default_imaging_plane["name"] - - if imaging_plane_name in nwbfile.imaging_planes: - return nwbfile - - add_devices_to_nwbfile(nwbfile=nwbfile, metadata=metadata) - - if user_provided_a_name: - # User explicitly requested a specific plane - search for it in metadata - imaging_planes_list = metadata.get("Ophys", {}).get("ImagingPlane", []) - metadata_found = next( - (plane for plane in imaging_planes_list if plane["name"] == imaging_plane_name), - None, - ) - - if metadata_found is None: - raise ValueError( - f"Metadata for Imaging Plane '{imaging_plane_name}' not found in metadata['Ophys']['ImagingPlane']." - ) - - # Copy user metadata to avoid mutation - imaging_plane_kwargs = metadata_found.copy() - - # Fill in any missing required fields with defaults - required_fields = ["name", "excitation_lambda", "indicator", "location", "device", "optical_channel"] - for field in required_fields: - if field not in imaging_plane_kwargs: - imaging_plane_kwargs[field] = default_imaging_plane[field] - else: - # User didn't provide a name, use local copy of defaults as kwargs - imaging_plane_kwargs = default_imaging_plane - - # Replace device name string with actual device object from nwbfile - device_name = imaging_plane_kwargs["device"] - imaging_plane_kwargs["device"] = nwbfile.devices[device_name] - - # Convert optical channel metadata dicts to OpticalChannel objects - imaging_plane_kwargs["optical_channel"] = [ - OpticalChannel(**channel_metadata) for channel_metadata in imaging_plane_kwargs["optical_channel"] - ] - - imaging_plane = ImagingPlane(**imaging_plane_kwargs) - nwbfile.add_imaging_plane(imaging_plane) - - return nwbfile - - -def add_image_segmentation_to_nwbfile(nwbfile: NWBFile, metadata: dict) -> NWBFile: - """ - .. deprecated:: 0.8.2 - This function is deprecated and will be removed on or after March 2026. - It is kept as-is for backward compatibility. Use high-level interface methods instead. - """ - warnings.warn( - "The 'add_image_segmentation_to_nwbfile' function is deprecated and will be removed on or after March 2026. " - "This is a low-level function that should not be called directly. " - "Use high-level interface methods like BaseSegmentationExtractorInterface.add_to_nwbfile() instead.", - FutureWarning, - stacklevel=2, - ) - - # Duplicated implementation - kept verbatim for backward compatibility - # Get ImageSegmentation name from metadata or use default - default_metadata = _get_default_segmentation_metadata() - default_name = default_metadata["Ophys"]["ImageSegmentation"]["name"] - - image_segmentation_name = metadata.get("Ophys", {}).get("ImageSegmentation", {}).get("name", default_name) - - ophys = get_module(nwbfile, "ophys", description="contains optical physiology processed data") - - # Add ImageSegmentation container if it doesn't already exist - if image_segmentation_name not in ophys.data_interfaces: - ophys.add(ImageSegmentation(name=image_segmentation_name)) - - return nwbfile - - -def add_photon_series_to_nwbfile( - imaging: ImagingExtractor, - nwbfile: NWBFile, - metadata: dict | None = None, - photon_series_type: Literal["TwoPhotonSeries", "OnePhotonSeries"] = "TwoPhotonSeries", - photon_series_index: int = 0, - parent_container: Literal["acquisition", "processing/ophys"] = "acquisition", - iterator_type: str | None = "v2", - iterator_options: dict | None = None, - always_write_timestamps: bool = False, -) -> NWBFile: - """ - .. deprecated:: 0.8.2 - This function is deprecated and will be removed on or after March 2026. - It is kept as-is for backward compatibility. Use high-level interface methods instead. - """ - warnings.warn( - "The 'add_photon_series_to_nwbfile' function is deprecated and will be removed on or after March 2026. " - "This is a low-level function that should not be called directly. " - "Use high-level interface methods like BaseImagingExtractorInterface.add_to_nwbfile() instead.", - FutureWarning, - stacklevel=2, - ) - - # Duplicated implementation - kept verbatim for backward compatibility - iterator_options = iterator_options or dict() - metadata = metadata or {} - - assert photon_series_type in [ - "OnePhotonSeries", - "TwoPhotonSeries", - ], "'photon_series_type' must be either 'OnePhotonSeries' or 'TwoPhotonSeries'." - - assert parent_container in [ - "acquisition", - "processing/ophys", - ], "'parent_container' must be either 'acquisition' or 'processing/ophys'." - - # Get defaults from single source of truth - default_metadata = _get_default_ophys_metadata() - default_photon_series = default_metadata["Ophys"][photon_series_type][0] - - # Extract photon series metadata from user or use defaults - user_photon_series_list = metadata.get("Ophys", {}).get(photon_series_type, []) - if user_photon_series_list: - if photon_series_index >= len(user_photon_series_list): - raise IndexError( - f"photon_series_index ({photon_series_index}) out of range. Must be less than {len(user_photon_series_list)}." - ) - user_photon_series_metadata = user_photon_series_list[photon_series_index] - - # Determine if imaging_plane was user-provided, if the value is None this will be used - # to signal that a default imaging plane should be created - imaging_plane_name = user_photon_series_metadata.get("imaging_plane") - - # Build photon series metadata from user input - photon_series_kwargs = user_photon_series_metadata.copy() - # Fill missing required fields with defaults - for field in ["name", "description", "unit", "imaging_plane"]: - if field not in photon_series_kwargs: - photon_series_kwargs[field] = default_photon_series[field] - else: - # User didn't provide photon series - use all defaults - photon_series_kwargs = default_photon_series - imaging_plane_name = None # Will create default imaging plane - - # Add imaging plane (None signals to create default imaging plane) - _add_imaging_plane_to_nwbfile( - nwbfile=nwbfile, - metadata=metadata, - imaging_plane_name=imaging_plane_name, - ) - - imaging_plane_name = photon_series_kwargs["imaging_plane"] - imaging_plane = nwbfile.get_imaging_plane(name=imaging_plane_name) - photon_series_kwargs["imaging_plane"] = imaging_plane - - # Add dimension: respect user-provided metadata, else derive from extractor - if "dimension" not in user_photon_series_metadata: - photon_series_kwargs["dimension"] = imaging.get_sample_shape() - - # This adds the data in way that is memory efficient - imaging_extractor_iterator = _imaging_frames_to_hdmf_iterator( - imaging=imaging, - iterator_type=iterator_type, - iterator_options=iterator_options, - ) - photon_series_kwargs["data"] = imaging_extractor_iterator - - # Add timestamps or rate - if always_write_timestamps: - timestamps = imaging.get_timestamps() - photon_series_kwargs.update(timestamps=timestamps) - else: - # Resolve timestamps: user-set > native hardware > none - timestamps_were_set = imaging.has_time_vector() - if timestamps_were_set: - timestamps = imaging.get_timestamps() - else: - timestamps = imaging.get_native_timestamps() - - timestamps_are_available = timestamps is not None - - if timestamps_are_available: - rate = calculate_regular_series_rate(series=timestamps) - timestamps_are_regular = rate is not None - starting_time = timestamps[0] - else: - rate = float(imaging.get_sampling_frequency()) - timestamps_are_regular = True - starting_time = 0.0 - - if timestamps_are_regular: - photon_series_kwargs.update(rate=rate, starting_time=starting_time) - else: - photon_series_kwargs.update(timestamps=timestamps) - - # Add the photon series to the nwbfile (either as OnePhotonSeries or TwoPhotonSeries) - photon_series_map = dict(OnePhotonSeries=OnePhotonSeries, TwoPhotonSeries=TwoPhotonSeries) - photon_series_class = photon_series_map[photon_series_type] - photon_series = photon_series_class(**photon_series_kwargs) - - if parent_container == "acquisition": - nwbfile.add_acquisition(photon_series) - elif parent_container == "processing/ophys": - ophys_module = get_module(nwbfile, name="ophys", description="contains optical physiology processed data") - ophys_module.add(photon_series) - - return nwbfile - - -def add_plane_segmentation_to_nwbfile( - segmentation_extractor: SegmentationExtractor, - nwbfile: NWBFile, - metadata: dict | None, - plane_segmentation_name: str | None = None, - include_roi_centroids: bool = True, - include_roi_acceptance: bool = True, - mask_type: Literal["image", "pixel", "voxel"] = "image", - iterator_options: dict | None = None, -) -> NWBFile: - """ - .. deprecated:: 0.8.2 - This function is deprecated and will be removed on or after March 2026. - It is kept as-is for backward compatibility. Use high-level interface methods instead. - """ - warnings.warn( - "The 'add_plane_segmentation_to_nwbfile' function is deprecated and will be removed on or after March 2026. " - "This is a low-level function that should not be called directly. " - "Use high-level interface methods like BaseSegmentationExtractorInterface.add_to_nwbfile() instead.", - FutureWarning, - stacklevel=2, - ) - - # Duplicated implementation - kept verbatim for backward compatibility - default_plane_segmentation_index = 0 - roi_ids = segmentation_extractor.get_roi_ids() - if include_roi_acceptance: - accepted_list = segmentation_extractor.get_accepted_list() - is_id_accepted = [int(roi_id in accepted_list) for roi_id in roi_ids] - rejected_list = segmentation_extractor.get_rejected_list() - is_id_rejected = [int(roi_id in rejected_list) for roi_id in roi_ids] - else: - is_id_accepted, is_id_rejected = None, None - if mask_type == "image": - image_or_pixel_masks = segmentation_extractor.get_roi_image_masks() - elif mask_type == "pixel" or mask_type == "voxel": - image_or_pixel_masks = segmentation_extractor.get_roi_pixel_masks() - else: - raise AssertionError( - "Keyword argument 'mask_type' must be one of either 'image', 'pixel', 'voxel'. " f"Received '{mask_type}'." - ) - if include_roi_centroids: - tranpose_image_convention = (1, 0) if len(segmentation_extractor.get_frame_shape()) == 2 else (1, 0, 2) - roi_locations = segmentation_extractor.get_roi_locations()[tranpose_image_convention, :].T - else: - roi_locations = None - - # Prepare quality metrics data - always attempt to include if available - segmentation_extractor_properties = {} - available_properties = segmentation_extractor.get_property_keys() - - # Extract available quality metrics - for property_key in available_properties: - values = segmentation_extractor.get_property(key=property_key, ids=roi_ids) - segmentation_extractor_properties[property_key] = { - "data": values, - "description": "", - } - - nwbfile = _add_plane_segmentation( - background_or_roi_ids=roi_ids, - image_or_pixel_masks=image_or_pixel_masks, - is_id_accepted=is_id_accepted, - is_id_rejected=is_id_rejected, - roi_locations=roi_locations, - default_plane_segmentation_index=default_plane_segmentation_index, - nwbfile=nwbfile, - metadata=metadata, - plane_segmentation_name=plane_segmentation_name, - include_roi_centroids=include_roi_centroids, - include_roi_acceptance=include_roi_acceptance, - mask_type=mask_type, - iterator_options=iterator_options, - segmentation_extractor_properties=segmentation_extractor_properties, - ) - return nwbfile - - -def add_background_plane_segmentation_to_nwbfile( - segmentation_extractor: SegmentationExtractor, - nwbfile: NWBFile, - metadata: dict | None, - background_plane_segmentation_name: str | None = None, - mask_type: Literal["image", "pixel", "voxel"] = "image", - iterator_options: dict | None = None, -) -> NWBFile: - """ - .. deprecated:: 0.8.2 - This function is deprecated and will be removed on or after March 2026. - It is kept as-is for backward compatibility. Use high-level interface methods instead. - """ - warnings.warn( - "The 'add_background_plane_segmentation_to_nwbfile' function is deprecated and will be removed on or after March 2026. " - "This is a low-level function that should not be called directly. " - "Use high-level interface methods like BaseSegmentationExtractorInterface.add_to_nwbfile() instead.", - FutureWarning, - stacklevel=2, - ) - - # Duplicated implementation - kept verbatim for backward compatibility - default_plane_segmentation_index = 1 - background_ids = segmentation_extractor.get_background_ids() - if mask_type == "image": - image_or_pixel_masks = segmentation_extractor.get_background_image_masks() - elif mask_type == "pixel" or mask_type == "voxel": - image_or_pixel_masks = segmentation_extractor.get_background_pixel_masks() - else: - raise AssertionError( - "Keyword argument 'mask_type' must be one of either 'image', 'pixel', 'voxel'. " f"Received '{mask_type}'." - ) - nwbfile = _add_plane_segmentation( - background_or_roi_ids=background_ids, - image_or_pixel_masks=image_or_pixel_masks, - default_plane_segmentation_index=default_plane_segmentation_index, - nwbfile=nwbfile, - metadata=metadata, - plane_segmentation_name=background_plane_segmentation_name, - mask_type=mask_type, - iterator_options=iterator_options, - ) - return nwbfile +from .roiextractors import _add_fluorescence_traces_to_nwbfile def add_fluorescence_traces_to_nwbfile( @@ -438,135 +58,3 @@ def add_fluorescence_traces_to_nwbfile( iterator_options=iterator_options, ) return nwbfile - - -def add_background_fluorescence_traces_to_nwbfile( - segmentation_extractor: SegmentationExtractor, - nwbfile: NWBFile, - metadata: dict | None, - background_plane_segmentation_name: str | None = None, - iterator_options: dict | None = None, - compression_options: dict | None = None, # TODO: remove completely after 10/1/2024 -) -> NWBFile: - """ - .. deprecated:: 0.8.2 - This function is deprecated and will be removed on or after March 2026. - It is kept as-is for backward compatibility. Use high-level interface methods instead. - """ - warnings.warn( - "The 'add_background_fluorescence_traces_to_nwbfile' function is deprecated and will be removed on or after March 2026. " - "This is a low-level function that should not be called directly. " - "Use high-level interface methods like BaseSegmentationExtractorInterface.add_to_nwbfile() instead.", - FutureWarning, - stacklevel=2, - ) - - # Duplicated implementation - kept verbatim for backward compatibility - # TODO: remove completely after 10/1/2024 - if compression_options is not None: - warnings.warn( - message=( - "Specifying compression methods and their options at the level of tool functions has been deprecated. " - "Please use the `configure_backend` tool function for this purpose." - ), - category=DeprecationWarning, - stacklevel=2, - ) - - default_plane_segmentation_index = 1 - - traces_to_add = segmentation_extractor.get_traces_dict() - # Filter empty data and background traces - traces_to_add = { - trace_name: trace - for trace_name, trace in traces_to_add.items() - if trace is not None and trace.size != 0 and trace_name == "neuropil" - } - if not traces_to_add: - return nwbfile - - background_ids = segmentation_extractor.get_background_ids() - nwbfile = _add_fluorescence_traces_to_nwbfile( - segmentation_extractor=segmentation_extractor, - traces_to_add=traces_to_add, - background_or_roi_ids=background_ids, - nwbfile=nwbfile, - metadata=metadata, - default_plane_segmentation_index=default_plane_segmentation_index, - plane_segmentation_name=background_plane_segmentation_name, - iterator_options=iterator_options, - ) - return nwbfile - - -def add_summary_images_to_nwbfile( - nwbfile: NWBFile, - segmentation_extractor: SegmentationExtractor, - metadata: dict | None = None, - plane_segmentation_name: str | None = None, -) -> NWBFile: - """ - .. deprecated:: 0.8.2 - This function is deprecated and will be removed on or after March 2026. - It is kept as-is for backward compatibility. Use high-level interface methods instead. - """ - warnings.warn( - "The 'add_summary_images_to_nwbfile' function is deprecated and will be removed on or after March 2026. " - "This is a low-level function that should not be called directly. " - "Use high-level interface methods like BaseSegmentationExtractorInterface.add_to_nwbfile() instead.", - FutureWarning, - stacklevel=2, - ) - - # Duplicated implementation - kept verbatim for backward compatibility - metadata = metadata or dict() - - # Get defaults from single source of truth - default_metadata = _get_default_ophys_metadata() - default_segmentation_images = default_metadata["Ophys"]["SegmentationImages"] - - # Extract SegmentationImages metadata from user or use defaults - user_segmentation_images = metadata.get("Ophys", {}).get("SegmentationImages", {}) - - # Get container name and description - images_container_name = user_segmentation_images.get("name", default_segmentation_images["name"]) - images_container_description = user_segmentation_images.get( - "description", default_segmentation_images["description"] - ) - - images_dict = segmentation_extractor.get_images_dict() - images_to_add = {img_name: img for img_name, img in images_dict.items() if img is not None} - if not images_to_add: - return nwbfile - - ophys_module = get_module(nwbfile=nwbfile, name="ophys", description="contains optical physiology processed data") - - # Add Images container if it doesn't exist - if images_container_name not in ophys_module.data_interfaces: - ophys_module.add(Images(name=images_container_name, description=images_container_description)) - image_collection = ophys_module.data_interfaces[images_container_name] - - # Determine plane segmentation name - default_plane_segmentation_name = default_metadata["Ophys"]["ImageSegmentation"]["plane_segmentations"][0]["name"] - plane_segmentation_name = plane_segmentation_name or default_plane_segmentation_name - - # Get images metadata for this plane segmentation - if plane_segmentation_name in user_segmentation_images: - images_metadata = user_segmentation_images[plane_segmentation_name] - elif plane_segmentation_name in default_segmentation_images: - images_metadata = default_segmentation_images[plane_segmentation_name] - else: - raise ValueError( - f"Plane segmentation '{plane_segmentation_name}' not found in metadata['Ophys']['SegmentationImages']" - ) - - for img_name, img in images_to_add.items(): - image_kwargs = dict(name=img_name, data=img.T) - image_metadata = images_metadata.get(img_name, None) - if image_metadata is not None: - image_kwargs.update(image_metadata) - - # Note that nwb uses the conversion width x height (columns, rows) and roiextractors uses the transpose - image_collection.add_image(GrayscaleImage(**image_kwargs)) - - return nwbfile diff --git a/tests/test_modalities/test_ophys/test_tools_roiextractors.py b/tests/test_modalities/test_ophys/test_tools_roiextractors.py index 6e85d3ed4..8a39e1bfb 100644 --- a/tests/test_modalities/test_ophys/test_tools_roiextractors.py +++ b/tests/test_modalities/test_ophys/test_tools_roiextractors.py @@ -36,11 +36,11 @@ ) from neuroconv.tools.roiextractors.roiextractors import ( _add_image_segmentation_to_nwbfile, - _add_imaging_plane_to_nwbfile, - _add_photon_series_to_nwbfile, + _add_imaging_plane_to_nwbfile_old_list_format, + _add_photon_series_to_nwbfile_old_list_format, _add_plane_segmentation_to_nwbfile, _add_summary_images_to_nwbfile, - _get_default_ophys_metadata, + _get_default_ophys_metadata_old_metadata_list, ) from neuroconv.utils import dict_deep_update @@ -177,8 +177,8 @@ def setUp(self): self.metadata["Ophys"].update(ImagingPlane=[self.imaging_plane_metadata]) - def test_add_imaging_plane_to_nwbfile(self): - _add_imaging_plane_to_nwbfile( + def test_add_imaging_plane_to_nwbfile_old_list_format(self): + _add_imaging_plane_to_nwbfile_old_list_format( nwbfile=self.nwbfile, metadata=self.metadata, imaging_plane_name=self.imaging_plane_name ) @@ -190,12 +190,12 @@ def test_add_imaging_plane_to_nwbfile(self): assert imaging_plane.description == self.imaging_plane_description def test_not_overwriting_imaging_plane_if_same_name(self): - _add_imaging_plane_to_nwbfile( + _add_imaging_plane_to_nwbfile_old_list_format( nwbfile=self.nwbfile, metadata=self.metadata, imaging_plane_name=self.imaging_plane_name ) self.imaging_plane_metadata["description"] = "modified description" - _add_imaging_plane_to_nwbfile( + _add_imaging_plane_to_nwbfile_old_list_format( nwbfile=self.nwbfile, metadata=self.metadata, imaging_plane_name=self.imaging_plane_name ) @@ -209,7 +209,7 @@ def test_add_two_imaging_planes(self): first_imaging_plane_description = "first_imaging_plane_description" self.imaging_plane_metadata["name"] = first_imaging_plane_name self.imaging_plane_metadata["description"] = first_imaging_plane_description - _add_imaging_plane_to_nwbfile( + _add_imaging_plane_to_nwbfile_old_list_format( nwbfile=self.nwbfile, metadata=self.metadata, imaging_plane_name=first_imaging_plane_name ) @@ -218,7 +218,7 @@ def test_add_two_imaging_planes(self): second_imaging_plane_description = "second_imaging_plane_description" self.imaging_plane_metadata["name"] = second_imaging_plane_name self.imaging_plane_metadata["description"] = second_imaging_plane_description - _add_imaging_plane_to_nwbfile( + _add_imaging_plane_to_nwbfile_old_list_format( nwbfile=self.nwbfile, metadata=self.metadata, imaging_plane_name=second_imaging_plane_name ) @@ -234,14 +234,14 @@ def test_add_two_imaging_planes(self): assert second_imaging_plane.name == second_imaging_plane_name assert second_imaging_plane.description == second_imaging_plane_description - def test_add_imaging_plane_to_nwbfile_raises_when_name_not_found_in_metadata(self): + def test_add_imaging_plane_to_nwbfile_old_list_format_raises_when_name_not_found_in_metadata(self): """Test adding an imaging plane raises an error when the name is not found in the metadata.""" imaging_plane_name = "imaging_plane_non_existing_in_the_metadata" with self.assertRaisesWith( exc_type=ValueError, exc_msg=f"Metadata for Imaging Plane '{imaging_plane_name}' not found in metadata['Ophys']['ImagingPlane'].", ): - _add_imaging_plane_to_nwbfile( + _add_imaging_plane_to_nwbfile_old_list_format( nwbfile=self.nwbfile, metadata=self.metadata, imaging_plane_name=imaging_plane_name ) @@ -254,10 +254,10 @@ def test_add_two_imaging_planes_from_metadata(self): second_imaging_plane_metadata = deepcopy(metadata["Ophys"]["ImagingPlane"][0]) second_imaging_plane_metadata.update(name="second_imaging_plane_name") imaging_planes_metadata.append(second_imaging_plane_metadata) - _add_imaging_plane_to_nwbfile( + _add_imaging_plane_to_nwbfile_old_list_format( nwbfile=self.nwbfile, metadata=metadata, imaging_plane_name=self.imaging_plane_name ) - _add_imaging_plane_to_nwbfile( + _add_imaging_plane_to_nwbfile_old_list_format( nwbfile=self.nwbfile, metadata=metadata, imaging_plane_name="second_imaging_plane_name" ) @@ -1212,7 +1212,7 @@ def test_add_fluorescence_traces_to_nwbfile_regular_timestamps(self): def test_add_fluorescence_traces_to_nwbfile_with_plane_segmentation_name_specified(self): plane_segmentation_name = "plane_segmentation_name" - metadata = _get_default_ophys_metadata() + metadata = _get_default_ophys_metadata_old_metadata_list() metadata = dict_deep_update(metadata, self.metadata) metadata["Ophys"]["ImageSegmentation"]["plane_segmentations"][0].update(name=plane_segmentation_name) @@ -1246,7 +1246,7 @@ def setUpClass(cls): cls.session_start_time = datetime.now().astimezone() - cls.metadata = _get_default_ophys_metadata() + cls.metadata = _get_default_ophys_metadata_old_metadata_list() cls.plane_segmentation_first_plane_name = "PlaneSegmentationFirstPlane" cls.metadata["Ophys"]["ImageSegmentation"]["plane_segmentations"][0].update( @@ -1448,7 +1448,7 @@ def setUp(self): def test_default_values(self): """Test adding two photon series with default values.""" - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata ) @@ -1481,7 +1481,7 @@ def test_invalid_iterator_type_raises_error(self): AssertionError, "'iterator_type' must be either 'v2' (recommended) or None.", ): - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata, @@ -1514,7 +1514,7 @@ def test_non_iterative_write_assertion(self): def test_non_iterative_two_photon(self): """Test adding two photon series without using DataChunkIterator.""" - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata, @@ -1535,7 +1535,7 @@ def test_non_iterative_two_photon(self): def test_deprecated_v1_iterator_two_photon(self): """Test adding two photon series with deprecated v1 iterator type.""" with self.assertWarns(FutureWarning): - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata, @@ -1560,7 +1560,7 @@ def test_iterator_options_propagation(self): """Test that iterator options are propagated to the data chunk iterator.""" buffer_shape = (20, 5, 5) chunk_shape = (10, 5, 5) - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata, @@ -1577,7 +1577,7 @@ def test_iterator_options_propagation(self): def test_iterator_options_chunk_mb_propagation(self): """Test that chunk_mb is propagated to the data chunk iterator and the chunk shape is correctly set to fit.""" chunk_mb = 10.0 - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata, @@ -1594,7 +1594,7 @@ def test_iterator_options_chunk_mb_propagation(self): def test_iterator_options_chunk_shape_is_at_least_one(self): """Test that when a small chunk_mb is selected the chunk shape is guaranteed to include at least one frame.""" chunk_mb = 1.0 - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata, @@ -1610,7 +1610,7 @@ def test_iterator_options_chunk_shape_is_at_least_one(self): def test_iterator_options_chunk_shape_does_not_exceed_maxshape(self): """Test that when a large chunk_mb is selected the chunk shape is guaranteed to not exceed maxshape.""" chunk_mb = 1000.0 - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata, @@ -1624,7 +1624,7 @@ def test_iterator_options_chunk_shape_does_not_exceed_maxshape(self): assert_array_equal(chunk_shape, data_chunk_iterator.maxshape) def test_add_two_photon_series_roundtrip(self): - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata ) @@ -1661,7 +1661,7 @@ def test_add_invalid_photon_series_type(self): AssertionError, "'photon_series_type' must be either 'OnePhotonSeries' or 'TwoPhotonSeries'.", ): - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata, @@ -1678,7 +1678,7 @@ def test_add_one_photon_series(self): binning=2, power=500.0, ) - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=metadata, @@ -1693,7 +1693,7 @@ def test_add_one_photon_series(self): self.assertEqual(one_photon_series.unit, "n.a.") def test_add_one_photon_series_roundtrip(self): - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.one_photon_series_metadata, @@ -1717,13 +1717,13 @@ def test_add_one_photon_series_roundtrip(self): expected_one_photon_series_shape = (self.num_samples, self.num_columns, self.num_rows) assert one_photon_series.shape == expected_one_photon_series_shape - def test_add_photon_series_to_nwbfile_invalid_module_name_raises(self): + def test_add_photon_series_to_nwbfile_old_list_format_invalid_module_name_raises(self): """Test that adding photon series with invalid module name raises error.""" with self.assertRaisesWith( exc_type=AssertionError, exc_msg="'parent_container' must be either 'acquisition' or 'processing/ophys'.", ): - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata, @@ -1735,7 +1735,7 @@ def test_add_one_photon_series_to_processing(self): metadata = self.one_photon_series_metadata metadata["Ophys"]["OnePhotonSeries"][0].update(name="OnePhotonSeriesProcessed") - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.one_photon_series_metadata, @@ -1748,7 +1748,7 @@ def test_add_one_photon_series_to_processing(self): def test_ophys_module_not_created_when_photon_series_added_to_acquisition(self): """Test that ophys module is not created when photon series are added to nwbfile.acquisition.""" - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=self.two_photon_series_metadata, @@ -1764,7 +1764,7 @@ def test_add_multiple_one_photon_series_with_same_imaging_plane(self): shared_photon_series_metadata["Ophys"]["ImagingPlane"][0]["name"] = shared_imaging_plane_name shared_photon_series_metadata["Ophys"]["OnePhotonSeries"][0]["imaging_plane"] = shared_imaging_plane_name - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=shared_photon_series_metadata, @@ -1772,7 +1772,7 @@ def test_add_multiple_one_photon_series_with_same_imaging_plane(self): ) shared_photon_series_metadata["Ophys"]["OnePhotonSeries"][0]["name"] = "second_photon_series" - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=self.imaging_extractor, nwbfile=self.nwbfile, metadata=shared_photon_series_metadata, @@ -1941,11 +1941,11 @@ def test_add_summary_images_to_nwbfile_from_two_planes(self): class TestNoMetadataMutation: - def test_get_default_ophys_metadata_returns_independent_instances(self): - """Test that _get_default_ophys_metadata() returns independent instances that don't share mutable state.""" + def test_get_default_ophys_metadata_old_metadata_list_returns_independent_instances(self): + """Test that _get_default_ophys_metadata_old_metadata_list() returns independent instances that don't share mutable state.""" # Get two instances - metadata1 = _get_default_ophys_metadata() - metadata2 = _get_default_ophys_metadata() + metadata1 = _get_default_ophys_metadata_old_metadata_list() + metadata2 = _get_default_ophys_metadata_old_metadata_list() # Store a snapshot of metadata2's Ophys section before mutating metadata1 metadata2_ophys_before = deepcopy(metadata2["Ophys"]) @@ -1961,7 +1961,7 @@ def test_get_default_ophys_metadata_returns_independent_instances(self): ), "Modifying metadata1 affected metadata2 - instances share mutable state" # Get a third instance after modifications to ensure fresh defaults - metadata3 = _get_default_ophys_metadata() + metadata3 = _get_default_ophys_metadata_old_metadata_list() assert ( metadata3["Ophys"] == metadata2_ophys_before ), "New instance after mutations differs from original - not getting fresh defaults" @@ -1983,7 +1983,7 @@ def test_add_devices_to_nwbfile_does_not_mutate_metadata(self): assert metadata == metadata_before, "Metadata was mutated" def test_add_imaging_plane_no_metadata_mutation(self): - """Test that _add_imaging_plane_to_nwbfile does not mutate the input metadata.""" + """Test that _add_imaging_plane_to_nwbfile_old_list_format does not mutate the input metadata.""" nwbfile = mock_NWBFile() # Create metadata with imaging plane (all fields provided) @@ -2014,13 +2014,15 @@ def test_add_imaging_plane_no_metadata_mutation(self): metadata_before = deepcopy(metadata) # Call function - _add_imaging_plane_to_nwbfile(nwbfile=nwbfile, metadata=metadata, imaging_plane_name="TestImagingPlane") + _add_imaging_plane_to_nwbfile_old_list_format( + nwbfile=nwbfile, metadata=metadata, imaging_plane_name="TestImagingPlane" + ) # Verify metadata was not mutated - compare entire dict structure assert metadata == metadata_before, "Metadata was mutated" def test_add_imaging_plane_no_partial_metadata_mutation(self): - """Test that _add_imaging_plane_to_nwbfile does not mutate partial user metadata when complemented with defaults.""" + """Test that _add_imaging_plane_to_nwbfile_old_list_format does not mutate partial user metadata when complemented with defaults.""" nwbfile = mock_NWBFile() # Create metadata with minimal imaging plane (missing some fields that will be filled from defaults) @@ -2048,13 +2050,15 @@ def test_add_imaging_plane_no_partial_metadata_mutation(self): metadata_before = deepcopy(metadata) # Call function (should fill in missing fields internally but not mutate the input) - _add_imaging_plane_to_nwbfile(nwbfile=nwbfile, metadata=metadata, imaging_plane_name="TestImagingPlane") + _add_imaging_plane_to_nwbfile_old_list_format( + nwbfile=nwbfile, metadata=metadata, imaging_plane_name="TestImagingPlane" + ) # Verify metadata was not mutated - compare entire dict structure assert metadata == metadata_before, "Metadata was mutated" def test_add_photon_series_no_metadata_mutation(self): - """Test that _add_photon_series_to_nwbfile does not mutate the input metadata.""" + """Test that _add_photon_series_to_nwbfile_old_list_format does not mutate the input metadata.""" from roiextractors.testing import generate_dummy_imaging_extractor nwbfile = mock_NWBFile() @@ -2098,7 +2102,7 @@ def test_add_photon_series_no_metadata_mutation(self): metadata_before = deepcopy(metadata) # Call function - _add_photon_series_to_nwbfile( + _add_photon_series_to_nwbfile_old_list_format( imaging=imaging_extractor, nwbfile=nwbfile, metadata=metadata,