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, WIP] Add localization for microgrids #10

Open
wants to merge 72 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
9af2132
[ENH, WIP] Add localization for microgrids
alexrockhill Apr 21, 2023
6ea3774
small bug
alexrockhill Apr 21, 2023
d0c272b
saved version with vasculature specifically
alexrockhill Apr 24, 2023
ff8f1d4
vasculature to surface
alexrockhill Apr 24, 2023
9f4f852
basically feature complete
alexrockhill Apr 24, 2023
158db2b
Merge branch 'main' into grids
alexrockhill Apr 24, 2023
531c035
fix style
alexrockhill Apr 24, 2023
3fb22f8
add rotation of surgical image
alexrockhill Apr 24, 2023
f6c07ae
fix surgical image controls
alexrockhill Apr 24, 2023
4a65012
bug fix
alexrockhill Apr 24, 2023
06235c1
add save view button
alexrockhill Apr 25, 2023
a06c802
black
alexrockhill Apr 25, 2023
b5dac1d
fix redraw bug
alexrockhill Apr 25, 2023
9cebe50
use buttons instead of sliders
alexrockhill Apr 25, 2023
803fa09
allow reloading
alexrockhill Apr 25, 2023
f3de507
fix skull toggling, allow loading
alexrockhill Apr 25, 2023
c666f5f
do radius interactively
alexrockhill Apr 26, 2023
94f82df
workaround for pyvista loc setter not working
alexrockhill Apr 26, 2023
d4f5790
finally working fix, loc and position do not properly sync with each …
alexrockhill Apr 26, 2023
070eedd
sdr version didn't work
alexrockhill Apr 26, 2023
0a76f8e
opencv didn't work either
alexrockhill Apr 26, 2023
5356605
revert registration, didn't work
alexrockhill Apr 26, 2023
7c97bda
Merge branch 'main' into grids
alexrockhill Aug 8, 2023
f2dc753
update
alexrockhill Dec 1, 2023
340020a
Merge branch 'grids' of https://github.com/alexrockhill/mne-gui-addon…
alexrockhill Dec 1, 2023
03e24d8
Merge branch 'main' of https://github.com/mne-tools/mne-gui-addons in…
alexrockhill Dec 1, 2023
49a414b
cruft
alexrockhill Dec 1, 2023
c63655a
style
alexrockhill Dec 1, 2023
1fe5818
style2
alexrockhill Dec 1, 2023
fc53ba9
Merge branch 'main' into grids
alexrockhill Dec 4, 2023
7487724
[BUG] Fix marching cubes not in the right space when CT is not aligned
alexrockhill Dec 4, 2023
3ee1c8d
try restricting pyqt version
alexrockhill Dec 4, 2023
a627217
update index, don't plot brain if not aligned
alexrockhill Dec 4, 2023
739afa7
fix broken link
alexrockhill Dec 4, 2023
49a253e
fix all tests are skipped
alexrockhill Dec 4, 2023
a560949
style
alexrockhill Dec 4, 2023
37c66f5
fix dep, tests
alexrockhill Dec 4, 2023
b44c4d7
try again ignore warning
alexrockhill Dec 4, 2023
77d8853
ignore in wrong place
alexrockhill Dec 4, 2023
4c2db14
wrong still
alexrockhill Dec 4, 2023
aef8607
cruft
alexrockhill Dec 4, 2023
290298f
space
alexrockhill Dec 4, 2023
b8e2c81
fix re
alexrockhill Dec 4, 2023
2632c63
mne-stable errors
alexrockhill Dec 5, 2023
4ed70e5
Merge branch 'bug' of https://github.com/alexrockhill/mne-gui-addons …
alexrockhill Dec 5, 2023
bf926c1
fix merge error
alexrockhill Dec 5, 2023
006be43
fix merge error2
alexrockhill Dec 5, 2023
eca9614
working
alexrockhill Dec 6, 2023
1ab565c
1.6 release
alexrockhill Dec 6, 2023
dfdc492
still fails on stable
alexrockhill Dec 6, 2023
5e3804d
fix tests after bug fixes in scan RAS conversion
alexrockhill Dec 6, 2023
f0a8a07
fix touch stc examples
alexrockhill Dec 6, 2023
7ae80b0
use seeg for morphing example
alexrockhill Dec 6, 2023
59aa9b1
Merge branch 'bug' of https://github.com/alexrockhill/mne-gui-addons …
alexrockhill Dec 6, 2023
612c178
Merge branch 'main' into grids
alexrockhill Dec 6, 2023
dc5bff1
Merge branch 'grids' of https://github.com/alexrockhill/mne-gui-addon…
alexrockhill Dec 6, 2023
098bfd8
add pandas dependency
alexrockhill Dec 6, 2023
ed235a9
wip
alexrockhill Dec 7, 2023
e5f924a
Merge branch 'main' into grids
alexrockhill Dec 7, 2023
645ac80
Merge branch 'grids' of https://github.com/alexrockhill/mne-gui-addon…
alexrockhill Dec 7, 2023
ddf796d
fix style
alexrockhill Dec 7, 2023
9bb5350
file didn't save
alexrockhill Dec 7, 2023
fdac92a
black
alexrockhill Dec 7, 2023
011df76
wip
alexrockhill Jan 2, 2024
aefedb2
style
alexrockhill Jan 2, 2024
492be66
fix test
alexrockhill Jan 2, 2024
770085a
fix dipy intersphinx
alexrockhill Jan 2, 2024
bc0107b
too many options
alexrockhill Jan 2, 2024
c09fc3d
didn't notice url change
alexrockhill Jan 3, 2024
a2f9b5d
no slash at the end
alexrockhill Jan 3, 2024
1a384db
use relative motion instead of xyz coordinate frame
alexrockhill Feb 2, 2024
5435a8b
remove radius spin box
alexrockhill Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"matplotlib": ("https://matplotlib.org/stable", None),
"nibabel": ("https://nipy.org/nibabel", None),
"dipy": (
"https://dipy.org/documentation/latest/",
"https://dipy.org/documentation/latest/objects.inv/",
"https://docs.dipy.org/latest/objects.inv",
"https://docs.dipy.org/stable/objects.inv",
),
"mne": ("https://mne.tools/stable", None),
"mne_bids": ("https://mne.tools/mne-bids/stable", None),
Expand Down
41 changes: 41 additions & 0 deletions examples/locate_microgrid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
.. _ex-ieeg-microgrid:

==================================
Locating an intracranial microgrid
==================================

For intracranial grids that are too small for even high-resolution
computed tomography (CT) images to detect, the contacts must be
aligned with an intraoperative image such as from a surgical
microscope as shown below.
"""

# Authors: Alex Rockhill <[email protected]>
#
# License: BSD-3-Clause

import numpy as np
import nibabel as nib
import mne
import mne_gui_addons as mne_gui

# path to sample sEEG
misc_path = mne.datasets.misc.data_path()
subjects_dir = misc_path / "ecog"

# GUI requires pyvista backend
mne.viz.set_3d_backend("pyvistaqt")

# we need two things:
# 1) The electrophysiology file which contains the channels names
# that we would like to associate with positions in the brain
# 2) A scope image of the grid
raw = mne.io.read_raw(misc_path / "ecog" / "sample_ecog_ieeg.fif")
trans = mne.coreg.estimate_head_mri_t("sample_ecog", subjects_dir)

raw.set_montage(None) # remove macro channels

gui = mne_gui.locate_ieeg(
raw.info, trans, subject="sample_ecog", subjects_dir=subjects_dir
)
7 changes: 4 additions & 3 deletions mne_gui_addons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
def locate_ieeg(
info,
trans,
base_image,
base_image=None,
subject=None,
subjects_dir=None,
groups=None,
Expand All @@ -38,10 +38,11 @@ def locate_ieeg(
----------
%(info_not_none)s
%(trans_not_none)s
base_image : path-like | nibabel.spatialimages.SpatialImage
base_image : path-like | nibabel.spatialimages.SpatialImage | None
The CT or MR image on which the electrode contacts can located. It
must be aligned to the Freesurfer T1 if ``subject`` and
``subjects_dir`` are provided. Path-like inputs and nibabel image
``subjects_dir`` are provided. If aligning a grid to the pial surface,
the T1 will be used by default. Path-like inputs and nibabel image
objects are supported.
%(subject)s
%(subjects_dir)s
Expand Down
29 changes: 25 additions & 4 deletions mne_gui_addons/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
QMessageBox,
QWidget,
QLineEdit,
QSlider,
)

from matplotlib import patheffects
Expand Down Expand Up @@ -180,6 +181,10 @@ def __init__(
self._subject_dir = (
op.join(subjects_dir, subject) if subject and subjects_dir else None
)
if self._subject_dir is None and base_image is None:
raise ValueError(
"`subjects_dir` must be provided if no `base_image` is provided"
)
self._load_image_data(base_image=base_image)

# GUI design
Expand Down Expand Up @@ -363,6 +368,7 @@ def _plot_images(self):
img_data,
cmap="gray",
aspect="auto",
interpolation="spline16",
zorder=1,
vmin=img_min,
vmax=img_max,
Expand Down Expand Up @@ -416,7 +422,10 @@ def _plot_images(self):
[1],
)[0]
rr = apply_trans(self._ras_vox_scan_ras_t, rr) # base image vox -> RAS
self._renderer.mesh(

self._head = dict(rr=rr, tris=tris)

self._head_actor, _ = self._renderer.mesh(
*rr.T,
triangles=tris,
color="gray",
Expand All @@ -425,7 +434,7 @@ def _plot_images(self):
render=False,
)
else:
self._renderer.mesh(
self._head_actor, _ = self._renderer.mesh(
*self._head["rr"].T,
triangles=self._head["tris"],
color="gray",
Expand All @@ -437,15 +446,15 @@ def _plot_images(self):
self._lh_actor, _ = self._renderer.mesh(
*self._lh["rr"].T,
triangles=self._lh["tris"],
color="white",
color="gray",
opacity=0.2,
reset_camera=False,
render=False,
)
self._rh_actor, _ = self._renderer.mesh(
*self._rh["rr"].T,
triangles=self._rh["tris"],
color="white",
color="gray",
opacity=0.2,
reset_camera=False,
render=False,
Expand Down Expand Up @@ -699,6 +708,17 @@ def keyPressEvent(self, event):
)
self._set_ras(ras)

def _make_slider(self, smin, smax, sval, sfun=None):
slider = QSlider(QtCore.Qt.Horizontal)
slider.setMinimum(int(round(smin)))
slider.setMaximum(int(round(smax)))
slider.setValue(int(round(sval)))
slider.setTracking(False) # only update on release
if sfun is not None:
slider.valueChanged.connect(sfun)
slider.keyPressEvent = self.keyPressEvent
return slider

def _on_click(self, event, axis):
"""Move to view on MRI and CT on click."""
if event.inaxes is self._figs[axis].axes[0]:
Expand All @@ -721,6 +741,7 @@ def _update_moved(self):
self._intensity_label.setText(
"intensity = {:.2f}".format(self._base_data[tuple(self._current_slice)])
)
self._update_camera(render=True)

@safe_event
def closeEvent(self, event):
Expand Down
Loading
Loading