mne-tools / mne-tools/mne-python

Reading in bvct digitizer file without LPA and RPA throws key error

Open
#13,115 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ENH
Dominant language
Python
Stars
3.5k
Forks
1.6k
Avg merge
1d 6h
Merged PRs (30d)
100

Description

Describe the new feature or enhancement

Hi,

I was trying to read a .bvct file and make a DigitMontage from it, but I noticed that _parse_brainvision_dig_montage in _dig_montage_utils.py assumes that an LPA and RPA coordinate is in the CapTrackElectrodeList. I don’t think this should be a rigid assumption since mne.channels.make_dig_montage can take in an LPA and RPA that are none. I was wondering if it was possible to change the implementation in _parse_brainvision_dig_montage from:

return dict( # BVCT stuff nasion=fids["nasion"], lpa=fids["lpa"], rpa=fids["rpa"], ch_pos=dig_ch_pos, coord_frame="unknown", )

to

return dict( # BVCT stuff nasion=fids.get("nasion", None), lpa=fids.get("lpa", None), rpa=fids.get("rpa", None), ch_pos=dig_ch_pos, coord_frame="unknown", )

as this would prevent the function from throwing a key error if no LPA or RPA exist within the bvct file.

Describe your proposed implementation

return dict( # BVCT stuff nasion=fids["nasion"], lpa=fids["lpa"], rpa=fids["rpa"], ch_pos=dig_ch_pos, coord_frame="unknown", )

to

return dict( # BVCT stuff nasion=fids.get("nasion", None), lpa=fids.get("lpa", None), rpa=fids.get("rpa", None), ch_pos=dig_ch_pos, coord_frame="unknown", )

Describe possible alternatives

Please let me know if there are alternatives for defaulting dictionary key access values in Python as I typically use this to resolve to access a key that doesn't exist

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect _parse_brainvision_dig_montage in _dig_montage_utils.py and reproduce the failure with a .bvct file that lacks LPA or RPA coordinates. Update the handling so missing fiducials do not cause a key error, then verify that make_dig_montage accepts the resulting missing coordinates without failing.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.