Skip to content

Commit

Permalink
Merge pull request #2794 from h-mayorquin/typing_to_write_binary
Browse files Browse the repository at this point in the history
Add typing to `write_binary_recording`
  • Loading branch information
alejoe91 authored May 10, 2024
2 parents 707f78a + 6cb32df commit e863b88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
25 changes: 15 additions & 10 deletions src/spikeinterface/core/recording_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import warnings
from pathlib import Path
import os
import gc
import mmap
import tqdm

Expand Down Expand Up @@ -68,12 +67,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,
):
"""
Expand All @@ -91,11 +90,14 @@ 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)
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
.. deprecated:: 0.103, use the `unsigned_to_signed` function instead.
{}
"""
job_kwargs = fix_job_kwargs(job_kwargs)
Expand All @@ -110,9 +112,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()
cast_unsigned = False
if auto_cast_uint:
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, stacklevel=2)

dtype_size_bytes = np.dtype(dtype).itemsize
num_channels = recording.get_num_channels()
Expand Down
1 change: 0 additions & 1 deletion src/spikeinterface/preprocessing/unsigned_to_signed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit e863b88

Please sign in to comment.