Commit c7d75528 authored by Matthijs's avatar Matthijs
Browse files

extended stackviewer GUI functionality

parent fdebd298
......@@ -32,6 +32,7 @@ from matplotlib.pyplot import subplots, show
import numpy as np
from .complex_field_visualization import complex_to_rgb
from .stack_viewer import XYZStackViewer, SingleStackViewer
from proxtoolbox.Utilities.OrbitalTomog import shifted_fft
def Phase_graphics(config, output):
......@@ -83,6 +84,8 @@ def Phase_graphics_3d(config, output):
phys_constraint_plot = XYZStackViewer(output['u1'],
name='Physical constraint satisfied (%s)' % config['constraint'])
fourier_constraint_plot = XYZStackViewer(output['u2'], name='Fourier constraint satisfied')
fourier_space_plot = XYZStackViewer(shifted_fft(output['u1']),
name='Fourier space under physical constraint (%s)' % config['constraint'])
convergence_plots, ax = subplots(1, 2, figsize=(7, 3))
ax[0].semilogy(output['change'])
......@@ -97,4 +100,4 @@ def Phase_graphics_3d(config, output):
convergence_plots.tight_layout()
show()
return phys_constraint_plot, fourier_constraint_plot, convergence_plots
return phys_constraint_plot, fourier_constraint_plot, fourier_space_plot, convergence_plots
import matplotlib.pyplot as plt
from matplotlib import get_backend
from numpy import max, min, iscomplexobj
from matplotlib.widgets import Slider
from matplotlib.widgets import Slider, RadioButtons
from warnings import warn
from .complex_field_visualization import complex_to_rgb
......@@ -68,7 +68,7 @@ class XYZStackViewer:
if get_backend() not in good_backends:
warn(Warning('Current matplotlib backend may not allow for optimal funcionality! Use, e.g., Qt'))
if volume.ndim == 4 and volume.shape[-1] in [3,4]:
if volume.ndim == 4 and volume.shape[-1] in [3, 4]:
rgb_plot = True
else:
# assert volume.ndim == 3, 'Functionality is designed for 3D arrays'
......@@ -79,12 +79,14 @@ class XYZStackViewer:
else:
show_colorbar = False
radio_start = 0
if data_transform is not None:
self.cast_fn = data_transform
elif iscomplexobj(volume):
self.cast_fn = complex_to_rgb
show_colorbar = False
rgb_plot = True
self.cast_fn = abs # complex_to_rgb
show_colorbar = True # False
rgb_plot = False # True
radio_start = 0 # 1
else:
def dummy(array):
return array
......@@ -138,6 +140,17 @@ class XYZStackViewer:
valinit=self.indices[2], valstep=1, valfmt='%d')
self.ax3slider.on_changed(self.update_3)
if iscomplexobj(self.volume):
self.fig.set_size_inches(10, 5)
self.fig.subplots_adjust(top=0.95)
rax = self.fig.add_axes([0.45, 0.75, 0.15, 0.2], facecolor=axcolor, frame_on=False)
self.abs_label = 'Abs value'
self.complexcolorlabel = 'Complex to color'
self.radio = RadioButtons(rax, (self.abs_label, self.complexcolorlabel), active=radio_start)
# self.radio.circles
self.radio.on_clicked(self.set_cast_fn)
# self.fig.tight_layout()
self.fig.show()
def update_1(self, n):
......@@ -158,3 +171,12 @@ class XYZStackViewer:
self.ax[2].images[0].set_array(self.cast_fn(self.volume[:, :, int(n)]))
self.fig.canvas.draw_idle()
def set_cast_fn(self, radio_label):
if radio_label == self.abs_label:
self.cast_fn = abs
elif radio_label == self.complexcolorlabel:
self.cast_fn = complex_to_rgb
self.update_1(self.ax1slider.val)
self.update_2(self.ax2slider.val)
self.update_3(self.ax3slider.val)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment