docs(tutorials): rework convertTrials tutorial (ragged-array API, correctness fixes, reordered flow)#857
Draft
ehennestad wants to merge 6 commits into
Draft
Conversation
Update the convertTrials live script tutorial. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Depends on #855.
Motivation
Problem — For someone learning trial-based conversion from the
convertTrialstutorial, the previous version taught outdated patterns and produced a subtly incorrect file. It stored spike waveforms through a workaround column, wrote null object references that breakpynwb'sto_dataframe, used a 1-basedidx_startfor its trial timeseries references (off by one for any schema-aware reader), stored the ElectricalSeries data in the wrong dimension order, and stepped through the sections in an order that made the trials table hard to follow.Solution — Rework the tutorial to use current MatNWB idioms and produce a schema-faithful,
pynwb-interoperable file, with a section order and prose that read cleanly top to bottom.What changed
waveformscolumn pluswaveform_mean/waveform_sd, built with the newaddDoublyRaggedArrayhelper — noSpikeEventSeriesworkaround.addRaggedArray, so trials without raw data simply have no reference instead of a null one (the previous null references brokepynwb'sto_dataframe).DeviceModel+Device.ObjectView/SoftLinkrather than hand-written HDF5 paths.idx_startfor trial timeseries references is now 0-basedstarting_timeandstarting_time_rateinstead of timestamps forElectricalSeries;ElectricalSeriesdata is written as channels × time; time-unit names are normalized to NWB's plural form (e.g.seconds).toTable(); the file is checked withinspectNwbFileat the end.basicUsage.mlxupdated (it depends onconvertTrials)Implementation notes
waveformsshortcut form (data{unit} = [numSpikes x numSamples]) assumes one electrode per unit, which holds for ALM-3; the tutorial documents the nesteddata{unit}{spike} = [numElectrodes x numSamples]form for the multi-electrode case.addRaggedArray/addDoublyRaggedArraymethods andutil.create_doubly_indexed_columnfrom feat(dynamictable): add ragged and doubly-ragged array column helpers #855.How to test
Requires the CRCNS ALM-3 dataset (see the links at the top of the tutorial). With
CRCNS_ALM3_ROOT_PATHpointing at the downloaded data, run the tutorial end to end:It exports
out/ANM255201_20141124.nwband finishes withinspectNwbFile. As a cross-check, the trials and units tables should read cleanly in pynwb, includingto_dataframe().Current tutorial: https://matnwb--852.org.readthedocs.build/en/852/pages/tutorials/convertTrials.html
New Tutorial: https://matnwb--857.org.readthedocs.build/en/857/pages/tutorials/convertTrials.html
Checklist
fix #XXwhereXXis the issue number?🤖 Generated with Claude Code