Skip to content

Commit

Permalink
fix, change to calling dipy directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Rockhill committed Aug 12, 2021
1 parent b07cd6b commit f30d0cb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
23 changes: 11 additions & 12 deletions mne/gui/_ieeg_locate_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def __init__(self, info, trans, aligned_ct, subject=None,
self._subject_dir = _check_subject_dir(subject, subjects_dir)
self._load_image_data(aligned_ct)

self._radius = int(_CH_PLOT_SIZE // 100)
self._radius = int(_CH_PLOT_SIZE // 50)
# initialize channel data
self._ch_index = 0
# load data, apply trans
Expand Down Expand Up @@ -304,6 +304,7 @@ def _plot_images(self):
self._ct_cutoff = int(round(ct_min))
text_kwargs = dict(fontsize=3, color='#66CCEE', family='monospace',
weight='bold', ha='center', va='center')
xyz = apply_trans(self._ras_vox_t, self._ras)
for axis in range(3):
self._plts[axis]._ax.clear()
ct_data = np.take(self._ct_data, self._current_slice[axis],
Expand All @@ -319,13 +320,11 @@ def _plot_images(self):
cmap=_CMAP, alpha=self._ch_alpha, vmin=0, vmax=_N_COLORS))
self._images['cursor'].append(
self._plts[axis]._ax.plot(
(self._ras[axis], self._ras[axis]),
(0, self._voxel_sizes[axis]),
(xyz[axis], xyz[axis]), (0, self._voxel_sizes[axis]),
color=[0, 1, 0], linewidth=0.25, alpha=0.5)[0])
self._images['cursor2'].append(
self._plts[axis]._ax.plot(
(0, self._voxel_sizes[axis]),
(self._ras[axis], self._ras[axis]),
(0, self._voxel_sizes[axis]), (xyz[axis], xyz[axis]),
color=[0, 1, 0], linewidth=0.25, alpha=0.5)[0])
# label axes
self._plts[axis]._fig.text(0.5, 0.05, _IMG_LABELS[axis][0],
Expand Down Expand Up @@ -457,7 +456,7 @@ def make_slider(smin, smax, sval, sfun=None):
ch_slider_vbox = QVBoxLayout()
self._alpha_slider = make_slider(0, 100, self._ch_alpha * 100,
self._update_ch_alpha)
ch_plot_max = int(np.mean(_CH_PLOT_SIZE) // 50)
ch_plot_max = _CH_PLOT_SIZE // 25 # max 1 / 25 of plot size
ch_slider_vbox.addWidget(self._alpha_slider)
self._radius_slider = make_slider(0, ch_plot_max, self._radius,
self._update_radius)
Expand Down Expand Up @@ -596,7 +595,7 @@ def _update_ch_selection(self):
self._group_selector.setCurrentIndex(self._groups[name])
self._update_group()
if not np.isnan(self._chs[name]).any():
self._ras = self._chs[name]
self._ras[:] = self._chs[name]
self._move_cursors_to_pos()
self._draw()

Expand Down Expand Up @@ -672,7 +671,7 @@ def _color_list_item(self, name=None):
@pyqtSlot()
def _mark_ch(self):
"""Mark the current channel as being located at the crosshair."""
self._chs[self._ch_names[self._ch_index]] = self._ras
self._chs[self._ch_names[self._ch_index]][:] = self._ras
self._color_list_item()
self._update_ch_images(draw=True)
self._save_ch_coords()
Expand All @@ -696,8 +695,8 @@ def _update_ch_images(self, axis=None, draw=False):
for axis in range(3) if axis is None else [axis]:
self._images['chs'][axis].set_data(
self._make_ch_image(axis))
if draw:
self._draw(axis)
if draw:
self._draw(axis)

def _update_ct_images(self, axis=None, draw=False):
"""Update the CT image(s)."""
Expand All @@ -708,8 +707,8 @@ def _update_ct_images(self, axis=None, draw=False):
ct_data[ct_data < self._ct_min_slider.value()] = np.nan
ct_data[ct_data > self._ct_max_slider.value()] = np.nan
self._images['ct'][axis].set_data(ct_data)
if draw:
self._draw(axis)
if draw:
self._draw(axis)

def _update_images(self, axis=None, draw=True):
"""Update CT and channel images when general changes happen."""
Expand Down
10 changes: 7 additions & 3 deletions tutorials/clinical/10_ieeg_localize.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

import nibabel as nib
import nilearn.plotting
from dipy.align import resample
from dipy.align import resample,

import mne
from mne.datasets import fetch_fsaverage
Expand Down Expand Up @@ -127,8 +127,12 @@ def plot_overlay(image, compare, title, thresh=None):
# This takes a while (~10 minutes) to execute so we skip actually running it
# here::
#
# reg_affine, _ = mne.transforms.compute_volume_registration(
# CT_orig, T1, pipeline='rigids', verbose=True)
# from dipy.align import center_of_mass, translation, rigid
# reg_data, reg_affine = dipy.align.affine_registration(
# moving=np.array(CT_orig.dataobj), moving_affine=CT_orig.affine,
# static=np.array(T1.dataobj), static_affine=T1.affine,
# pipeline=[center_of_mass, translation, rigid])
# CT_aligned = nib.MGHImage(reg_data.astype(np.float32), T1.affine)
#
# And instead we just hard-code the resulting 4x4 matrix:

Expand Down

0 comments on commit f30d0cb

Please sign in to comment.