Skip to content

Commit

Permalink
plots tests added/updated for configuration settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mpatrou committed Aug 21, 2023
1 parent eee4f87 commit 25fdfea
Show file tree
Hide file tree
Showing 3 changed files with 430 additions and 28 deletions.
25 changes: 18 additions & 7 deletions src/shiver/views/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)
from qtpy.QtCore import Signal

from shiver.configuration import get_data
from .loading_buttons import LoadingButtons
from .histogram_parameters import HistogramParameter
from .workspace_tables import InputWorkspaces, HistogramWorkspaces
Expand Down Expand Up @@ -78,13 +79,7 @@ def make_slice_finish(self, ws_name, ndims):
self.makeslice_finish_signal.emit(ws_name, ndims)

def _make_slice_finish(self, ws_name, ndims):
display_name = self.plot_display_name_callback(ws_name, ndims)
min_intensity = self.histogram_parameters.dimensions.intensity_min.text()
max_intensity = self.histogram_parameters.dimensions.intensity_max.text()
intensity_limits = {
"min": float(min_intensity) if min_intensity != "" else None,
"max": float(max_intensity) if max_intensity != "" else None,
}
display_name, intensity_limits = self.get_plot_data(ws_name, ndims)
do_default_plot(ws_name, ndims, display_name, intensity_limits)
self.histogram_workspaces.histogram_workspaces.set_selected(ws_name)

Expand Down Expand Up @@ -203,3 +198,19 @@ def unset_all(self):
self.input_workspaces.mde_workspaces.unset_all()
self.input_workspaces.norm_workspaces.deselect_all()
self.set_field_invalid_state(self.input_workspaces.mde_workspaces)

def get_plot_data(self, ws_name, ndims):
"""Get display name and intensities data for plotting."""
plot_title_preference = get_data("main_tab.plot", "title")
display_name = None
if plot_title_preference == "full":
display_name = self.plot_display_name_callback(ws_name, ndims)
if plot_title_preference == "name_only":
display_name = ws_name.name()
min_intensity = self.histogram_parameters.dimensions.intensity_min.text()
max_intensity = self.histogram_parameters.dimensions.intensity_max.text()
intensity_limits = {
"min": float(min_intensity) if min_intensity != "" else None,
"max": float(max_intensity) if max_intensity != "" else None,
}
return (display_name, intensity_limits)
49 changes: 37 additions & 12 deletions src/shiver/views/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,44 @@
import matplotlib.pyplot as plt
from mantidqt.widgets.sliceviewer.presenters.presenter import SliceViewer
from mantidqt.plotting.functions import manage_workspace_names, plot_md_ws_from_names
from shiver.configuration import get_data


@manage_workspace_names
def do_1d_plot(workspaces, display_name, intensity_limits=None):
def do_1d_plot(workspaces, display_name, intensity_limits=None, log_scale=False):
"""Create an 1D plot for the provided workspace"""
fig = plot_md_ws_from_names(workspaces, False, False)
plot_title = display_name if display_name else workspaces[0].name()
min_limit = intensity_limits["min"] if intensity_limits is not None and "min" in intensity_limits else None
max_limit = intensity_limits["max"] if intensity_limits is not None and "max" in intensity_limits else None
fig.axes[0].set_ylim(min_limit, max_limit)

# logarithic case
if log_scale:
fig.axes[0].set_yscale("log")

# y limits
if not (min_limit is None and max_limit is None):
fig.axes[0].set_ylim(min_limit, max_limit)

fig.canvas.manager.set_window_title(display_name)
fig.axes[0].set_title(plot_title)
return fig


@manage_workspace_names
def do_colorfill_plot(workspaces, display_name=None, intensity_limits=None):
def do_colorfill_plot(workspaces, display_name=None, intensity_limits=None, log_scale=False):
"""Create a colormesh plot for the provided workspace"""
fig, axis = plt.subplots(subplot_kw={"projection": "mantid"})
plot_title = display_name or workspaces[0].name()
# y limits
min_limit = intensity_limits["min"] if intensity_limits is not None and "min" in intensity_limits else None
max_limit = intensity_limits["max"] if intensity_limits is not None and "max" in intensity_limits else None
colormesh = axis.pcolormesh(workspaces[0], vmin=min_limit, vmax=max_limit)

# logarithic case
scale_norm = "linear"
if log_scale:
scale_norm = "log"
colormesh = axis.pcolormesh(workspaces[0], vmin=min_limit, vmax=max_limit, norm=scale_norm)
axis.set_title(plot_title)
fig.canvas.manager.set_window_title(plot_title)

Expand All @@ -34,7 +49,7 @@ def do_colorfill_plot(workspaces, display_name=None, intensity_limits=None):


@manage_workspace_names
def do_slice_viewer(workspaces, parent=None, intensity_limits=None):
def do_slice_viewer(workspaces, parent=None, intensity_limits=None, log_scale=False):
"""Open sliceviewer for the provided workspace"""
presenter = SliceViewer(ws=workspaces[0], parent=parent)

Expand All @@ -48,21 +63,31 @@ def do_slice_viewer(workspaces, parent=None, intensity_limits=None):
if intensity_limits is not None and intensity_limits["max"] is not None
else presenter.view.data_view.colorbar.cmax_value
)
presenter.view.data_view.colorbar.cmin.setText(f"{min_limit:.4}")
presenter.view.data_view.colorbar.clim_changed()
presenter.view.data_view.colorbar.cmax.setText(f"{max_limit:.4}")
presenter.view.data_view.colorbar.clim_changed()

# y limits
if not (min_limit is None and max_limit is None):
presenter.view.data_view.colorbar.cmin.setText(f"{min_limit:.4}")
presenter.view.data_view.colorbar.clim_changed()
presenter.view.data_view.colorbar.cmax.setText(f"{max_limit:.4}")
presenter.view.data_view.colorbar.clim_changed()

# logarithic case
if log_scale:
norm_scale = "Log"
presenter.view.data_view.colorbar.norm.setCurrentText(norm_scale)
presenter.view.data_view.colorbar.norm_changed()

presenter.view.show()
return presenter.view


def do_default_plot(workspace, ndims, display_name=None, intensity_limits=None):
"""Create the default plot for the workspace and number of dimensions"""
log_scale = get_data("main_tab.plot", "logarithmic_intensity")
if ndims == 1:
return do_1d_plot([workspace], display_name, intensity_limits)
return do_1d_plot([workspace], display_name, intensity_limits, log_scale)
if ndims == 2:
return do_colorfill_plot([workspace], display_name, intensity_limits)
return do_colorfill_plot([workspace], display_name, intensity_limits, log_scale)
if ndims in (3, 4):
return do_slice_viewer([workspace], intensity_limits=intensity_limits)
return do_slice_viewer([workspace], intensity_limits=intensity_limits, log_scale=log_scale)
return None
Loading

0 comments on commit 25fdfea

Please sign in to comment.