Skip to content

Commit

Permalink
refs #9826. Stitch as part of process.
Browse files Browse the repository at this point in the history
If stitch is checked, then the stitched output workspace will be generated as part of the processing. If it is done after, then it is completed as part of the plot process
  • Loading branch information
OwenArnold committed Jul 7, 2014
1 parent 860b337 commit 729738a
Showing 1 changed file with 57 additions and 24 deletions.
81 changes: 57 additions & 24 deletions Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py
Expand Up @@ -167,7 +167,7 @@ def _table_modified(self, row, column):
if not self.loading:
self.mod_flag = True
plotbutton = self.tableMain.cellWidget(row, self.plot_col).children()[1]
self._reset_plot_button(plotbutton)
self.__reset_plot_button(plotbutton)

def _plot_row(self):
"""
Expand Down Expand Up @@ -222,9 +222,9 @@ def _reset_table(self):
self.checkTickAll.setCheckState(0)
for row in range(self.tableMain.rowCount()):
plotbutton = self.tableMain.cellWidget(row, self.plot_col).children()[1]
self._reset_plot_button(plotbutton)
self.__reset_plot_button(plotbutton)

def _reset_plot_button(self, plotbutton):
def __reset_plot_button(self, plotbutton):
"""
Reset the provided plot button to ti's default state: disabled and with no cache
"""
Expand Down Expand Up @@ -276,7 +276,7 @@ def _initialise_table(self):
elif column == self.plot_col:
button = QtGui.QPushButton('Plot')
button.setProperty("row", row)
self._reset_plot_button(button)
self.__reset_plot_button(button)
button.setToolTip('Plot the workspaces produced by processing this row.')
button.clicked.connect(self._plot_row)
item = QtGui.QWidget()
Expand Down Expand Up @@ -668,6 +668,10 @@ def _set_all_stitch(self,state):
for row in range(self.tableMain.rowCount()):
self.tableMain.cellWidget(row, self.stitch_col).children()[1].setCheckState(state)


def __checked_row_stiched(self, row):
return self.tableMain.cellWidget(row, self.stitch_col).children()[1].checkState() > 0

def _process(self):
"""
Process has been pressed, check what has been selected then pass the selection (or whole table) to quick
Expand Down Expand Up @@ -756,6 +760,31 @@ def _process(self):
overlapHigh.append(qmax)
if wksp[i].find(',') > 0 or wksp[i].find(':') > 0:
wksp[i] = first_wq.name()

if self.__checked_row_stiched(row):
if (len(runno) == 1):
logger.notice("Nothing to combine for processing row : " + str(row))
else:
w1 = getWorkspace(wksp[0])
w2 = getWorkspace(wksp[-1])
if (len(runno) == 2):
outputwksp = runno[0] + '_' + runno[1][3:5]
else:
outputwksp = runno[0] + '_' + runno[-1][3:5]
begoverlap = w2.readX(0)[0]
# get Qmax
if (self.tableMain.item(row, i * 5 + 4).text() == ''):
overlapHigh = 0.3 * max(w1.readX(0))

Qmin = min(w1.readX(0))
Qmax = max(w2.readX(0))

wcomb = combineDataMulti(wksp, outputwksp, overlapLow, overlapHigh, Qmin, Qmax, -dqq, 1, keep=True)
if self.tableMain.item(row, self.scale_col).text():
Scale(InputWorkspace=outputwksp, OutputWorkspace=outputwksp, Factor=1 / float(self.tableMain.item(row, self.scale_col).text()))


# Enable the plot button
plotbutton = self.tableMain.cellWidget(row, self.plot_col).children()[1]
plotbutton.setProperty('runno',runno)
plotbutton.setProperty('overlapLow', overlapLow)
Expand Down Expand Up @@ -798,15 +827,15 @@ def _plot(self, plotbutton):
dqq = float(self.tableMain.item(row, 15).text())
except:
logger.error("Unable to plot row, required data couldn't be retrieved")
_reset_plot_button(plotbutton)
self.__reset_plot_button(plotbutton)
return
for i in range(len(runno)):
ws_name_binned = wksp[i] + '_binned'
ws = getWorkspace(wksp[i])
if len(overlapLow):
Qmin = overlapLow[0]
else:
Qmin = w1.readX(0)[0]
Qmin = min(w1.readX(0))
if len(overlapHigh):
Qmax = overlapHigh[len(overlapHigh) - 1]
else:
Expand All @@ -826,29 +855,28 @@ def _plot(self, plotbutton):
g[0].activeLayer().setAxisScale(Layer.Left, Imin * 0.1, Imax * 10, Layer.Log10)
g[0].activeLayer().setAxisScale(Layer.Bottom, Qmin * 0.9, Qmax * 1.1, Layer.Log10)
g[0].activeLayer().setAutoScale()
if (self.tableMain.cellWidget(row, self.stitch_col).children()[1].checkState() > 0):
if (len(runno) == 1):
logger.notice("Nothing to combine!")
elif (len(runno) == 2):

# Create and plot stitched outputs
if self.__checked_row_stiched(row):
if (len(runno) == 2):
outputwksp = runno[0] + '_' + runno[1][3:5]
else:
outputwksp = runno[0] + '_' + runno[2][3:5]
begoverlap = w2.readX(0)[0]
# get Qmax
if (self.tableMain.item(row, i * 5 + 4).text() == ''):
overlapHigh = 0.3 * max(w1.readX(0))
wcomb = combineDataMulti(wkspBinned, outputwksp, overlapLow, overlapHigh, Qmin, Qmax, -dqq, 1)
if self.tableMain.item(row, self.scale_col).text():
Scale(InputWorkspace=outputwksp, OutputWorkspace=outputwksp, Factor=1 / float(self.tableMain.item(row, self.scale_col).text()))
Qmin = getWorkspace(outputwksp).readX(0)[0]
if not getWorkspace(outputwksp, report_error=False):
# Stitching has not been done as part of processing, so we need to do it here.
wcomb = combineDataMulti(wkspBinned, outputwksp, overlapLow, overlapHigh, Qmin, Qmax, -dqq, 1, keep=True)
if self.tableMain.item(row, self.scale_col).text():
Scale(InputWorkspace=outputwksp, OutputWorkspace=outputwksp, Factor=1 / float(self.tableMain.item(row, self.scale_col).text()))

Qmin = min(getWorkspace(outputwksp).readX(0))
Qmax = max(getWorkspace(outputwksp).readX(0))
if canMantidPlot:
gcomb = plotSpectrum(outputwksp, 0, True)
titl = groupGet(outputwksp, 'samp', 'run_title')
gcomb.activeLayer().setTitle(titl)
gcomb.activeLayer().setAxisScale(Layer.Left, 1e-8, 100.0, Layer.Log10)
gcomb.activeLayer().setAxisScale(Layer.Bottom, Qmin * 0.9, Qmax * 1.1, Layer.Log10)


def _name_trans(self, transrun):
"""
Expand Down Expand Up @@ -1277,18 +1305,23 @@ def groupGet(wksp, whattoget, field=''):
else:
return 0

def getWorkspace(wksp):
def getWorkspace(wksp, report_error=True):
"""
Gets the first workspace associated with the given string. Does not load.
"""
if isinstance(wksp, Workspace):
return wksp
elif isinstance(wksp, str):
if isinstance(mtd[wksp], WorkspaceGroup):
exists = mtd.doesExist(wksp)
if not exists:
if report_error:
logger.error( "Unable to get workspace: " + str(wksp))
return exists # Doesn't exist
else:
return exists # Doesn't exist
elif isinstance(mtd[wksp], WorkspaceGroup):
wout = mtd[wksp][0]
else:
wout = mtd[wksp]
return wout
else:
logger.error( "Unable to get workspace: " + str(wksp))
return 0

0 comments on commit 729738a

Please sign in to comment.