Skip to content

Store missing BIDS channel coordinates as empty arrays - #589

Merged
suraj-ranganath merged 2 commits into
developfrom
cursor/bids-missing-coordinates-c56b
Nov 11, 2026
Merged

suraj-ranganath merged 2 commits into
developfrom
cursor/bids-missing-coordinates-c56b

Conversation

@suraj-ranganath

Copy link
Copy Markdown
Member

Missing electrode coordinates from pop_load_frombids are empty arrays, the same value used when a channel location is cleared. Saving that dataset and loading it again keeps the empty coordinates.

Fixes #538

Open in Web Open in Cursor 

pop_load_frombids replaces coordinates left empty by eeg_checkchanlocs
with the empty numeric value used for a cleared channel. A channel with
no electrodes.tsv row keeps those empty values through save and reload.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 11, 2026 06:16

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

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.

@claude

claude Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 58s —— View job


Code review

  • Overall assessment: Looks good. The fix does what the PR says: after eeg_checkchanlocs, any None coordinate (theta, radius, X/Y/Z, sph_*) in chanlocs and chaninfo.nodatchans is replaced with a copy of numeric_null, which defaults to np.array([]). This uses the same empty value as clear_chanloc, and pop_saveset/pop_loadset keep it on a round trip.
  • Highest-risk area: the post-processing at the end of pop_load_frombids (src/eegprep/functions/popfunc/pop_load_frombids.py:625-628). eeg_checkchanlocs still deliberately uses None for missing numeric fields (see its docstring), so this change only affects the BIDS loader, which is the right scope for pop_load_frombids leaves None in chanlocs fields; pop_saveset raises TypeError on them #538.
  • Merge recommendation: Safe to merge.

Blocking

None.

Important

None.

Nits

  • tests/test_bids_load_frombids_helpers.py:821-839: the new test writes the EDF+ file by hand instead of using the existing _write_edf_family helper in the same file (AGENTS.md: "reuse … local helpers already present in the relevant test file"). There's an inline comment with the replacement code.

Test gaps

None. The new test covers both cases: a channel with coordinates and a channel missing from electrodes.tsv. It also checks chaninfo.plotrad/shrink and the save/load round trip.

EEGLAB parity notes

None. Empty [] coordinates for channels without locations match how EEGLAB stores them. I couldn't compare against bids_importchanlocs.m line by line because this checkout doesn't include the vendored EEGLAB tree.

Checked: correctness of the None → empty-array replacement (including copying the array so channels don't share one object), handling of nodatchans, docs and changelog updates, test behavior, and AGENTS.md compliance. I did not run the test locally because test execution in this job needs approval.

Comment on lines +821 to +839
edf_path = eeg_dir / "sub-01_task-x_eeg.edf"
writer = pyedflib.EdfWriter(str(edf_path), len(names), file_type=pyedflib.FILETYPE_EDFPLUS)
writer.setSignalHeaders(
[
{
"label": name,
"dimension": "uV",
"sample_frequency": 250,
"physical_min": -500,
"physical_max": 500,
"digital_min": -32768,
"digital_max": 32767,
"transducer": "",
"prefilter": "",
}
for name in names
]
)
writer.writeSamples(list(np.random.default_rng(0).standard_normal((len(names), 250)) * 20))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This writes the EDF+ file by hand, but the same file already has a helper for it: _write_edf_family / _signal_headers (

def _write_edf_family(
path: Path,
signals: list[np.ndarray],
*,
labels: list[str],
srate: int,
file_type: int,
digital_min: int,
digital_max: int,
annotations: list[tuple[float, str]] | None = None,
) -> None:
writer = pyedflib.EdfWriter(str(path), len(signals), file_type=file_type)
writer.setSignalHeaders(_signal_headers(labels, srate=srate, digital_min=digital_min, digital_max=digital_max))
writer.writeSamples(signals)
for onset, text in annotations or []:
writer.writeAnnotation(onset, 0.5, text)
writer.close()
). AGENTS.md §Testing says: "Avoid duplicate fixtures; reuse tests/fixtures.py or local helpers already present in the relevant test file."

Suggested fix: replace this block with:

_write_edf_family(
    edf_path,
    list(np.random.default_rng(0).standard_normal((len(names), 250)) * 20),
    labels=names,
    srate=250,
    file_type=pyedflib.FILETYPE_EDFPLUS,
    digital_min=-32768,
    digital_max=32767,
)

The helper's physical range is ±100 µV, and that still covers the ~N(0, 20) signal.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖
The test now writes the EDF with _write_edf_family.

The round-trip test writes its recording with the shared EDF helper.

Co-authored-by: Suraj Ranganath <[email protected]>
@cursor
cursor Bot marked this pull request as draft November 11, 2026 06:20
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 11, 2026 06:37
@claude

claude Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Claude Code is working…

I'll analyze this and get back to you.

View job run

@suraj-ranganath
suraj-ranganath marked this pull request as draft November 11, 2026 06:37
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 11, 2026 06:37
@claude

claude Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 37s —— View job


Code review

  • Overall assessment: Looks good. Reviewed head c432f67. After eeg_checkchanlocs, pop_load_frombids now replaces any None coordinate (theta, radius, X/Y/Z, sph_*) in chanlocs and in chaninfo.nodatchans with its own copy of numeric_null. With the default numeric_null, that copy is np.array([]), the same value clear_chanloc (plugins/EEG_BIDS/coords.py:108) uses when it clears a channel location.
  • Highest-risk area: src/eegprep/functions/popfunc/pop_load_frombids.py:625-628. eeg_checkchanlocs itself still returns None for missing numeric fields, so only the BIDS loader changes, which is the right scope for pop_load_frombids leaves None in chanlocs fields; pop_saveset raises TypeError on them #538. The code after this point only assigns channel type, so nothing downstream does arithmetic on the empty arrays.
  • Merge recommendation: Safe to merge.

Blocking

None.

Important

None.

Nits

None. The earlier nit about writing the EDF file by hand is fixed: the test now uses _write_edf_family.

Test gaps

None. test_missing_electrode_coordinates_round_trip_as_empty_arrays covers:

  • a channel that has coordinates
  • a channel with no row in electrodes.tsv
  • empty chaninfo.plotrad and shrink
  • the pop_saveset → pop_loadset round trip

EEGLAB parity notes

None. EEGLAB stores a channel without a location as empty [] coordinates, so this change matches it.

Checked for:

I couldn't run the test or ruff because running commands in this job needs approval.

@cursor

cursor Bot commented Nov 11, 2026

Copy link
Copy Markdown

🤖
The review of c432f67 is safe to merge. The two inline comments are the earlier nit about writing the EDF by hand and the reply that the test now uses _write_edf_family. That nit is already fixed on this head, and the review of this head found nothing left to change. No re-review is needed.

@suraj-ranganath
suraj-ranganath merged commit aec5e53 into develop Nov 11, 2026
17 of 18 checks passed
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.

pop_load_frombids leaves None in chanlocs fields; pop_saveset raises TypeError on them

2 participants