diff --git a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h index dd0dafb01debe9aa181282b4a222c9e416029de2..42a61d65fe4f9d3c2afc09053084eacc202b2e57 100644 --- a/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h +++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h @@ -42,7 +42,7 @@ namespace Mantid /// Algorithm's name for identification. @see Algorithm::name virtual const std::string name() const {return "Stitch1D";} /// Algorithm's version for identification. @see Algorithm::version - virtual int version() const {return 4;} + virtual int version() const {return 3;} /// Algorithm's category for identification. @see Algorithm::category virtual const std::string category() const {return "Reflectometry";} ///Summary of algorithm's purpose diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/Stitch1D.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/Stitch1D.py deleted file mode 100644 index e90d44e0cd08738481f00bc346e9984a660d8941..0000000000000000000000000000000000000000 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/Stitch1D.py +++ /dev/null @@ -1,217 +0,0 @@ -from mantid.simpleapi import * - -from mantid.api import * -from mantid.kernel import * -import numpy as np - -class Stitch1D(PythonAlgorithm): - - def category(self): - return "Reflectometry\\ISIS;PythonAlgorithms" - - def name(self): - return "Stitch1D" - - def version(self): - return 3 - - def summary(self): - return "Stitches single histogram matrix workspaces together" - - def PyInit(self): - - histogram_validator = HistogramValidator() - - self.declareProperty(MatrixWorkspaceProperty("LHSWorkspace", "", Direction.Input, validator=histogram_validator), "Input workspace") - self.declareProperty(MatrixWorkspaceProperty("RHSWorkspace", "", Direction.Input, validator=histogram_validator), "Input workspace") - self.declareProperty(MatrixWorkspaceProperty("OutputWorkspace", "", Direction.Output), "Output stitched workspace") - - self.declareProperty(name="StartOverlap", defaultValue=-1.0, doc="Overlap x-value in units of x-axis. Optional.") - self.declareProperty(name="EndOverlap", defaultValue=-1.0, doc="End overlap x-value in units of x-value. Optional.") - self.declareProperty(FloatArrayProperty(name="Params", values=[0.1]), doc="Rebinning Parameters. See Rebin for format. If only a single value is provided, start and end are taken from input workspaces.") - self.declareProperty(name="ScaleRHSWorkspace", defaultValue=True, doc="Scaling either with respect to workspace 1 or workspace 2.") - self.declareProperty(name="UseManualScaleFactor", defaultValue=False, doc="True to use a provided value for the scale factor.") - self.declareProperty(name="ManualScaleFactor", defaultValue=1.0, doc="Provided value for the scale factor.") - self.declareProperty(name="OutScaleFactor", defaultValue=-2.0, direction = Direction.Output, doc="The actual used value for the scaling factor.") - - def has_non_zero_errors(self, ws): - errors = ws.extractE() - count = len(errors.nonzero()[0]) - return count > 0 - - - def __run_as_child(self, name, **kwargs): - """Run a named algorithm and return the - algorithm handle - - Parameters: - name - The name of the algorithm - kwargs - A dictionary of property name:value pairs - """ - alg = AlgorithmManager.createUnmanaged(name) - alg.initialize() - alg.setChild(True) - - if 'OutputWorkspace' in alg: - alg.setPropertyValue("OutputWorkspace","UNUSED_NAME_FOR_CHILD") - - alg.setRethrows(True) - for key, value in kwargs.iteritems(): - alg.setProperty(key, value) - - alg.execute() - return alg.getProperty("OutputWorkspace").value - - def __to_single_value_ws(self, value): - value_ws = self.__run_as_child("CreateSingleValuedWorkspace", DataValue=value) - return value_ws - - - def __find_indexes_start_end(self, startOverlap, endOverlap, workspace): - a1=workspace.binIndexOf(startOverlap) - a2=workspace.binIndexOf(endOverlap) - if a1 == a2: - raise RuntimeError("The Params you have provided for binning yield a workspace in which start and end overlap appear in the same bin. Make binning finer via input Params.") - return a1, a2 - - def __calculate_x_intersection(self): - lhs_ws = self.getProperty("LHSWorkspace").value - rhs_ws = self.getProperty("RHSWorkspace").value - lhs_x = lhs_ws.readX(0) - rhs_x = rhs_ws.readX(0) - return rhs_x[0], lhs_x[-1] - - def __get_start_overlap(self, range_tolerance): - start_overlap_property = self.getProperty('StartOverlap') - start_overlap = start_overlap_property.value - range_tolerance - min, max = self.__calculate_x_intersection() - start_overlap_beyond_range = (start_overlap < min) or (start_overlap > max) - if start_overlap_property.isDefault or start_overlap_beyond_range: - if start_overlap_beyond_range and not start_overlap_property.isDefault: - logger.warning("StartOverlap is outside range at %0.4f, Min is %0.4f, Max is %0.4f . Forced to be: %0.4f" % (start_overlap, min, max, min)) - start_overlap = min - logger.information("StartOverlap calculated to be: %0.4f" % start_overlap) - return start_overlap - - def __get_end_overlap(self, range_tolerance): - end_overlap_property = self.getProperty('EndOverlap') - end_overlap = end_overlap_property.value + range_tolerance - min, max = self.__calculate_x_intersection() - end_overlap_beyond_range = (end_overlap < min) or (end_overlap > max) - if end_overlap_property.isDefault or end_overlap_beyond_range: - if end_overlap_beyond_range and not end_overlap_property.isDefault: - logger.warning("EndOverlap is outside range at %0.4f, Min is %0.4f, Max is %0.4f. Forced to be: %0.4f" % (end_overlap, min, max, max)) - end_overlap = max - logger.information("EndOverlap calculated to be: %0.4f" % end_overlap) - return end_overlap - - ''' - Fetch and create rebin parameters. - If a single step is provided, then the min and max values are taken from the input workspaces. - ''' - def __create_rebin_parameters(self): - params = None - user_params = self.getProperty("Params").value - if user_params.size >= 3: - params = user_params - else: - lhs_ws = self.getProperty("LHSWorkspace").value - rhs_ws = self.getProperty("RHSWorkspace").value - params = list() - params.append(np.min(lhs_ws.readX(0))) - params.append(user_params[0]) - params.append(np.max(rhs_ws.readX(0))) - return params - - def PyExec(self): - # Just forward the other properties on. - range_tolerance = 1e-9 - - startOverlap = self.__get_start_overlap(range_tolerance) - endOverlap = self.__get_end_overlap(range_tolerance) - scaleRHSWorkspace = self.getProperty('ScaleRHSWorkspace').value - useManualScaleFactor = self.getProperty('UseManualScaleFactor').value - manualScaleFactor = self.getProperty('ManualScaleFactor').value - outScaleFactor = self.getProperty('OutScaleFactor').value - - params = self.__create_rebin_parameters() - - lhs_rebinned = self.__run_as_child("Rebin", InputWorkspace=self.getProperty("LHSWorkspace").value, Params=params) - rhs_rebinned = self.__run_as_child("Rebin", InputWorkspace=self.getProperty("RHSWorkspace").value, Params=params) - - xRange = lhs_rebinned.readX(0) - minX = xRange[0] - maxX = xRange[-1] - if(round(startOverlap, 9) < round(minX, 9)): - raise RuntimeError("Stitch1D StartOverlap is outside the X range after rebinning. StartOverlap: %0.9f, X min: %0.9f" % (startOverlap, minX)) - if(round(endOverlap, 9) > round(maxX, 9)): - raise RuntimeError("Stitch1D EndOverlap is outside the X range after rebinning. EndOverlap: %0.9f, X max: %0.9f" % (endOverlap, maxX)) - - if(startOverlap > endOverlap): - raise RuntimeError("Stitch1D cannot have a StartOverlap > EndOverlap. StartOverlap: %0.9f, EndOverlap: %0.9f" % (startOverlap, endOverlap)) - - a1, a2 = self.__find_indexes_start_end(startOverlap, endOverlap, lhs_rebinned) - - if not useManualScaleFactor: - - lhsOverlapIntegrated = self.__run_as_child("Integration", InputWorkspace=lhs_rebinned, RangeLower=startOverlap, RangeUpper=endOverlap) - rhsOverlapIntegrated = self.__run_as_child("Integration", InputWorkspace=rhs_rebinned, RangeLower=startOverlap, RangeUpper=endOverlap) - - y1=lhsOverlapIntegrated.readY(0) - y2=rhsOverlapIntegrated.readY(0) - if scaleRHSWorkspace: - ratio = self.__run_as_child("Divide", LHSWorkspace=lhsOverlapIntegrated, RHSWorkspace=rhsOverlapIntegrated) - rhs_rebinned = self.__run_as_child("Multiply", LHSWorkspace=rhs_rebinned, RHSWorkspace=ratio) - scalefactor = y1[0]/y2[0] - else: - - ratio = self.__run_as_child("Divide", RHSWorkspace=lhsOverlapIntegrated, LHSWorkspace=rhsOverlapIntegrated) - lhs_rebinned = self.__run_as_child("Multiply", LHSWorkspace=lhs_rebinned, RHSWorkspace=ratio) - scalefactor = y2[0]/y1[0] - else: - manualScaleFactorWS = self.__to_single_value_ws(manualScaleFactor) - if scaleRHSWorkspace: - rhs_rebinned = self.__run_as_child("Multiply", LHSWorkspace=rhs_rebinned, RHSWorkspace=manualScaleFactorWS) - else: - lhs_rebinned = self.__run_as_child("Multiply", LHSWorkspace=lhs_rebinned, RHSWorkspace=manualScaleFactorWS) - scalefactor = manualScaleFactor - - # Mask out everything BUT the overlap region as a new workspace. - overlap1 = self.__run_as_child("MultiplyRange", InputWorkspace=lhs_rebinned, StartBin=0,EndBin=a1,Factor=0) - overlap1 = self.__run_as_child("MultiplyRange", InputWorkspace=overlap1,StartBin=a2,Factor=0) - - # Mask out everything BUT the overlap region as a new workspace. - overlap2 = self.__run_as_child("MultiplyRange", InputWorkspace=rhs_rebinned,StartBin=0,EndBin=a1,Factor=0) - overlap2 = self.__run_as_child("MultiplyRange", InputWorkspace=overlap2,StartBin=a2,Factor=0) - - # Mask out everything AFTER the start of the overlap region - lhs_rebinned = self.__run_as_child("MultiplyRange", InputWorkspace=lhs_rebinned, StartBin=a1+1, Factor=0) - - # Mask out everything BEFORE the end of the overlap region - rhs_rebinned = self.__run_as_child("MultiplyRange",InputWorkspace=rhs_rebinned,StartBin=0,EndBin=a2-1,Factor=0) - - # Calculate a weighted mean for the overlap region - overlapave = None - if self.has_non_zero_errors(overlap1) and self.has_non_zero_errors(overlap2): - overlapave = self.__run_as_child("WeightedMean", InputWorkspace1=overlap1,InputWorkspace2=overlap2) - else: - self.log().information("Using un-weighted mean for Stitch1D overlap mean") - # Calculate the mean. - sum = self.__run_as_child("Plus", LHSWorkspace=overlap1, RHSWorkspace=overlap2) - denominator = self.__to_single_value_ws(2.0) - overlapave = self.__run_as_child("Divide", LHSWorkspace=sum, RHSWorkspace=denominator) - - # Add the Three masked workspaces together to create a complete x-range - result = self.__run_as_child("Plus", LHSWorkspace=lhs_rebinned, RHSWorkspace=overlapave) - result = self.__run_as_child("Plus", LHSWorkspace=rhs_rebinned, RHSWorkspace=result) - #RenameWorkspace(InputWorkspace=result, OutputWorkspace=self.getPropertyValue("OutputWorkspace")) - - self.setProperty('OutputWorkspace', result) - self.setProperty('OutScaleFactor', scalefactor) - - return None - - -############################################################################################# - -AlgorithmFactory.subscribe(Stitch1D()) diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt index 0fd5009bf3727fb868de124c7f64fc0ae6fd0ab5..960f9acae7b994e199704f4361f27a8085fe18e3 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt @@ -31,7 +31,6 @@ set ( TEST_PY_FILES SavePlot1DTest.py SortDetectorsTest.py SortXAxisTest.py - Stitch1DTest.py Stitch1DManyTest.py SuggestTibCNCSTest.py SuggestTibHYSPECTest.py diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/Stitch1DTest.py b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/Stitch1DTest.py deleted file mode 100644 index 83d16a1a173d91915e47461d14399e2f1684a514..0000000000000000000000000000000000000000 --- a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/Stitch1DTest.py +++ /dev/null @@ -1,242 +0,0 @@ -import unittest -import numpy -from mantid.simpleapi import * -from mantid.kernel import * -from mantid.api import * - -class Stitch1DTest(unittest.TestCase): - - a = None - b = None - x = None - e = None - - def setUp(self): - x = numpy.arange(-1, 1.2, 0.2) - e = numpy.arange(-1, 1, 0.2) - e.fill(0) - self.e = e - self.x = x - a = CreateWorkspace(UnitX="1/q", DataX=x, DataY=[0,0,0,3,3,3,3,3,3,3], NSpec=1, DataE=e) - b = CreateWorkspace(UnitX="1/q", DataX=x, DataY=[2,2,2,2,2,2,2,0,0,0], NSpec=1, DataE=e) - self.a = a - self.b = b - - def tearDown(self): - # Cleanup - DeleteWorkspace(self.a) - DeleteWorkspace(self.b) - - def test_startoverap_greater_than_end_overlap_throws(self): - try: - stitched = Stitch1D(LHSWorkspace=self.b, RHSWorkspace=self.a, StartOverlap=self.x[-1], EndOverlap=self.x[0], Params='0.2') - self.assertTrue(False, "Should have thrown with StartOverlap < x max") - except RuntimeError: - pass - - def test_lhsworkspace_must_be_histogram(self): - x = numpy.arange(-1, 1, 0.2) - e = numpy.arange(-1, 1, 0.2) - lhs_ws = CreateWorkspace(UnitX="1/q", DataX=x, DataY=[0,0,0,3,3,3,3,3,3,3], NSpec=1, DataE=e) - self.assertTrue(not lhs_ws.isHistogramData(), "Input LHS WS SHOULD NOT be histogram for this test") - self.assertTrue(self.a.isHistogramData(), "Input RHS WS should SHOULD be histogram for this test") - try: - stitched = Stitch1D(LHSWorkspace=lhs_ws, RHSWorkspace=self.a, StartOverlap=self.x[-1], EndOverlap=self.x[0], Params='0.2') - except ValueError: - pass - finally: - DeleteWorkspace(lhs_ws) - - def test_rhsworkspace_must_be_histogram(self): - x = numpy.arange(-1, 1, 0.2) - e = numpy.arange(-1, 1, 0.2) - rhs_ws = CreateWorkspace(UnitX="1/q", DataX=x, DataY=[0,0,0,3,3,3,3,3,3,3], NSpec=1, DataE=e) - self.assertTrue(self.a.isHistogramData(), "Input LHS WS SHOULD be histogram for this test") - self.assertTrue(not rhs_ws.isHistogramData(), "Input RHS WS should SHOULD NOT be histogram for this test") - try: - stitched = Stitch1D(LHSWorkspace=self.a, RHSWorkspace=rhs_ws, StartOverlap=self.x[-1], EndOverlap=self.x[0], Params='0.2') - except ValueError: - pass - finally: - DeleteWorkspace(rhs_ws) - - def test_stitching_uses_suppiled_params(self): - stitched, scale = Stitch1D(LHSWorkspace=self.b, RHSWorkspace=self.a, StartOverlap=-0.4, EndOverlap=0.4, Params='-0.8, 0.2, 1') - - #Check the ranges on the output workspace against the param inputs. - - out_x_values = stitched.readX(0) - x_min = numpy.min(out_x_values) - x_max = numpy.max(out_x_values) - self.assertEqual(x_min, -0.8) - self.assertEqual(x_max, 1) - DeleteWorkspace(stitched) - - def test_stitching_determines_params(self): - - x1 = numpy.arange(-1, 1, 0.2) - x2 = numpy.arange(0.4, 1.6, 0.2) - ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=[1,1,1,1,1,1,1,1,1], NSpec=1) - ws2 = CreateWorkspace(UnitX="1/q", DataX=x2, DataY=[1,1,1,1,1,1], NSpec=1) - - demanded_step_size = 0.2 - stitched, scale = Stitch1D(LHSWorkspace=ws1, RHSWorkspace=ws2, StartOverlap=0.4, EndOverlap=1.0, Params=demanded_step_size) - - #Check the ranges on the output workspace against the param inputs. - - out_x_values = stitched.readX(0) - x_min = numpy.min(out_x_values) - x_max = numpy.max(out_x_values) - step_size = out_x_values[1] - out_x_values[0] - - self.assertEqual(x_min, -1) - self.assertAlmostEqual(x_max-demanded_step_size, 1.4, places=6) - self.assertAlmostEqual(step_size, demanded_step_size, places=6) - - DeleteWorkspace(stitched) - DeleteWorkspace(ws1) - DeleteWorkspace(ws2) - - - def test_stitching_determines_start_and_end_overlap(self): - x1 = numpy.arange(-1, 0.6, 0.2) # Produces x from -1 to 0.4 in steps of 0.2 - x2 = numpy.arange(-0.4, 1.2, 0.2) # Produces x from -0.4 to 1 in steps of 0.2 - ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=[1,1,1,3,3,3,3], NSpec=1) - ws2 = CreateWorkspace(UnitX="1/q", DataX=x2, DataY=[1,1,1,1,3,3,3], NSpec=1) - - stitched, scale = Stitch1D(LHSWorkspace=ws1, RHSWorkspace=ws2, Params=[-1, 0.2, 1] - ) - - stitched_y = stitched.readY(0) - stitched_x = stitched.readX(0) - - overlap_indexes = numpy.where((stitched_y >= 1.0009) & (stitched_y <= 3.0001))[0] - - start_overlap_determined = stitched_x[overlap_indexes[0]] - end_overlap_determined = stitched_x[overlap_indexes[-1]] - print start_overlap_determined, end_overlap_determined - - - self.assertAlmostEqual(start_overlap_determined, -0.4, places=9) - self.assertAlmostEqual(end_overlap_determined, 0.2, places=9) - - def test_stitching_forces_start_overlap(self): - x1 = numpy.arange(-1, 0.6, 0.2) # Produces x from -1 to 0.4 in steps of 0.2 - x2 = numpy.arange(-0.4, 1.2, 0.2) # Produces x from -0.4 to 1 in steps of 0.2 - ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=[1,1,1,3,3,3,3], NSpec=1) - ws2 = CreateWorkspace(UnitX="1/q", DataX=x2, DataY=[1,1,1,1,3,3,3], NSpec=1) - - # Overlap region is only physically between -0.4 and 0.4 - stitched, scale = Stitch1D(LHSWorkspace=ws1, RHSWorkspace=ws2, Params=[-1, 0.2, 1], StartOverlap=-0.5) # Start overlap is out of range!! - - stitched_y = stitched.readY(0) - stitched_x = stitched.readX(0) - - overlap_indexes = numpy.where((stitched_y >= 1.0009) & (stitched_y <= 3.0001))[0] - - start_overlap_determined = stitched_x[overlap_indexes[0]] - end_overlap_determined = stitched_x[overlap_indexes[-1]] - print start_overlap_determined, end_overlap_determined - - - self.assertAlmostEqual(start_overlap_determined, -0.4, places=9) - self.assertAlmostEqual(end_overlap_determined, 0.2, places=9) - - def test_stitching_forces_end_overlap(self): - x1 = numpy.arange(-1, 0.6, 0.2) # Produces x from -1 to 0.4 in steps of 0.2 - x2 = numpy.arange(-0.4, 1.2, 0.2) # Produces x from -0.4 to 1 in steps of 0.2 - ws1 = CreateWorkspace(UnitX="1/q", DataX=x1, DataY=[1,1,1,3,3,3,3], NSpec=1) - ws2 = CreateWorkspace(UnitX="1/q", DataX=x2, DataY=[1,1,1,1,3,3,3], NSpec=1) - - # Overlap region is only physically between -0.4 and 0.4 - stitched, scale = Stitch1D(LHSWorkspace=ws1, RHSWorkspace=ws2, Params=[-1, 0.2, 1], EndOverlap=0.5) # End overlap is out of range!! - - stitched_y = stitched.readY(0) - stitched_x = stitched.readX(0) - - overlap_indexes = numpy.where((stitched_y >= 1.0009) & (stitched_y <= 3.0001))[0] - - start_overlap_determined = stitched_x[overlap_indexes[0]] - end_overlap_determined = stitched_x[overlap_indexes[-1]] - print start_overlap_determined, end_overlap_determined - - - self.assertAlmostEqual(start_overlap_determined, -0.4, places=9) - self.assertAlmostEqual(end_overlap_determined, 0.2, places=9) - - def test_stitching_scale_right(self): - stitched = Stitch1D(LHSWorkspace=self.b, RHSWorkspace=self.a, StartOverlap=-0.4, EndOverlap=0.4, Params='0.2') - # Check the types returned - self.assertTrue(isinstance(stitched, tuple), "Output should be a tuple containing OuputWorkspace as well as the scale factor") - self.assertTrue(isinstance(stitched[0], MatrixWorkspace)) - # Check the scale factor - self.assertAlmostEquals(stitched[1], 2.0/3.0, places=9) - # Fetch the arrays from the output workspace - yValues = numpy.around(stitched[0].readY(0), decimals=6) - eValues = numpy.around(stitched[0].readE(0), decimals=6) - xValues = numpy.around(stitched[0].readX(0), decimals=6) - # Check that the output Y-Values are correct. - self.assertEquals(1, len(numpy.unique(yValues)), "Output YVaues should all be 2") - self.assertEquals(2, yValues[0], "Output YValues should all be 2") - # Check that the output E-Values are correct. - self.assertEquals(0, len(eValues.nonzero()[0]), "Output Error values should all be non-zero") - # Check that the output X-Values are correct. - self.assertEquals(set(numpy.around(self.x, decimals=6)), set(xValues)) - DeleteWorkspace(stitched[0]) - - - def test_stitching_scale_left(self): - stitched = Stitch1D(LHSWorkspace=self.b, RHSWorkspace=self.a, StartOverlap=-0.4, EndOverlap=0.4, Params='0.2', ScaleRHSWorkspace=False) - - # Check the types returned - self.assertTrue(isinstance(stitched, tuple), "Output should be a tuple containing OuputWorkspace as well as the scale factor") - self.assertTrue(isinstance(stitched[0], MatrixWorkspace)) - # Check the scale factor - self.assertAlmostEquals(stitched[1], 3.0/2.0, places=9) - # Fetch the arrays from the output workspace - yValues = numpy.around(stitched[0].readY(0), decimals=6) - eValues = numpy.around(stitched[0].readE(0), decimals=6) - xValues = numpy.around(stitched[0].readX(0), decimals=6) - # Check that the output Y-Values are correct. - self.assertEquals(1, len(numpy.unique(yValues)), "Output YVaues should all be 2") - self.assertEquals(3, yValues[0], "Output YValues should all be 3") - # Check that the output E-Values are correct. - self.assertEquals(0, len(eValues.nonzero()[0]), "Output Error values should all be non-zero") - # Check that the output X-Values are correct. - self.assertEquals(set(numpy.around(self.x, decimals=6)), set(xValues)) - DeleteWorkspace(stitched[0]) - - def test_stitching_manual_scale_factor_scale_right(self): - stitched = Stitch1D(LHSWorkspace=self.b, RHSWorkspace=self.a, ScaleRHSWorkspace=True, UseManualScaleFactor=True, StartOverlap=-0.4, EndOverlap=0.4, Params='0.2', ManualScaleFactor=2.0/3.0) - self.assertAlmostEquals(stitched[1], 2.0/3.0, places=9) - # Fetch the arrays from the output workspace - yValues = numpy.around(stitched[0].readY(0), decimals=6) - eValues = numpy.around(stitched[0].readE(0), decimals=6) - xValues = numpy.around(stitched[0].readX(0), decimals=6) - # Check that the output Y-Values are correct. - self.assertEquals(1, len(numpy.unique(yValues)), "Output YVaues should all be 2") - self.assertEquals(2, yValues[0], "Output YValues should all be 2") - # Check that the output E-Values are correct. - self.assertEquals(0, len(eValues.nonzero()[0]), "Output Error values should all be non-zero") - # Check that the output X-Values are correct. - self.assertEquals(set(numpy.around(self.x, decimals=6)), set(xValues)) - DeleteWorkspace(stitched[0]) - - def test_stitching_manual_scale_factor_scale_left(self): - stitched = Stitch1D(LHSWorkspace=self.b, RHSWorkspace=self.a, StartOverlap=-0.4, EndOverlap=0.4, Params='0.2', ScaleRHSWorkspace=False, UseManualScaleFactor=True, ManualScaleFactor=3.0/2.0) - self.assertAlmostEquals(stitched[1], 3.0/2.0, places=9) - # Fetch the arrays from the output workspace - yValues = numpy.around(stitched[0].readY(0), decimals=6) - eValues = numpy.around(stitched[0].readE(0), decimals=6) - xValues = numpy.around(stitched[0].readX(0), decimals=6) - # Check that the output Y-Values are correct. - self.assertEquals(1, len(numpy.unique(yValues)), "Output YVaues should all be 2") - self.assertEquals(3, yValues[0], "Output YValues should all be 3") - # Check that the output E-Values are correct. - self.assertEquals(0, len(eValues.nonzero()[0]), "Output Error values should all be non-zero") - # Check that the output X-Values are correct. - self.assertEquals(set(numpy.around(self.x, decimals=6)), set(xValues)) - DeleteWorkspace(stitched[0]) - -if __name__ == '__main__': - unittest.main()