Repository navigation
Add the plot tier to eegprep-lean - #409
Merged
Merged
Conversation
The network tier checks conformance to a contract another team serves at zarr.nemar.org, so it fails on an outage there as readily as on a real divergence. That is not a reason to turn an unrelated pull request red, so it runs daily rather than on pull requests, where a failure means the contract and this reader have diverged. test.yml already claimed a scheduled job covered this tier. It did not exist, so until now the contract tests ran nowhere.
plot_window draws a window as stacked traces with the first channel at
the top, and to_png renders the figure to bytes.
Three things are deliberate. Nothing imports matplotlib.pyplot: pyplot
selects a backend when imported and in a browser that backend wants the
DOM, so this uses the Figure API, and a subprocess test asserts pyplot
stays unimported because that failure is invisible natively. The y-axis
carries no unit, because the array declares scale and offset but not
what they produce; amplitude is stated as a scale bar instead. Traces
are demeaned for display, since level-0 channels sit at per-channel
offsets in the thousands that differ by more than the signal spans.
Default spacing follows the median channel amplitude rather than the
largest, so one high-amplitude channel overlaps its neighbors instead of
flattening every other channel to an unreadable line.
window.py now imports zarr inside read_window rather than at module
scope, so the plot tier installs and runs on its own. CI exercises each
extra separately for that reason.
The README install table credited the base install with reading a window
of data, which needs the zarr extra. Corrected, along with why zarr is an
extra rather than a base dependency as ADR 0069 has it: a declared zarr
makes micropip.install("eegprep-lean") fail outright, because zarr
installs under Pyodide only with deps=False.
Contributor
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, reopen this pull request to trigger a review.
Contributor
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
The lazy loader caught every ImportError and reported it as the extra not being installed. An ImportError raised from inside store.py or plot.py looks identical from outside, so a bug in either would tell the reader to install something they already have while the real error stayed buried in the cause. It now checks ImportError.name against the packages the extra actually installs and re-raises anything else untouched. Covered in test_index.py, which runs in the base tier, with errors the interpreter really raised rather than constructed stand-ins.
The unit is on the channel group, not on the level-0 array. Reading only the array, which carries scale, offset and physical_formula but not the unit they produce, led this package to state that units were unknowable and to label channels by index. Both were wrong: nm000103 names its channels E1..E129 and declares them in uV, one document up. The same document says level 0 is not always the rate the recording was acquired at. The store resamples it to min(native rate, modality cap), 250 Hz for electroencephalography, so nm000103 was recorded at 500 Hz and arrives here at 250. A reader that reported only rate let a caller believe they held the recording as acquired. channels.py is base tier, stdlib only, so a session can learn what a recording's channels are called and what they are measured in without installing zarr or numpy. A Window now carries labels, unit and original_rate; a window reports a unit only when every channel in it agrees on one, because the store contract says to read the unit from the channel and magnetoencephalography is a Tesla-based unit, not a voltage. Stored counts never carry the unit, since they are not in it. Also from review: - read_window imports zarr inside its own body, which put its failure past the lazy loader in __init__ and gave a bare ModuleNotFoundError where every other name explains itself. The hint tables moved to extras.py so both paths give the same message. - The extras table is now checked against a literal map rather than against itself, after a remapping mutation agreed with its own expectation. - Covered the ax= parameter, the shape guard, the scale bar's position, the axis limits and the title, each of which survived a mutation. - test.yml gains a both-extras offline tier, which TestExtras's docstring already claimed existed.
The install table credits the base with reading the channel list, and nothing showed how. read_group_metadata is what does it, and it needs no extra.
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.
Draws what the reader reads, and corrects two things the reader was getting wrong.
The correction that matters
This package previously stated that physical units are not knowable and labeled channels by index. Both were wrong, and the mistake was reading the level-0 array, which carries
scale,offsetandphysical_formulabut not the unit they produce. The unit is one document up, on the channel group.nm000103names its channelsE1..E129and declares them inuV.The same document says something else worth knowing: level 0 is not always the rate the recording was acquired at. The store resamples level 0 to
min(native rate, modality cap), 250 Hz for electroencephalography, sonm000103was recorded at 500 Hz and arrives here at 250. A reader reporting onlyratelets a caller believe they hold the recording as acquired.So
channels.pyis new, base tier and standard library only: a session can learn what a recording's channels are called and what they are measured in without installing zarr or numpy. AWindownow carrieslabels,unitandoriginal_rate.A window reports a unit only when every channel in it agrees on one, because the store contract says to read the unit from the channel rather than the modality, and magnetoencephalography is a Tesla-based unit, not a voltage. Stored counts never carry the unit, because they are not in it.
The plot
plot_windowstacks traces with the first channel at the top;to_pngrenders to bytes. Behind theplotextra.Nothing imports
matplotlib.pyplot. pyplot selects a backend when imported, and in a browser that backend wants the DOM. TheFigureAPI needs none, and bytes are what the browser case wants anyway. A subprocess test asserts pyplot stays unimported, because that failure is invisible natively and fatal in Pyodide.Traces are demeaned for display. Level-0 channels on
nm000103sit at offsets of -16250, -25999 and -28396, differing by more than the signal spans, so without it every trace is a flat line at its own level. It never touches the window, anddemean=Falsedraws values as they are. Demeaning, not detrending.Default spacing follows the median channel amplitude, not the largest. One high-amplitude channel is ordinary in raw EEG, and scaling to it flattens everything else to an unreadable line.
Tiers stand alone
window.pyimports zarr insideread_window, so[plot]installs and works without[zarr]. CI runs four offline tiers, and the base tier caught a real bug while this was written: a module-scopenumpyimport in a new test file made it fail collection instead of skip.[zarr][plot]Live tier: 7 passed against
zarr.nemar.org.Review findings, all addressed
read_windowlost its friendly error. Deferring the zarr import moved its failure past the lazy loader in__init__, so it raised a bareModuleNotFoundErrorwhere every other name explains itself. Hint tables moved toextras.pyso both paths give the same message.ax=parameter, the shape guard, the scale bar's position (height alone did not pin it; a bar drawn above the top trace is the same height), the axis limits, and the title contents.test.ymlgained a both-extras offline tier, whichTestExtras's docstring already claimed existed.[zarr,preprocess]. ADR 0069 measured cumulatively, so that figure includes matplotlib; the row is now[zarr,plot,preprocess]and says[zarr,preprocess]alone has not been measured.FALLBACK_SPACINGcomment said "every channel is flat" when the rule triggers on the median.The scheduled job that was claimed but missing
test.ymlsaid the network tier was "covered by the scheduled live job". No such job existed, so the contract tests ran nowhere.lean-live.ymladds it, daily and on dispatch, deliberately not on pull requests: those tests fail on an outage atzarr.nemar.orgas readily as on a real divergence.A divergence from ADR 0069
The install table credited the bare install with "read a window of data", which needs the
zarrextra. ADR 0069's table puts zarr in the base, and the implementation cannot follow it: zarr installs under Pyodide only withdeps=False, so a declared zarr makesmicropip.install("eegprep-lean")fail outright. Recorded in nemarOrg/nemar-cli#1468.Verification
Twenty mutations applied one at a time, each caught. One survives offline and is covered in the live tier only:
unitcarried onto stored counts, which onlyread_windowcomposes and nothing offline exercises, because that needs a real sharded zarr store. Worth closing with a local store served over loopback; not in this PR.