Skip to content

Commit

Permalink
Merge pull request #2407 from SasView/release_5.0.6_plotting_fixes
Browse files Browse the repository at this point in the history
[Release 5.0.6] Master 5.0.6 release PR
  • Loading branch information
butlerpd authored Jan 27, 2023
2 parents ccc9d48 + 099067d commit c8ac08f
Show file tree
Hide file tree
Showing 23 changed files with 221 additions and 108 deletions.
2 changes: 2 additions & 0 deletions src/sas/logger_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def config_production(self):
logging.captureWarnings(True)
logger = logging.getLogger(self.name)
logging.getLogger('matplotlib').setLevel(logging.WARN)
logging.getLogger('numba').setLevel(logging.WARN)
return logger

def config_development(self):
Expand All @@ -42,6 +43,7 @@ def config_development(self):
logging.captureWarnings(True)
self._disable_debug_from_config()
logging.getLogger('matplotlib').setLevel(logging.WARN)
logging.getLogger('numba').setLevel(logging.WARN)
return logger

def _disable_debug_from_config(self):
Expand Down
2 changes: 1 addition & 1 deletion src/sas/qtgui/Calculators/DataOperationUtilityPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def onPrepareOutputData(self):
""" Prepare datasets to be added to DataExplorer and DataManager """
name = self.txtOutputData.text()
self.output.name = name
self.output.id = name + str(time.time())
new_item = GuiUtils.createModelItemWithPlot(
self.output,
name=name)
Expand Down Expand Up @@ -410,7 +411,6 @@ def updatePlot(self, graph, layout, data):
# plot 2D data
plotter2D = Plotter2DWidget(self, quickplot=True)
plotter2D.scale = 'linear'

plotter2D.ax.tick_params(axis='x', labelsize=8)
plotter2D.ax.tick_params(axis='y', labelsize=8)

Expand Down
30 changes: 27 additions & 3 deletions src/sas/qtgui/Calculators/UI/SldPanel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>490</width>
<height>446</height>
<width>552</width>
<height>495</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -308,10 +308,16 @@
</item>
<item row="4" column="0">
<widget class="QWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>466</width>
<height>32</height>
<height>50</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand All @@ -320,6 +326,12 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>28</height>
</size>
</property>
<property name="text">
<string>Recalculate</string>
</property>
Expand All @@ -340,13 +352,25 @@
</item>
<item row="0" column="2">
<widget class="QPushButton" name="closeButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>28</height>
</size>
</property>
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="helpButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>28</height>
</size>
</property>
<property name="text">
<string>Help</string>
</property>
Expand Down
42 changes: 32 additions & 10 deletions src/sas/qtgui/MainWindow/DataExplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def __init__(self, parent=None, guimanager=None, manager=None):
self.cbgraph.editTextChanged.connect(self.enableGraphCombo)
self.cbgraph.currentIndexChanged.connect(self.enableGraphCombo)

self.cbgraph_2.editTextChanged.connect(self.enableGraphCombo)
self.cbgraph_2.currentIndexChanged.connect(self.enableGraphCombo)

# Proxy model for showing a subset of Data1D/Data2D content
self.data_proxy = QtCore.QSortFilterProxyModel(self)
self.data_proxy.setSourceModel(self.model)
Expand Down Expand Up @@ -696,6 +699,10 @@ def deleteFile(self, event):

# Delete corresponding open plots
self.closePlotsForItem(item)
# Close result panel if results represent the deleted data item
# Results panel only stores Data1D/Data2D object
# => QStandardItems must still exist for direct comparison
self.closeResultPanelOnDelete(GuiUtils.dataFromItem(item))

self.model.removeRow(ind)
# Decrement index since we just deleted it
Expand Down Expand Up @@ -940,9 +947,12 @@ def updatePlotName(self, name_tuple):
Modify the name of the current plot
"""
old_name, current_name = name_tuple
ind = self.cbgraph.findText(old_name)
self.cbgraph.setCurrentIndex(ind)
self.cbgraph.setItemText(ind, current_name)
graph = self.cbgraph
if self.current_view == self.freezeView:
graph = self.cbgraph_2
ind = graph.findText(old_name)
graph.setCurrentIndex(ind)
graph.setItemText(ind, current_name)

def add_data(self, data_list):
"""
Expand Down Expand Up @@ -972,12 +982,15 @@ def updateGraphCombo(self, graph_list):
"""
Modify Graph combo box on graph add/delete
"""
orig_text = self.cbgraph.currentText()
self.cbgraph.clear()
self.cbgraph.insertItems(0, graph_list)
ind = self.cbgraph.findText(orig_text)
graph = self.cbgraph
if self.current_view == self.freezeView:
graph = self.cbgraph_2
orig_text = graph.currentText()
graph.clear()
graph.insertItems(0, graph_list)
ind = graph.findText(orig_text)
if ind > 0:
self.cbgraph.setCurrentIndex(ind)
graph.setCurrentIndex(ind)

def updatePerspectiveCombo(self, index):
"""
Expand Down Expand Up @@ -1207,11 +1220,13 @@ def appendPlot(self):
# new plot data; check which tab is currently active
if self.current_view == self.treeView:
new_plots = GuiUtils.plotsFromCheckedItems(self.model)
graph = self.cbgraph
else:
new_plots = GuiUtils.plotsFromCheckedItems(self.theory_model)
graph = self.cbgraph_2

# old plot data
plot_id = str(self.cbgraph.currentText())
plot_id = str(graph.currentText())
try:
assert plot_id in PlotHelper.currentPlots(), "No such plot: %s" % (plot_id)
except:
Expand Down Expand Up @@ -1883,7 +1898,14 @@ def closePlotsForItem(self, item):

pass # debugger anchor

def onAnalysisUpdate(self, new_perspective=""):
def closeResultPanelOnDelete(self, data):
"""
Given a data1d/2d object, close the fitting results panel if currently populated with the data
"""
# data - Single data1d/2d object to be deleted
self.parent.results_panel.onDataDeleted(data)

def onAnalysisUpdate(self, new_perspective_name: str):
"""
Update the perspective combo index based on passed string
"""
Expand Down
26 changes: 12 additions & 14 deletions src/sas/qtgui/MainWindow/GuiManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,31 @@ def addWidgets(self):
"""
Populate the main window with widgets
"""
# Add the console window as another docked widget
self.logDockWidget = QDockWidget("Log Explorer", self._workspace)
self.logDockWidget.setObjectName("LogDockWidget")
self.logDockWidget.visibilityChanged.connect(self.updateLogContextMenus)


self.listWidget = QTextBrowser()
self.logDockWidget.setWidget(self.listWidget)
self._workspace.addDockWidget(Qt.BottomDockWidgetArea, self.logDockWidget)

# Preload all perspectives
self.loadAllPerspectives()

# Add FileDialog widget as docked
self.filesWidget = DataExplorerWindow(self._parent, self, manager=self._data_manager)
ObjectLibrary.addObject('DataExplorer', self.filesWidget)

self.dockedFilesWidget = QDockWidget("Data Explorer", self._workspace)
self.dockedFilesWidget.setFloating(False)
self.dockedFilesWidget.setWidget(self.filesWidget)

# Modify menu items on widget visibility change
self.dockedFilesWidget.visibilityChanged.connect(self.updateContextMenus)

self._workspace.addDockWidget(Qt.LeftDockWidgetArea, self.dockedFilesWidget)
self._workspace.resizeDocks([self.dockedFilesWidget], [305], Qt.Horizontal)

# Add the console window as another docked widget
self.logDockWidget = QDockWidget("Log Explorer", self._workspace)
self.logDockWidget.setObjectName("LogDockWidget")
self.logDockWidget.visibilityChanged.connect(self.updateLogContextMenus)


self.listWidget = QTextBrowser()
self.logDockWidget.setWidget(self.listWidget)
self._workspace.addDockWidget(Qt.BottomDockWidgetArea, self.logDockWidget)

# Add other, minor widgets
self.ackWidget = Acknowledgements()
self.aboutWidget = AboutBox()
Expand All @@ -168,8 +166,8 @@ def addWidgets(self):
self.results_frame.setVisible(False)
self.results_panel.windowClosedSignal.connect(lambda: self.results_frame.setVisible(False))

self._workspace.toolBar.setVisible(LocalConfig.TOOLBAR_SHOW)
self._workspace.actionHide_Toolbar.setText("Show Toolbar")
custom_config = get_custom_config()
self._workspace.toolBar.setVisible(custom_config.TOOLBAR_SHOW)

# Add calculators - floating for usability
self.SLDCalculator = SldPanel(self)
Expand Down
5 changes: 2 additions & 3 deletions src/sas/qtgui/MainWindow/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from PyQt5.QtWidgets import QSplashScreen
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt
from PyQt5.QtCore import Qt, QTimer

# Local UI
from sas.qtgui.UI import main_resources_rc
Expand All @@ -35,7 +35,7 @@ def __init__(self, screen_resolution, parent=None):
self.screen_width = screen_resolution.width()
self.screen_height = screen_resolution.height()
self.setCentralWidget(self.workspace)

QTimer.singleShot(100, self.showMaximized)
# Temporary solution for problem with menubar on Mac
if sys.platform == "darwin": # Mac
self.menubar.setNativeMenuBar(False)
Expand Down Expand Up @@ -110,7 +110,6 @@ def run_sasview():

# Show the main SV window
mainwindow = MainSasViewWindow(screen_resolution)
mainwindow.showMaximized()

# no more splash screen
splash.finish(mainwindow)
Expand Down
13 changes: 9 additions & 4 deletions src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,17 @@ def residualsData1D(reference_data, current_data, weights):
pass

residuals.x = current_data.x[index][0]
residuals.dy = numpy.ones(len(residuals.y))
residuals.dy = None
residuals.dx = None
residuals.dxl = None
residuals.dxw = None
residuals.ytransform = 'y'
if reference_data.isSesans:
residuals.xtransform = 'x'
residuals.xaxis('\\rm{z} ', 'A')
# For latter scale changes
residuals.xaxis('\\rm{Q} ', 'A^{-1}')
else:
residuals.xaxis('\\rm{Q} ', 'A^{-1}')
residuals.yaxis('\\rm{Residuals} ', 'normalized')

return residuals
Expand All @@ -572,7 +576,7 @@ def residualsData2D(reference_data, current_data, weight):
residuals.qx_data = current_data.qx_data
residuals.qy_data = current_data.qy_data
residuals.q_data = current_data.q_data
residuals.err_data = numpy.ones(len(residuals.data))
residuals.err_data = None
residuals.xmin = min(residuals.qx_data)
residuals.xmax = max(residuals.qx_data)
residuals.ymin = min(residuals.qy_data)
Expand Down Expand Up @@ -604,7 +608,6 @@ def plotResiduals(reference_data, current_data, weights):
res_name = reference_data.name if reference_data.name else reference_data.filename
residuals.name = "Residuals for " + str(theory_name) + "[" + res_name + "]"
residuals.title = residuals.name
residuals.ytransform = 'y'

# when 2 data have the same id override the 1 st plotted
# include the last part if keeping charts for separate models is required
Expand Down Expand Up @@ -632,6 +635,8 @@ def plotPolydispersities(model):
# similar to FittingLogic._create1DPlot() but different data/axes
data1d = Data1D(x=xarr, y=yarr)
xunit = model.details[name][0]
data1d.xtransform = 'x'
data1d.ytransform = 'y'
data1d.xaxis(r'\rm{{{}}}'.format(name.replace('_', '\_')), xunit)
data1d.yaxis(r'\rm{probability}', 'normalized')
data1d.scale = 'linear'
Expand Down
16 changes: 11 additions & 5 deletions src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,10 @@ def initializeGlobals(self):
self.q_range_min = OptionsWidget.QMIN_DEFAULT
self.q_range_max = OptionsWidget.QMAX_DEFAULT
self.npts = OptionsWidget.NPTS_DEFAULT
self.log_points = False
self.log_points = True
self.weighting = 0
self.chi2 = None

# Does the control support UNDO/REDO
# temporarily off
self.undo_supported = False
Expand Down Expand Up @@ -330,6 +331,7 @@ def initializeWidgets(self):
self.options_widget = OptionsWidget(self, self.logic)
layout.addWidget(self.options_widget)
self.tabOptions.setLayout(layout)
self.options_widget.setLogScale(self.log_points)

# Smearing widget
layout = QtWidgets.QGridLayout()
Expand Down Expand Up @@ -1805,6 +1807,9 @@ def paramDictFromResults(self, results):
logger.error(msg)
return

if results.mesg:
logger.warning(results.mesg)

param_list = results.param_list # ['radius', 'radius.width']
param_values = results.pvec # array([ 0.36221662, 0.0146783 ])
param_stderr = results.stderr # array([ 1.71293015, 1.71294233])
Expand Down Expand Up @@ -1879,7 +1884,7 @@ def prepareFitters(self, fitter=None, fit_id=0):

# Data going in
data = self.logic.data
model = copy.deepcopy(self.kernel_module)
model = self.kernel_module
qmin = self.q_range_min
qmax = self.q_range_max

Expand Down Expand Up @@ -2237,7 +2242,7 @@ def _requestPlots(self, item_name, item_model):
data_shown = False
item = None
for item, plot in plots.items():
if fitpage_name in plot.name:
if plot.plot_role != Data1D.ROLE_DATA and fitpage_name in plot.name:
data_shown = True
self.communicate.plotRequestedSignal.emit([item, plot], self.tab_id)
# return the last data item seen, if nothing was plotted; supposed to be just data)
Expand All @@ -2252,6 +2257,7 @@ def onOptionsUpdate(self):
# set Q range labels on the main tab
self.lblMinRangeDef.setText(GuiUtils.formatNumber(self.q_range_min, high=True))
self.lblMaxRangeDef.setText(GuiUtils.formatNumber(self.q_range_max, high=True))
self.recalculatePlotData()

def setDefaultStructureCombo(self):
"""
Expand Down Expand Up @@ -4207,12 +4213,12 @@ def updatePageWithParameters(self, line_dict, warn_user=True):
pass
if 'smearing_min' in line_dict.keys():
try:
self.smearing_widget.dq_l = float(line_dict['smearing_min'][0])
self.smearing_widget.dq_r = float(line_dict['smearing_min'][0])
except ValueError:
pass
if 'smearing_max' in line_dict.keys():
try:
self.smearing_widget.dq_r = float(line_dict['smearing_max'][0])
self.smearing_widget.dq_l = float(line_dict['smearing_max'][0])
except ValueError:
pass

Expand Down
Loading

0 comments on commit c8ac08f

Please sign in to comment.