Skip to content

Commit

Permalink
Re #6151 Move resolution algorithm to API2
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Dec 18, 2012
1 parent 90911e2 commit f221acb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
See [http://www.mantidproject.org/Reduction_for_HFIR_SANS SANS Reduction] documentation for details.
*WIKI*"""

from MantidFramework import *
from mantidsimple import *
import math
import mantid.simpleapi as api
from mantid.api import *
from mantid.kernel import *
import math

class ReactorSANSResolution(PythonAlgorithm):
"""
Expand All @@ -23,23 +23,18 @@ def name(self):

def PyInit(self):
# Input workspace
self.declareWorkspaceProperty("InputWorkspace", "", Direction.Input, Description="Name the workspace to calculate the resolution for")
# Output workspace to put the transmission histo into
self.declareProperty("OutputWorkspace", "", Description="Name of the workspace that will contain the resolution histogram")
self.declareProperty(MatrixWorkspaceProperty("InputWorkspace", "",
direction=Direction.Input))

# Dummy property for temporary backward compatibility
# The output workspace property is not used and the resolution is
# added to the input workspace
self.declareProperty("OutputWorkspace", "",
doc="Obsolete: not used")

def PyExec(self):
input_ws = self.getProperty("InputWorkspace")
if input_ws.getAxis(0).getUnit().name() != "MomentumTransfer":
raise RuntimeError, "ReactorSANSResolution expects an input workspace with units of Q"

output_ws_name = self.getProperty("OutputWorkspace")

if input_ws.getName() != output_ws_name:
CloneWorkspace(input_ws, output_ws_name)
output_ws = mtd[output_ws_name]
else:
output_ws = input_ws

input_ws = self.getProperty("InputWorkspace").value

# Q resolution calculation
# All distances in mm
wvl = None
Expand Down Expand Up @@ -76,9 +71,10 @@ def PyExec(self):
res_factor += (math.pow(k*sample_apert_radius*(source_sample_distance+sample_detector_distance)/(source_sample_distance*sample_detector_distance), 2)/4.0)
res_factor += math.pow(k*pixel_size_x/sample_detector_distance, 2)/12.0

for i in range(len(output_ws.readX(0))):
output_ws.dataDx(0)[i] = math.sqrt(res_factor+math.pow((output_ws.readX(0)[i]*d_wvl), 2)/6.0)
for i in range(len(input_ws.readX(0))):
input_ws.dataDx(0)[i] = math.sqrt(res_factor+math.pow((input_ws.readX(0)[i]*d_wvl), 2)/6.0)
else:
raise RuntimeError, "ReactorSANSResolution could not find all the run parameters needed to compute the resolution."

mtd.registerPyAlgorithm(ReactorSANSResolution())

registerAlgorithm(ReactorSANSResolution)
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,12 @@ def PyExec(self):
alg.execute()
output_ws = alg.getProperty("OutputWorkspace").value

# Q resolution
#if reducer._resolution_calculator is not None:
# reducer._resolution_calculator(InputWorkspace=output_ws,
# OutputWorkspace=output_ws)

# Add output workspace to the list of important output workspaces
#reducer.output_workspaces.append(output_ws)
# Q resolution
alg = AlgorithmManager.create("ReactorSANSResolution")
alg.initialize()
alg.setChild(True)
alg.setProperty("InputWorkspace", output_ws)
alg.execute()

msg = "Performed radial averaging between Q=%g and Q=%g" % (qmin, qmax)
self.setProperty("OutputMessage", msg)
Expand Down

0 comments on commit f221acb

Please sign in to comment.