Skip to content

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

Open
@MatthewChen37

Description

@MatthewChen37

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions