Skip to content

Commit

Permalink
fixed some little things
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrockhill committed Jul 27, 2021
1 parent fdee7ff commit 9516e48
Showing 1 changed file with 40 additions and 24 deletions.
64 changes: 40 additions & 24 deletions mne/gui/_ieeg_locate_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
from ..utils import (logger, _check_fname, requires_nibabel, warn,
_validate_type)

_IMG_LABELS = [['I', 'P'], ['I', 'L'], ['P', 'L']]
_IMG_LABELS = [['Inf', 'P'], ['Inf', 'L'], ['P', 'L']]
_CH_PLOT_SIZE = np.array([1024, 1024])
_ZOOM_STEP_SIZE = 5
_CT_MIN_DEFAULT = 0.5
_CT_MIN_DEFAULT = 0.9

_UNIQUE_COLORS = [(0.1, 0.42, 0.43), (0.9, 0.34, 0.62), (0.47, 0.51, 0.3),
(0.47, 0.55, 0.99), (0.79, 0.68, 0.06), (0.34, 0.74, 0.05),
Expand Down Expand Up @@ -103,7 +103,7 @@ def showPopup(self):
class SlicePlots(FigureCanvasQTAgg):
"""Initializes figure in pyqt for slice plots."""

def __init__(self, parent=None, width=16, height=16, dpi=300):
def __init__(self, parent=None, width=12, height=10, dpi=300):
self._fig, self._axes = plt.subplots(2, 2, figsize=(width, height),
dpi=dpi)
self._axes = self._axes.flatten()
Expand Down Expand Up @@ -142,9 +142,10 @@ def __init__(self, info, aligned_ct, subject, subjects_dir=None,
self._chs = self._load_ch_coords(info)
self._ch_names = list(self._chs.keys())
self._group_channels(groups)
"""

# GUI design
self._make_slice_plots()
self._plt = SlicePlots(self)
self._make_plot_images()

button_hbox = self._get_button_bar()
slider_hbox = self._get_slider_bar()
Expand All @@ -170,7 +171,7 @@ def __init__(self, info, aligned_ct, subject, subjects_dir=None,

name = self._ch_names[self._ch_index]
if not np.isnan(self._chs[name]).any():
self._move_cursors_to_pos()"""
self._move_cursors_to_pos()

def _load_image_data(self, ct):
"""Get MRI and CT data to display and transforms to/from vox/RAS."""
Expand Down Expand Up @@ -284,25 +285,29 @@ def _save_info(self):
'unless ``fname`` is passed (probably only used '
'from command line) which will allow saving over')

def _make_slice_plots(self):
def _make_plot_images(self):
"""Use the MRI and CT to make plots."""
self._plt = SlicePlots(self)
# Plot sagittal (0), coronal (1) or axial (2) view
self._images = dict(mri=list(), ct=list(), chs=list(),
cursor=list(), cursor2=list())
ct_cutoff = np.quantile(
self._ct_data[~np.isnan(self._ct_data)], _CT_MIN_DEFAULT)
self._ct_data[~np.isnan(self._ct_data)], _CT_MIN_DEFAULT) \
if self._T1_on else 0 # only cut off by default if T1 is on
self._ct_min_slider.setValue(ct_cutoff)
ct_min, ct_max = np.nanmin(self._ct_data), np.nanmax(self._ct_data)
ct_cmap = 'autumn_r' if self._T1_on else 'gray'
for axis in range(3):
img_data = np.take(self._mri_data, self._current_slice[axis],
axis=axis).T
self._images['mri'].append(self._plt._axes[axis].imshow(
img_data, cmap='gray', aspect='auto'))
self._plt._axes[axis].clear()
if self._T1_on:
img_data = np.take(self._mri_data, self._current_slice[axis],
axis=axis).T
self._images['mri'].append(self._plt._axes[axis].imshow(
img_data, cmap='gray', aspect='auto'))
ct_data = np.take(self._ct_data, self._current_slice[axis],
axis=axis).T
ct_data[ct_data < ct_cutoff] = np.nan
self._images['ct'].append(self._plt._axes[axis].imshow(
ct_data, cmap='autumn_r', aspect='auto', alpha=0.5,
ct_data, cmap=ct_cmap, aspect='auto', alpha=0.5,
vmin=ct_min, vmax=ct_max))
self._images['chs'].append(
self._plt._axes[axis].imshow(
Expand All @@ -324,15 +329,17 @@ def _make_slice_plots(self):
self._plt._axes[axis].set_xticks([])
self._plt._axes[axis].set_yticks([])
# label axes
self._plt._axes[axis].set_xlabel(
_IMG_LABELS[axis][0], fontsize=4)
self._plt._axes[axis].set_ylabel(
_IMG_LABELS[axis][1], fontsize=4)
self._plt._axes[axis].text(
self._img_ranges[axis][3] * 0.6,
self._img_ranges[axis][1] * 0.05,
_IMG_LABELS[axis][0], fontsize=1, color='w')
self._plt._axes[axis].text(
self._img_ranges[axis][3] * 0.05,
self._img_ranges[axis][1] * 0.6,
_IMG_LABELS[axis][1], fontsize=1, color='w')
self._plt._axes[axis].axis(self._img_ranges[axis])
self._plt._fig.suptitle('', fontsize=14)
self._plt._fig.tight_layout()
self._plt._fig.subplots_adjust(left=0.03, bottom=0.07,
wspace=0.15, hspace=0.15)
self._plt._fig.subplots_adjust(bottom=0, left=0, right=1,
top=1, wspace=0, hspace=0)
self._plt._fig.canvas.mpl_connect('scroll_event', self._on_scroll)
self._plt._fig.canvas.mpl_connect(
'button_release_event', self._on_click)
Expand Down Expand Up @@ -392,7 +399,9 @@ def _get_button_bar(self):
brush.setStyle(QtCore.Qt.SolidPattern)
group_model.setData(group_model.index(i, 0),
brush, QtCore.Qt.BackgroundRole)
self._group_selector.clicked.connect(self._update_group)
self._group_selector.clicked.connect(self._select_group)
self._group_selector.currentIndexChanged.connect(
self._update_group) # need to update background color after
button_hbox.addWidget(self._group_selector)

return button_hbox
Expand Down Expand Up @@ -499,6 +508,7 @@ def _select_group(self):
self._groups[self._ch_names[self._ch_index]] = group
# color differently if found already
self._color_list_item(self._ch_names[self._ch_index])
self._update_group()

def _update_group(self):
"""Set background for closed group menu."""
Expand All @@ -507,6 +517,7 @@ def _update_group(self):
).round().astype(int)
self._group_selector.setStyleSheet(
'background-color: rgb({:d},{:d},{:d})'.format(*rgb))
self._group_selector.update()

def _on_scroll(self, event):
"""Process mouse scroll wheel event to zoom."""
Expand Down Expand Up @@ -539,6 +550,9 @@ def _update_ch_selection(self):
self._ch_label.setText(name)
self._ch_list.setCurrentIndex(
self._ch_list_model.index(self._ch_index, 0))
# if not marked, change group label automatically
if np.isnan(self._chs[name]).any():
self._group_selector.setCurrentIndex(self._groups[name])
self._update_group()
if not np.isnan(self._chs[name]).any():
self._move_cursors_to_pos()
Expand Down Expand Up @@ -597,6 +611,7 @@ def _check_update_RAS(self):
"""Check whether the RAS textbox is done being edited."""
if '\n' in self._RAS_textbox.toPlainText():
self._update_RAS(event=None)
self._ch_list.setFocus() # remove focus from text edit

def _color_list_item(self, name=None):
"""Color the item in the view list for easy id of marked channels."""
Expand Down Expand Up @@ -769,7 +784,8 @@ def _key_press_event(self, event):
if event.text() == 'b':
# Toggle T1 scan on and off
self._T1_on = not self._T1_on
self._update_images(draw=True)
logger.info('Turning T1 ' + ('on' if self._T1_on else 'off'))
self._make_plot_images()

if event.text() == 'h':
# Show help
Expand Down

0 comments on commit 9516e48

Please sign in to comment.