Repository navigation
Write all channels of a stream with one HDF5 write (writeContinuousDataBatch) - #1
Merged
Merged
Conversation
oruebel
marked this pull request as ready for review
October 27, 2026 07:04
…taBatch) Implement RecordEngine::writeContinuousDataBatch: the GUI passes all recorded channels of a data stream (one ElectricalSeries) for a block; convert them to int16, interleave them into the [sample][channel] layout of the dataset (in 64 x 64 tiles), and write the data and timestamps with a single ElectricalSeries::writeAllChannels call instead of one HDF5 write per channel. Any other combination of channels is written channel by channel. The sample numbers, the time range of the recording (dataWritten) and the stream start times are shared with writeContinuousData (writeBlockSampleNumbers, finishContinuousWrite). GUI development (open-ephys/plugin-GUI#711, 5a16ccf) calls writeContinuousDataBatch for the NWB2 engine if the plugin's library version is 2.0 or newer; GUI v1.1.0 keeps calling writeContinuousData. Tested on GUI development: data identical to the source for one and two streams (Merger), with spikes, events and messages, several recordings, and recordings across the File Reader loop; complete, gap-free sample numbers for 20 s recordings with 3072 and 4608 channels. Record Thread time spent writing at 384/1536/3072 channels (Release): 3.1/12.9/23.8% (one write per channel: 8.6/35.0/71.8%). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
oruebel
force-pushed
the
batch-writes
branch
from
November 10, 2026 19:59
36c7293 to
c01842e
Compare
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.
Context
@jsiegle I had prioritized several needed updates in AqNWB but am now starting to look at updating the nwb-format plugin for OpenEphys to use AqNWB and bring the plugin up-to-date with the latest version of NWB.
This PR is currently in draft mode because it depends on several changes/fixes in AqNWB that are in pending PRs, so we should hold off with merging until after I have made an AqNWB release with the required changes. However, I figured it would be useful to start the review of this in parallel so we can test and refine the changes.AqNWB with the necessary changes for this PR was released on 11/03/2026 so the PR now points to the corresponding 0.5.0 release of AqNWB.Because this PR updates to the latest version of NWB, I also created follow-up PRs:
Both are in draft mode until this PR is merged, in case there are further changes here.
While working on this PR, I found four issues in the Open Ephys GUI (see GUI issues below). They are fixed on
development(v1.2.0), and this PR uses the fixes when they are available. Update (2026-11-20): this PR now also includes three follow-ups that were reviewed on the fork to support: 1) batch writes, 2) session and subject metadata in the Record Node's options, and 3) a faster int16 conversion.Summary
This PR replaces the NWB writer of the plugin (
NWBFormat.h/.cpp) with AqNWB 0.5 and rewrites theNWB Filefile source on top of AqNWB's read API. It supersedes #4 (it builds on the commits of #4) and closes open-ephys-plugins#7.The files are valid NWB 2.11 and pass the NWB Inspector at
BEST_PRACTICE_VIOLATION(exceptcheck_empty_table, see below). The goal was to stay schema compliant without custom extensions or workarounds, and to update the readers (python-tools, NWB File Source) as necessary to correctly work with the updated format.Main changes:
EventsTables for TTL events and messages, epochs for the recordings, and sample numbers insync/sample_numbers(see File layout).EngineParameter) are never applied to the Record Node's engine open-ephys/plugin-GUI#710) or in a JSON metadata file (Set session and subject metadata through the NWB2 options of the Record Node #2, closes Set session and subject metadata through record engine parameters open-ephys-plugins/nwb-format#7).timestamps_reference_timeis now the time of timestamp 0.writeContinuousDataBatch, Record Node: allow plugin record engines to opt in to batch writes (writeContinuousDataBatch) open-ephys/plugin-GUI#711; Write all channels of a stream with one HDF5 write (writeContinuousDataBatch) #1).GUI versions
development; recommended)The plugin requires plugin API version 10 (GUI v1.x).
File layout
As before, each experiment (start/stop of acquisition) is written to a separate file
experiment<N>.nwb, and the recordings within an experiment are appended to the same datasets. Existing files are never changed: if the data directory is changed between recordings, the next recording starts a new file in the new directory. That file is namedexperiment<N>_recording<M>.nwbif the directory already containsexperiment<N>.nwb(python-tools support in open-ephys/open-ephys-python-tools#51)./acquisition/<source>-<id>.<stream>(ElectricalSeries)synctosync/sample_numbers, to improve format compliance.channel_conversion. The previous plugin stored the factor in bothdata.conversionandchannel_conversion, so NWB readers scaled the data twice./acquisition/<source>-<id>.<stream>.<electrode>(SpikeEventSeries)sync/sample_numbers.data.conversion(one factor per waveform)./events/<processor>-<id>.<stream>.TTL(TTL_1,TTL_2, ... for further channels; named like the Binary event folders)EventsTable(new in NWB 2.11) withline,state,full_word,sample_number, instead of a.TTLTimeSeries in/acquisition/events/messagesEventsTablewithannotation,sample_number, instead of a TimeSeries of strings/events/sync_messagesEventsTable/intervals/epochsTimeIntervalstable/general/extracellular_ephys/electrodeschannel_typecolumn/general,/general/subjectNote:
sync/sample_numbersis not yet part of the NWB schema.TimeSeries/syncis a group without a specification for its contents, so validation doesn't flag the dataset. We are discussing a standard location for sample numbers in NeurodataWithoutBorders/nwb-schema#712. For now, I think theTimeSeries/syncgroup is a good place. Previously, the plugin used a datasetTimeSeries/syncinstead, which was not schema compliant.Robustness and performance
writeContinuousDataBatch. The plugin converts them to int16, interleaves them in 64 x 64 tiles, and writes the block with oneElectricalSeries::writeAllChannelscall. With GUI v1.1.0, the GUI callswriteContinuousDataper channel, and the plugin writes one column per call.convertFloatToInt16LE, so the written values are unchanged. In a micro-benchmark it takes 0.25 ns per sample, compared with 0.41 ns for JUCE.Performance tests
Setup:
The scripts and full results are on the fork's
perf-testsbranch.The Record Thread's time spent writing continuous data is the share of real time; 100% would mean the engine can't keep up:
The middle column was measured with a prototype on
perf-tests. It writes the blocks the same way and uses an earlier version of the conversion (0.32 instead of 0.25 ns per sample), so this PR should be at least as fast. With the batch API and the JUCE conversion, the share was 3.1%, 12.9% and 23.8%.Results:
Timestamp handling
Timestamps are the GUI's synchronized timestamps, as in the Binary format: seconds since timestamp 0 of the GUI (sample 0 of the main stream, normally the start of acquisition).
timestamps_reference_timeandsession_start_timeare set to the time of timestamp 0: the system time when the first recording of the file starts (the "Software Time" sync message) minus the first recorded timestamp. The previous plugin used the time the file was created, so all times were offset by the time between the start of acquisition and the start of recording. Streams that aren't synchronized have timestamps of -1, as in the Binary format; the epochs ignore them.Session and subject metadata
The metadata is applied when an NWB file is created, at the first recording of each experiment. There are three ways to set it; the README has the details.
The Record Node's NWB2 options (gear button next to the recording format; GUI v1.2.0):
They are saved with the signal chain and can be set through the HTTP API as
engine_NWB2_<id>.A JSON metadata file with the same structure as NeuroConv metadata, with more
NWBFileandSubjectfields than the options. The plugin reads the file set in the options, or elsenwb_metadata.jsonnext to the recording. Options that are set override the values in the file; empty options don't.After recording, with PyNWB or NWB GUIDE.
If fields that DANDI requires for the subject are missing, the plugin logs a warning. It logs an error for a date of birth that isn't a full ISO 8601 date and time with time zone, which AqNWB can't write.
was_generated_byrecords the GUI and plugin versions.NWB File Source
The
NWB Filefile source now reads with AqNWB, with lazy reads instead of loading whole datasets. It plays back:Playback is bit-exact, compared with a Binary recording of the played-back data. It handles the File Reader's event ranges of both GUI v1.1.0 and v1.2.0 (open-ephys/plugin-GUI#712).
Known limitations
EventsTable.check_empty_table, which can be skipped with--ignore check_empty_table(see check_empty_table should not fire on a table that was written empty on purpose nwbinspector#761).Unitstable in AqNWB (Record the sorted unit IDs of spikes open-ephys-plugins/nwb-format#8, Add support for theUnitstable aqnwb#351).DeviceModel, e.g. probe manufacturer and model) will follow after the next AqNWB release (Write device metadata with the NWB 2.11DeviceModelopen-ephys-plugins/nwb-format#13).Dependencies
Build and CI
libs/<platform>.installtarget installs their runtime libraries into the GUI'sshareddirectory (shared-api10on macOS).shared/next to the plugin, signed on macOS, as zmq-interface does.main, so the packaging is only exercised after this PR is merged.mainbranch of the Open Ephys GUI on all platforms.open-ephys-lib-v1.1.0.zip(which hasRecordEngine::writeContinuousDataBatch) instead of building the GUI, and runs onwindows-2022, as the GUI does./general/was_generated_by. It stays a literal inOpenEphysLib.cpp, since the deploy steps read it from theinfo->libVersionline.Testing
On macOS, with GUI v1.2.0 (
development, d90de30) and v1.1.0:GUI issues
Found while working on this PR; all are fixed on
development(v1.2.0) and retested:EngineParameter) are never applied to the Record Node's engine open-ephys/plugin-GUI#710: record engine parameters were never applied. The NWB2 options need this fix.writeContinuousDataBatch) open-ephys/plugin-GUI#711: batch writes were only used for the Binary engine. The block writes need this fix.AI usage declaration
🤖 Generated with the help of Claude Code. All changes have been reviewed by @oruebel.