Skip to content

Commit

Permalink
Merge branch 'main' of github.com:spikeinterface/spikeinterface into …
Browse files Browse the repository at this point in the history
…fix_matched_filtering
  • Loading branch information
yger committed May 24, 2024
2 parents 326e9e5 + d18cec2 commit 72d2fa1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
10 changes: 7 additions & 3 deletions src/spikeinterface/core/baserecording.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def time_to_sample_index(self, time_s, segment_index=None):
rs = self._recording_segments[segment_index]
return rs.time_to_sample_index(time_s)

def _save(self, format="binary", **save_kwargs):
def _save(self, format="binary", verbose: bool = False, **save_kwargs):
# handle t_starts
t_starts = []
has_time_vectors = []
Expand All @@ -510,7 +510,7 @@ def _save(self, format="binary", **save_kwargs):
file_paths = [folder / f"traces_cached_seg{i}.raw" for i in range(self.get_num_segments())]
dtype = kwargs.get("dtype", None) or self.get_dtype()

write_binary_recording(self, file_paths=file_paths, dtype=dtype, **job_kwargs)
write_binary_recording(self, file_paths=file_paths, dtype=dtype, verbose=verbose, **job_kwargs)

from .binaryrecordingextractor import BinaryRecordingExtractor

Expand Down Expand Up @@ -540,14 +540,18 @@ def _save(self, format="binary", **save_kwargs):

cached = SharedMemoryRecording.from_recording(self, **job_kwargs)
else:
from spikeinterface.core import NumpyRecording

cached = NumpyRecording.from_recording(self, **job_kwargs)

elif format == "zarr":
from .zarrextractors import ZarrRecordingExtractor

zarr_path = kwargs.pop("zarr_path")
storage_options = kwargs.pop("storage_options")
ZarrRecordingExtractor.write_recording(self, zarr_path, storage_options, **kwargs, **job_kwargs)
ZarrRecordingExtractor.write_recording(
self, zarr_path, storage_options, verbose=verbose, **kwargs, **job_kwargs
)
cached = ZarrRecordingExtractor(zarr_path, storage_options)

elif format == "nwb":
Expand Down
12 changes: 7 additions & 5 deletions src/spikeinterface/core/job_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def split_job_kwargs(mixed_kwargs):
def divide_segment_into_chunks(num_frames, chunk_size):
if chunk_size is None:
chunks = [(0, num_frames)]
elif chunk_size > num_frames:
chunks = [(0, num_frames)]
else:
n = num_frames // chunk_size

Expand Down Expand Up @@ -245,12 +247,12 @@ def ensure_chunk_size(
else:
raise ValueError("chunk_duration must be str or float")
else:
# Edge case to define single chunk per segment for n_jobs=1.
# All chunking parameters equal None mean single chunk per segment
if n_jobs == 1:
# not chunk computing
# TODO Discuss, Sam, is this something that we want to do?
# Even in single process mode, we should chunk the data to avoid loading the whole thing into memory I feel
# Am I wrong?
chunk_size = None
num_segments = recording.get_num_segments()
samples_in_larger_segment = max([recording.get_num_samples(segment) for segment in range(num_segments)])
chunk_size = samples_in_larger_segment
else:
raise ValueError("For n_jobs >1 you must specify total_memory or chunk_size or chunk_memory")

Expand Down
7 changes: 2 additions & 5 deletions src/spikeinterface/core/recording_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def write_binary_recording(
add_file_extension: bool = True,
byte_offset: int = 0,
auto_cast_uint: bool = True,
verbose: bool = True,
verbose: bool = False,
**job_kwargs,
):
"""
Expand All @@ -100,7 +100,7 @@ def write_binary_recording(
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.
verbose: bool
If True, output is verbose
This is the verbosity of the ChunkRecordingExecutor
{}
"""
job_kwargs = fix_job_kwargs(job_kwargs)
Expand Down Expand Up @@ -351,9 +351,6 @@ def write_memory_recording(recording, dtype=None, verbose=False, auto_cast_uint=
else:
init_args = (recording, arrays, None, None, dtype, cast_unsigned)

if "verbose" in job_kwargs:
del job_kwargs["verbose"]

executor = ChunkRecordingExecutor(
recording, func, init_func, init_args, verbose=verbose, job_name="write_memory_recording", **job_kwargs
)
Expand Down
13 changes: 10 additions & 3 deletions src/spikeinterface/core/tests/test_job_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,9 @@ def test_ensure_n_jobs():


def test_ensure_chunk_size():
recording = generate_recording(num_channels=2)
recording = generate_recording(num_channels=2, durations=[5.0, 2.5]) # This is the default value for two semgents
dtype = recording.get_dtype()
assert dtype == "float32"
# make serializable
recording = recording.save()

chunk_size = ensure_chunk_size(recording, total_memory="512M", chunk_size=None, chunk_memory=None, n_jobs=2)
assert chunk_size == 32000000
Expand All @@ -69,6 +67,15 @@ def test_ensure_chunk_size():
chunk_size = ensure_chunk_size(recording, chunk_duration="500ms")
assert chunk_size == 15000

# Test edge case to define single chunk for n_jobs=1
chunk_size = ensure_chunk_size(recording, n_jobs=1, chunk_size=None)
chunks = divide_recording_into_chunks(recording, chunk_size)
assert len(chunks) == recording.get_num_segments()
for chunk in chunks:
segment_index, start_frame, end_frame = chunk
assert start_frame == 0
assert end_frame == recording.get_num_frames(segment_index=segment_index)


def func(segment_index, start_frame, end_frame, worker_ctx):
import os
Expand Down

0 comments on commit 72d2fa1

Please sign in to comment.