From 40a3463ab038674ac22646eee737fc459ecf14f0 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Thu, 2 May 2024 14:51:27 -0600 Subject: [PATCH 1/4] add typing to write_binary --- src/spikeinterface/core/recording_tools.py | 17 ++++++++--------- .../preprocessing/unsigned_to_signed.py | 1 - 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index 7934a61429..8fc475390f 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -68,12 +68,12 @@ def _init_binary_worker(recording, file_path_dict, dtype, byte_offest, cast_unsi def write_binary_recording( - recording, - file_paths, - dtype=None, - add_file_extension=True, - byte_offset=0, - auto_cast_uint=True, + recording: "BaseRecording", + file_paths: list[Path | str] | Path | str, + dtype: np.ndtype = None, + add_file_extension: bool = True, + byte_offset: int = 0, + auto_cast_uint: bool = True, **job_kwargs, ): """ @@ -94,7 +94,7 @@ def write_binary_recording( If True, file the ".raw" file extension is added if the file name is not a "raw", "bin", or "dat" byte_offset: int, default: 0 Offset in bytes for the binary file (e.g. to write a header) - auto_cast_uint: bool, default: True + auto_cast_uint: bool, default: True If True, unsigned integers are automatically cast to int if the specified dtype is signed {} """ @@ -110,8 +110,7 @@ def write_binary_recording( file_path_list = [add_suffix(file_path, ["raw", "bin", "dat"]) for file_path in file_path_list] dtype = dtype if dtype is not None else recording.get_dtype() - cast_unsigned = False - if auto_cast_uint: + if auto_cast_uint: #TODO should we deprecate this given that we have `unsigned_to_signed`? cast_unsigned = determine_cast_unsigned(recording, dtype) dtype_size_bytes = np.dtype(dtype).itemsize diff --git a/src/spikeinterface/preprocessing/unsigned_to_signed.py b/src/spikeinterface/preprocessing/unsigned_to_signed.py index 0ffafed78c..bf7e48838c 100644 --- a/src/spikeinterface/preprocessing/unsigned_to_signed.py +++ b/src/spikeinterface/preprocessing/unsigned_to_signed.py @@ -4,7 +4,6 @@ from ..core.core_tools import define_function_from_class from .basepreprocessor import BasePreprocessor, BasePreprocessorSegment -from .filter import fix_dtype class UnsignedToSignedRecording(BasePreprocessor): From 9d5180a53f38964a0a2a3e730e8e3a8905ff27b7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 May 2024 20:52:50 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spikeinterface/core/recording_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index 8fc475390f..4b6ab8c6e3 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -94,7 +94,7 @@ def write_binary_recording( If True, file the ".raw" file extension is added if the file name is not a "raw", "bin", or "dat" byte_offset: int, default: 0 Offset in bytes for the binary file (e.g. to write a header) - auto_cast_uint: bool, default: True + auto_cast_uint: bool, default: True If True, unsigned integers are automatically cast to int if the specified dtype is signed {} """ @@ -110,7 +110,7 @@ def write_binary_recording( file_path_list = [add_suffix(file_path, ["raw", "bin", "dat"]) for file_path in file_path_list] dtype = dtype if dtype is not None else recording.get_dtype() - if auto_cast_uint: #TODO should we deprecate this given that we have `unsigned_to_signed`? + if auto_cast_uint: # TODO should we deprecate this given that we have `unsigned_to_signed`? cast_unsigned = determine_cast_unsigned(recording, dtype) dtype_size_bytes = np.dtype(dtype).itemsize From 37bb61163ce1b62d32889dee33224c372954d7ad Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Fri, 10 May 2024 07:46:09 -0600 Subject: [PATCH 3/4] add deprecation, improve the docstring --- src/spikeinterface/core/recording_tools.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index 8fc475390f..55477d8018 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -4,7 +4,6 @@ import warnings from pathlib import Path import os -import gc import mmap import tqdm @@ -91,10 +90,12 @@ def write_binary_recording( The path to the file. dtype: dtype or None, default: None Type of the saved data - If True, file the ".raw" file extension is added if the file name is not a "raw", "bin", or "dat" + add_file_extension, bool, default: True + If True, and the file path does not end in "raw", "bin", or "dat" then "raw" is added as an extension. byte_offset: int, default: 0 - Offset in bytes for the binary file (e.g. to write a header) - auto_cast_uint: bool, default: True + Offset in bytes for the binary file (e.g. to write a header). This is useful in case you want to append data + to an existing file where you wrote a header or other data before. + auto_cast_uint: bool, default: True If True, unsigned integers are automatically cast to int if the specified dtype is signed {} """ @@ -110,8 +111,12 @@ def write_binary_recording( file_path_list = [add_suffix(file_path, ["raw", "bin", "dat"]) for file_path in file_path_list] dtype = dtype if dtype is not None else recording.get_dtype() - if auto_cast_uint: #TODO should we deprecate this given that we have `unsigned_to_signed`? + if auto_cast_uint: # TODO should we deprecate this given that we have `unsigned_to_signed`? cast_unsigned = determine_cast_unsigned(recording, dtype) + warning_message = ( + "auto_cast_uint is deprecated and will be removed in 0.103. Use the `unsigned_to_signed` function instead." + ) + warnings.warn(warning_message, DeprecationWarning) dtype_size_bytes = np.dtype(dtype).itemsize num_channels = recording.get_num_channels() From 6cb32df62670caeed41b1b6d316fcf216c53ac81 Mon Sep 17 00:00:00 2001 From: Heberto Mayorquin Date: Fri, 10 May 2024 08:51:07 -0600 Subject: [PATCH 4/4] Update src/spikeinterface/core/recording_tools.py Co-authored-by: Alessio Buccino --- src/spikeinterface/core/recording_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/recording_tools.py b/src/spikeinterface/core/recording_tools.py index e74c24a740..2f228432b0 100644 --- a/src/spikeinterface/core/recording_tools.py +++ b/src/spikeinterface/core/recording_tools.py @@ -117,7 +117,7 @@ def write_binary_recording( warning_message = ( "auto_cast_uint is deprecated and will be removed in 0.103. Use the `unsigned_to_signed` function instead." ) - warnings.warn(warning_message, DeprecationWarning) + warnings.warn(warning_message, DeprecationWarning, stacklevel=2) dtype_size_bytes = np.dtype(dtype).itemsize num_channels = recording.get_num_channels()