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

ENH: Enable sensor-specific OPM coregistration in mne coreg #11405

Merged
merged 14 commits into from
Nov 7, 2023

Conversation

larsoner
Copy link
Member

@larsoner larsoner commented Jan 3, 2023

This PR does a few things:

  • Adds a Kernel Flux MEG helmet based on their CAD
  • Adds canonical sensor positions (based on the CAD)
  • Adds a nonlinear matchied field displacement interpolator to take the CAD helmet to measured sensor positions. Assuming the number and placement of sensors EDIT: or other fixed points is fixed for a given system, this should allow generalization of a canonical/idealized CAD-based helmet to actual 3D printed or deformed helmets for individual participants.
  • An option to show the MEG sensors as well: ENH: Add MEG sensor option to coreg #12098
  • Disable backface culling on the MEG sensors if we haven't already: ENH: Add MEG sensor option to coreg #12098
  • Add support for adjusting sensor alpha in mne.viz.plot_alignment by passing dict to meg
  • Add some sample Kernel data with example

With this I get the following coreg:

Output
Getting helmet for system Kernel_Flux
    Deforming to match info using 39 matched points:
    1. Affine: 1.1°, 1.8 mm, 1.00× scale
    2. Nonlinear displacement: mean=2.7, max=8.5 mm

Screenshot from 2023-01-03 13-43-59

I think in follow-up PRs we'l want

  1. A way to have mne coreg fix/adjust the head coordinate frame definition. Even with our existing OPM dataset from years ago, the head and MRI coordinate frames are taken as equal, which they shouldn't be. We should allow for using the current (in the GUI) head<->MRI transformation and current LPA/Nasion/RPA (from the MRI) to be used to adjust LPA/Nasion/RPA in info['dig'], which in turn should update the head coordinate frame definition, which in turn should change the rest of info['dig'] and info['chs][ii]['loc'] etc. We'll need some buttons and/or UI for this, but in principle I think this makes sense. We can test this easily with our existing OPM dataset by implementing it in the non-GUI Coreg object first.
  2. A way to tell ICP fitting to use the MEG sensor locations as if they were digitization points
  3. To add canonical helmets for other systems and/or adapt deformations to other schemes

Helps with #11276

@larsoner larsoner added this to the 1.4 milestone Jan 3, 2023
@jasmainak
Copy link
Member

jasmainak commented Jan 3, 2023

@larsoner at Martinos we are currently at the stage of experimenting with subject-specific helmets ... I am not sure when/if we will transition to generic helmets. The question of optimal helmet needs some research ...

Whatever pipeline is developed in MNE should hopefully be a little flexible so that it's not too specific to a particular system. Things are still under flux in my opinion.

@larsoner
Copy link
Member Author

larsoner commented Jan 3, 2023

Whatever pipeline is developed in MNE should hopefully be a little flexible so that it's not too specific to a particular system. Things are still under flux in my opinion.

Indeed, I think that's going to be the case with the plan above

@jasmainak
Copy link
Member

jasmainak commented Jan 3, 2023

Even with our existing OPM dataset, the head and MRI coordinate frames are taken as equal, which they shouldn't be.

The way I am thinking, one could define 5 or so index points on the helmet that need to be coregistered with the index points from the CAD file to get the dev_head_t ... this could be done using Procrusteas but potentially checked or adjusted using the GUI.

The head-MRI trans could be learned using the fiducials and digitized head surface points.

@larsoner larsoner modified the milestones: 1.4, 1.5 Apr 21, 2023
@larsoner larsoner modified the milestones: 1.5, 1.6 Jul 31, 2023
@larsoner larsoner self-assigned this Oct 1, 2023
@larsoner larsoner changed the title WIP: Enable OPM coregistration in mne coreg ENH: Enable subject-specific OPM coregistration in mne coreg Oct 10, 2023
* upstream/main: (37 commits)
  Use constrained layout in matplotlib visualization (mne-tools#12050)
  Add raw stc (mne-tools#12001)
  [MRG] update codeowners (mne-tools#12089)
  DOC: Morlet wavelet length in tfr_morlet (mne-tools#12073)
  BUG: Fix bug with mne browser backend (mne-tools#12078)
  Cache avatars (mne-tools#12077)
  BUG: Fix bug with ch_name resolution (mne-tools#12086)
  add unicode roundtrip for FIF (mne-tools#12080)
  add Ivan to names.inc (mne-tools#12081)
  MAINT: Work around PySide 6.5.3 event loop error (mne-tools#12076)
  mne-tools#11608, buggfix and docstring update (mne-tools#12066)
  MAINT: Fix broken examples (mne-tools#12074)
  Add UI Event linking to DraggableColorbar (mne-tools#12057)
  handle lazy loading through .pyi type stubs (mne-tools#12072)
  BUG: Fix bug with sensor_colors (mne-tools#12068)
  clean  up some deprecations (mne-tools#12067)
  Allow not dropping bads when creating or plotting Spectrum objs (mne-tools#12006)
  Collapsible html repr for raw/info (mne-tools#12064)
  BUG: Fix bug with pickling MNEBadsList (mne-tools#12063)
  add details for Denis (mne-tools#12065)
  ...
@larsoner larsoner changed the title ENH: Enable subject-specific OPM coregistration in mne coreg ENH: Enable sensor-specific OPM coregistration in mne coreg Oct 10, 2023
@larsoner larsoner removed the request for review from dengemann October 10, 2023 16:45
* upstream/main: (35 commits)
  [DOC] Add documentation for setting montage order (mne-tools#12160)
  Fix inferring fiducials from EEGLAB (mne-tools#12165)
  Try to fix ICA Report (mne-tools#12167)
  BUG: Fix bug with Report.add_ica component number (mne-tools#12156)
  MAINT: Add rstcheck to CIs and pre-commit (mne-tools#12163)
  DOC: fix sphinx style typos (mne-tools#12161)
  MAINT: Fix linkcheck (mne-tools#12162)
  ENH: Add multiple label support to source_band_induced_power, source_induced_power (mne-tools#12026)
  Allow automated metadata generation to be bounded by "row events" instead of explicit time windows (mne-tools#12118)
  ENH: Collapse only in doc gen (mne-tools#12145)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12155)
  BUG: Fix bug with interior points not showing (mne-tools#12148)
  ENH: Warn about versions in sys_info (mne-tools#12146)
  Fix in conftest.py (mne-tools#12150)
  ENH: set color for bad channel with spatial_colors=True (mne-tools#12142)
  DOC: Better documentation of realign_raw (mne-tools#12135)
  Add mne-icalabel wildcard (mne-tools#12143)
  Remove LGTM.com configuration file (mne-tools#12139)
  DOC: Fix typo found by codespell (mne-tools#12140)
  DOC: Document governance updates (mne-tools#12133)
  ...
* upstream/main:
  MAINT: Add branch coverage (mne-tools#12174)
  OpenSSF (mne-tools#12175)
  fix docstring in 60_sleep.py (mne-tools#12171)
  FIX: skip empty lines in read_raw_eyelink (mne-tools#12172)
  FIX: Fix bug with coreg scalars (mne-tools#12164)
  Changed casting rule in np.clip to allow reading of raw GDF files (mne-tools#12168)
@drammock
Copy link
Member

drammock commented Nov 6, 2023

from the PR description

I think in follow-up PRs we'll want [...]

@larsoner can you open issues for items 1 and 2 (if you haven't already)? I think item 3 (add built-in models of other mfg's helmets) doesn't need an issue, we can just add them when folks ask for them.

@larsoner
Copy link
Member Author

larsoner commented Nov 6, 2023

@drammock FYI I did end up adding a kernel dataset example. It should be building now!

mne/data/helmets/Kernel_Flux_ch_pos.txt Outdated Show resolved Hide resolved
mne/surface.py Outdated Show resolved Hide resolved
mne/surface.py Outdated Show resolved Hide resolved
mne/utils/config.py Outdated Show resolved Hide resolved
Copy link
Member

@drammock drammock left a comment

Choose a reason for hiding this comment

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

reviewed just the new example this time.

examples/datasets/kernel_phantom.py Outdated Show resolved Hide resolved
examples/datasets/kernel_phantom.py Outdated Show resolved Hide resolved
examples/datasets/kernel_phantom.py Outdated Show resolved Hide resolved
examples/datasets/kernel_phantom.py Outdated Show resolved Hide resolved
examples/datasets/kernel_phantom.py Outdated Show resolved Hide resolved
Copy link
Member Author

@larsoner larsoner left a comment

Choose a reason for hiding this comment

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

Think I got all the comments @drammock !

Comment on lines +274 to +277
logger.info(
"Using untransformed helmet, not enough sensors found to deform to match "
f"acquisition based on sensor positions (got {len(fro)}, need at least 4)"
)
Copy link
Member Author

Choose a reason for hiding this comment

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

@drammock took a stab at improving these, see if you think they make more sense now

Copy link
Member

Choose a reason for hiding this comment

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

that works, thanks!

@drammock drammock merged commit cc377da into mne-tools:main Nov 7, 2023
28 checks passed
@drammock drammock deleted the kernel branch November 7, 2023 16:16
larsoner added a commit to JD-Zhu/mne-python that referenced this pull request Nov 7, 2023
* upstream/main:
  ENH: Enable sensor-specific OPM coregistration in mne coreg (mne-tools#11405)
  Tweak README.rst (mne-tools#12166)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12177)
  MAINT: Add branch coverage (mne-tools#12174)
  OpenSSF (mne-tools#12175)
  fix docstring in 60_sleep.py (mne-tools#12171)
  FIX: skip empty lines in read_raw_eyelink (mne-tools#12172)
larsoner added a commit to pablomainar/mne-python that referenced this pull request Nov 8, 2023
* upstream/main:
  BUG: Fix bug with spectrum warning (mne-tools#12186)
  Add argument splash to disable splash-screen from Qt-browser (mne-tools#12185)
  BUG: Fix bug with logging and n_jobs>1 (mne-tools#12154)
  Use gray logo (works in light and dark modes) (mne-tools#12184)
  Tweak logo for dark mode (mne-tools#12176)
  ENH: Improve Covariance.__repr__ (mne-tools#12181)
  ENH: Enable sensor-specific OPM coregistration in mne coreg (mne-tools#11405)
  Tweak README.rst (mne-tools#12166)
  [pre-commit.ci] pre-commit autoupdate (mne-tools#12177)
  MAINT: Add branch coverage (mne-tools#12174)
  OpenSSF (mne-tools#12175)
  fix docstring in 60_sleep.py (mne-tools#12171)
  FIX: skip empty lines in read_raw_eyelink (mne-tools#12172)
  FIX: Fix bug with coreg scalars (mne-tools#12164)
  Changed casting rule in np.clip to allow reading of raw GDF files (mne-tools#12168)
  [DOC] Add documentation for setting montage order (mne-tools#12160)
  Fix inferring fiducials from EEGLAB (mne-tools#12165)
larsoner added a commit to hoechenberger/mne-python that referenced this pull request Nov 8, 2023
…o-pyproject.toml

* upstream/main:
  MAINT: Fix CIs (mne-tools#12188)
  BUG: Fix bug with default alpha and axes (mne-tools#12187)
  BUG: Fix bug with spectrum warning (mne-tools#12186)
  Add argument splash to disable splash-screen from Qt-browser (mne-tools#12185)
  BUG: Fix bug with logging and n_jobs>1 (mne-tools#12154)
  Use gray logo (works in light and dark modes) (mne-tools#12184)
  Tweak logo for dark mode (mne-tools#12176)
  ENH: Improve Covariance.__repr__ (mne-tools#12181)
  ENH: Enable sensor-specific OPM coregistration in mne coreg (mne-tools#11405)
  Tweak README.rst (mne-tools#12166)
snwnde pushed a commit to snwnde/mne-python that referenced this pull request Mar 20, 2024
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.

3 participants