Skip to content

Fix zero_channel_pad case when selected frames are outside of original data region - #1979

Merged
h-mayorquin merged 6 commits into
SpikeInterface:mainfrom
JoeZiminski:fix_end_of_file_zero_padding_case
Oct 30, 2023
Merged

h-mayorquin merged 6 commits into
SpikeInterface:mainfrom
JoeZiminski:fix_end_of_file_zero_padding_case

Conversation

@JoeZiminski

@JoeZiminski JoeZiminski commented Sep 11, 2023 •

Copy link
Copy Markdown
Contributor

I was running into an error when using Kilosort's skip_kilosort_preprocessing that would crash when running preprocessing during binary-writing prior to sorting.

The (test) file I was running had a period at the end of the trace which was required to be purely padding (for running in kilosort), and was larger than the chunk size. This meant that calls were made to zero_channel_pad.get_traces() which had both a start and end frame larger than the original data size. This led to the below function call:

            original_traces = self.get_original_traces_shifted(
                start_frame=start_frame,
                end_frame=end_frame,
                channel_indices=channel_indices,
            )

with start_frame and end_frame that were larger than the original data.

As a fix, this PR adds another case in which both the start_frame and end_frame are larger than the data - if this is True, then an array that consists of only padding is returned.

I must admit I am not very familiar with the uses of zero_channel_pad.py and have not considered deeply the effect of adding this code to other uses of the function beyond fixing the problem I was having. However, I think in the case that:

start_frame > self.num_samples_in_original_segment and end_frame > self.num_samples_in_original_segment

There is nothing else that you could possibly need to do except return an array full of padding? And this is quite a rare and unique circumstance, so I don't think this conditional will erroneously catch other cases.

@alejoe91 alejoe91 added the preprocessing Related to preprocessing module label Sep 12, 2023
@h-mayorquin

Copy link
Copy Markdown
Contributor

What is the error that you are getting?
Can you add a test here:

https://github.com/SpikeInterface/spikeinterface/blob/9fe8efe0941c90c7fb3e46cf67f1aa710f5cd292/src/spikeinterface/preprocessing/tests/test_zero_padding.py

If this fails it indicates that there is a problem with this block as well so I would like to fix that.

if end_frame >= self.padding_start:
original_traces = self.get_original_traces_shifted(
start_frame=start_frame,
end_frame=end_frame,
channel_indices=channel_indices,
)
padded_frames_at_the_start = max(self.padding_start - start_frame, 0)
end_of_original_traces = padded_frames_at_the_start + original_traces.shape[0]
output_traces[padded_frames_at_the_start:end_of_original_traces, :] = original_traces

@h-mayorquin

Copy link
Copy Markdown
Contributor

Or alternatively just generate a minimal example to reproduce the error and I will add the tests.

@h-mayorquin h-mayorquin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will really like a test for this behavior. I will not like for this to be merged without one.

@JoeZiminski

JoeZiminski commented Sep 12, 2023 •

Copy link
Copy Markdown
Contributor Author

Hi @h-mayorquin thanks for this, completely agree this needs a test prior to merge, in general that's a good policy to have (that no PR is merged without a corresponding test of new feature). In this case I overlooked this! As an aside, more generally, it might be nice to have a PR pull request template for spikeinterface (e.g. example) to serve as a checklist of such things, and help with documentation of changes. If you think this is worthwhile I will open an issue.

I include the stacktrace and code used to run, but will add a proper test ASAP )(today). In this case the code depends on the file which is 75000 samples long and requires 56200 samples padding at the end for kilosort. The specific error dependends on the preprocessing chain, but in general is some variant of having an empty array in a get_traces() call due to the start_frame being larger than the end_frame.

I believe the fundamental problem is that this line is triggered. In this case, the self.padding_start=0, self.padding_end=56200, self.num_samples_in_original_segment=75000, and the expected num samples in the file is 131200. It fails when the start_frame=90000 and end_frame=120000. Therefore this conditional is triggered almost as a default, because the case in which there is no data within start_frame, end_frame is not caught. Then, this line in get_original_traces_shifted() sets original_end_frame to self.num_samples_in_original_segment=75000 so the get_traces() is called with a start_frame=90000 and end_frame=75000.

spikeinterface/src/spikeinterface/sorters/runsorter.py:148: in run_sorter
    return run_sorter_local(**common_kwargs)
spikeinterface/src/spikeinterface/sorters/runsorter.py:173: in run_sorter_local
    SorterClass.setup_recording(recording, output_folder, verbose=verbose)
spikeinterface/src/spikeinterface/sorters/basesorter.py:203: in setup_recording
    cls._setup_recording(recording, sorter_output_folder, sorter_params, verbose)
spikeinterface/src/spikeinterface/sorters/external/kilosortbase.py:156: in _setup_recording
    write_binary_recording(
spikeinterface/src/spikeinterface/core/core_tools.py:314: in write_binary_recording
    executor.run()
spikeinterface/src/spikeinterface/core/job_tools.py:376: in run
    res = self.func(segment_index, frame_start, frame_stop, worker_ctx)
spikeinterface/src/spikeinterface/core/core_tools.py:234: in _write_binary_chunk
    traces = recording.get_traces(start_frame=start_frame, end_frame=end_frame, segment_index=segment_index, cast_unsigned=cast_unsigned)
spikeinterface/src/spikeinterface/core/baserecording.py:284: in get_traces
    traces = rs.get_traces(start_frame=start_frame, end_frame=end_frame, channel_indices=channel_indices)
spikeinterface/src/spikeinterface/preprocessing/zero_channel_pad.py:103: in get_traces
    original_traces = self.get_original_traces_shifted(start_frame=start_frame, end_frame=end_frame, channel_indices=channel_indices,)
spikeinterface/src/spikeinterface/preprocessing/zero_channel_pad.py:125: in get_original_traces_shifted
    original_traces = self.parent_recording_segment.get_traces(
spikeinterface/src/spikeinterface/preprocessing/filter.py:150: in get_traces
    filtered_traces = scipy.signal.sosfiltfilt(self.coeff, traces_chunk, axis=0)
/nfs/nhome/live/jziminski/.conda/envs/spikewrap/lib/python3.10/site-packages/scipy/signal/_signaltools.py:4440: in sosfiltfilt
    edge, ext = _validate_pad(padtype, padlen, x, axis,
/nfs/nhome/live/jziminski/.conda/envs/spikewrap/lib/python3.10/site-packages/scipy/signal/_signaltools.py:4209: in _validate_pad
    raise ValueError("The length of the input vector x must be greater "
E   ValueError: The length of the input vector x must be greater than padlen, which is 33.
data_path = Path(r"/ceph/neuroinformatics/neuroinformatics/scratch/jziminski/ephys/code/test_run")
output_path = Path(r"/ceph/neuroinformatics/neuroinformatics/scratch/jziminski/ephys/code/sorter_output")

recording = se.read_spikeglx(data_path)

recording = bandpass_filter(
    recording, freq_min=300, freq_max=6000
)

Kilosort2_5Sorter.set_kilosort2_5_path("/ceph/neuroinformatics/neuroinformatics/scratch/jziminski/ephys/code/Kilosort-2.5")

ss.run_sorter("kilosort2_5",
              recording,
              output_folder=output_path,
              delete_tmp_files=False,
              skip_kilosort_preprocessing=True,
              do_correction=False,
              scaleproc=200,
              n_jobs=1
              )

@JoeZiminski

JoeZiminski commented Sep 12, 2023 •

Copy link
Copy Markdown
Contributor Author

Hey @h-mayorquin I have pushed a new test case (note, this increases the num_samples parameter to 10,000 to get this to work, the reason discussed below). This isn't meant to be a final-version on the tests as I think it could be done better (e.g. as this now means all other tests are running at 10k samples when they don't need to), but just to highlight the problem. (Apologies BTW, this message got longer than anticipated).

The error is only observed with certain preprocessing steps. Without running the preprocessing in the test (e.g. commenting recording = bandpass_filter(recording, freq_min=300, freq_max=6000) in the new test) the test passes. The reason can be seen by putting a breakpoint at this line. In some cases the call to get_original_traces_shifted() returns an empty array, however this is filled into an array of the fill value by the rest of the code block, and so does not result in an error. For example, if start_frame=4000, end_frame=5000, and self.padding_start=5000 then end_frame >= self.padding_start is True and get_original_traces_shifted() is called out of the actual data boundaries, returning an empty trace. However, the rest of the block fills it in with the fill value. I think then works, but is not the intended use case of this code block.

This call can lead to some strange behaviour when the chunk retrieved is entirely in a padding region that occurs after the original data e.g. if the original data has 10000 samples, then 5000 padding samples are added at the start and end. Then say start_frame=16000, end_frame=17000 will trigger this block. If you but a breakpoint in get_original_traces_shifted() (e.g. if start_frame == 16000: breakpoint() in the current test case, without the implemented fix, the strange behaviour can be observed. In particular, self.parent_recording_segment.get_traces is called with original_start_frame that is larger than original_end_frame. However, this does not result in an error because it just returns an empty array, which is filled in (as above). (This is a discussion for another day, but I think get_traces() should error when nonsense indicies are passed, to stop silent strange behaviour such as this).

However, if filtering is run, then an error is exposed because the call goes to the parent (i.e. filter's) get_traces(). Specifically, then the behaviour depenends on this call to get_chunk_with_margin() in filter.py. As far as I can tell, this function will under some circumstances return non-empty data arrays without error if end_frame < start_frame. However, if end_frame is many samples before start_frame (I can't find an exact cutoff) then it will return an empty trace.

For example, calling:

start_frame=1000
end_frame=999
traces_chunk, left_margin, right_margin = get_chunk_with_margin(self.parent_recording_segment, start_frame, end_frame, channel_indices, self.margin, add_reflect_padding=False,)

traces_chunk.shape # (299, 4)
# with end_frame=850, traces_chunk.shape = (150, 4)
# end_frame=500, traces_chunk.shape = (0, 4)

So, if the start_frame is much larger than end_frame, filtering is run on an empty array causing an error. This only manifests when end_frame is quite a lot smaller that start_frame as compared to the margin. Therefore, I had to increase the samples on the test case to see the error.

Anyway, so the bug only manifests when:

  • certain preprocessing steps (e.g. filtering) are performed.
  • a get_traces() call is made on data that is completely in the end-padding (i.e. after the original data) region. This causes this line to set the end-frame incorrectly.
  • the chunk size is large compared to the margin used in get_chunk_with_margin(). This means end_frame is quite a lot smaller than start_frame so get_chunk_with_margin() returns an empty trace. Under most normal use this would be observed, but is not observed for small-sample test cases.

I think this padding problem is a difficult one to solve as there are a lot of potential edge cases as you indicate highlighting the importance of testing any changes. The full set of possible cases (I think) are, considering a trace with padding before and after the original data:

  1. retrieve all-padding region from the first padding section.
  2. retrieve some padding, some data from the first padding / data section.
  3. retrieve entirely data section.
  4. retrieve some data, some padding from the end padding section.
  5. retrieve all padding from the end padding section.

I think it might make sense to explicitly handle each case in the zero_channel_pad get_traces() call. Also, if you agree, it might be worth raising an issue to add checks on get_traces() and get_chunk_with_margin() to ensure nonsense indicies are caught.

@h-mayorquin h-mayorquin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single comment to highlight an error in my code.

@@ -119,11 +126,12 @@ def get_original_traces_shifted(self, start_frame, end_frame, channel_indices):
"""
original_start_frame = max(start_frame - self.padding_start, 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
original_start_frame = max(start_frame - self.padding_start, 0)
original_start_frame = min(max(start_frame - self.padding_start, 0) self.num_samples_in_original_segment),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the original_end_frame is capped at self.num_samples_in_original_segment, the same cap should be applied to original_start_frame.

Another alternative, is to remove the two caps.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See here:

#1984

Where the tests are passed after this modification.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good! I believe there are 7 cases to handle here (which are captured already in your tests), and involve combinations of data with (padding start only, padding end only, padding start and end) x (index start padding + data, index data only, index end padding + data). I believe this code handles all cases well. An extra benefit of handling the padding-only case at the level above would be they do not need to be considered here.

@h-mayorquin

Copy link
Copy Markdown
Contributor

@JoeZiminski
Thanks a lot. The example that you added as a test helped me pin down this. Let's discuss to see if we agree. First, I pointed an error in the implementation here. It was not detect in my testing because the recording that I used for testing behaves like numpy for slicing. I will clarify what I mean below.

Now, I think this has uncover what I think is the deep source of the error:
I like to think that the source of this error is in bandpass_filter:

https://github.com/JoeZiminski/spikeinterface/blob/dce34a8f48592fdf0085e3998d22e2506f62386e/src/spikeinterface/preprocessing/filter.py#L130-L147

if the chunk margin is np.array([]) then there should be an early return that returns np.array([]). Instead you get the error that you received.

The reason for this is that recorders should behave like numpy array with respect to slicing. In numpy you have the following behavior:

In [1]: x = np.ones(10)[15:13]

In [2]: x[15:13]
Out[2]: array([], dtype=float64)

In [3]: x[5:3]
Out[3]: array([], dtype=float64)

In [4]: x[10:10]
Out[4]: array([], dtype=float64)

But look what happens with the bandpass filter:

from spikeinterface.core.generate import generate_recording, generate_sorting
from spikeinterface.preprocessing import bandpass_filter


recording = generate_recording()
recording_filtered = bandpass_filter(recording, freq_min=300, freq_max=6000)

recording_filtered.get_traces(start_frame=1300, end_frame=1000, segment_index=0)

File [~/miniconda3/envs/spikeinterface_env/lib/python3.10/site-packages/scipy/signal/_signaltools.py:4411](https://file+.vscode-resource.vscode-cdn.net/home/heberto/development/spikeinterface/bin/~/miniconda3/envs/spikeinterface_env/lib/python3.10/site-packages/scipy/signal/_signaltools.py:4411), in sosfiltfilt(sos, x, axis, padtype, padlen)
   4409 ntaps = 2 * n_sections + 1
   4410 ntaps -= min((sos[:, 2] == 0).sum(), (sos[:, 5] == 0).sum())
-> 4411 edge, ext = _validate_pad(padtype, padlen, x, axis,
   4412                           ntaps=ntaps)
   4414 # These steps follow the same form as filtfilt with modifications
   4415 zi = sosfilt_zi(sos)  # shape (n_sections, 2) --> (n_sections, ..., 2, ...)

File [~/miniconda3/envs/spikeinterface_env/lib/python3.10/site-packages/scipy/signal/_signaltools.py:4180](https://file+.vscode-resource.vscode-cdn.net/home/heberto/development/spikeinterface/bin/~/miniconda3/envs/spikeinterface_env/lib/python3.10/site-packages/scipy/signal/_signaltools.py:4180), in _validate_pad(padtype, padlen, x, axis, ntaps)
   4178 # x's 'axis' dimension must be bigger than edge.
   4179 if x.shape[axis] <= edge:
-> 4180     raise ValueError("The length of the input vector x must be greater "
   4181                      "than padlen, which is %d." % edge)
   4183 if padtype is not None and edge > 0:
   4184     # Make an extension of length `edge` at each
   4185     # end of the input array.
   4186     if padtype == 'even':

ValueError: The length of the input vector x must be greater than padlen, which is 33.

This is the assertion that you were seeing.

@h-mayorquin

Copy link
Copy Markdown
Contributor

@JoeZiminski
So to summarize, my beliefs right now. Let me know if you disagree and where so we can move this forward. I think you got a good summary of the test cases above

retrieve all-padding region from the first padding section.
retrieve some padding, some data from the first padding / data section.
retrieve entirely data section.
retrieve some data, some padding from the end padding section.
retrieve all padding from the end padding section.

If you look at the test that I added previously they tried to cover exactly this variety of cases. The problem is that they did it with a recorder with that follows numpy slicing convention and the bandpass_filter does not.

So, specific points:

  • The code of TracePaddedRecording works as expected as a long as the original recording that is padded follows the numpy slicing convention.
  • There is an internal error when padding at the end of the original recording where the start_frame and the end_frame are inverted Fix zero_channel_pad case when selected frames are outside of original data region #1979 (comment). This however, should still work as long as the original recording follows the numpy convention (e.g. array[10:10] == array[12:10] if you array.size == 10).
  • bandpass_filter get_traces should have the slicing behavior of numpy and right now it does not.

@JoeZiminski

JoeZiminski commented Sep 13, 2023 •

Copy link
Copy Markdown
Contributor Author

Thanks @h-mayorquin! That makes a lot of sense, I can see that the error is resolved if the numpy-style slicing convention is maintained for recording object. I also saw this error for phase_shift (sorry we have a big meeting today but I can write a test this afternoon) so I think this would need to be made numpy-sliceable as well.

I think it would make sense to handle explicitly the cases in which we are in a padding-only region (i.e. in the pre-data padding and post-data padding regions) so no call is made to get_original_traces_shifted() unless data is definately required to be retrieved. This should make the intention behind the code clearer and this also does not rely on recording objects acting like numpy arrays when slicing. This would just be something like (pseudocode, and need to check whether stict inequalities are used):

end_padding_begin_idx =  original_data_size + padding_start

if (start_frame > end_padding_start and end_frame > end_padding_begin_idx )  or
    (start_frame < padding_start and end_frame < padding_start):
    return output_traces

That said, it would be good to write a test to ensure all recording objects act consistently when slides out of bounds / with end_frame < start_frame. I can write an issue for this and maybe we can open a PR adding tests for this down the line.

In terms of testing this, I guess adding pre-processing to the tests in test_zero_channel_pad.py might not be the right place, if this is mainly for unit-tests. Is there an integration test suite this could be added to? For example, it might be worth testing such preprocessing steps parameterised over various combinations and settings.

The next question is out of scope for this PR and concerns a major design choice of SI so feel free to ignore. But, do you know the benefits of recording objects slicing like numpy arrays? Although it adds flexibility, it is difficult to determine the cases when such slicing is intended vs. when it is a mistake and should be flagged. For example, I cannot off the top of my head think of a reason to index the data with end_frame > data_size or end_frame < start_frame. I think attempting to do this in most cases (e.g. for non-expert users) would be an error rather than intended.

I will respond to other comments ASAP, thanks!

@h-mayorquin

Copy link
Copy Markdown
Contributor

I think it would make sense to handle explicitly the cases in which we are in a padding-only region (i.e. in the pre-data padding and post-data padding regions) so no call is made to get_original_traces_shifted() unless data is definately required to be retrieved. This should make the intention behind the code clearer and this also does not rely on recording objects acting like numpy arrays when slicing. This would just be something like (pseudocode, and need to check whether stict inequalities are used):

Mmm yeah, I kind of wanted to avoid that because I though the following code is already handling that case:

# After the padding, the original traces are placed in the middle until the end of the original traces
if end_frame >= self.padding_start:
original_traces = self.get_original_traces_shifted(
start_frame=start_frame,
end_frame=end_frame,
channel_indices=channel_indices,
)
padded_frames_at_the_start = max(self.padding_start - start_frame, 0)
end_of_original_traces = padded_frames_at_the_start + original_traces.shape[0]
output_traces[padded_frames_at_the_start:end_of_original_traces, :] = original_traces

But that is implicit... and I think you are right that "explicit is better than implicit". I will check some performance and and I will probably move to your suggestion.

That said, it would be good to write a test to ensure all recording objects act consistently when slides out of bounds / with end_frame < start_frame. I can write an issue for this and maybe we can open a PR adding tests for this down the line.

In terms of testing this, I guess adding pre-processing to the tests in test_zero_channel_pad.py might not be the right place, if this is mainly for unit-tests. Is there an integration test suite this could be added to? For example, it might be worth testing such preprocessing steps parameterised over various combinations and settings.

The next question is out of scope for this PR and concerns a major design choice of SI so feel free to ignore. But, do you know the benefits of recording objects slicing like numpy arrays? Although it adds flexibility, it is difficult to determine the cases when such slicing is intended vs. when it is a mistake and should be flagged. For example, I cannot off the top of my head think of a reason to index the data with end_frame > data_size or end_frame < start_frame. I think attempting to do this in most cases (e.g. for non-expert users) would be an error rather than intended.

We wiill be discussing this issues here:
#1989

@JoeZiminski

JoeZiminski commented Sep 13, 2023 •

Copy link
Copy Markdown
Contributor Author

Thanks @h-mayorquin for the link to discussion and consideration let's see how things look on the performance side. I added a test case for the phase_shift, it results in a similar problem (I think the root cause is the same, but error message different). This root problem is out of scope for this PR and concerns the slicing API which is discussed elsewhere. However, if we do handle the padding-only case outside of get_original_traces_shifted() would allow zero_channel_padding.py to ignore this issue for now. Cheers!

(sorry BTW forgot to pre-commit install on this machine, done now :'D)

@JoeZiminski

JoeZiminski commented Sep 13, 2023 •

Copy link
Copy Markdown
Contributor Author

BTW for the inequality on

if start_frame > self.padding_start and end_frame < self.num_samples_in_original_segment + self.padding_start:

should the first inequality be start_frame >= self.padding_start? If I understand correctly padding_start is the upper-bound on the padding and padding goes from 0:padding_start e.g. if padding_start=5 the padded sample indices will be 0, 1, 2, 3, 4. As such the data would start at sample 5, start_frame >= self.padding_start.

@JoeZiminski

Copy link
Copy Markdown
Contributor Author

Hey @h-mayorquin hope things are good! did you have any more thoughts on this in terms of performance? My guess is because its skips the block entirely, this should always be faster than the previous version. Happy to make any required changes!

@h-mayorquin

Copy link
Copy Markdown
Contributor

Sorry, @JoeZiminski . I actually had in my todo list to come back to this today (I was away the last two weeks) but I ran out of time.

I will come back to you tomorrow and hopefullly we can get this through this week. Thanks for following on this.

@JoeZiminski

Copy link
Copy Markdown
Contributor Author

Thanks @h-mayorquin sorry to catch you just as you just got back! Sounds good no rush, thanks a lot for your help!

@h-mayorquin

Copy link
Copy Markdown
Contributor

@JoeZiminski
I took a look at this today. This is fine, I would like to have a lighter test than the one that you added but is not trivial. I toyed with something like adding a mock object but because of the Spikeinterface separation between Extractors and Segments (something taht I dislike) that could not be done.

I also think that your solution covers one case which mine does not, so it is not only more explicit but actually correct. Can you add these two tests to confirm this:

@pytest.mark.parametrize("padding_start, padding_end", [(5, 5), (0, 5), (5, 0), (0, 0)])
def test_trace_padded_recording_retrieve_only_start_padding(recording, padding_start, padding_end):
    num_samples = recording.get_num_samples()
    num_channels = recording.get_num_channels()

    padded_recording = TracePaddedRecording(
        parent_recording=recording,
        padding_start=padding_start,
        padding_end=padding_end,
    )

    # Retrieve the padding at the start and test it
    padded_traces_start = padded_recording.get_traces(start_frame=0, end_frame=padding_start)
    expected_traces = np.zeros((padding_start, num_channels))
    assert np.allclose(padded_traces_start, expected_traces)
    

@pytest.mark.parametrize("padding_start, padding_end", [(5, 5), (0, 5), (5, 0), (0, 0)])
def test_trace_padded_recording_retrieve_only__padding(recording, padding_start, padding_end):
    num_samples = recording.get_num_samples()
    num_channels = recording.get_num_channels()

    padded_recording = TracePaddedRecording(
        parent_recording=recording,
        padding_start=padding_start,
        padding_end=padding_end,
    )
    
    # Retrieve the padding at the end and test it
    start_frame =  padding_start + num_samples
    end_frame = padding_start + num_samples + padding_end
    padded_traces_end = padded_recording.get_traces(start_frame=start_frame, end_frame=end_frame)
    expected_traces = np.zeros((padding_end, num_channels))
    assert np.allclose(padded_traces_end, expected_traces)

If these test pass let's go with the solution here. I would remove the heavy tests that you added here later when I have a general testing framework in line with #1989.

@h-mayorquin

Copy link
Copy Markdown
Contributor

BTW for the inequality on

if start_frame > self.padding_start and end_frame < self.num_samples_in_original_segment + self.padding_start:

should the first inequality be start_frame >= self.padding_start? If I understand correctly padding_start is the upper-bound on the padding and padding goes from 0:padding_start e.g. if padding_start=5 the padded sample indices will be 0, 1, 2, 3, 4. As such the data would start at sample 5, start_frame >= self.padding_start.

As for this, I was not thinking on this like bounds but as "numbers" so counting actual units. (which is not clear in the docstring) Let me think more about it but feel free to suggest which semantics are better.

@alejoe91 alejoe91 added this to the 0.99.0 milestone Oct 25, 2023

@h-mayorquin h-mayorquin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoeZiminski
Thanks a bunch for all your work.
As we want to have a release soon, we would like to add your fix as it is, I will add the tests that I suggested in a small follow up PR.

@h-mayorquin
h-mayorquin merged commit 712e576 into SpikeInterface:main Oct 30, 2023
@JoeZiminski

Copy link
Copy Markdown
Contributor Author

Thanks @h-mayorquin, sorry for the slow response. Cheers for taking care of this and merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preprocessing Related to preprocessing module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants