Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include OPM channels as megmag under .pick/get_coil_types() #1222

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AmaiaBA
Copy link

@AmaiaBA AmaiaBA commented Jan 31, 2024

PR Description

Description:
This pull request addresses an issue encountered when using the write_raw_bids() command for OPM (Optically Pumped Magnetometer) data. The problem arises in the _channels_tsv() function, which throws a KeyError when attempting to access a key in the map_chs dictionary.


Error Details:

File ~/miniconda3/envs/mne/lib/python3.11/site-packages/mne_bids/write.py:157, in _channels_tsv(raw, fname, overwrite)
    155     if _channel_type in get_specific:
    156         _channel_type = coil_type(raw.info, idx, _channel_type)
--> 157     ch_type.append(map_chs[_channel_type])
    158     description.append(map_desc[_channel_type])
    159 low_cutoff, high_cutoff = (raw.info["highpass"], raw.info["lowpass"])

KeyError: 'mag'

Issue Explanation:
The error occurs because the key _channel_type is not present in the map_chs dictionary. Specifically, when using any of the supported channel types for OPMs, _channel_type is set to 'mag' instead of 'megmag'. This discrepancy is due to the fact that get_coil_types() under mne_bids/pick.py does not include OPM channels.


Solution:
To resolve this issue, I expanded the list of supported OPM channels in get_coil_types():

megmag=(
            FIFF.FIFFV_COIL_POINT_MAGNETOMETER,
            FIFF.FIFFV_COIL_VV_MAG_W,
            FIFF.FIFFV_COIL_VV_MAG_T1,
            FIFF.FIFFV_COIL_VV_MAG_T2,
            FIFF.FIFFV_COIL_VV_MAG_T3,
            FIFF.FIFFV_COIL_NM_122,
            FIFF.FIFFV_COIL_MAGNES_MAG,
            FIFF.FIFFV_COIL_BABY_MAG,
            # support for OPM data
            FIFF.FIFFV_COIL_QUSPIN_ZFOPM_MAG, # QuSpin v1
            FIFF.FIFFV_COIL_QUSPIN_ZFOPM_MAG2, # QuSpin v2
            FIFF.FIFFV_COIL_FIELDLINE_OPM_MAG_GEN1, # FieldLine v1
            FIFF.FIFFV_COIL_KERNEL_OPM_MAG_GEN1, # Kernel
        )

This modification ensures that OPM channels are properly accounted for in _channel_type when using write_raw_bids().

Merge checklist

Maintainer, please confirm the following before merging.
If applicable:

  • All comments are resolved
  • This is not your own PR
  • All CIs are happy
  • PR title starts with [MRG]
  • whats_new.rst is updated
  • New contributors have been added to CITATION.cff
  • PR description includes phrase "closes <#issue-number>"

Copy link

welcome bot commented Jan 31, 2024

Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴🏽‍♂️

Copy link

codecov bot commented Jan 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (87eea28) 97.61% compared to head (b6686b7) 97.61%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1222   +/-   ##
=======================================
  Coverage   97.61%   97.61%           
=======================================
  Files          40       40           
  Lines        8685     8685           
=======================================
  Hits         8478     8478           
  Misses        207      207           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sappelhoff
Copy link
Member

Hi there, thanks for the PR.

I am not sure whether we should include this here before OPM has been "properly" included in BIDS: bids-standard/bids-specification#1676

any other opinions?

@jasmainak
Copy link
Member

I think we should enable the specific coil type for now so people can share their data ... of course, sharing helmet designs etc should also be included in the specification but we should not wait for the specification to be updated. You can imagine updating info['chs'] to include the sensor locations in a fif file as was done with conventional MEG

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.

None yet

3 participants