Repository navigation
Conversation
Central sends up to 300 samples (10 ms) per UDP datagram and the recording PC can write datagrams out of order: the packets' timestamps are right, only their place in the file is not (NeuralEnsemble#1937). Older .nev files also hold spikes of different electrodes out of order relative to one another, by up to 15 ms, each electrode's own spikes in order (NeuralEnsemble#1755). - PTP .nsX: a step back in the timestamps whose packets sort, within 10 ms, into an even grid (no duplicate, overlap or gap) is read in timestamp order: the few rows involved are remapped in _get_analogsignal_chunk and the timestamps, and the steps they made as written are no gaps. Other steps back stay inside the segment, as before. The grid is the criterion; 10 ms only bounds the search. - NEV: a spike is compared only with the previous spike on its electrode (other packets with the previous packet of their type, as since NeuralEnsemble#1924). A step back of up to 10 ms is a packet written late, not a clock reset; each unit's spikes come in timestamp order. A larger step back is a reset, placed at the largest step back between consecutive packets of the type since that electrode's previous spike, so the spikes of other electrodes written after the reset are in the new segment. - Counted in nsx_reordered_packets / nev_reordered_packets (late packets within a segment), with one warning each. Tests: no new test functions. The "ptp with missing samples" file misses no samples (its ns4/ns6 have runs of 10/30 samples written after the next run, and its NEV a spike written after a later one on its electrode), so the two gap tests now use pause_and_resume, a PTP file with a real 3.6 s gap. The reordering is asserted in the existing tests on samples_out_of_order_in_ptp_timestamps (and a copy with steps back that do not sort into the grid), on the missing-samples NEV, and with synthetic spikes in test_nev_segments_ignore_order_between_packet_types (the 10 ms bound, and electrodes out of order relative to one another).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As discussed in #1937. Packets in Blackrock files are not always written in the order of their timestamps, and today
BlackrockRawIOreads every step back as a gap or a clock reset. This reads them in timestamp order instead, so a step back is a reset only when it can't be explained by packets out of order. Closes #1755.Two sources of out-of-order packets:
.nevfiles (BlackrockIO can't read my nev files. #1755, spec 2.3): spikes on different electrodes are written up to 15 ms out of order relative to one another, while each electrode's own spikes are in order. That file reads as 178 segments against 1 in its ns6, and can't be loaded with the ns6. This is the case where @h-mayorquin suggested in BlackrockIO can't read my nev files. #1755 to "only segment if the data within the channel suffers a big jump".The changes:
.nsX: at a step back, the samples within 10 ms around it are sorted by timestamp. If no sample moves by more than 10 ms and the sorted samples lie on the sampling grid (each one half a period to two periods after the one before: no duplicate, overlap or gap), they are read in that order, and the forward steps they made as written are not gaps. The grid is the criterion; the 10 ms only bounds the search. Any other step back stays inside the segment, as on master since BlackrockRawIO: extendgap_tolerance_msto the standard nsx formats #1880. Only the few rows involved are remapped, in_get_analogsignal_chunkand_get_blackrock_timestamps; the memory maps are unchanged..nev: a spike is compared only with the previous spike on its electrode; other packets are compared with the previous packet of their type, as since Blackrock: detect NEV clock resets per packet type #1924. A step back of up to 10 ms is a packet written late, not a reset, and each unit's spikes are returned in timestamp order. A larger step back is a reset. A reset sends every electrode's clock back, so it is still found (the rule from Adapting BlackrockIO for new features of version 2.3 #523), and it is placed at the largest step back between consecutive spikes since that electrode's previous spike. That way the spikes of other electrodes written after the reset are in the new segment. For the.nevthere is no grid, so the 10 ms is the criterion itself, as Heberto noted in Are the segments of a block ordered in time? #1937.nsx_reordered_packets(per nsX) andnev_reordered_packets(late packets within a segment), with one warning each.On every Blackrock recording in ephy_testing_data, segments and spikes are the same as on master except for the two PTP files below (one recording in two copies) and the reordered recording mentioned at the end. That includes the reset, pause and multi-block files.
Tests: no new test functions.
blackrock_ptp_with_missing_samplesmisses no samples: its ns4 and ns6 have runs of 10 and 30 samples written after the next run, and its.nevhas a spike written 1.7 ms after a later spike on the same electrode. Sotest_get_blackrock_timestamps_ptp_with_gapsandtest_gap_tolerance_ms_parameternow useversion_3_0/time_structure/pause_and_resume, a PTP file with a real 3.6 s gap. They pass on master too.test_ptp_backward_steps_stay_inside_the_segment(samples_out_of_order_in_ptp_timestamps, the same streams) also checks the counts and that samples and timestamps come in timestamp order, whole and in windows that start or end inside a moved run. It also checks that a step back that does not sort into the grid stays as written: in a copy of the ns6, one sample written 13 ms early and one written twice.test_nev_spikes_at_segment_edges_ptpalso checks that the late spike is not a reset (one segment) and that each unit's spikes are in timestamp order.test_nev_segments_ignore_order_between_packet_typesalso checks, with synthetic spikes, that a spike stepping back 10 ms is not a reset, 10 ms plus one tick is, and a spike on another electrode 15 ms behind is not compared.The file attached to #1755 now reads as one segment and loads with its ns6. It may be worth adding to ephy_testing_data, with the reporter's permission. I also have a signal-generator recording from a Gemini Hub and an NSP, with a copy that has packets moved out of order the way the recording PC was seen to write them; both read the same. It is in a zip, with the script that makes the copy, at https://github.com/cboulay/python-neo/releases/tag/test-data-blackrock-ptp-comments.
This should unblock the chunked
.nevreading Heberto described in #1955. It touches the same loop in_get_event_segment_idsas #1959.