Skip to content
Snippets Groups Projects
Commit 4484d76c authored by Doucet, Mathieu's avatar Doucet, Mathieu
Browse files

Clean up example reducer. Re #3570

parent fc15538a
No related branches found
No related tags found
No related merge requests found
...@@ -28,12 +28,13 @@ class ExampleLoader(PythonAlgorithm): ...@@ -28,12 +28,13 @@ class ExampleLoader(PythonAlgorithm):
return "ExampleLoader" return "ExampleLoader"
def PyInit(self): def PyInit(self):
self.declareProperty("File_name", "") self.declareProperty("Filename", "")
self.declareProperty("OutputWorkspace", "") self.declareProperty("OutputWorkspace", "")
def PyExec(self): def PyExec(self):
filename = self.getProperty("File_name") filename = self.getProperty("Filename")
output_ws = self.getProperty("OutputWorkspace") output_ws = self.getProperty("OutputWorkspace")
LoadAscii(filename, output_ws)
print filename, output_ws print filename, output_ws
...@@ -85,14 +85,18 @@ if __name__ == '__main__': ...@@ -85,14 +85,18 @@ if __name__ == '__main__':
r = ExampleReducer() r = ExampleReducer()
# Append a fake data file # Append a fake data file
r.append_data_file("~/sample_data.txt") r.append_data_file("AsciiExample.txt")
# Example of a standard algorithm used as a reduction step. Note that InputWorkspace and OutputWorkspace # Example of a standard algorithm used as a reduction step. Note that InputWorkspace and OutputWorkspace
# are overwritten by the Reducer. They can be set to Non at this point. # are overwritten by the Reducer. They can be set to Non at this point.
#r.set_first_step(CreateWorkspace, OutputWorkspace=None, DataX='1', DataY='1', DataE='1') #r.set_first_step(CreateWorkspace, OutputWorkspace=None, DataX='1', DataY='1', DataE='1')
step = ExampleLoader()
step.initialize() #step = ExampleLoader()
r.set_first_step(step) #step.initialize()
#r.set_first_step(step)
r.set_first_step(LoadAscii, Filename=None, OutputWorkspace=None)
#r._first_step.setProperty("Separator", "Tab")
# Set up an algorithm to be used as part of a reduction step # Set up an algorithm to be used as part of a reduction step
alg = mtd._createAlgProxy("Scale") alg = mtd._createAlgProxy("Scale")
......
...@@ -51,19 +51,16 @@ def validate_loader(f): ...@@ -51,19 +51,16 @@ def validate_loader(f):
# If we have an algorithm proxy, get the actual algorithm # If we have an algorithm proxy, get the actual algorithm
algorithm = algorithm._getHeldObject() algorithm = algorithm._getHeldObject()
if isinstance(algorithm, types.StringType):
raise RuntimeError, "Use an algorithm function you moron"
if isinstance(algorithm, types.StringType): if isinstance(algorithm, types.StringType):
# If we have a string, assume it's an algorithm name # If we have a string, assume it's an algorithm name
class _AlgorithmStep(ReductionStep): class _AlgorithmStep(ReductionStep):
def __init__(self): def __init__(self):
self.algorithm = None self.algorithm = None
self._data_file = None self._data_file = None
if "filename" in kwargs:
self._data_file = kwargs["filename"]
def get_algorithm(self): def get_algorithm(self):
return self.algorithm return self.algorithm
def setProperty(self, key, value):
kwargs[key]=value
def execute(self, reducer, inputworkspace=None, outputworkspace=None): def execute(self, reducer, inputworkspace=None, outputworkspace=None):
""" """
Create a new instance of the requested algorithm object, Create a new instance of the requested algorithm object,
...@@ -97,16 +94,16 @@ def validate_loader(f): ...@@ -97,16 +94,16 @@ def validate_loader(f):
kwargs[key] = arg kwargs[key] = arg
# Override input and output workspaces # Override input and output workspaces
if "Workspace" in propertyOrder: if "Workspace" in kwargs:
algorithm.setPropertyValue("Workspace", MantidFramework._makeString(inputworkspace).lstrip('? ')) kwargs["Workspace"] = inputworkspace
if "OutputWorkspace" in propertyOrder: if "OutputWorkspace" in kwargs:
algorithm.setPropertyValue("OutputWorkspace", MantidFramework._makeString(inputworkspace).lstrip('? ')) kwargs["OutputWorkspace"] = inputworkspace
if "Filename" in propertyOrder: if "Filename" in kwargs:
algorithm.setPropertyValue("Filename", data_file) kwargs["Filename"] = data_file
if "AlternateName" in kwargs and \ if "AlternateName" in kwargs and \
kwargs["AlternateName"] in propertyOrder: kwargs["AlternateName"] in propertyOrder:
algorithm.setPropertyValue(kwargs["AlternateName"], data_file) kwargs[kwargs["AlternateName"]] = data_file
# set the properties of the algorithm # set the properties of the algorithm
ialg = proxy._getHeldObject() ialg = proxy._getHeldObject()
...@@ -115,6 +112,8 @@ def validate_loader(f): ...@@ -115,6 +112,8 @@ def validate_loader(f):
ialg.setPropertyValue(key, MantidFramework._makeString(kwargs[key]).lstrip('? ')) ialg.setPropertyValue(key, MantidFramework._makeString(kwargs[key]).lstrip('? '))
proxy.execute() proxy.execute()
if "OutputMessage" in propertyOrder:
return proxy.getPropertyValue("OutputMessage")
return "%s applied" % proxy.name() return "%s applied" % proxy.name()
return f(reducer, _AlgorithmStep()) return f(reducer, _AlgorithmStep())
...@@ -124,10 +123,10 @@ def validate_loader(f): ...@@ -124,10 +123,10 @@ def validate_loader(f):
def __init__(self): def __init__(self):
self.algorithm = algorithm self.algorithm = algorithm
self._data_file = None self._data_file = None
if "filename" in kwargs:
self._data_file = kwargs["filename"]
def get_algorithm(self): def get_algorithm(self):
return self.algorithm return self.algorithm
def setProperty(self, key, value):
kwargs[key]=value
def execute(self, reducer, inputworkspace=None, outputworkspace=None): def execute(self, reducer, inputworkspace=None, outputworkspace=None):
""" """
Create a new instance of the requested algorithm object, Create a new instance of the requested algorithm object,
...@@ -218,6 +217,8 @@ def validate_step(f): ...@@ -218,6 +217,8 @@ def validate_step(f):
self.algorithm = None self.algorithm = None
def get_algorithm(self): def get_algorithm(self):
return self.algorithm return self.algorithm
def setProperty(self, key, value):
kwargs[key]=value
def execute(self, reducer, inputworkspace=None, outputworkspace=None): def execute(self, reducer, inputworkspace=None, outputworkspace=None):
""" """
Create a new instance of the requested algorithm object, Create a new instance of the requested algorithm object,
...@@ -268,6 +269,8 @@ def validate_step(f): ...@@ -268,6 +269,8 @@ def validate_step(f):
self.algorithm = algorithm self.algorithm = algorithm
def get_algorithm(self): def get_algorithm(self):
return self.algorithm return self.algorithm
def setProperty(self, key, value):
kwargs[key]=value
def execute(self, reducer, inputworkspace=None, outputworkspace=None): def execute(self, reducer, inputworkspace=None, outputworkspace=None):
""" """
Create a new instance of the requested algorithm object, Create a new instance of the requested algorithm object,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment