Skip to content

Commit

Permalink
fix loading 2D data for new slicer and flagging batch+2D data loading
Browse files Browse the repository at this point in the history
  • Loading branch information
dehoni committed Sep 20, 2023
1 parent cf4ac19 commit 8005823
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 34 deletions.
52 changes: 27 additions & 25 deletions src/sas/qtgui/Perspectives/Inversion/InversionPerspective.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions src/sas/qtgui/Perspectives/Inversion/InversionWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/sas/qtgui/Plotting/Slicers/SectorSlicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 8005823

Please sign in to comment.