Skip to content

docs(tutorials): rework convertTrials tutorial (ragged-array API, correctness fixes, reordered flow) - #857

Open
ehennestad wants to merge 11 commits into
add-ragged-array-methodsfrom
update-convert-trials-tutorial
Open

ehennestad wants to merge 11 commits into
add-ragged-array-methodsfrom
update-convert-trials-tutorial

Conversation

@ehennestad

@ehennestad ehennestad commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #855.

Motivation

Reworks the convertTrials tutorial to use the ragged-array methods from #855 and fixes errors in the file it writes, such as a 1-based idx_start and ElectricalSeries data in the wrong dimension order.

Problem — For someone learning trial-based conversion from the convertTrials tutorial, 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 break pynwb's to_dataframe, used a 1-based idx_start for 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

  • Spike data now uses the standard Units-table columns: a doubly-ragged waveforms column plus waveform_mean / waveform_sd, built with the new addDoublyRaggedArray helper — no SpikeEventSeries workaround.
  • Raw per-trial voltage traces are linked from the trials table with addRaggedArray, so trials without raw data simply have no reference instead of a null one (the previous null references broke pynwb's to_dataframe).
  • Devices are modeled with DeviceModel + Device.
  • All cross-references use object-based ObjectView / SoftLink rather than hand-written HDF5 paths.
  • Correctness fixes in the exported file: idx_start for trial timeseries references is now 0-based
  • Use starting_time and starting_time_rate instead of timestamps for an ElectricalSeries whose sampling is regular; a series with irregular sampling keeps timestamps
  • ElectricalSeries data is written as channels × time; time-unit names are normalized to NWB's plural form (e.g. seconds).
  • Sections reordered for flow (trials table → trial-aligned timeseries references → units → raw acquisition), prose rewritten, and the trials table is displayed with toTable(); the file is checked with inspectNwbFile at the end.
  • basicUsage.mlx updated (it depends on convertTrials)
  • Each per-trial ElectricalSeries owns its own electrodes DynamicTableRegion. A neurodata object has one location in the file, so a region shared across the series was exported as copies with a warning per trial.
  • The plain script tutorials/convertTrials.m is removed; the live script replaces it. The tutorial test skips convertTrials.mlx, which needs the ALM-3 dataset, and the ecephys tutorial's link now points at the live script.
  • matnwb_exportTutorials skips convertTrials in a default export, because it needs the ALM-3 dataset. It also turns the recycle bin off while it exports (recycle('off')) and restores the setting afterwards.
  • ecephys.html is exported again in full from MATLAB R2024b, so its diff also holds changed styling and outputs, such as nwb_version: '2.11.0'.
Implementation notes
  • Each unit's waveforms are passed in the orientation of the waveforms column's data: samples down the rows, one waveform per column. The shortcut form (data{unit} = [numSamples x numSpikes]) assumes one electrode per unit, which holds for ALM-3. The tutorial documents the multi-electrode forms, data{unit}{spike} = [numSamples x numElectrodes] or one [numSamples x numElectrodes x numSpikes] array per unit.
  • Depends on the addRaggedArray / addDoublyRaggedArray methods and util.create_indexed_column from feat(dynamictable): add addRaggedArray for ragged and doubly ragged columns #855.

How to test

Requires the CRCNS ALM-3 dataset (see the links at the top of the tutorial). With CRCNS_ALM3_ROOT_PATH pointing at the downloaded data, run the tutorial end to end:

run('tutorials/convertTrials.mlx')   % or open and run the live script

It exports out/ANM255201_20141124.nwb and finishes with inspectNwbFile. As a cross-check, the trials and units tables should read cleanly in pynwb, including to_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

  • Have you ensured the PR description clearly describes the problem and solutions?
  • Have you checked to ensure that there aren't other open or previously closed Pull Requests for the same change?
  • If this PR fixes an issue, is the first line of the PR description fix #XX where XX is the issue number?

🤖 Generated with Claude Code

@ehennestad ehennestad added the topic: docs related to documentation label Sep 27, 2026
@ehennestad
ehennestad force-pushed the update-convert-trials-tutorial branch from 12cd0e9 to 3d7e427 Compare September 28, 2026 20:56
@ehennestad
ehennestad added this pull request to stack #893 September 28, 2026 20:56
@ehennestad
ehennestad force-pushed the update-convert-trials-tutorial branch from 3d7e427 to ff60f8e Compare October 1, 2026 09:30
@ehennestad
ehennestad force-pushed the update-convert-trials-tutorial branch 2 times, most recently from da3b863 to e487874 Compare October 1, 2026 15:01
@ehennestad
ehennestad marked this pull request as ready for review October 1, 2026 18:32
@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.51%. Comparing base (0ae6b7f) to head (f3038b8).

Additional details and impacted files
@@                    Coverage Diff                    @@
##           add-ragged-array-methods     #857   +/-   ##
=========================================================
  Coverage                     95.51%   95.51%           
=========================================================
  Files                           241      241           
  Lines                          9033     9033           
=========================================================
  Hits                           8628     8628           
  Misses                          405      405           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ehennestad
ehennestad force-pushed the update-convert-trials-tutorial branch 2 times, most recently from 3bddef0 to 294f9c3 Compare October 6, 2026 15:33
@ehennestad ehennestad added this to the v2.12.0 milestone Oct 7, 2026
@ehennestad
ehennestad force-pushed the update-convert-trials-tutorial branch from fce94f0 to 2e9101c Compare November 12, 2026 13:38
@ehennestad ehennestad mentioned this pull request Nov 12, 2026
2 of 3 tasks
ehennestad and others added 11 commits November 13, 2026 09:17
Update the convertTrials live script tutorial.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The tutorial now lives in convertTrials.mlx, so the plain script goes.
The tutorial test skips the live script because it needs the CRCNS
ALM-3 dataset.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
convertTrials is a live script, so matnwb_exportTutorials selects it
with the other tutorials. It needs the CRCNS ALM-3 dataset and stops
at its dataset check without it. The default IgnoreFiles now lists
it, next to basicUsage, which reads the file convertTrials writes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ehennestad
ehennestad force-pushed the update-convert-trials-tutorial branch from 2e9101c to f3038b8 Compare November 13, 2026 08:17

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: docs related to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant