Skip to content

Commit

Permalink
Re #4303 adding Q rebin
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Jan 30, 2012
1 parent 2deea47 commit 96b7742
Show file tree
Hide file tree
Showing 5 changed files with 375 additions and 38 deletions.
42 changes: 24 additions & 18 deletions Code/Mantid/Framework/PythonAPI/PythonAlgorithms/RefLReduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ def PyInit(self):
self.declareListProperty("NormBackgroundPixelRange", [123, 137], Validator=ArrayBoundedValidator(Lower=0))
self.declareListProperty("LowResAxisPixelRange", [115, 210], Validator=ArrayBoundedValidator(Lower=0))
self.declareListProperty("TOFRange", [9000., 23600.], Validator=ArrayBoundedValidator(Lower=0))
self.declareListProperty("Binning", [0,200,200000],
Description="Positive is linear bins, negative is logorithmic")
self.declareListProperty("TOFBinning", [0.,200.,200000.],
Description="Positive is linear bins, negative is logarithmic")
self.declareProperty("QCutEnabled", False)
self.declareListProperty("QBinning", [0.001,0.001,0.2],
Description="Positive is linear bins, negative is logarithmic")
# Output workspace to put the transmission histo into
self.declareWorkspaceProperty("OutputWorkspace", "", Direction.Output)

def PyExec(self):
self._binning = self.getProperty("Binning")
if len(self._binning) != 1 and len(self._binning) != 3:
raise RuntimeError("Can only specify (width) or (start,width,stop) for binning. Found %d values." % len(self._binning))
if len(self._binning) == 3:
if self._binning[0] == 0. and self._binning[1] == 0. and self._binning[2] == 0.:
raise RuntimeError("Failed to specify the binning")
tof_binning = self.getProperty("TOFBinning")
if len(tof_binning) != 1 and len(tof_binning) != 3:
raise RuntimeError("Can only specify (width) or (start,width,stop) for binning. Found %d values." % len(tof_binning))
if len(tof_binning) == 3:
if tof_binning[0] == 0. and tof_binning[1] == 0. and tof_binning[2] == 0.:
raise RuntimeError("Failed to specify the TOF binning")

run_numbers = self.getProperty("RunNumbers")
allow_multiple = False
Expand All @@ -50,7 +53,16 @@ def PyExec(self):
data_back = self.getProperty("SignalBackgroundPixelRange")

TOFrange = self.getProperty("TOFRange") #microS
Qrange = [0.001,0.001,0.2] #Qmin, Qwidth, Qmax

q_cut_enabled = self.getProperty("QCutEnabled")
q_binning = None
if q_cut_enabled:
q_binning = self.getProperty("QBinning")
if len(q_binning) != 1 and len(q_binning) != 3:
raise RuntimeError("Can only specify (width) or (start,width,stop) for binning. Found %d values." % len(q_binning))
if len(q_binning) == 3:
if q_binning[0] == 0. and q_binning[1] == 0. and q_binning[2] == 0.:
raise RuntimeError("Failed to specify the q-binning")

#Due to the frame effect, it's sometimes necessary to narrow the range
#over which we add all the pixels along the low resolution
Expand Down Expand Up @@ -127,7 +139,7 @@ def PyExec(self):

# Rebin data (x-axis is in TOF)
ws_histo_data = ws_name+"_histo"
Rebin(InputWorkspace=ws_event_data, OutputWorkspace=ws_histo_data, Params=self._binning)
Rebin(InputWorkspace=ws_event_data, OutputWorkspace=ws_histo_data, Params=tof_binning)

# Keep only range of TOF of interest
CropWorkspace(ws_histo_data,ws_histo_data,XMin=TOFrange[0], XMax=TOFrange[1])
Expand Down Expand Up @@ -173,7 +185,7 @@ def PyExec(self):
sample_to_detector=dSD,
theta=theta,
geo_correction=False,
Qrange=Qrange)
Qrange=q_binning)


#_tof_axis = mt2.readX(0)[:]
Expand Down Expand Up @@ -230,7 +242,7 @@ def PyExec(self):
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=tof_binning)

# Keep only range of TOF of interest
CropWorkspace(ws_norm_histo_data, ws_norm_histo_data, XMin=TOFrange[0], XMax=TOFrange[1])
Expand Down Expand Up @@ -298,12 +310,6 @@ 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)

# CropWorkspace(output_ws, output_ws, XMin=TOFrange[0], XMax=TOFrange[1])



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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class DataSets(BaseScriptElement):
data_files = [0]
norm_file = 0

# Q range
q_min = 0.001
q_step = 0.001
q_max = 0.2
q_cut_enabled = False

def __init__(self):
super(DataSets, self).__init__()
Expand All @@ -50,7 +55,9 @@ def to_script(self):
script += " SubtractNormBackground=%s,\n" % str(self.NormBackgroundFlag)
script += " LowResAxisPixelRange=%s,\n" % str(self.x_range)
script += " TOFRange=%s,\n" % str(self.DataTofRange)
script += " Binning=[0,200,200000],\n"
if self.q_cut_enabled:
script += " QCutEnabled=True"
script += " QBinning=[%s,%s,%s],\n" % (self.q_min, self.q_step, self.q_max)
script += " OutputWorkspace='reflectivity_%s')" % str(self.data_files[0])
script += "\n"

Expand Down Expand Up @@ -91,6 +98,13 @@ def to_xml(self):
xml += "<norm_from_back_pixels>%s</norm_from_back_pixels>\n" % str(self.NormBackgroundRoi[0])
xml += "<norm_to_back_pixels>%s</norm_to_back_pixels>\n" % str(self.NormBackgroundRoi[1])
xml += "<norm_dataset>%s</norm_dataset>\n" % str(self.norm_file)

# Q cut
xml += "<q_min>%s</q_min>\n" % str(self.q_min)
xml += "<q_step>%s</q_step>\n" % str(self.q_step)
xml += "<q_max>%s</q_max>\n" % str(self.q_max)
xml += "<q_cut_enabled>%s</q_cut_enabled>" % str(self.q_cut_enabled)

xml += "</Data>\n"

return xml
Expand Down Expand Up @@ -122,7 +136,9 @@ def from_xml_element(self, instrument_dom):
self.DataPeakDiscreteSelection = BaseScriptElement.getStringElement(instrument_dom, "peak_discrete_selection")

#background flag
self.DataBackgroundFlag = BaseScriptElement.getBoolElement(instrument_dom, "background_flag")
self.DataBackgroundFlag = BaseScriptElement.getBoolElement(instrument_dom,
"background_flag",
default=DataSets.DataBackgroundFlag)

#background from/to pixels
self.DataBackgroundRoi = [BaseScriptElement.getIntElement(instrument_dom, "back_roi1_from"),
Expand All @@ -141,14 +157,22 @@ def from_xml_element(self, instrument_dom):
BaseScriptElement.getIntElement(instrument_dom, "norm_to_peak_pixels")]

#background flag
self.NormBackgroundFlag = BaseScriptElement.getBoolElement(instrument_dom, "norm_background_flag")
self.NormBackgroundFlag = BaseScriptElement.getBoolElement(instrument_dom,
"norm_background_flag",
default=DataSets.NormBackgroundFlag)

#background from/to pixels
self.NormBackgroundRoi = [BaseScriptElement.getIntElement(instrument_dom, "norm_from_back_pixels"),
BaseScriptElement.getIntElement(instrument_dom, "norm_to_back_pixels")]

self.norm_file = BaseScriptElement.getIntElement(instrument_dom, "norm_dataset")

# Q cut
self.q_min = BaseScriptElement.getFloatElement(instrument_dom, "q_min", default=DataSets.q_min)
self.q_max = BaseScriptElement.getFloatElement(instrument_dom, "q_max", default=DataSets.q_max)
self.q_step = BaseScriptElement.getFloatElement(instrument_dom, "q_step", default=DataSets.q_step)
self.q_cut_enabled = BaseScriptElement.getBoolElement(instrument_dom, "q_cut_enabled", default=False)

def reset(self):
"""
Reset state
Expand All @@ -166,3 +190,8 @@ def reset(self):
self.NormPeakPixels = DataSets.NormPeakPixels
self.norm_file = DataSets.norm_file
self.x_range = DataSets.x_range
# Q range
self.q_min = DataSets.q_min
self.q_step = DataSets.q_step
self.q_max = DataSets.q_max
self.q_cut_enabled = DataSets.q_cut_enabled
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def initialize_content(self):
self._summary.x_min_edit.setValidator(QtGui.QDoubleValidator(self._summary.x_min_edit))
self._summary.x_max_edit.setValidator(QtGui.QDoubleValidator(self._summary.x_max_edit))

self._summary.q_cut_chk.setChecked(False)
self.connect(self._summary.q_cut_chk, QtCore.SIGNAL("clicked(bool)"), self._enable_q_cut)
self._summary.q_min_edit.setValidator(QtGui.QDoubleValidator(self._summary.q_min_edit))
self._summary.q_max_edit.setValidator(QtGui.QDoubleValidator(self._summary.q_max_edit))
self._summary.q_step_edit.setValidator(QtGui.QDoubleValidator(self._summary.q_step_edit))
self._enable_q_cut(self._summary.q_cut_chk.isChecked())

self._summary.norm_peak_from_pixel.setValidator(QtGui.QIntValidator(self._summary.norm_peak_from_pixel))
self._summary.norm_peak_to_pixel.setValidator(QtGui.QIntValidator(self._summary.norm_peak_to_pixel))
self._summary.norm_background_from_pixel1.setValidator(QtGui.QIntValidator(self._summary.norm_background_from_pixel1))
Expand All @@ -86,6 +93,11 @@ def initialize_content(self):
if not os.path.isdir("/SNS/REF_L"):
self._summary.auto_reduce_check.hide()

def _enable_q_cut(self, is_enabled):
self._summary.q_min_edit.setEnabled(is_enabled)
self._summary.q_max_edit.setEnabled(is_enabled)
self._summary.q_step_edit.setEnabled(is_enabled)

def _create_auto_reduce_template(self):
m = self.get_editing_state()
m.data_files = ["runNumber"]
Expand Down

0 comments on commit 96b7742

Please sign in to comment.