Skip to content

Fix #2201 - #2223

Merged
alejoe91 merged 2 commits into
SpikeInterface:mainfrom
h-mayorquin:fix_concatenate_segments
Nov 22, 2023
Merged

alejoe91 merged 2 commits into
SpikeInterface:mainfrom
h-mayorquin:fix_concatenate_segments

Conversation

@h-mayorquin

@h-mayorquin h-mayorquin commented Nov 17, 2023 •

Copy link
Copy Markdown
Contributor

Annoying bug that happens with concatenation but can happen with any recording that is long enough. Here is the problem. To create the file, the size of the file-to-be is esimated with this line:

https://github.com/h-mayorquin/spikeinterface/blob/65e4c178dc3bd0f826ce2b10fcb31a8e7da4698b/src/spikeinterface/core/core_tools.py#L297

But sometimes the number of frames is a numpy scalar (and not a python integer). Numpy scalars behave like numpy objects and they have an overflow. That means that the file size ends up being smaller than it should and the writting to the buffer fails.

You can see that there is an overflown ins the screenshot that the user shared with us:

image

Plus, you can see that the concatenated recording is smaller than the pieces.

So, to solves it, we need to be sure that get_num_samples()i is not a numpy scalar but a python scalar (they can be as long as as they need to be). I modified the code to do that.

@h-mayorquin h-mayorquin added bug Something isn't working core Changes to core module extractors Related to extractors module labels Nov 17, 2023
@h-mayorquin h-mayorquin self-assigned this Nov 17, 2023
executor.run()


# used by write_binary_recording + ChunkRecordingExecutor

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 moved this so it follows the pattern that all the ChunkRecordingExector chunk functions follow. The function is after the caller of ChunkRecordingExecutor. Sorry for my OCD.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No worries! Honestly I also found it aannoying

d["t_start"] = None
d["time_vector"] = None
d["sampling_frequency"] = sampling_frequency
time_kwargs = {}

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.

This also got in my way when debuggin, sorry @samuelgarcia . If you want to keep single letter, feel free to rever to something other than d.

@DradeAW

DradeAW commented Nov 20, 2023

Copy link
Copy Markdown
Contributor

But sometimes the number of frames is a numpy scalar (and not a python integer). Numpy scalars behave like numpy objects and they have an overflow

You managed to exceed an int64!?
I'm curious to know in what context

@h-mayorquin

Copy link
Copy Markdown
Contributor Author

@DradeAW
I am not sure it was int64. But this is the line:

        data_size_bytes = dtype_size_bytes * num_frames * num_channels

num_frames as a numpy scalar, so that means data_size_bytes was also a numpy scalar. The product exceed the size of the numpy dtype and there the error. You can check the parent issue for the numbers, they will be reflected on the screenshots and you can calculate from there what datatype was being used.

@DradeAW

DradeAW commented Nov 20, 2023

Copy link
Copy Markdown
Contributor

For a recording using 8 bytes (int64, float64) lasting a full day at 100 kHz on 10,000 channels, that's 6.9*10^14
int64 = 2^63 = 9.2*10^18

I already had a problem of overflow with the coincidence matrix.
I think we should stop using int32 and int16 in cases where it does not matter to stop this problem from happening. int64 covers almost all cases and is future-proof.

@h-mayorquin

h-mayorquin commented Nov 20, 2023 •

Copy link
Copy Markdown
Contributor Author

For these kind of thing normal python int is even better. The problem was that we propagated from neo numpy scalar without knowing. There was no intentional choice at any step of the chain.

@alejoe91
alejoe91 marked this pull request as ready for review November 22, 2023 11:09
@alejoe91
alejoe91 merged commit 3abc55e into SpikeInterface:main Nov 22, 2023
@h-mayorquin
h-mayorquin deleted the fix_concatenate_segments branch November 23, 2023 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working core Changes to core module extractors Related to extractors module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants