Repository navigation
Teach NEMAR's assistant and notebook a power spectrum and an ERP image - #483
Merged
Merged
Conversation
Contributor
Preview Deployment
This preview will be updated automatically when you push new commits. |
neuromechanist
added a commit
that referenced
this pull request
Sep 24, 2026
np.convolve is one-dimensional and an even tap count shifts the signal by half a sample, so the prompt now says to filter the plotted channel (or loop), with an odd tap count it gives as code. It says to read every channel of the group for these analyses, and to offer the power spectrum when a recording has no events that name conditions. EOG and ECG are spelled out. Review findings on #483. Tested: pytest tests/test_assistants and tests/test_core/test_config (690 passed); the recipe as now written is the one the OSC docs' chat example runs, which reproduces the page's -4.2 uV.
neuromechanist
added a commit
that referenced
this pull request
Sep 24, 2026
The spectrum cell stops with a message on a recording with no samples, which the index contract allows. The notebook and the changelog spell out ERP, EOG, ECG and EMG. Review findings on #483. Tested: the cells in CPython on nm000103 and xx099906; the notebook e2e check in both environments.
neuromechanist
added a commit
that referenced
this pull request
Sep 24, 2026
The figure check allowed a plotting cell that silently drew nothing, as long as another cell drew one. It now requires exactly one figure from each of the starter's two plotting cells. Review finding on #483. Tested: bun notebook/e2e-check.js --environment production and develop (all checks pass, figures per code cell [0,0,1,1]).
Member
Author
Review responseOne Sonnet review, which also checked the signal processing with scripts. Every finding is fixed.
Gates:
|
JupyterLab renders only the cells in view, so once a starter is longer than the viewport the read cell's output leaves the DOM and the check timed out. The read line, the figure count and any error now come from the notebook model; the figure check allows one figure per cell rather than one in all, and an error names its cell, type and message. Tested: bun notebook/e2e-check.js --environment production and develop (all checks pass); before the fix, a longer starter timed out on the read line, and a SciPy error in an off-screen cell was invisible to the old Traceback search.
A prompt section on Welch's method, filtering and epoching in numpy (the chat runtime has no SciPy), and on finding a dataset's conditions from nemar_get_events' columns_summary before asking for them with where and columns, with ERP CORE's N170 as the worked example. The dataset-page questions offer the power spectrum and an ERP image first. The widget test's templates are relabeled as a fixture, not NEMAR's list. Tested: pytest tests/test_assistants and tests/test_core/test_config; bun frontend/test-widget-dataset-questions.js (64 passed); the worked example's numbers come from running it on nm000132.
The last cell reads the first two minutes of the recording and plots each channel's spectrum and their median, with SciPy, leaving out EOG, ECG and EMG channels by name. It takes Welch's periodograms one segment at a time: scipy.signal.welch's strided view of every segment at once overflows the browser's 32-bit Python on a long multichannel read. It links to NEMAR's worked examples for more. Tested: the notebook e2e check in both environments; the cells in CPython on nm000132, nm000103, xx099903 (EMG, 259 channels at 1000 Hz), xx099904 and xx099906; the segment-wise average matches scipy.signal.welch to 1e-15.
np.convolve is one-dimensional and an even tap count shifts the signal by half a sample, so the prompt now says to filter the plotted channel (or loop), with an odd tap count it gives as code. It says to read every channel of the group for these analyses, and to offer the power spectrum when a recording has no events that name conditions. EOG and ECG are spelled out. Review findings on #483. Tested: pytest tests/test_assistants and tests/test_core/test_config (690 passed); the recipe as now written is the one the OSC docs' chat example runs, which reproduces the page's -4.2 uV.
The spectrum cell stops with a message on a recording with no samples, which the index contract allows. The notebook and the changelog spell out ERP, EOG, ECG and EMG. Review findings on #483. Tested: the cells in CPython on nm000103 and xx099906; the notebook e2e check in both environments.
The figure check allowed a plotting cell that silently drew nothing, as long as another cell drew one. It now requires exactly one figure from each of the starter's two plotting cells. Review finding on #483. Tested: bun notebook/e2e-check.js --environment production and develop (all checks pass, figures per code cell [0,0,1,1]).
neuromechanist
force-pushed
the
feature/nemar-erp-core-examples
branch
from
September 24, 2026 18:12
820b764 to
cbd0dca
Compare
This was referenced Sep 24, 2026
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.
What changed
NEMAR's assistant now covers the two analyses a reader asks for first: a power spectrum of a recording's EEG channels, and an ERP image of its conditions. Its notebook starter ends with the power spectrum for any recording. ERP CORE (nm000132) is the worked example; the full walkthrough lives in the documentation (nemarOrg/docs#43, and the OSC documentation).
The chat (
src/assistants/nemar/config.yaml)A prompt section, "Spectra, events and ERP images", under "Running code in the reader's browser". It covers:
window.labels;nemar_get_events'columns_summary, then asking for only those rows withwhereandcolumns;It is generic on purpose: BIDS names conditions in
trial_type, and datasets also usevalueor their own columns (ERP CORE's faces are inevent_type). It also says what to do against an MCP server that predates the filters: the answer has nocolumns_summary, the filters are ignored, and every row comes back.The dataset-page questions offer the power spectrum and an ERP image second and third.
The notebook (
src/assistants/nemar/notebook/starter.ipynb)scipy.signal.welchbuilds a strided view of every segment at once, whose nominal size overflows Pyodide's 32-bit address space on a long multichannel read (ValueError: array is too big, reproduced in Pyodide 0.29.5 at 129 channels by 30,000 samples). The segment-wise average matcheswelchto 1e-15.The notebook check (
notebook/e2e-check.js)welchfailure above surfaced; the old search of the page's text for "Traceback" could not see it in an off-screen cell.Tested
bun notebook/e2e-check.js --environment productionand--environment develop: all checks pass, with one figure each from the read cell and the spectrum cell and no errors.tests/test_assistants,tests/test_scripts/test_build_notebook_site.pyandtests/test_core/test_config(746 passed);bun frontend/test-widget-dataset-questions.js(64 passed); nbformat validation.Depends on
The chat's filters need nemarOrg/nemar-cli#1501, and nm000132's events need nemarOrg/nemar-cli#1499 (merged into dev). Both reach mcp.nemar.org with nemar-cli's next release. Until then, production's
get_eventsdeclines nm000132 and ignores the filters, and the prompt accounts for that.