def _handle_amp_change(self, change): self._toggle_updating_state() state = self._state widget = self._widget widget['amplitude_slider'].disabled = True new_amp = change['new'] * 1e-9 self._state['dipole_amplitude'] = new_amp if (state['dipole_pos']['x'] is not None and state['dipole_ori']['x'] is not None and state['dipole_pos'] != state['dipole_ori']): plot_evoked(widget, state, fwd_path=self._fwd_path, subject=self._subject, info=self._info, ras_to_head_t=self._ras_to_head_t, exact_solution=self._exact_solution, bem_path=self._bem_path, head_to_mri_t=self._trans, fwd_lookup_table=self._fwd_lookup_table, t1_img=self._t1_img) self._toggle_updating_state() widget['amplitude_slider'].disabled = False
def _handle_preset_selection_change(self, change): self._toggle_updating_state() preset_name = change['new'] if preset_name == 'Select Preset…': self._toggle_updating_state() return preset = self._preset_coords[preset_name] pos = np.array(preset['pos']).astype(float) ori = np.array(preset['ori']).astype(float) ori /= np.linalg.norm(ori) pos = dict(x=pos[0], y=pos[1], z=pos[2]) ori = dict(x=ori[0], y=ori[1], z=ori[2]) self._state['dipole_pos'] = pos self._state['dipole_ori'] = ori for plane, coord in pos.items(): self._state['slice_coord'][plane]['val'] = coord state = self._state widget = self._widget update_dipole_pos(dipole_pos_ras=pos, ras_to_head_t=self._ras_to_head_t, widget=self._widget, evoked=self._evoked) update_dipole_ori(dipole_ori_ras=ori, ras_to_head_t=self._ras_to_head_t, widget=self._widget, evoked=self._evoked) self._plot_slice(axis='all') draw_dipole_if_necessary(state=self._state, widget=self._widget, markers=self._markers) if (state['dipole_pos']['x'] is not None and state['dipole_ori']['x'] is not None and state['dipole_pos'] != state['dipole_ori']): plot_evoked(widget, state, fwd_path=self._fwd_path, subject=self._subject, info=self._info, ras_to_head_t=self._ras_to_head_t, exact_solution=self._exact_solution, bem_path=self._bem_path, head_to_mri_t=self._trans, fwd_lookup_table=self._fwd_lookup_table, t1_img=self._t1_img) self._toggle_updating_state()
def _handle_slice_click(self, event): if event.button != MouseButton.LEFT: return self._toggle_updating_state() widget, markers, state = self._widget, self._markers, self._state in_ax = event.inaxes if in_ax is None: # User clicked into the figure, but outside an axes self._toggle_updating_state() return x, y = event.xdata, event.ydata # Which slice (axis) was clicked in? for axis, fig in widget['fig'].items(): if fig is in_ax.figure: break x_idx, y_idx = get_axis_names_from_slice(slice_view=axis, all_axes=widget['fig'].keys()) remaining_idx = axis if state['mode'] == 'slice_browser': handle_click_in_slice_browser_mode(widget, markers, state, x, y, x_idx, y_idx, self._evoked, self._t1_img_canonical_data) elif state['mode'] == 'set_dipole_pos': handle_click_in_set_dipole_pos_mode(widget, state, x_idx, y_idx, remaining_idx, x, y, self._ras_to_head_t, evoked=self._evoked) elif state['mode'] == 'set_dipole_ori': # Construct the 3D coordinates of the clicked-on point handle_click_in_set_dipole_ori_mode(widget, state, x_idx, y_idx, remaining_idx, x, y, self._ras_to_head_t, evoked=self._evoked) self._plot_dipole_markers_and_arrow() self._enable_crosshair_cursor() if (state['dipole_pos']['x'] is not None and state['dipole_ori']['x'] is not None and state['dipole_pos'] != state['dipole_ori']): plot_evoked(widget, state, fwd_path=self._fwd_path, subject=self._subject, info=self._info, ras_to_head_t=self._ras_to_head_t, exact_solution=self._exact_solution, bem_path=self._bem_path, head_to_mri_t=self._trans, fwd_lookup_table=self._fwd_lookup_table, t1_img=self._t1_img) self._toggle_updating_state()