NEMAR-computed iEEG geometry
Many intracranial electroencephalography (iEEG) datasets record where each electrode contact sits, but only in the subject’s own coordinate frame, or in a template frame that is missing or mislabeled. The Brain panel of NEMAR, the Neuroelectromagnetic Data Archive and Tools Resource, can place contacts on a template brain only when a dataset declares a standard template frame (see The iEEG spatial view). Where a dataset already holds what is needed to reach a template frame, NEMAR computes the positions itself, checks them, and commits them to the dataset as ordinary Brain Imaging Data Structure (BIDS) files that say they were computed by NEMAR.
This page explains what those files are, how each is made and verified, how to read their provenance, and what dataset authors can do about them.
This page covers:
- What NEMAR writes, and what it never writes.
- The three methods.
- The checks, in plain words, with their thresholds and their limits.
- Reading a computed file.
- How the files reach a dataset.
- For dataset authors: precedence, replacing, removing and editing.
- Subject surfaces in the Brain panel.
- References.
What NEMAR writes
Section titled “What NEMAR writes”A computed result is a pair of files beside the authors’ own, in millimeters:
sub-01/ieeg/sub-01_space-fsaverage_electrodes.tsvsub-01/ieeg/sub-01_space-fsaverage_coordsystem.jsonThe space- entity names the template.
NEMAR writes only these labels:
fsaverage, for frames referenced to the FreeSurfer average surface, including frames the authors call MNI305 or MNI-305 (Montreal Neurological Institute (MNI) 305 space).IXI549Space, for positions reached through a Statistical Parametric Mapping (SPM) deformation field.- A declared MNI152 variant, for example a near-miss such as
MNI152NLin6ASym, when the positions verify against theMNI152NLin2009cAsymsurface. The file is written under the variant’s own label, not relabeled asMNI152NLin2009cAsym. A subject with several sessions gets one pair per session, with theses-entity in the name as usual.
Two further kinds of file exist.
When a dataset has an electrodes.tsv but no coordsystem.json at all, and the frame is verified, NEMAR adds the missing sidecar for the existing file.
And .nemar/ieeg-geometry.json at the dataset root lists every path the pipeline owns, with the inputs it was computed from (see Reading a computed file).
NEMAR never edits an author’s file.
What is never written
Section titled “What is never written”- Positions of depth contacts from an affine transform. FreeSurfer’s
talairach.xfmis a 12-parameter linear fit with a typical error of 10 to 15 mm at the contacts, which is not worth committing as data. Depth contacts reached only that way are left out, and the report counts them. - The label
MNIwithout a variant, andTalairach. Neither names one template, so a position under either label cannot be checked against one surface. - A new label for a frame that is not a template. A frame declared
ACPC(anterior commissure-posterior commissure space) orScanRAS, or tied to the subject’s own scan throughIntendedFor, is never relabeled as a template. It can only be transformed, and only by a method below that passes its checks. - Anything that fails a check. A candidate that fails is reported and discarded.
The three methods
Section titled “The three methods”Version numbers below follow the NEMAR convention for mirrored datasets: version N.0.0 is the upstream snapshot and version N.0.1 holds NEMAR’s corrections (see How the files reach a dataset).
Labels for contacts already on fsaverage
Section titled “Labels for contacts already on fsaverage”Some datasets list contact positions that sit exactly on vertices of the FreeSurfer average surface (fsaverage), because the authors projected their contacts onto it, but the coordinate-system file is absent or says the frame is native.
Here nothing needs to be transformed, and the positions are copied unchanged into a space-fsaverage pair with the frame named correctly.
NEMAR looks for a candidate label in three places, in order:
the coordinate-system file (including a nearly valid label such as a misspelled one),
the dataset’s descriptions and README,
and finally a blind trial of fsaverage and MNI152NLin2009cAsym with no textual hint.
The authors’ own term, for example “MNI-305”, is kept in iEEGCoordinateSystemDescription.
A template named only in a README or description needs specific evidence, as defined below; with weaker evidence the file goes to a person and nothing is written.
Surface-based registration for cortical contacts
Section titled “Surface-based registration for cortical contacts”When a dataset ships a subject’s FreeSurfer directory, NEMAR carries cortical contacts (electrocorticography (ECoG), grid, strip and surface contacts) to fsaverage through the subject’s own sphere registration.
Each contact within 3.0 mm of the subject’s pial surface is moved to the vertex of the sixth-order fsaverage surface (fsaverage6) that the subject’s registration to the sphere assigns to its nearest pial vertex.
The written positions therefore lie on fsaverage6 vertices by construction.
This is the surface-based registration described by Fischl and colleagues (see References).
FreeSurfer surfaces are in a right-anterior-superior (RAS) frame called tkr RAS, while scanner coordinates differ by a fixed offset called c_ras. NEMAR tests both readings against the subject’s own surface. It keeps the declared frame when it fits, switches only when the other reading fits clearly better, and otherwise refuses the subject as “frame ambiguous” rather than guessing.
Depth contacts are not handled by this method. They are never snapped to the cortical surface.
Deformation inversion for depth contacts
Section titled “Deformation inversion for depth contacts”Some datasets ship a deformation field from the SPM software (a y_ file), which maps the template space to the subject’s scan.
Electrodes sit in the subject’s frame, so NEMAR inverts the field numerically, contact by contact (the residual of the inversion is recorded in the sidecar),
and writes the result as space-IXI549Space, the default template space of SPM12.
This method covers depth contacts (stereo-electroencephalography, sEEG), deep brain stimulation (DBS) contacts and contacts of unknown type.
A file that contains any cortical contact is not handled by this method at all; the cortical contacts belong to the surface method.
The field must lie on SPM12’s template grid (121 by 145 by 121 voxels at 1.5 mm, or a crop of it on the same lattice); any other grid is passed to a person.
An electrodes file is paired with a field only when the file’s IntendedFor names the scan the field was computed from, or, when IntendedFor is absent, when template verification of every candidate file has a clear winner.
A file whose IntendedFor names a different scan is never paired with the field.
The checks
Section titled “The checks”The label and SPM methods check every result against a reference surface of the space it claims, and nothing is written unless the check passes.
The surface method is graded differently: by the contacts’ fit to the subject’s own pial surface plus a registration check (see below), because its fsaverage positions are on fsaverage6 vertices by construction.
The references are the fsaverage6 pial surface and the MNI152NLin2009cAsym tissue shell, both distributed with their licenses.
A check measures, for each contact, the distance to the nearest vertex of the reference surface, and for depth contacts whether the contact lies inside the surface.
The evidence is graded as follows.
| Grade | Applies to | What it means in plain words |
|---|---|---|
| Specific | Cortical contacts with a median distance of at most 2.0 mm from the reference surface, or contacts on template vertices (median at most 1.0 mm) | The positions fit this template and, where the shift control is run, no nearby alternative |
| Plausible | Depth contacts with a median distance of at most 6.0 mm and at least 90 percent of contacts inside the surface or within 5.0 mm of it | The positions are consistent with this template, and not proof of it |
| Fail | Anything else | Nothing is written |
The shift control. For contacts claimed to sit on template vertices with no textual hint, the same contacts shifted by 10 mm along each of the three axes, in both directions, must all fail the test. A shifted copy fails when its median distance is above 1.0 mm and at least 1.5 times the unshifted median. This shows that the match is specific to the position and not a property of any point near the brain.
What is required to write. Specific evidence suffices.
Plausible evidence is written only when independent evidence for the frame exists too:
cortical contacts of the same subject that give specific evidence in the same frame,
a near-miss label in the coordinate-system file that names the target space,
or a transform shipped by the dataset whose own check passed (the SPM field check below).
A template named only in a README or description is not independent evidence; it needs specific evidence, otherwise the file goes to a person.
What the checks cannot show
Section titled “What the checks cannot show”- Depth contacts discriminate frames poorly. In their correct frame, real depth contacts are only about 82 to 89 percent strictly inside the pial surface, because the outer contacts of a shaft sit in bone or cerebrospinal fluid. A frame error of 10 to 20 mm changes the median distance and the inside fraction too little to detect. A depth-contact check is therefore a plausibility check: it catches gross errors such as a wrong file, a sign error or a wrong unit. It does not measure accuracy.
- The MNI shell has no sulci.
For depth contacts checked against the
MNI152NLin2009cAsymshell, the rule is at least 95 percent of contacts inside it and none more than 10.0 mm outside. The median distance is reported but not judged, because the shell is a smooth surface and depth contacts are deep in the folds. - The SPM field check excludes only errors of roughly 10 mm or more.
Before an SPM field is trusted, at least 2,000 sampled vertices of the subject’s own pial surface are mapped through the inverted field.
Their median distance to the template shell must be at most 6.0 mm (10th percentile at most 2.0 mm).
The mapped surface’s centroid must be within 10 mm of the shell’s and each axis extent within 10 percent, compared against the cerebrum only (the shell is cut at z of -40 mm, because it also includes cerebellum and brainstem).
This catches a reversed or grossly wrong field, and larger errors along most axes.
A 5 mm to 10 mm error along the anterior-posterior axis can pass.
The check proves a field’s direction, not which subject or electrodes file it belongs to; that pairing comes from
IntendedFornaming the field’s scan, or a clear template-verification winner (see Deformation inversion). - The registration check for the surface method is of the same kind. It tests that the subject’s sampled surface lands in the right place, with the right extent and side, and that an affine fit to its mapped positions leaves a median residual of at most 15.0 mm, which a scrambled registration does not. It does not give a per-contact error.
- Template spaces differ.
IXI549Spacesits a few millimeters fromMNI152NLin2009cAsym, and a position in one is approximate in the other. - A computed position is not a localization. NEMAR does not localize electrodes or correct anyone’s data; it carries positions the dataset already holds into a template frame, and says how well that fit.
Reading a computed file
Section titled “Reading a computed file”A computed coordsystem.json carries four fields that matter:
iEEGCoordinateSystemis the template label (fsaverage,IXI549Spaceor a declared MNI152 variant).iEEGCoordinateSystemDescriptionexplains the frame, including the authors’ own term where they used one.iEEGCoordinateProcessingDescriptionalways begins with “Computed by NEMAR”. It names the pipeline version, the source file, the method, the evidence and the numbers behind it: distances, the inside fraction, the field or registration check and the number of contacts left out, with the reason for each.iEEGCoordinateProcessingReferencelinks this page.
The ownership file .nemar/ieeg-geometry.json lists each owned path with the Git object identifier of each input file it was computed from, the method and the verification result.
It is written deterministically: the same inputs give the same bytes.
It also records a checksum of each file as written, which is how NEMAR tells an untouched file from one a person edited.
How the files reach a dataset
Section titled “How the files reach a dataset”Datasets mirrored from OpenNeuro. A mirror is a copy of an upstream snapshot at version N.0.0, and NEMAR’s own corrections follow as version N.0.1. The computed files arrive in version N.0.1. A mirror with no re-pull pending gets one version N.0.1 for its geometry, after the dry-run report for that dataset has been reviewed. Each version N.0.1 mints a version Digital Object Identifier (DOI), as described in DOI and versioning.
Datasets pushed to NEMAR. The same files are offered as a pull request to the dataset. Nothing is committed until the dataset’s owner merges it.
When upstream publishes a new snapshot. A re-pull regenerates the computed files from the new snapshot instead of copying the old ones forward, so a file never outlives the data it was computed from. A path the new run does not produce is deleted together with its ownership entry, except a hand-edited file (with its pair), which is kept (see Hand edits). If the regeneration fails, the previous computed files are left out of the new version, and the snapshot’s own files are not held back by it.
For dataset authors
Section titled “For dataset authors”Your files always win. If a subject already has electrodes in a template space, nothing is computed for that subject and that space.
Upstream adds a file at a computed path. The upstream file wins, the path leaves the ownership list, and it is never regenerated again.
Replacing a computed file. Add your own file at the same path. For a mirror, that means publishing it upstream; for a dataset you pushed to NEMAR, commit it to your dataset.
Removing computed files. For a dataset you pushed to NEMAR, the files arrive as a pull request, so you can decline it or edit it before merging. For files already committed, or on a mirror, write to support@nemar.org naming the dataset and the files, or replace them with your own as above.
Hand edits. A computed file whose bytes differ from the checksum NEMAR recorded is treated as yours and kept, with its pair: if either file of a pair is edited, both are kept. It keeps its ownership entry and is never regenerated or deleted. NEMAR no longer vouches for it, and its sidecar still says “Computed by NEMAR”, so say in your own commit that you changed it, or replace it with a file under your own provenance text.
If a computed position looks wrong. Report it through the “Report a problem” link in the footer of this site, with the dataset identifier and the file. The sidecar names every input, so the cause can be traced.
Subject surfaces in the Brain panel
Section titled “Subject surfaces in the Brain panel”Some datasets ship the subject’s own cortical surfaces in the same frame as the contacts. NEMAR converts a surface that fits its contacts into the compact mesh format the Brain panel reads, and stores it beside the dataset’s Zarr copy, not in the dataset. The surfaces are display data: BIDS has no place for meshes, so nothing is committed to the dataset for them.
The surfaces may be FreeSurfer, GIfTI or MATLAB files. The Brain panel offers such a surface as a frame option named “Subject anatomy”, prefixed with the space when the dataset has several (for example “ACPC: Subject anatomy”), with the label “This subject’s anatomy, from the dataset’s own surfaces”. For a plausible fit rather than a specific one, the label adds “approximate alignment (depth contacts)”. Meshes are simplified to a size a browser can draw. A mesh is written only when the simplification moved the contacts’ median distance by at most 0.5 mm and no surface point by more than 1.0 mm at the 99th percentile. For a subject with a surface for one hemisphere only, the panel draws only that hemisphere and says so; it does not fall back to the template for the other side.
References
Section titled “References”- Fischl B, Sereno MI, Dale AM. Cortical surface-based analysis II: inflation, flattening, and a surface-based coordinate system. NeuroImage 9(2), 195-207 (1999). doi:10.1006/nimg.1998.0396
- Fischl B, Sereno MI, Tootell RBH, Dale AM. High-resolution intersubject averaging and a coordinate system for the cortical surface. Human Brain Mapping 8(4), 272-284 (1999). doi:10.1002/(SICI)1097-0193(1999)8:4<272::AID-HBM10>3.0.CO;2-4
- Fischl B. FreeSurfer. NeuroImage 62(2), 774-781 (2012). doi:10.1016/j.neuroimage.2012.01.021
- Ashburner J, Friston KJ. Unified segmentation. NeuroImage 26(3), 839-851 (2005). doi:10.1016/j.neuroimage.2005.02.018
- Fonov V, Evans AC, Botteron K, Almli CR, McKinstry RC, Collins DL, Brain Development Cooperative Group. Unbiased average age-appropriate atlases for pediatric studies. NeuroImage 54(1), 313-327 (2011). doi:10.1016/j.neuroimage.2010.07.033
The fsaverage surfaces are distributed with FreeSurfer under the FreeSurfer Software License, and the MNI152NLin2009cAsym template through TemplateFlow; both are used here with their notices.
Template surfaces are used in modified form (resampled, and for the MNI template a cut tissue shell), and each carries its license.