Repository navigation
[eegprep-lean] Set chanlocs type from the Zarr group's channel_type - #669
Conversation
read_window carries each channel's channel_type as Window.types, and to_eeg writes it to chanlocs[i]["type"], so selecting channels by type excludes ECG, EOG and others stored in the EEG group. Fixes #668 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
A Zarr channel with no channel_type is EEG, and neighbors that declare a type keep it. to_mne_raw maps those types onto MNE's own channel types and sends a type MNE does not have to misc. Co-authored-by: Suraj Ranganath <[email protected]>
A blank, n/a, or nan channel_type is stored as '' so chanlocs.type stays missing. to_mne_raw is the place that treats that empty type as eeg. Co-authored-by: Suraj Ranganath <[email protected]>
Interim until sccn/eegprep#669: nemar-ica's Zarr read types each chanlocs row from the store's group metadata, row by row; decomposition_input records every row's [label, type] and its digest, hashed in the ica step. Tested: serving-input module (32), ICA and Zarr files (151 passed, 1 xfailed).
A JSON null channel_type was stored as the string None. Treat it as untyped before converting to text, and name a Window.types length mismatch from to_eeg. Co-authored-by: Suraj Ranganath <[email protected]>
stored_channel_type(None) is the empty type, matching a null channel_type. to_eeg raises ValueError when a Window.types entry is not text. Co-authored-by: Suraj Ranganath <[email protected]>
|
claude review this |
Every Zarr read types each chanlocs row as its store states it (interim until sccn/eegprep#669), so nemar-floor leaves a typed ECG row out of its signal channels as on the dataset directory. Tested; revert-checked.
Code review
BlockingNone. ImportantNone. NitsNone. Test gapsNone. EEGLAB parity notesNone. An untyped channel is stored as Checked for correctness bugs, EEGLAB parity, data structure compatibility, changed-behavior tests, and CLAUDE.md/AGENTS.md compliance. |
Brings the post-#681 Claude review workflow onto this pull request. Co-authored-by: Suraj Ranganath <[email protected]>
HEOG and VEOG become eog, TRIG becomes stim, TEMP becomes temperature, and the NIRS names follow the same table. An empty chanlocs.type is not selected as EEG. Co-authored-by: Suraj Ranganath <[email protected]>
|
🤖 to_mne_raw now follows the MNE-BIDS channel-type map. HEOG and VEOG become eog, TRIG becomes stim, TEMP becomes temperature, and the NIRS names become fnirs_cw_amplitude, fnirs_od, hbo, and hbr. A name still outside that set, such as EKG, stays misc, so an EEG pick still leaves it out while create_eog_epochs, pick('eog') and find_events can see the aliased channels. The README and changelog no longer say an empty chanlocs.type counts as EEG: eeg_decodechan matches exactly, so pop_select(eeg, chantype=["EEG"]) does not pick it. |
|
claude review this |
Line noise is a conditional 50/60 Hz band-stop until ZapLine-plus parity is measured; ASR repairs bursts only and reports asrBurstFraction (sccn/eegprep#684); channel types kept per row and keyed (sccn/eegprep#669, #2344); a view refuses rather than mislead; neuroschema 0.6.0 marked in preparation (nemarOrg/neuroschema#21), montage licensing stays a release precondition. Tested: adr-index test.
* Add ADR 0137: quality views drawn in browser Views are declared data the browser draws; no figure image is stored. Folds in the decisions on activations, electrode positions inferred from names, the public derivative, spectrum parameters, metric names and the plan hash. Indexed in both README lists. Tested: bun test test/adr-index.unit.test.ts. * Mark ADR 0134 partially superseded by 0137 Adds the pointer under ADR 0134's header and a note on its index line; the rest of 0134 is unchanged. Tested: bun test test/adr-index.unit.test.ts. * Fold PZ, sensor-labels and digest into ADR 0137 Activations reproduce the Zarr decomposition input exactly (store-content rounding, unit, average reference) with the 1 Hz high-pass as a display filter; positions from names are nemar.sensor-labels.v1 with stated defaults and refusal reasons; a store content_sha256 is null only for profile archive. Tested: adr-index and docs-links tests. * Address review round 1 on ADR 0137 Spectrum bound, archive-only null digest, homes rows named, supersession scope aligned across headers and index, file sizes and caps, first product-file route, anonymity gate, layout-role frame fields, converter follow-up #2343, README status date. Tested: adr-index and docs-links tests. * Revise ADR 0137 decomposition and activations The decomposition always reads preprocessed data (high-pass, line-noise removal, ASR cutoff 30, bad channels removed) on Zarr and BIDS inputs; activations are one browser multiply by the folded unmixing, sphere and average-reference matrices and approximate the decomposition input by design. Adds the raw-input alternative with the fixture numbers and the sccn/eegprep#668 limitation. Tested: adr-index and docs-links tests. * Align ADR 0137 with owner decisions for merge Line noise is a conditional 50/60 Hz band-stop until ZapLine-plus parity is measured; ASR repairs bursts only and reports asrBurstFraction (sccn/eegprep#684); channel types kept per row and keyed (sccn/eegprep#669, #2344); a view refuses rather than mislead; neuroschema 0.6.0 marked in preparation (nemarOrg/neuroschema#21), montage licensing stays a release precondition. Tested: adr-index test. * Name the bad-segment table in ADR 0137 rule Decision 1 and the README load-bearing line: an activation or signal-window view that has no bad-segment table says so on the page. Tested: adr-index and docs-links tests.
* Keep level-0 counts on the Zarr read ZarrSource.load(keep_counts=True) keeps the store's int16 counts, read-only, with the array's conversion; the bound counts them and a level 0 that is not int16 is refused before its signal. Tested by test_nemar_ica_serving_input.py. * Decompose the serving copy as stored On the Zarr input nemar-ica fits the floor's good channels as stored (store rounding, microvolts, average reference), skips ASR as serving_input and records decomposition_input; the BIDS path is unchanged. Tested by test_nemar_ica_serving_input.py and test_nemar_ica.py. * Test the serving decomposition input The 1e-12 C9 identity, bit-for-bit rows, the content digest, the floor's good channels in store order, the ASR skip, the int16 guards and the two inputs' plan hashes; stand-in stores get per-channel scale, offset and dtype. 17 + targeted recipe files pass. * Document the decomposition input docs/recipes.md: the two inputs, the record block, the bound, the new failure words and the version rule. * Revert the raw serving-copy input The owner's correction: the decomposition gets the full preprocessing on the Zarr input too. Back to the epic's code for the read, the pipeline, the outputs, their tests and docs. * Set nemar-ica's ASR cutoff to 30 The owner's value (clean_rawdata's BurstCriterion), passed and hashed in place of eegprep's 5; legacy NEMAR used 20. Tested: test_nemar_ica.py ASR state test. * Turn on AMICA's sample rejection do_reject with AMICA's defaults (rejsig 3, rejstart 2, rejint 3, numrej 3; pAMICA's maxrej) on both engines, passed and hashed. Tested: test_nemar_ica.py keyword sets and the binary's parameter file. * Record the input and write browser weights decomposition_input on both inputs (preprocessing steps, channels, unit, reference; the store and its digest on Zarr) and, on Zarr, _servingunmixing.tsv: the unmixing with the average reference and the store unit folded in, plus browser_transform. Tested: test_nemar_ica_serving_input.py (22) and test_nemar_ica.py. * Document the input, the weights and legacy docs/recipes.md: the ASR cutoff and rejection, the rank rule, decomposition_input, the browser matrix and its caveat, the comparison with legacy NEMAR, the untyped-channel limit and the version reasoning. * Let a recipe set the floor's high-pass nemar_floor.steps.Embedding: an embedding recipe may replace clean_drifts by a pop_eegfiltnew FIR high-pass (design recorded) and RANSAC's correlation threshold; the floor keeps its own (golden --check passes). * Let the floor's tables list a recipe's spans write_product(extra_segments=...): spans an embedding recipe removed are rows of _badsegments.tsv and _samplemask.tsv beside the floor's windows; the floor passes none (golden --check passes). * Stop AMICA at convergence or 4000 iterations use_min_dll (1e-9, maxincs 5) and use_grad_norm (1e-7) on at the Fortran defaults for both engines, passed and hashed; --ica-max-iter defaults to 4000. A strict xfail pins that eegprep writes the binary's thresholds as 0.000000. Tested: test_nemar_ica.py. * Cut ASR bursts, legacy filters, BIDS weights nemar-ica: floor with a 0.5 Hz FIR high-pass and RANSAC 0.85; ASR's bursts cut by eegprep's clean_artifacts (spans in the record and the floor's tables); the browser matrix on both inputs, matched by label with an unchecked caption on BIDS. Tested in the next commit. * Test the owner's nemar-ica defaults Burst cut and its parity with the recorded ASR state, the high-pass and threshold (and the floor keeping its own), AMICA's stops, the BIDS matrix and caption. test_nemar_ica_serving_input.py 28 passed; test_nemar_ica.py 89 passed, 1 xfailed. * Document the owner's nemar-ica defaults docs/recipes.md: high-pass, 0.85, burst cut and its records, AMICA's stops and 4000 iterations, the BIDS browser matrix, the legacy table, the binary-threshold bug and the version reasoning. * Keep known non-EEG rows out of ICA Interim until sccn/eegprep#669: nemar-ica's Zarr read types each chanlocs row from the store's group metadata, row by row; decomposition_input records every row's [label, type] and its digest, hashed in the ica step. Tested: serving-input module (32), ICA and Zarr files (151 passed, 1 xfailed). * Document row-by-row channel types docs/recipes.md: the interim typing on nemar-ica's Zarr read, the record's channel_types and digest, the legacy row and the limit. * Turn AMICA's sample rejection off The owner's decision for seed stability: do_reject False on both engines, its schedule still passed and hashed; tests expect no rejection pass and every sample kept. * Bin ICA iterations up to 4000 The cap is 4000, so the iterations histogram gets a 2000-4000 bin; the command test checks the last edge. * Repair ASR bursts and record their share Nothing is cut: asrBurstFraction, the share of samples ASR at cutoff 30 changed (eegprep's own 1e-8 rule, checked against clean_artifacts), is in the ICA facts, summary metrics, recordings table and dataset distribution; the spans stay flagged burst rows (asr_repaired). Tested; revert-checked. * Type Zarr rows on the floor's read too Every Zarr read types each chanlocs row as its store states it (interim until sccn/eegprep#669), so nemar-floor leaves a typed ECG row out of its signal channels as on the dataset directory. Tested; revert-checked. * Cite sccn/eegprep#680 at the binary's xfail * Document the burst share and rejection off asrBurstFraction's meaning (the share ASR at the fixed cutoff 30 repairs, comparable across datasets) and where it is recorded; AMICA's rejection off with its schedule hashed; typed rows on every Zarr read and the floor decision it changes; sccn/eegprep#680 at the binary's stops. * Test the repaired-sample rule directly The fixture's repairs never land between 1e-12 and 1e-3 uV, so a direct test pins eegprep's 1e-8 summed-change rule, a block's edge and the shape guard; the clean_artifacts test now rebuilds its cut exactly. The mask starts at zeros, so a gap cannot read as repaired. Revert-checked (6 mutations). * Add a script that times nemar-ica's fit scripts/measure_ica_time.py fits the recipe's own call on a synthetic long, high-channel input and prints wall time, peak RSS and, on CUDA, torch's peak GPU memory and jobs per GPU by memory; the operator's first-GPU-run steps use it. Smoke-run on the CPU; not run on a GPU. * Say flagged, not removed, for burst rows The floor's badsegments and samplemask descriptions said the recipe removed its spans; nemar-ica now repairs and flags them. The burst test checks the wording; revert-checked. * Clock each iteration in the timing script Two runs' difference was at the mercy of the machine's load; the script now reads the start of each iteration of pAMICA's torch loop and reports median seconds per iteration before and after the Newton start, and the projection to 4000 iterations. Smoke-run on the CPU. * Digest channel types as RFC 8785 JSON channel_types_sha256 is now the SHA-256 of the UTF-8 bytes of {"channel_types": [...]} in RFC 8785 canonical form (neuroschema's nemar.view-digest.v1 form): UTF-16 name order, no ASCII escaping, no final newline. common.determinism.jcs covers strings, arrays, objects, literals and safe integers and refuses the rest. Pinned to three neuroschema vectors (98bb0da) and to a non-ASCII digest computed with JSON.stringify. Revert-checked (10 mutations). * Document the RFC 8785 types digest docs/recipes.md states the canonical form of channel_types_sha256 and points at the vectors test. * Record the CPU thread option, default 1 docs/operator.md: one thread stays the default (bit_reproducible true; the GPU is the main path); --ica-threads N is an option for a CPU run, measured 2.2 times faster at 4 threads, without the reproducibility statement. * Count asrBurstFraction among ICA's metrics The plugin-manifest test pinned nemar-ica's own summary metrics at four; asrBurstFraction (cff6a23) makes five, a name no plugin metric may take. Tested. * Move every layer to 1.0.0-b2 The source release v0.1.1 published every layer at 1.0.0-b1, so the changes since are 1.0.0-b2: nemar-floor (typed Zarr rows), nemar-ica and the common layer. Golden decisions moved to nemar-floor-1.0.0-b2 and regenerated: only recipe.version and plan_hash change. The rule counts a source release as a publication. Needs nemar-cli's registry and progress vectors at 1.0.0-b2 and the progress pin moved first (docs/contracts.md); until then 17 contract, checkpoint and smoke tests fail. * Pin nemar-cli 055731fa for 1.0.0-b2 maps Progress and runner pins move to nemar-cli 055731fa (#2350), whose vectors carry 1.0.0-b2 for nemar-floor and nemar-ica; only the vectors changed. The smoke test's example of an unpinned version is now 1.0.0-b999. Contract tests pass with the drift comparison required. * Run the full e2e pAMICA at the recipe's 4000 The full length reads steps.DEFAULT_MAX_ITER from the source (the module collects without eegprep) and runs pAMICA as the registry does; a runtime-environment test pins the reading to the constant. The amica15 leg is capped at 2000, its stops being inert (sccn/eegprep#680). The image test job's limit is 90 minutes: the last full run bounds the new one near 42. * Say ICA fits the repaired copy, nothing cut docs/recipes.md: the ica row says the fit is on the ASR-repaired, re-referenced copy with nothing cut; the dead burst_mask_inconsistent failure row is gone (nothing emits it since the cut was removed); the Zarr section no longer says the serving copy has no channel types. * Keep channel_types_mismatch as the detail apply_types ran inside the loader's try, whose RecordingError handler re-raised with the code as the detail, so a mismatch was recorded as convert_failed/convert_failed. It now runs after, and a test changes the label eegprep-lean's second metadata read returns for one row and expects convert_failed/channel_types_mismatch. Revert-checked. * Shade only written tables; no placeholder columns browser_transform.shaded names _badsegments.tsv only (seconds; the mask is the archive's grid), null exactly when it was not written (one rule, segment_tables_written). The segment tables' descriptions name only what ran, and spans with neither a mask nor a step are refused instead of owned by 'None'. On a dataset directory, labels that cannot head columns give browser_transform null with browser_transform_reason labels_unusable and no _servingunmixing.tsv. The floor's docstring says when the tables are absent and that _channels.tsv is always written. Tested; revert-checked (8 mutations). * Cite sccn/eegprep#684 for the repaired mask qc.asr_repaired and the qc module's list of gaps cite sccn/eegprep#684 (clean_asr does not return its repaired mask); docs/upstream.md gains nemar-ica's table: #669, #671, #680 and #684, with what the recipe does meanwhile. * Set nemar-ica's RANSAC max_broken_time to 0.5 Embedding gains max_broken_time; nemar-ica passes 0.5, legacy's clean_rawdata default and eegprep's clean_artifacts ChannelCriterionMaxBadTime; recorded in bad_channels' parameters and hashed. nemar-floor keeps 0.4 (golden unchanged). The fixture's decision is the same at 0.4 and 0.5 (19 good). Docs and the legacy table say so. Revert-checked. * Describe asrBurstFraction precisely The share of samples ASR's reconstruction changed, at its update resolution (0.5 s windows, a 50-sample step) and relative to the recording's own calibration; comparable across datasets as the same rule, not as an absolute amount of noise. * Fix stale 2000, do_reject and hash texts The binary's do_reject is written as 0; the pre-check, the E1R paragraph and the fit cost speak of the recipe's 4000 iterations (the binary's leg capped at 2000); docs/unverified.md states the measured CPU fit times; the floor_plan_hash comment says it is not a nemar-floor product's hash. * Smoke-test the ICA timing script 8 channels, 30 seconds, 60 iterations on the CPU: the script must exit 0 and read both per-iteration rates and the projection. Revert-checked: without the iteration clock the rates are null and it fails. * Name the ASR state writer state_text canonical_text only writes _asr.json, whose recorded digest is of the file's bytes; the name and docstring now say so and point at determinism.jcs for value digests (channel_types_sha256). No byte changes.
read_window now carries each channel's channel_type from the group metadata as Window.types, and to_eeg writes it to chanlocs type, so selecting EEG channels by type leaves out ECG, EOG and other channels stored in the EEG group, as on the BIDS path. Adds tests for the read, the dictionary, and pop_select with chantype EEG.
Fixes #668
🤖 Generated with Claude Code
read_window carries each channel's channel_type, and to_eeg writes it to chanlocs type, so selecting EEG channels by type leaves out an ECG or EOG stored in the EEG group. A missing key, JSON null, blank, n/a, or nan type stays ''. EEGLAB keeps an untyped chanlocs.type empty, so pop_select(eeg, chantype=["EEG"]) does not pick it. A declared type is kept. to_mne_raw is where an empty type becomes eeg. Declared types follow MNE's own set, and BIDS names that are not themselves MNE types follow MNE-BIDS: HEOG and VEOG to eog, TRIG to stim, TEMP to temperature, and the NIRS names to fnirs_cw_amplitude, fnirs_od, hbo and hbr. A name still outside that set, such as EKG, becomes misc. ch_types overrides Window.types. A value or a count MNE will not take raises ValueError from to_mne_raw. A Window.types count that does not match the channels, or an entry that is not text, raises ValueError from to_eeg.
Before: GroupMetadata.types on EEG, (no channel_type), ECG returned None, a JSON null became the string None, and to_mne_raw marked EOG, ECG, HEOG and TRIG as eeg or misc.
After: EEG, a missing key, ECG, EOG, n/a and null reads ('EEG', '', 'ECG', 'EOG', '', ''). to_mne_raw of EEG, EOG, ECG returns ['eeg', 'eog', 'ecg']. HEOG, VEOG, TRIG and TEMP return ['eog', 'eog', 'stim', 'temperature'].
Fixes #668