Skip to content

Commit

Permalink
Re #4303 Added automated stitching to REFL
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Jan 20, 2012
1 parent 0d254a2 commit ffb78b6
Show file tree
Hide file tree
Showing 13 changed files with 493 additions and 65 deletions.
69 changes: 43 additions & 26 deletions Code/Mantid/Framework/PythonAPI/PythonAlgorithms/RefLReduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ def PyExec(self):
# Pick a good workspace name
ws_name = "refl%d" % run_numbers[0]
ws_event_data = ws_name+"_evt"

# Load the data into its workspace
LoadEventNexus(Filename=data_file, OutputWorkspace=ws_event_data)
if not mtd.workspaceExists(ws_event_data):
LoadEventNexus(Filename=data_file, OutputWorkspace=ws_event_data)

# Get metadata
mt_run = mtd[ws_event_data].getRun()
Expand Down Expand Up @@ -155,24 +157,25 @@ def PyExec(self):
#Create a new event workspace of only the range of pixel of interest
#background range (along the y-axis) and of only the pixel
#of interest along the x-axis (to avoid the frame effect)
theta = tthd_rad - ths_rad
mt2 = wks_utility.createIntegratedWorkspace(mtd[ws_histo_data],
"IntegratedDataWks",
fromXpixel=Xrange[0],
toXpixel=Xrange[1],
fromYpixel=BackfromYpixel,
toYpixel=BacktoYpixel,
maxX=maxX,
maxY=maxY)
maxY=maxY,
source_to_detector=dMD,
theta=theta)

theta = tthd_rad - ths_rad
_tof_axis = mt2.readX(0)[:]
#_tof_axis = mt2.readX(0)[:]
########## This was used to test the R(Q)
##Convert the data without background subtraction to R(Q)
q_array = wks_utility.convertToRvsQ(dMD=dMD,
theta=theta,
tof=_tof_axis)

q_array_reversed = q_array[::-1]
#q_array = wks_utility.convertToRvsQ(dMD=dMD,
# theta=theta,
# tof=_tof_axis)
#q_array_reversed = q_array[::-1]

# Background
Transpose(InputWorkspace='IntegratedDataWks',
Expand All @@ -185,12 +188,19 @@ def PyExec(self):
OutputWorkspace='TransposedID',
StartX=BackfromYpixel,
Mode='Mean',
EndX=data_peak[0])
EndX=data_peak[0],
OutputMode="Return Background")
Transpose(InputWorkspace='TransposedID',
OutputWorkspace='DataWks')
OutputWorkspace='DataBckWks')

ConvertToHistogram("DataBckWks", OutputWorkspace="DataBckWks")
RebinToWorkspace(WorkspaceToRebin="DataBckWks", WorkspaceToMatch="IntegratedDataWks", OutputWorkspace="DataBckWks")
Minus("IntegratedDataWks", "DataBckWks", OutputWorkspace="DataWks")




# Work on Normalization file
# Work on Normalization file #########################################
# Find full path to event NeXus data file
f = FileFinder.findRuns("REF_L%d" %normalization_run)
if len(f)>0 and os.path.isfile(f[0]):
Expand All @@ -205,36 +215,33 @@ def PyExec(self):
ws_norm_event_data = ws_norm+"_evt"
ws_norm_histo_data = ws_norm+"_histo"

LoadEventNexus(Filename=norm_file, OutputWorkspace=ws_norm_event_data)
if not mtd.workspaceExists(ws_norm_event_data):
LoadEventNexus(Filename=norm_file, OutputWorkspace=ws_norm_event_data)

# Rebin data
Rebin(InputWorkspace=ws_norm_event_data,
OutputWorkspace=ws_norm_histo_data,
Params=self._binning)
Rebin(InputWorkspace=ws_norm_event_data, OutputWorkspace=ws_norm_histo_data, Params=self._binning)

# Keep only range of TOF of interest
CropWorkspace(ws_norm_histo_data,
'CropHistoNorm',
XMin=TOFrange[0],
XMax=TOFrange[1])
CropWorkspace(ws_norm_histo_data, ws_norm_histo_data, XMin=TOFrange[0], XMax=TOFrange[1])

# Normalized by Current (proton charge)
NormaliseByCurrent(InputWorkspace='CropHistoNorm',
OutputWorkspace='NormWks')
NormaliseByCurrent(InputWorkspace=ws_norm_histo_data, OutputWorkspace=ws_norm_histo_data)

##Background subtraction

#Create a new event workspace of only the range of pixel of interest
#background range (along the y-axis) and of only the pixel
#of interest along the x-axis (to avoid the frame effect)
mt3_norm = wks_utility.createIntegratedWorkspace(mtd['NormWks'],
mt3_norm = wks_utility.createIntegratedWorkspace(mtd[ws_norm_histo_data],
"IntegratedNormWks",
fromXpixel=Xrange[0],
toXpixel=Xrange[1],
fromYpixel=BackfromYpixel,
toYpixel=BacktoYpixel,
maxX=maxX,
maxY=maxY)
maxY=maxY,
source_to_detector=dMD,
theta=theta)

Transpose(InputWorkspace='IntegratedNormWks',
OutputWorkspace='TransposedID')
Expand All @@ -247,10 +254,16 @@ def PyExec(self):
OutputWorkspace='TransposedID',
StartX=BackfromYpixel,
Mode='Mean',
EndX=norm_peak[0])
EndX=norm_peak[0],
OutputMode="Return Background")

Transpose(InputWorkspace='TransposedID',
OutputWorkspace='NormWks')
OutputWorkspace='NormBckWks')

ConvertToHistogram("NormBckWks", OutputWorkspace="NormBckWks")
RebinToWorkspace(WorkspaceToRebin="NormBckWks", WorkspaceToMatch="IntegratedNormWks", OutputWorkspace="NormBckWks")
Minus("IntegratedNormWks", "NormBckWks", OutputWorkspace="NormWks")


#perform the integration myself
mt_temp = mtd['NormWks']
Expand All @@ -269,6 +282,10 @@ def PyExec(self):
output_ws = self.getPropertyValue("OutputWorkspace")

SumSpectra(InputWorkspace="NormalizedWks", OutputWorkspace=output_ws)
#ConvertToHistogram(InputWorkspace=output_ws,OutputWorkspace=output_ws)
#ConvertUnits(InputWorkspace=output_ws,Target="MomentumTransfer",OutputWorkspace=output_ws)


self.setProperty("OutputWorkspace", mtd[output_ws])

mtd.registerPyAlgorithm(RefLReduction())
1 change: 1 addition & 0 deletions Code/Mantid/scripts/Interface/reduction_application.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys, os
import traceback
from PyQt4 import QtGui, QtCore, uic
from mantidsimple import *

# Check whether Mantid is available
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"""
from interface import InstrumentInterface
from reduction_gui.widgets.reflectometer.refl_data_simple import DataReflWidget
from reduction_gui.widgets.reflectometer.refl_parameters import ParametersReflWidget
from reduction_gui.widgets.reflectometer.refl_norm import NormReflWidget
from reduction_gui.widgets.reflectometer.advanced import AdvancedWidget
from reduction_gui.widgets.output import OutputWidget
from reduction_gui.widgets.reflectometer.stitcher import StitcherWidget
#from reduction_gui.widgets.reflectometer.refl_parameters import ParametersReflWidget
#from reduction_gui.widgets.reflectometer.refl_norm import NormReflWidget
#from reduction_gui.widgets.reflectometer.advanced import AdvancedWidget
#from reduction_gui.widgets.output import OutputWidget

#from reduction_gui.reduction.hfir_reduction import HFIRReductionScripter
from reduction_gui.reduction.reflectometer.refl_reduction import REFLReductionScripter

from reduction_gui.reduction.reflectometer.refl_data_proxy import DataProxy

Expand All @@ -24,10 +25,11 @@ def __init__(self, name, settings):
super(REFLInterface, self).__init__(name, settings)

# Scripter object to interface with Mantid
# self.scripter = HFIRReductionScripter(name=name)
self.scripter = REFLReductionScripter(name=name)

# data REF_L tab
self.attach(DataReflWidget(settings = self._settings, name=name, data_proxy=DataProxy))
self.attach(DataReflWidget(settings = self._settings, name=name))
self.attach(StitcherWidget(settings = self._settings))

# normalization REF_L tab
#self.attach(NormReflWidget(settings = self._settings, data_proxy=DataProxy))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ class DataSets(BaseScriptElement):
NormBackgroundRoi = [123, 137]

# Data files
data_files = [66421]
norm_file = 66196
#data_files = [66421]
#norm_file = 66196
data_files = [0]
norm_file = 0


def __init__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ def to_script(self):
Generate reduction script
@param execute: if true, the script will be executed
"""

script = "# REF_L reduction script\n"
script += "# Script automatically generated on %s\n\n" % time.ctime(time.time())

script += "from MantidFramework import *\n"
script += "mtd.initialise(False)\n"
script += "from mantidsimple import *\n\n"

script = ""
for item in self.data_sets:
script += item.to_script()
script += "\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This is a fake version of the Reducer for testing purposes.
"""
import time
from scripter import BaseReductionScripter
from reduction_gui.reduction.scripter import BaseReductionScripter

class REFLReductionScripter(BaseReductionScripter):
"""
Expand All @@ -23,23 +23,22 @@ def to_script(self, file_name=None):
script = "# REF_L reduction script\n"
script += "# Script automatically generated on %s\n\n" % time.ctime(time.time())

# script += "from MantidFramework import *\n"
# script += "mtd.initialise(False)\n"
## script += "from reduction.instruments.sans.hfir_command_interface import *\n"
# script += "\n"
#
# for item in self._observers:
# if item.state() is not None:
# script += str(item.state())
#
# script += "SaveIqAscii()\n"
# script += "Reduce1D()\n"

script += "from MantidFramework import *\n"
script += "mtd.initialise(False)\n"
script += "from mantidsimple import *\n\n"

for item in self._observers:
if item.state() is not None:
script += str(item.state())

if file_name is not None:
f = open(file_name, 'w')
f.write(script)
f.close()




return script


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def set_state(self, state):
Populate the UI elements with the data from the given state.
@param state: data object
"""
if IS_IN_MANTIDPLOT:
if False and IS_IN_MANTIDPLOT:
ws_name = "reflectivity"
ws_list = [n for n in mtd.keys() if n.startswith(ws_name)]
g = _qti.app.graph(ws_name)
Expand All @@ -169,12 +169,16 @@ def set_state(self, state):
g.setName(ws_name)

self._summary.angle_list.clear()
for item in state.data_sets:
if item is not None:
item_widget = QtGui.QListWidgetItem(unicode(str(','.join([str(i) for i in item.data_files]))), self._summary.angle_list)
item_widget.setData(QtCore.Qt.UserRole, item)
if len(state.data_sets)==1 and state.data_sets[0].data_files[0]==0:
pass
else:
for item in state.data_sets:
if item is not None:
item_widget = QtGui.QListWidgetItem(unicode(str(','.join([str(i) for i in item.data_files]))), self._summary.angle_list)
item_widget.setData(QtCore.Qt.UserRole, item)

self.set_editing_state(state.data_sets[0])
if len(state.data_sets)>0:
self.set_editing_state(state.data_sets[0])

def set_editing_state(self, state):

Expand Down

0 comments on commit ffb78b6

Please sign in to comment.