Skip to content
Draft
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# v0.9.4 (Upcoming)

## Removals, Deprecations and Changes
* Made `nwbfile_path` a required parameter in `write_recording_to_nwbfile`, `write_sorting_to_nwbfile`, and `write_sorting_analyzer_to_nwbfile`. To add data to an in-memory NWBFile, use `add_recording_to_nwbfile`, `add_sorting_to_nwbfile`, or `add_sorting_analyzer_to_nwbfile` instead. [PR #1689](https://github.com/catalystneuro/neuroconv/pull/1689)
* `write_recording_to_nwbfile`, `write_sorting_to_nwbfile`, and `write_sorting_analyzer_to_nwbfile` now return `None` in append mode (`append_on_disk_nwbfile=True`) instead of the NWBFile object. [PR #1689](https://github.com/catalystneuro/neuroconv/pull/1689)
* Removed the deprecated `iterator_opts` parameter from `write_recording_to_nwbfile`. Use `iterator_options` instead. [PR #1689](https://github.com/catalystneuro/neuroconv/pull/1689)
* Removed stale `iterator_type='v1'` deprecation note from `BaseImagingExtractorInterface.add_to_nwbfile` docstring. [PR #1689](https://github.com/catalystneuro/neuroconv/pull/1689)
* Removed the deprecated `iterator_type='v1'` option from `_imaging_frames_to_hdmf_iterator`. Use `iterator_type='v2'` (default) instead. [PR #1679](https://github.com/catalystneuro/neuroconv/pull/1679)
* Removed support for passing `rate` in trace metadata for fluorescence traces. The rate is now always calculated automatically from the segmentation extractor's timestamps or sampling frequency. [PR #1679](https://github.com/catalystneuro/neuroconv/pull/1679)
* Removed the deprecated `stub_frames` parameter from ophys interfaces (`BaseImagingExtractorInterface`, `BaseSegmentationExtractorInterface`, `BrukerTiffMultiPlaneConverter`, `BrukerTiffSinglePlaneConverter`, `MiniscopeConverter`, `Suite2pSegmentationInterface`, `MinianSegmentationInterface`, `MiniscopeImagingDataInterface`). Use `stub_samples` instead. [PR #1676](https://github.com/catalystneuro/neuroconv/pull/1676)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ def add_to_nwbfile(
The type of iterator for chunked data writing.
'v2': Uses iterative write with control over chunking and progress bars.
None: Loads all data into memory before writing (not recommended for large datasets).
Note: 'v1' is deprecated and will be removed on or after March 2026.
iterator_options : dict, optional
Options for controlling the iterative write process (buffer size, progress bars).
See the `pynwb tutorial on iterative write <https://pynwb.readthedocs.io/en/stable/tutorials/advanced_io/plot_iterative_write.html#sphx-glr-tutorials-advanced-io-plot-iterative-write-py>`_
Expand Down
177 changes: 13 additions & 164 deletions src/neuroconv/tools/spikeinterface/spikeinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,7 @@ def add_recording_metadata_to_nwbfile(

def write_recording_to_nwbfile(
recording: BaseRecording,
nwbfile_path: FilePath | None = None,
nwbfile_path: FilePath,
nwbfile: pynwb.NWBFile | None = None,
metadata: dict | None = None,
overwrite: bool = False,
Expand All @@ -1664,7 +1664,6 @@ def write_recording_to_nwbfile(
*,
iterator_type: str | None = "v2",
iterator_options: dict | None = None,
iterator_opts: dict | None = None,
backend: Literal["hdf5", "zarr"] | None = None,
backend_configuration: HDF5BackendConfiguration | ZarrBackendConfiguration | None = None,
append_on_disk_nwbfile: bool = False,
Expand All @@ -1676,10 +1675,8 @@ def write_recording_to_nwbfile(
Parameters
----------
recording : spikeinterface.BaseRecording
nwbfile_path : FilePath, optional
nwbfile_path : FilePath
Path for where to write or load (if overwrite=False) the NWBFile.
If not provided, only adds data to the in-memory nwbfile without writing to disk.
**Deprecated**: Using this function without nwbfile_path is deprecated. Use `add_recording_to_nwbfile` instead.
nwbfile : NWBFile, optional
If passed, this function will fill the relevant fields within the NWBFile object.
E.g., calling::
Expand Down Expand Up @@ -1777,53 +1774,10 @@ def write_recording_to_nwbfile(
Returns
-------
NWBFile or None
The NWBFile object when writing a new file or using an in-memory nwbfile.
The NWBFile object when writing a new file.
Returns None when appending to an existing file on disk (append_on_disk_nwbfile=True).
**Deprecated**: Returning NWBFile in append mode is deprecated and will return None in or after March 2026.
"""

# Handle deprecated usage without nwbfile_path
if nwbfile_path is None:
warnings.warn(
"Using 'write_recording_to_nwbfile' without 'nwbfile_path' to only add data to an in-memory nwbfile is deprecated "
"and will be removed in or after March 2026. Use 'add_recording_to_nwbfile' instead.",
DeprecationWarning,
stacklevel=2,
)
if nwbfile is None:
raise ValueError(
"Either 'nwbfile_path' or 'nwbfile' must be provided. "
"To add data to an in-memory nwbfile, use 'add_recording_to_nwbfile' instead."
)
# Call add_recording_to_nwbfile for deprecated behavior
add_recording_to_nwbfile(
recording=recording,
nwbfile=nwbfile,
metadata=metadata,
write_as=write_as,
es_key=es_key,
iterator_type=iterator_type,
iterator_options=iterator_options if iterator_options is not None else iterator_opts,
null_values_for_properties=null_values_for_properties,
)
return nwbfile

# Handle deprecated iterator_opts parameter
if iterator_opts is not None:
warnings.warn(
"The 'iterator_opts' parameter is deprecated and will be removed on or after March 2026. "
"Use 'iterator_options' instead.",
FutureWarning,
stacklevel=2,
)
if iterator_options is None:
iterator_options = iterator_opts
else:
raise ValueError(
"Both 'iterator_opts' and 'iterator_options' were specified. "
"Please use only 'iterator_options' as 'iterator_opts' is deprecated."
)

appending_to_in_memory_nwbfile = nwbfile is not None
file_initially_exists = nwbfile_path.exists()
allowed_to_modify_existing = overwrite or append_on_disk_nwbfile
Expand Down Expand Up @@ -1885,13 +1839,6 @@ def write_recording_to_nwbfile(

else:
# Append mode: read existing file, add data, write back
warnings.warn(
"Returning an NWBFile object when using append_on_disk_nwbfile=True is deprecated "
"and will return None in or after March 2026.",
DeprecationWarning,
stacklevel=2,
)

IO = BACKEND_NWB_IO[backend]

with IO(path=str(nwbfile_path), mode="r+", load_namespaces=True) as io:
Expand All @@ -1918,7 +1865,7 @@ def write_recording_to_nwbfile(
if verbose:
print(f"NWB file saved at {nwbfile_path}!")

return nwbfile # Will return None in March 2026
return None


def _add_units_table_to_nwbfile(
Expand Down Expand Up @@ -2335,7 +2282,7 @@ def _add_units_table_to_nwbfile(

def write_sorting_to_nwbfile(
sorting: BaseSorting,
nwbfile_path: FilePath | None = None,
nwbfile_path: FilePath,
nwbfile: pynwb.NWBFile | None = None,
metadata: dict | None = None,
overwrite: bool = False,
Expand All @@ -2361,10 +2308,8 @@ def write_sorting_to_nwbfile(
Parameters
----------
sorting : spikeinterface.BaseSorting
nwbfile_path : FilePath, optional
nwbfile_path : FilePath
Path for where to write or load (if overwrite=False) the NWBFile.
If not provided, only adds data to the in-memory nwbfile without writing to disk.
**Deprecated**: Using this function without nwbfile_path is deprecated. Use `add_sorting_to_nwbfile` instead.
nwbfile : NWBFile, optional
If passed, this function will fill the relevant fields within the NWBFile object.
E.g., calling::
Expand Down Expand Up @@ -2421,41 +2366,10 @@ def write_sorting_to_nwbfile(
Returns
-------
NWBFile or None
The NWBFile object when writing a new file or using an in-memory nwbfile.
The NWBFile object when writing a new file.
Returns None when appending to an existing file on disk (append_on_disk_nwbfile=True).
**Deprecated**: Returning NWBFile in append mode is deprecated and will return None in or after March 2026.
"""

# Handle deprecated usage without nwbfile_path
if nwbfile_path is None:
warnings.warn(
"Using 'write_sorting_to_nwbfile' without 'nwbfile_path' to only add data to an in-memory nwbfile is deprecated "
"and will be removed in or after March 2026. Use 'add_sorting_to_nwbfile' instead.",
DeprecationWarning,
stacklevel=2,
)
if nwbfile is None:
raise ValueError(
"Either 'nwbfile_path' or 'nwbfile' must be provided. "
"To add data to an in-memory nwbfile, use 'add_sorting_to_nwbfile' instead."
)
# Call add_sorting_to_nwbfile for deprecated behavior
add_sorting_to_nwbfile(
sorting=sorting,
nwbfile=nwbfile,
unit_ids=unit_ids,
property_descriptions=property_descriptions,
skip_properties=skip_properties,
write_as=write_as,
units_name=units_name,
units_description=units_description,
waveform_means=waveform_means,
waveform_sds=waveform_sds,
unit_electrode_indices=unit_electrode_indices,
null_values_for_properties=null_values_for_properties,
)
return nwbfile

appending_to_in_memory_nwbfile = nwbfile is not None
file_initially_exists = nwbfile_path.exists()
allowed_to_modify_existing = overwrite or append_on_disk_nwbfile
Expand Down Expand Up @@ -2521,13 +2435,6 @@ def write_sorting_to_nwbfile(

else:
# Append mode: read existing file, add data, write back
warnings.warn(
"Returning an NWBFile object when using append_on_disk_nwbfile=True is deprecated "
"and will return None in or after March 2026.",
DeprecationWarning,
stacklevel=2,
)

IO = BACKEND_NWB_IO[backend]

with IO(path=str(nwbfile_path), mode="r+", load_namespaces=True) as io:
Expand Down Expand Up @@ -2557,7 +2464,7 @@ def write_sorting_to_nwbfile(
if verbose:
print(f"NWB file saved at {nwbfile_path}!")

return nwbfile # Will return None in March 2026
return None


def add_sorting_analyzer_to_nwbfile(
Expand Down Expand Up @@ -2690,7 +2597,7 @@ def add_sorting_analyzer_to_nwbfile(

def write_sorting_analyzer_to_nwbfile(
sorting_analyzer: SortingAnalyzer,
nwbfile_path: FilePath | None = None,
nwbfile_path: FilePath,
nwbfile: pynwb.NWBFile | None = None,
metadata: dict | None = None,
overwrite: bool = False,
Expand Down Expand Up @@ -2722,10 +2629,8 @@ def write_sorting_analyzer_to_nwbfile(
----------
sorting_analyzer : spikeinterface.SortingAnalyzer
The sorting analyzer object to be written to the NWBFile.
nwbfile_path : FilePath, optional
nwbfile_path : FilePath
Path for where to write or load (if overwrite=False) the NWBFile.
If not provided, only adds data to the in-memory nwbfile without writing to disk.
**Deprecated**: Using this function without nwbfile_path is deprecated. Use `add_sorting_analyzer_to_nwbfile` instead.
nwbfile : NWBFile, optional
If passed, this function will fill the relevant fields within the NWBFile object.
E.g., calling::
Expand Down Expand Up @@ -2782,60 +2687,10 @@ def write_sorting_analyzer_to_nwbfile(
Returns
-------
nwbfile : pynwb.NWBFile or None
The in-memory NWBFile object. Returns None when append_on_disk_nwbfile=True (to be implemented in or after March 2026).
The NWBFile object when writing a new file.
Returns None when appending to an existing file on disk (append_on_disk_nwbfile=True).
"""

# Handle deprecated usage without nwbfile_path
if nwbfile_path is None:
warnings.warn(
"Using 'write_sorting_analyzer_to_nwbfile' without 'nwbfile_path' to only add data to an in-memory nwbfile is deprecated "
"and will be removed in or after March 2026. Use 'add_sorting_analyzer_to_nwbfile' instead.",
DeprecationWarning,
stacklevel=2,
)
if nwbfile is None:
raise ValueError(
"Either 'nwbfile_path' or 'nwbfile' must be provided. "
"To add data to an in-memory nwbfile, use 'add_sorting_analyzer_to_nwbfile' instead."
)

# Ensure metadata exists
metadata = metadata if metadata is not None else dict()

# Get recording
if recording is None and sorting_analyzer.has_recording():
recording = sorting_analyzer.recording
assert recording is not None, (
"recording not found. To add the electrode table, the sorting_analyzer "
"needs to have a recording attached or the 'recording' argument needs to be used."
)

# Call add_sorting_analyzer_to_nwbfile for deprecated behavior
if write_electrical_series:
add_electrical_series_kwargs = add_electrical_series_kwargs or dict()
add_recording_to_nwbfile(
recording=recording,
nwbfile=nwbfile,
metadata=metadata,
null_values_for_properties=null_values_for_properties,
**add_electrical_series_kwargs,
)

add_sorting_analyzer_to_nwbfile(
sorting_analyzer=sorting_analyzer,
nwbfile=nwbfile,
metadata=metadata,
recording=recording,
unit_ids=unit_ids,
skip_properties=skip_properties,
property_descriptions=property_descriptions,
write_as=write_as,
units_name=units_name,
units_description=units_description,
null_values_for_properties=null_values_for_properties,
)
return nwbfile

# Ensure metadata exists
if metadata is None:
metadata = dict()
Expand Down Expand Up @@ -2922,12 +2777,6 @@ def write_sorting_analyzer_to_nwbfile(

else:
# Append mode: read existing file, add data, write back
warnings.warn(
"Returning an NWBFile object in append mode is deprecated and will return None in or after March 2026.",
DeprecationWarning,
stacklevel=2,
)

IO = BACKEND_NWB_IO[backend]

with IO(path=str(nwbfile_path), mode="r+", load_namespaces=True) as io:
Expand Down Expand Up @@ -2967,7 +2816,7 @@ def write_sorting_analyzer_to_nwbfile(
if verbose:
print(f"NWB file saved at {nwbfile_path}!")

return nwbfile # Will return None in March 2026
return None


def _get_electrode_group_indices(recording, nwbfile):
Expand Down
Loading