Repository navigation
BlackrockRawIO: read .nev spike waveforms lazily - #1955
h-mayorquin merged 1 commit into
Conversation
…ing them at parse
|
@cboulay could you take a look |
cboulay
left a comment
There was a problem hiding this comment.
Thanks, this is the shape I hoped for. I checked it against master on every Blackrock file in ephy_testing_data that opens (39 of them). Spike timestamps and waveforms are identical for every unit and segment, both with no time range and with each half of the segment as t_start/t_stop. The Blackrock tests pass locally.
One thing for the follow-ups: the peak during parse is not only the memory map. _get_event_segment_ids builds event_segment_ids as an int64 per packet, not per spike, and masks keeps one bool array per packet type alive through the loop. That is 8 bytes per packet plus 1 per type, about 15 bytes per packet for 3.0 with its 7 types. On our 90 GB .nev files (about 0.9 billion packets) that is around 13 GB before any page of the map counts. If _get_event_segment_ids returned the boundary positions instead, each type could get its ids with np.searchsorted(boundaries, positions, side="right") on its own positions, and no array would be the length of the file. That also fits your chunked-read step, since a chunk only needs the boundaries found so far.
Smaller things:
nev_data["Spikes"]no longer has awaveformfield. The attribute isn't private and our code read it, so it is worth a line in the release notes.- Each
get_spike_raw_waveformscall maps the whole data region again. Harmless on 64-bit, just noting it. - A test that reads a unit's waveforms with
t_start/t_stopand compares them with a slice of the full read would pin the new order (slice, then read).
…ork only) Fork-only per python-neo#1931 (remote reading stays out of rawio for now). Rebuilt on upstream's open-file headers (NeuralEnsemble#1940), merged NSx blocks (NeuralEnsemble#1880) and lazy NEV waveforms (NeuralEnsemble#1955), replacing the streaming series of blackrock-integration-2026-11-07. - A filename with "://" opens through fsspec (storage_options); local files keep every upstream code path, memory maps included. fsspec is the optional "remote" extra. - Files open through _open/_exists/_get_file_size, so NeuralEnsemble#1940's header reads work remotely. - Signal chunks and PTP timestamps of a remote file read only the requested rows, block by block for a segment that merges several (_read_remote_chunk, _read_rows). - A remote PTP .nsX finds its gaps and steps back with a scan in pieces (_scan_ptp_ticks), with the whole-array arithmetic, so the segments and gap report are the same. - A remote NEV (but 2.3, which needs every packet to match segments with the NSx) is scanned in pieces at open: events are kept, spikes are summarized (units, counts per segment and unit, segment times) in _nev_spikes; segment boundaries follow _get_event_segment_ids (per packet type, comments skipped, packets up to 10 ms late not resets). One unit's spikes are read with another pass (_spike_records, NeuralEnsemble#1955's table). Unmatched packets are counted across the pieces. - _iter_nev_pieces, _nev_masks_and_types and _spike_waveforms stay for connectome-curate, which streams every spike in one pass. iter_spikes() is gone (NeuralEnsemble#1931: not wanted upstream). Dropped from the old branch: the buffer description for standard NSx (unused; NeuralEnsemble#1880's merged segments are not one region) and the gap-scan helper in rawio.utils (the scan now reuses _detect_timestamp_gaps).
…ork only) Fork-only per python-neo#1931 (remote reading stays out of rawio for now). Rebuilt on upstream's open-file headers (NeuralEnsemble#1940), merged NSx blocks (NeuralEnsemble#1880) and lazy NEV waveforms (NeuralEnsemble#1955), replacing the streaming series of blackrock-integration-2026-11-07. - A filename with "://" opens through fsspec (storage_options); local files keep every upstream code path, memory maps included. fsspec is the optional "remote" extra. - Files open through _open/_exists/_get_file_size, so NeuralEnsemble#1940's header reads work remotely. - Signal chunks and PTP timestamps of a remote file read only the requested rows, block by block for a segment that merges several (_read_remote_chunk, _read_rows). - A remote PTP .nsX finds its gaps and steps back with a scan in pieces (_scan_ptp_ticks), with the whole-array arithmetic, so the segments and gap report are the same. - A remote NEV (but 2.3, which needs every packet to match segments with the NSx) is scanned in pieces at open: events are kept, spikes are summarized (units, counts per segment and unit, segment times) in _nev_spikes; segment boundaries follow _get_event_segment_ids (per packet type, comments skipped, packets up to 10 ms late not resets). One unit's spikes are read with another pass (_spike_records, NeuralEnsemble#1955's table). Unmatched packets are counted across the pieces. - _iter_nev_pieces, _nev_masks_and_types and _spike_waveforms stay for connectome-curate, which streams every spike in one pass. iter_spikes() is gone (NeuralEnsemble#1931: not wanted upstream). Dropped from the old branch: the buffer description for standard NSx (unused; NeuralEnsemble#1880's merged segments are not one region) and the gap-scan helper in rawio.utils (the scan now reuses _detect_timestamp_gaps).
…ork only) Fork-only per python-neo#1931 (remote reading stays out of rawio for now). Rebuilt on upstream's open-file headers (NeuralEnsemble#1940), merged NSx blocks (NeuralEnsemble#1880) and lazy NEV waveforms (NeuralEnsemble#1955), replacing the streaming series of blackrock-integration-2026-11-07. - A filename with "://" opens through fsspec (storage_options); local files keep every upstream code path, memory maps included. fsspec is the optional "remote" extra. - Files open through _open/_exists/_get_file_size, so NeuralEnsemble#1940's header reads work remotely. - Signal chunks and PTP timestamps of a remote file read only the requested rows, block by block for a segment that merges several (_read_remote_chunk, _read_rows). - A remote PTP .nsX finds its gaps and steps back with a scan in pieces (_scan_ptp_ticks), with the whole-array arithmetic, so the segments and gap report are the same. - A remote NEV (but 2.3, which needs every packet to match segments with the NSx) is scanned in pieces at open: events are kept, spikes are summarized (units, counts per segment and unit, segment times) in _nev_spikes; segment boundaries follow _get_event_segment_ids (per packet type, comments skipped, packets up to 10 ms late not resets). One unit's spikes are read with another pass (_spike_records, NeuralEnsemble#1955's table). Unmatched packets are counted across the pieces. - _iter_nev_pieces, _nev_masks_and_types and _spike_waveforms stay for connectome-curate, which streams every spike in one pass. iter_spikes() is gone (NeuralEnsemble#1931: not wanted upstream). Dropped from the old branch: the buffer description for standard NSx (unused; NeuralEnsemble#1880's merged segments are not one region) and the gap-scan helper in rawio.utils (the scan now reuses _detect_timestamp_gaps).
|
Thanks I think the test you suggested should be a general check. It applies to every reader that returns waveforms and right now none of them is tested with a time range. I opened an issue to add it to the compliance tests: Concerning the memory during parse, I agree, I have a solution let me open a PR just now, I will tag you. On your two smaller points:
|
This is the second step of the plan I described in #1931 after #1940 read the headers through an open file. Right now
_read_nev_datacopies every spike packet with its waveform at parse. This PR keeps a small table per spike instead (timestamp, electrode, unit and the position of its packet in the file) andget_spike_raw_waveformsreads the waveforms of the requested unit from those positions. It also selects byt_startandt_stopbefore reading so a time range only reads the waveforms inside it.On the 2.24 GB Trellis file from #1941 the memory held after parse goes from 2.46 GB to 0.44 GB. Parse goes from 54 s to 33 s, the timestamps of all 512 units from 85 s to 21 s and their waveforms from 93 s to 49 s (Linux laptop, spinning disk). The spikes and waveforms are the same as master on that file and on every Blackrock recording on gin.
The peak during parse is still about the size of the file. Finding the spikes needs the packet id of every packet and those are read through a memory map of the whole file. The kernel can drop these pages but they count as resident memory of the process. What I would like to do after this:
.nevparse would work on any file object, a step towards remote reading without a second code path as discussed in Reading Blackrock recordings from fsspec URLs: is remote reading in scope for rawio? #1931. This needs_get_event_segment_idsto work from the arrays of each packet type instead of the whole file. That is the function the reordering proposed in Are the segments of a block ordered in time? #1937 will change. So I will wait for that PR.int64per spike, 8 of its 19 bytes.This should close #1941.