Skip to content

Commit

Permalink
Re #4303 better range selection widget
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Feb 6, 2012
1 parent dc5a5b2 commit 39eeea2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ def _plot_tof(self):

f = FileFinder.findRuns("REF_L%s" % str(self._summary.norm_run_number_edit.text()))
if len(f)>0 and os.path.isfile(f[0]):
data_manipulation.tof_distribution(f[0])
def call_back(xmin, xmax):
self._summary.data_from_tof.setText("%-d" % int(xmin))
self._summary.data_to_tof.setText("%-d" % int(xmax))
data_manipulation.tof_distribution(f[0], call_back)

def _add_data(self):
state = self.get_editing_state()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def _apply(self):
item = self._workspace_list[i]
data = DataSet(item.name)
data.load(True, True)
xmin,xmax = data.get_range()
data.set_range(xmin+0.002,xmax-0.001)
item.set_user_data(data)

if item.is_selected():
Expand Down
18 changes: 14 additions & 4 deletions Code/Mantid/scripts/LargeScaleStructures/data_stitching.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,38 @@ class RangeSelector(object):
class _Selector(object):
def __init__(self):
self._call_back = None
self._graph = "StitcherRangeSelector"
self._graph = "Range Selector"

def disconnect(self):
_qti.app.disconnect(_qti.app.mantidUI, QtCore.SIGNAL("x_range_update(double,double)"), self._call_back)

def connect(self, ws, call_back):
def connect(self, ws, call_back, xmin=None, xmax=None):
self._call_back = call_back
_qti.app.connect(_qti.app.mantidUI, QtCore.SIGNAL("x_range_update(double,double)"), self._call_back)
g = _qti.app.graph(self._graph)
if g is not None:
g.close()
g = _qti.app.mantidUI.pyPlotSpectraList(ws,[0],True)
g.setName(self._graph)
l=g.activeLayer()
try:
title = ws[0].replace("_"," ")
title.strip()
except:
title = " "
l.setTitle(" ")
l.setCurveTitle(0, title)
if xmin is not None and xmax is not None:
l.setScale(2,xmin,xmax)
_qti.app.selectMultiPeak(g,False)

@classmethod
def connect(cls, ws, call_back):
def connect(cls, ws, call_back, xmin=None, xmax=None):
if RangeSelector.__instance is not None:
RangeSelector.__instance.disconnect()
else:
RangeSelector.__instance = RangeSelector._Selector()
RangeSelector.__instance.connect(ws, call_back)
RangeSelector.__instance.connect(ws, call_back, xmin=xmin, xmax=xmax)

class DataSet(object):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,33 @@
from mantidsimple import *
from reduction.instruments.reflectometer import wks_utility

def tof_distribution(file_path):
def tof_distribution(file_path, callback=None):
"""
Plot counts as a function of TOF for a given REF_L data file
"""
ws = "__REFL_TOF_distribution"
graph_name = "TOF distribution"
ws = "__TOF_distribution"
LoadEventNexus(Filename=file_path, OutputWorkspace=ws)
Rebin(InputWorkspace=ws,OutputWorkspace=ws,Params="0,200,200000")
SumSpectra(InputWorkspace=ws, OutputWorkspace=ws)
g = _qti.app.graph(graph_name)
if g is None:
g = _qti.app.mantidUI.pyPlotSpectraList([ws],[0],True)
g.setName(graph_name)
x = mtd[ws].readX(0)
y = mtd[ws].readY(0)
xmin = x[0]
xmax = None
for i in range(len(y)):
if y[i]==0.0 and xmax is None:
xmin = x[i]
if y[i]>0:
xmax = x[i]

l=g.activeLayer()
l.setScale(2,xmin,xmax)
l.setTitle(" ")

# Get range of TOF where we have data
x = mtd[ws].readX(0)
y = mtd[ws].readY(0)
xmin = x[0]
xmax = None
for i in range(len(y)):
if y[i]==0.0 and xmax is None:
xmin = x[i]
if y[i]>0:
xmax = x[i]

if callback is not None:
from LargeScaleStructures import data_stitching
data_stitching.RangeSelector.connect([ws], callback, xmin=xmin, xmax=xmax)

def counts_vs_y_distribution(file_path, callback=None):
ws = "__REFL_data"
ws_output = "__REFL_Y_distribution"
graph_name = "Counts vs Y"
ws_output = "__Counts_vs_Y"
LoadEventNexus(Filename=file_path, OutputWorkspace=ws)

# 1D plot
Expand Down Expand Up @@ -60,28 +56,6 @@ def counts_vs_y_distribution(file_path, callback=None):

if callback is not None:
from LargeScaleStructures import data_stitching
#def callback(xmin,xmax):
# print xmin,xmax
data_stitching.RangeSelector.connect([ws_output], callback)

return

g = _qti.app.graph(graph_name)
if g is None:
g = _qti.app.mantidUI.pyPlotSpectraList([ws_output],[0],True)
g.setName(graph_name)
x = mtd[ws_output].readX(0)
y = mtd[ws_output].readY(0)
xmin = x[0]
xmax = None
for i in range(len(y)):
if y[i]==0.0 and xmax is None:
xmin = x[i]
if y[i]>0:
xmax = x[i]

l=g.activeLayer()
l.setScale(2,xmin,xmax)
l.setTitle(" ")


0 comments on commit 39eeea2

Please sign in to comment.