Skip to content

feat: resolve and join iEEG contacts (IS-C1) - #548

Merged
neuromechanist merged 10 commits into
feature/issue-537-epic-spatialfrom
feat/is-c1-contacts
Nov 18, 2026
Merged

neuromechanist merged 10 commits into
feature/issue-537-epic-spatialfrom
feat/is-c1-contacts

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Card IS-C1 of the iEEG spatial plan: one pure module that, for an iEEG recording, resolves the dataset's own _electrodes.tsv and _coordsystem.json files through the data plane and returns the recording's contacts.

  • src/lib/ieeg-spatial/geometry.ts
    • resolveRecordingGeometry({ datasetId, version, recording, listDir, readText }) walks the recording's directory and every ancestor to the dataset root, applies BIDS inheritance per space (a file applies when every entity except space equals the recording's; deepest directory wins, then most entities; a tie is ambiguous), pairs a coordsystem only with an equal space (both absent counts as equal), and returns every space, ordered by name, none preferred.
    • Frames are template (case-insensitive match to the BIDS appendix table, canonical spelling and caseNormalized), native (ACPC, ScanRAS), described (Other, description verbatim), pixels, or unknown (with a why). No description, prefix or partial match promotes a frame.
    • Units m, cm, mm scale to millimeters; n/a, absent or anything else leaves values as written and unitsDeclared: false. Nothing is inferred from magnitudes.
    • Reasons are the closed set no_electrodes_file, no_coordinates, all_zero, unreadable, no_coordsystem, ambiguous, listing_failed.
    • joinChannels(space, labels): exact name first, then A-B / A - B when exactly one - split names two contacts (position at the midpoint, marked bipolar); otherwise unlocated with a cause. No case folding, no prefix.
    • dataPlaneSource(id, version) is the production listDir (the real fetchDirListing) and readText.
  • test/fixtures/ieeg-geometry/: 119 real files and directory listings from 19 public datasets plus one pinned BIDS appendix file, byte for byte, 369 KB of content (about 780 KB of disk blocks), with SOURCES.json (dataset, version, path, URL, bytes, SHA-256); the pinned BIDS appendix entry also carries its license note (CC-BY-4.0, source URL and commit).
  • src/lib/ieeg-spatial/geometry.test.ts: 51 tests.

Gates (final head, after review round 1)

  • bun install --frozen-lockfile: Checked 416 installs across 568 packages (no changes).
  • bun run test src/lib/ieeg-spatial: Test Files 2 passed (2), Tests 72 passed (72) (51 here, 21 from IS-M1).
  • bun run test: Test Files 177 passed | 3 skipped (180), Tests 5037 passed | 14 skipped (5051).
  • bun run lint: Checked 423 files in 190ms. No fixes applied.
  • bun run typecheck: Result (490 files): 0 errors, 0 warnings, 19 hints (same hints as the base).
  • Leak check (three commands) on geometry.ts, geometry.test.ts and SOURCES.json: nothing printed.
  • Mutation checks (each mutation applied to one line of geometry.ts, tests rerun, then reverted; git status --porcelain clean afterwards): 25 mutations, none survived, rerun on the merged head. Card tests 1 to 7: space compared with the recording's entities (34 fail), n/a as 0 (5), unit scale dropped (1), case-sensitive template compare (2), prefix accepted (1), Other mapped to a template (4), bipolar joined by the first name only (4), no_electrodes_file on a failed listing (4). Review round 1: deleting the exact-name duplicate_contact return, the pair duplicate_contact return, or the ambiguous_pair return each fails the new join test (1 each). Also killed: coordsystem paired across spaces, entities ignored, tie broken silently, depth reversed, entity count reversed, root not walked, all_zero dropped, header untrimmed, exact join skipped, no_position treated as located, unnamed rows kept, non-200 read returning its body, a changed fixture byte, an unlisted fixture file.
  • The epic tip 366e4d4 (IS-M1) is merged into this branch.

Not run, would check

  • CI on this PR: every job green on the final head, because the manager reads gh pr checks.
  • The data-plane adapter was exercised over local HTTP servers (status 200, 404, 500, refused connection) with real bytes; a live read of the production data plane was not part of the tests.

Deviations and findings

  • Passed stop condition, accepted by the owner's driver. The card's stop condition says to stop when a fixture dataset's files disagree with the census facts. Test 1 as written asks for both spaces of one on005522 recording. In on005522 each subject has one space (MNI152NLin6ASym for 91 directories, Talairach for 3), never two in one directory. The per-subject pairing is tested on on005522; the both-spaces case uses real recordings that do have two: nm000485 (Other and Talairach), on004473 (ACPC and ScanRAS), on004457 (spaceless and ACPC), on006253 (session-level fsaverage plus a subject-level space-mni file with no coordsystem).
  • Test 4 names mni and MNI as declared labels. Of the 5,845 readable raw-tree coordsystem files in the 164 public iEEG datasets whose manifest could be read, none declares an iEEGCoordinateSystem of mni, MNI or MNI152; those occur only as space entities (nm000405, on003374, on006253) and the files declare Other or no coordsystem. So nm000405 is unknown through the entity mismatch rule, and the prefix mutation is proven on a known-answer label table (mni, MNI, MNI152, MNI152NLin6, ...).
  • Hand-written inputs, labeled as known-answer inputs in the tests: names-only listings (no file content) for the ambiguous branch and the depth and entity-count precedence rules, and contact rows built from real on005522 contacts for the duplicate_contact and ambiguous_pair joins. No public data reaches any of these.
  • no_coordsystem never withholds contacts. The plan counts the 8 datasets with an electrodes file and no coordsystem among the 97 with usable coordinates, so such a space is shown in its own frame with undeclared units and carries the word as frame.why.
  • Branch name is feat/is-c1-contacts as the manager gave it (the card says feature/is-c1-ieeg-geometry).
  • The tests were written after the module, not before; each test was proven by mutation instead.

Patch notes for other owners

For IS-V1 (the panel):

  • A contact at 0 0 0 inside a file that also has real rows is returned at the origin, as written. Only a file whose every located row is at the origin is all_zero (the card's rule; documented in the module header). Real files do this (on005670, on006890); the panel may treat origin placements as suspect.
  • unreadable covers a transient read failure (HTTP 500, network error, abort) and a malformed file alike; listing_failed may be transient too. There is no retry and no size cap on reads. Do not cache either as permanent; offer a retry. The data plane has answered 500 intermittently to sidecar reads.
  • Show millimeters only when units.unit === "mm". Unit null (58 datasets) is labeled "as written", with no scale claim. Pixels frames carry unit "pixels".
  • Word each space's refusal separately, and never auto-pick the first space: the order is by space value, not a recommendation.
  • A described frame carries its description verbatim. An unknown frame through space_mismatch loses the native label, so show both declared and spaceEntity.
  • Check signal.aborted before rendering a result.
  • Use the join result's cause and contacts; never re-implement joins.
  • on004100 declares fsaverage in meters but its values are millimeter-sized (17.7791 for one contact); the declared unit decides, so those contacts land 1000 times too far out. A "far outside a head" warning belongs in the panel; this module does not infer.
  • on005522 writes -999 in size; it is returned as size: null (an area cannot be negative).

Other:

  • The deprecated spellings the appendix lists apart (fsaverage3 to fsaverage6, UNCInfant0V21 and kin) are unknown.
  • Frame axes are not reoriented; contacts are in the declared frame as written.
  • The AGENTS.md architecture map has no src/lib/ieeg-spatial/ entry; that edit is outside this card's scope.

Card: IS-C1.
Part of #537

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Deploying nemar-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7d3a020
Status: ✅  Deploy successful!
Preview URL: https://681fd74f.nemar-website.pages.dev
Branch Preview URL: https://feat-is-c1-contacts.nemar-website.pages.dev

View logs

@neuromechanist
neuromechanist merged commit f320f1f into feature/issue-537-epic-spatial Nov 18, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feat/is-c1-contacts branch November 18, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant