From 80058232811c890cedad1f521ad6af8995e93c55 Mon Sep 17 00:00:00 2001 From: dehoni Date: Wed, 20 Sep 2023 17:18:51 +0100 Subject: [PATCH] fix loading 2D data for new slicer and flagging batch+2D data loading --- .../Inversion/InversionPerspective.py | 52 ++++++++++--------- .../Perspectives/Inversion/InversionWidget.py | 10 ++-- .../qtgui/Plotting/Slicers/SectorSlicer.py | 8 +-- 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py b/src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py index 7c7c2644ad..515702c5bc 100644 --- a/src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py +++ b/src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py @@ -16,14 +16,13 @@ # pr inversion calculation elements from sas.sascalc.pr.invertor import Invertor -from sas.qtgui.Plotting.PlotterData import Data1D +from sas.qtgui.Plotting.PlotterData import Data1D, Data2D # Batch calculation display from sas.qtgui.Utilities.GridPanel import BatchInversionOutputPanel from sas.qtgui.Perspectives.perspective import Perspective from sas.qtgui.Perspectives.Inversion.InversionWidget import InversionWidget, DICT_KEYS, NUMBER_OF_TERMS, REGULARIZATION -from sasdata.dataloader import Data2D logger = logging.getLogger(__name__) @@ -320,33 +319,36 @@ def setData(self, data_item=None, is_batch=False, tab_index=None): - items = [data_item] if is_batch else data_item + items = [data_item] if (is_batch and len([data_item])>1) else data_item for data in items: logic_data = GuiUtils.dataFromItem(data) is_2Ddata = isinstance(logic_data, Data2D) - - - # Find the first unassigned tab. - # If none, open a new tab. - available_tabs = [tab.acceptsData() for tab in self.tabs] - tab_ids = [tab.tab_id for tab in self.tabs] - if tab_index is not None: - if tab_index not in tab_ids: - self.addData(data = data, is2D=is_2Ddata, is_batch=is_batch, tab_index=tab_index) + if is_2Ddata and is_batch: + msg = "2D Data cannot be inverted as Batch" + raise RuntimeError(msg) + else: + # Find the first unassigned tab. + # If none, open a new tab. + available_tabs = [tab.acceptsData() for tab in self.tabs] + tab_ids = [tab.tab_id for tab in self.tabs] + if tab_index is not None: + if tab_index not in tab_ids: + self.addData(data = data, is2D=is_2Ddata, is_batch=is_batch, tab_index=tab_index) + else: + self.setCurrentIndex(tab_index-1) + self.swapData(data = data, is2D = is_2Ddata) + return + #debug Batch mode, gives none Type has no attribute name + if not is_batch and np.any(available_tabs): + first_good_tab = available_tabs.index(True) + self.tabs[first_good_tab].data = data + self.tabs[first_good_tab].updateTab(data = data, is2D = is_2Ddata) + else: - self.setCurrentIndex(tab_index-1) - self.swapData(data = data, is2D = is_2Ddata) - return - #debug Batch mode, gives none Type has no attribute name - if not is_batch and np.any(available_tabs): - first_good_tab = available_tabs.index(True) - self.tabs[first_good_tab].data = data - self.tabs[first_good_tab].updateTab(data = data, is2D = is_2Ddata) - - else: - self.addData(data = data, is2D=is_2Ddata, is_batch=is_batch, tab_index = tab_index) - - + self.addData(data = data, is2D=is_2Ddata, is_batch=is_batch, tab_index = tab_index) + + + def swapData(self, data = None, is2D = False): diff --git a/src/sas/qtgui/Perspectives/Inversion/InversionWidget.py b/src/sas/qtgui/Perspectives/Inversion/InversionWidget.py index 4f0b5810e5..6e15b71a01 100644 --- a/src/sas/qtgui/Perspectives/Inversion/InversionWidget.py +++ b/src/sas/qtgui/Perspectives/Inversion/InversionWidget.py @@ -555,7 +555,7 @@ def stopCalculation(self): def check_q_low(self, q_value=None): """ Validate the low q value """ if not q_value: - q_value = float(self.minQInput.text()) if self.minQInput.text() else '0.0' + q_value = float(self.minQInput.text()) if self.minQInput.text() else 0.0 q_min = min(self._calculator.x) if any(self._calculator.x) else 0.0 q_max = self._calculator.get_qmax() if self._calculator.get_qmax() is not None else np.inf if q_value > q_max: @@ -573,7 +573,7 @@ def check_q_low(self, q_value=None): def check_q_high(self, q_value=None): """ Validate the value of high q sent by the slider """ if not q_value: - q_value = float(self.maxQInput.text()) if self.maxQInput.text() else '1.0' + q_value = float(self.maxQInput.text()) if self.maxQInput.text() else 1.0 q_max = max(self._calculator.x) if any(self._calculator.x) else np.inf q_min = self._calculator.get_qmin() if self._calculator.get_qmin() is not None else 0.0 if q_value > q_max: @@ -1325,9 +1325,9 @@ def updateSlicerParams(self): self.phi = self.startPoint self.deltaPhi = (180 / self.noOfSlices) print(self.deltaPhi) - self.setSlicerParms() + self.setSlicerParams() - def setSlicerParms(self): + def setSlicerParams(self): params = self.plot2D.slicer.getParams() params["Phi [deg]"] = self.phi params["Delta_Phi [deg]"] = self.deltaPhi @@ -1344,7 +1344,7 @@ def muiltiSlicer(self): for i in range(self.noOfSlices): params["Phi [deg]"] = self.phi - self.setSlicerParms() + self.setSlicerParams() slicePlot = self.plot2D.slicer.captureSlice() slicePlot.title += ' φ {}'.format(self.phi) slicePlot.phi = self.phi diff --git a/src/sas/qtgui/Plotting/Slicers/SectorSlicer.py b/src/sas/qtgui/Plotting/Slicers/SectorSlicer.py index 84bd411fda..e74f65d1be 100644 --- a/src/sas/qtgui/Plotting/Slicers/SectorSlicer.py +++ b/src/sas/qtgui/Plotting/Slicers/SectorSlicer.py @@ -69,7 +69,7 @@ def __init__(self, base, axes, item=None, color='black', zorder=3): self.left_line.qmax = self.qmax # draw the sector self.update() - self._post_data() + self._post_data(show_plots = False) self.draw() self.setModelFromParams() @@ -283,7 +283,7 @@ def setParams(self, params): self.left_line.update(phi=phi, delta=None, mline=self.main_line, side=True, left=True) # Post the new corresponding data - self._post_data(nbins=self.nbins) + self._post_data(nbins=self.nbins, show_plots = False) self.draw() def draw(self): @@ -391,13 +391,13 @@ def update(self, phi=None, delta=None, mline=None, else: self.phi = numpy.fabs(self.phi) if side: - self.theta = mline.alpha + self.phi + self.theta = mline.theta + self.phi if mline is not None: if delta != 0: self.theta2 = mline + delta else: - self.theta2 = mline.alpha + self.theta2 = mline.theta if delta == 0: theta3 = self.theta + delta else: