Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/Unexpected effect in global timestamp computation #21

Open
larsrollik opened this issue Jun 6, 2023 · 5 comments
Open

Bug/Unexpected effect in global timestamp computation #21

larsrollik opened this issue Jun 6, 2023 · 5 comments

Comments

@larsrollik
Copy link

OpenEphys GUI: 0.6.4
open-ephys-python-tools: 0.1.4

In a recently acquired session, global timestamps are miscalculated, because the events are sorted by timestamp, but the sample_number is therefore shuffled. When the global timestamp function takes the iloc[0] and iloc[-1] sample_number, then these are not the first and last sample in the acquisition.

You can see already in the head of the events dataframe that the sorting of the sample_number is random:

Out[1]: 
       line  sample_number    timestamp  ...  stream_index  stream_name state
0         1      113210450 -9906.177509  ...             1    ProbeA-AP     1
1         1      113209520 -9840.472230  ...             1    ProbeA-AP     0
2         1      113208648 -9778.864699  ...             1    ProbeA-AP     1
3         1      113206516 -9628.237112  ...             1    ProbeA-AP     0
4         1      113206244 -9609.020084  ...             1    ProbeA-AP     1
...     ...            ...          ...  ...           ...          ...   ...
25263     1       12873859   149.820794  ...             0   ProbeA-LFP     0
25264     1       12874087   149.911938  ...             0   ProbeA-LFP     1
25265     1       12510866   149.958667  ...             0   ProbeA-LFP     1
25266     1       12510889   149.967867  ...             0   ProbeA-LFP     0
25267     1       12510992   150.009067  ...             0   ProbeA-LFP     1

When checking the synchronization event counts and sample differences between the synch channels, they match perfectly, just not according to the built-in function.

Note that with the negative timestamp values, the timestamps set to -1 as not synchronized are in the middle section of the events dataframe.

@medengineer
Copy link
Member

Hi,

This should be fixed in the latest release here:

https://pypi.org/project/open-ephys-python-tools/0.1.5/

@larsrollik
Copy link
Author

Thank you, yesterday's release seems to fix it.

@larsrollik
Copy link
Author

Sorry, I misread in the diff of the latest merge that the sorting of the events dataframe was changed, but this is not the case for BinaryRecording instances.

See

if self._version >= 0.6:
self._events = pd.concat(df).sort_values(by=['timestamp', 'stream_index'], ignore_index=True)
else:
self._events = pd.concat(df).sort_values(by=['sample_number', 'stream_index'], ignore_index=True)
.

The original issue remains in https://github.com/open-ephys/open-ephys-python-tools/releases/tag/v0.1.5

@larsrollik larsrollik reopened this Jun 7, 2023
@medengineer
Copy link
Member

I see. Does changing timestamp to sample_number on line 207 above fix the issue on your end w/ version 0.1.5?

@larsrollik
Copy link
Author

larsrollik commented Jun 9, 2023

I assume so. It's done like that for the OpenEphysRecording type. But I have not written tests for it.

self._events = pd.concat(events).sort_values(by=['sample_number', 'stream_index'], ignore_index=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants