From 4484d76c2c87f1c88fa074ed7f17e6939380f24e Mon Sep 17 00:00:00 2001 From: Mathieu Doucet <doucetm@ornl.gov> Date: Fri, 16 Sep 2011 20:46:31 +0000 Subject: [PATCH] Clean up example reducer. Re #3570 --- .../instruments/example/ExampleRedStep.py | 5 +-- .../instruments/example/example_reducer.py | 12 ++++--- Code/Mantid/scripts/reduction/reducer.py | 31 ++++++++++--------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Code/Mantid/scripts/reduction/instruments/example/ExampleRedStep.py b/Code/Mantid/scripts/reduction/instruments/example/ExampleRedStep.py index bf4380030b9..ca1815780c3 100644 --- a/Code/Mantid/scripts/reduction/instruments/example/ExampleRedStep.py +++ b/Code/Mantid/scripts/reduction/instruments/example/ExampleRedStep.py @@ -28,12 +28,13 @@ class ExampleLoader(PythonAlgorithm): return "ExampleLoader" def PyInit(self): - self.declareProperty("File_name", "") + self.declareProperty("Filename", "") self.declareProperty("OutputWorkspace", "") def PyExec(self): - filename = self.getProperty("File_name") + filename = self.getProperty("Filename") output_ws = self.getProperty("OutputWorkspace") + LoadAscii(filename, output_ws) print filename, output_ws diff --git a/Code/Mantid/scripts/reduction/instruments/example/example_reducer.py b/Code/Mantid/scripts/reduction/instruments/example/example_reducer.py index 10519284018..2e050d6d2a1 100644 --- a/Code/Mantid/scripts/reduction/instruments/example/example_reducer.py +++ b/Code/Mantid/scripts/reduction/instruments/example/example_reducer.py @@ -85,14 +85,18 @@ if __name__ == '__main__': r = ExampleReducer() # 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 # 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') - step = ExampleLoader() - step.initialize() - r.set_first_step(step) + + #step = ExampleLoader() + #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 alg = mtd._createAlgProxy("Scale") diff --git a/Code/Mantid/scripts/reduction/reducer.py b/Code/Mantid/scripts/reduction/reducer.py index 3fcc23aaaf9..cf7163674be 100644 --- a/Code/Mantid/scripts/reduction/reducer.py +++ b/Code/Mantid/scripts/reduction/reducer.py @@ -51,19 +51,16 @@ def validate_loader(f): # If we have an algorithm proxy, get the actual algorithm algorithm = algorithm._getHeldObject() - if isinstance(algorithm, types.StringType): - raise RuntimeError, "Use an algorithm function you moron" - if isinstance(algorithm, types.StringType): # If we have a string, assume it's an algorithm name class _AlgorithmStep(ReductionStep): def __init__(self): self.algorithm = None self._data_file = None - if "filename" in kwargs: - self._data_file = kwargs["filename"] def get_algorithm(self): return self.algorithm + def setProperty(self, key, value): + kwargs[key]=value def execute(self, reducer, inputworkspace=None, outputworkspace=None): """ Create a new instance of the requested algorithm object, @@ -97,16 +94,16 @@ def validate_loader(f): kwargs[key] = arg # Override input and output workspaces - if "Workspace" in propertyOrder: - algorithm.setPropertyValue("Workspace", MantidFramework._makeString(inputworkspace).lstrip('? ')) - if "OutputWorkspace" in propertyOrder: - algorithm.setPropertyValue("OutputWorkspace", MantidFramework._makeString(inputworkspace).lstrip('? ')) - if "Filename" in propertyOrder: - algorithm.setPropertyValue("Filename", data_file) + if "Workspace" in kwargs: + kwargs["Workspace"] = inputworkspace + if "OutputWorkspace" in kwargs: + kwargs["OutputWorkspace"] = inputworkspace + if "Filename" in kwargs: + kwargs["Filename"] = data_file if "AlternateName" in kwargs and \ kwargs["AlternateName"] in propertyOrder: - algorithm.setPropertyValue(kwargs["AlternateName"], data_file) + kwargs[kwargs["AlternateName"]] = data_file # set the properties of the algorithm ialg = proxy._getHeldObject() @@ -115,6 +112,8 @@ def validate_loader(f): ialg.setPropertyValue(key, MantidFramework._makeString(kwargs[key]).lstrip('? ')) proxy.execute() + if "OutputMessage" in propertyOrder: + return proxy.getPropertyValue("OutputMessage") return "%s applied" % proxy.name() return f(reducer, _AlgorithmStep()) @@ -124,10 +123,10 @@ def validate_loader(f): def __init__(self): self.algorithm = algorithm self._data_file = None - if "filename" in kwargs: - self._data_file = kwargs["filename"] def get_algorithm(self): return self.algorithm + def setProperty(self, key, value): + kwargs[key]=value def execute(self, reducer, inputworkspace=None, outputworkspace=None): """ Create a new instance of the requested algorithm object, @@ -218,6 +217,8 @@ def validate_step(f): self.algorithm = None def get_algorithm(self): return self.algorithm + def setProperty(self, key, value): + kwargs[key]=value def execute(self, reducer, inputworkspace=None, outputworkspace=None): """ Create a new instance of the requested algorithm object, @@ -268,6 +269,8 @@ def validate_step(f): self.algorithm = algorithm def get_algorithm(self): return self.algorithm + def setProperty(self, key, value): + kwargs[key]=value def execute(self, reducer, inputworkspace=None, outputworkspace=None): """ Create a new instance of the requested algorithm object, -- GitLab