def setUp(self):
     if self._integration is None:
         self.__class__._integration = create_algorithm("Integration")
         self.__class__._integration.initialize()
     if self._mask_dets is None:
         self.__class__._mask_dets = create_algorithm("MaskDetectors")
         self.__class__._mask_dets.initialize()
 def create_sample_workspace(self, name, numMonitors=0):
     args = {
         'OutputWorkspace': name,
         'Function': 'Flat background',
         'NumMonitors': numMonitors,
         'NumBanks': 1,
     }
     alg = create_algorithm('CreateSampleWorkspace', **args)
     alg.setLogging(False)
     alg.execute()
     loadInstrArgs = {
         'Workspace': name,
         'InstrumentName': 'FIGARO',
         'RewriteSpectraMap': False
     }
     loadInstrument = create_algorithm('LoadInstrument', **loadInstrArgs)
     loadInstrument.setLogging(False)
     loadInstrument.execute()
     addSampleLogArgs = {
         'Workspace': name,
         'LogType': 'Number',
         'LogName': common.SampleLogs.TWO_THETA,
         'NumberType': 'Double',
         'LogText': '5.6',
         'LogUnit': 'degree'
     }
     addSampleLog = create_algorithm('AddSampleLog', **addSampleLogArgs)
     addSampleLog.setLogging(False)
     addSampleLog.execute()
     self.assertEquals(mtd.getObjectNames(), [name])
 def testFigaroSumInLambdaExecutes(self):
     args = {
         'Run': 'ILL/Figaro/000002.nxs',
         'OutputWorkspace': 'direct',
         'ForegroundHalfWidth': [6, 6],
         'FlatBackground': 'Background OFF',
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertTrue(alg.isExecuted())
     args = {
         'InputWorkspace': 'direct',
         'OutputWorkspace': 'direct-fgd'
     }
     alg = create_algorithm('ReflectometryILLSumForeground', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertTrue(alg.isExecuted())
     args = {
         'Run': 'ILL/Figaro/000002.nxs',
         'OutputWorkspace': 'reflected',
         'ForegroundHalfWidth': [6, 6],
         'FlatBackground': 'Background OFF',
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertTrue(alg.isExecuted())
     args = {
         'InputWorkspace': 'reflected',
         'OutputWorkspace': 'reflected-fgd',
         'DirectForegroundWorkspace': 'direct-fgd',
         'DirectBeamWorkspace': 'direct'
     }
     alg = create_algorithm('ReflectometryILLSumForeground', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertTrue(alg.isExecuted())
 def testReflectedBeamSumInQExecutes(self):
     dirWS = illhelpers.create_poor_mans_d17_workspace()
     illhelpers.add_chopper_configuration_D17(dirWS)
     illhelpers.add_slit_configuration_D17(dirWS, 0.02, 0.03)
     dirBeamPosWS = illhelpers.refl_create_beam_position_ws('dirBeamPosWS', dirWS, 0., 128)
     dirWS = illhelpers.refl_preprocess('dirWS', dirWS, dirBeamPosWS)
     args = {
         'InputWorkspace': dirWS,
         'OutputWorkspace': 'dirForeground',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLSumForeground', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertTrue(alg.isExecuted())
     dirForeground = alg.getProperty('OutputWorkspace').value
     reflWS = illhelpers.create_poor_mans_d17_workspace()
     illhelpers.refl_rotate_detector(reflWS, 1.2)
     illhelpers.add_chopper_configuration_D17(reflWS)
     illhelpers.add_slit_configuration_D17(reflWS, 0.02, 0.03)
     reflBeamPosWS = illhelpers.refl_create_beam_position_ws('reflBeamPosWS', reflWS, 1.2, 128)
     reflWS = illhelpers.refl_preprocess('refWS', reflWS, reflBeamPosWS)
     args = {
         'InputWorkspace': reflWS,
         'OutputWorkspace': 'foreground',
         'DirectForegroundWorkspace': dirForeground,
         'SummationType': 'SumInQ',
         'DirectBeamWorkspace': dirWS,
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLSumForeground', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertTrue(alg.isExecuted())
 def test_all_child_properties_are_present(self):
     # Get the properties for the child algorithm, apart from a list of known
     # exclusions
     child_alg = create_algorithm('ReflectometryReductionOneAuto')
     excluded = ['ThetaIn', 'ThetaLogName', 'Diagnostics',
                 'OutputWorkspaceBinned', 'OutputWorkspaceWavelength']
     child_props = set([prop.name for prop in child_alg.getProperties() if prop.name not in excluded])
     # Check the child properties exist in the parent algorithm
     actual_alg = create_algorithm('ReflectometryReductionOneLiveData')
     actual_props = set([prop.name for prop in actual_alg.getProperties()])
     if not child_props.issubset(actual_props):
         assert False, "The following child properties are not implemented in the parent algorithm:\n" \
         + str(child_props.difference(actual_props))
 def testForegroundBackgroundRanges(self):
     inWSName = 'ReflectometryILLPreprocess_test_ws'
     self.create_sample_workspace(inWSName)
     ws = mtd[inWSName]
     # Add special background fitting zones around the exclude zones.
     lowerBkgIndices = [26]
     for i in lowerBkgIndices:
         ys = ws.dataY(i)
         ys += 5.0
     # Add negative 'exclude zone' around the peak.
     lowerExclusionIndices = [27, 28]
     for i in lowerExclusionIndices:
         ys = ws.dataY(i)
         ys -= 1000.0
     # Add a peak to the sample workspace.
     foregroundIndices = [29, 30, 31]
     for i in foregroundIndices:
         ys = ws.dataY(i)
         ys += 1000.0
     # The second exclusion zone is wider.
     upperExclusionIndices = [32, 33, 34]
     for i in upperExclusionIndices:
         ys = ws.dataY(i)
         ys -= 1000.0
     # The second fitting zone is wider.
     upperBkgIndices = [35, 36]
     for i in upperBkgIndices:
         ys = ws.dataY(i)
         ys += 5.0
     args = {
         'InputWorkspace': inWSName,
         'OutputWorkspace': 'unused_for_child',
         'BeamCentre': 30,
         'ForegroundHalfWidth': [1],
         'LowAngleBkgOffset': len(lowerExclusionIndices),
         'LowAngleBkgWidth': len(lowerBkgIndices),
         'HighAngleBkgOffset': len(upperExclusionIndices),
         'HighAngleBkgWidth': len(upperBkgIndices),
         'FluxNormalisation': 'Normalisation OFF',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEquals(outWS.getNumberHistograms(), 100)
     for i in range(outWS.getNumberHistograms()):
         ys = outWS.readY(i)
         if i in lowerBkgIndices:
             numpy.testing.assert_equal(ys, 0)
         elif i in lowerExclusionIndices:
             numpy.testing.assert_equal(ys, -1005)
         elif i in foregroundIndices:
             numpy.testing.assert_equal(ys, 995)
         elif i in upperExclusionIndices:
             numpy.testing.assert_equal(ys, -1005)
         elif i in upperBkgIndices:
             numpy.testing.assert_equal(ys, 0)
         else:
             numpy.testing.assert_equal(ys, -5)
 def test_value_member_returns_python_list_for_multiple_files(self):
     algorithm = create_algorithm('Load', Filename='MUSR15189,15190,15191.nxs',OutputWorkspace='w',
                               SpectrumMin=1,SpectrumMax=1,child=True)
     prop = algorithm.getProperty("Filename")
     filenames = prop.value
     self.assertTrue(isinstance(filenames, list))
     self.assertEquals(len(filenames), 3)
 def _backgroundSubtraction(self, subtractionType):
     inWSName = 'ReflectometryILLPreprocess_test_ws'
     self.create_sample_workspace(inWSName)
     # Add a peak to the sample workspace.
     ws = mtd[inWSName]
     ys = ws.dataY(49)
     ys += 10.0
     args = {
         'InputWorkspace': inWSName,
         'OutputWorkspace': 'unused_for_child',
         'LinePosition': 49,
         'FluxNormalisation': 'Normalisation OFF',
         'FlatBackground': subtractionType,
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEquals(outWS.getNumberHistograms(), 100)
     ysSize = outWS.blocksize()
     for i in range(outWS.getNumberHistograms()):
         ys = outWS.readY(i)
         if i != 49:
             numpy.testing.assert_almost_equal(ys, [0.0] * ysSize)
         else:
             numpy.testing.assert_almost_equal(ys, [10.0] * ysSize)
     self.assertEquals(mtd.getObjectNames(), ['ReflectometryILLPreprocess_test_ws'])
 def testSumInQModeProducesDX(self):
     dirWS = illhelpers.create_poor_mans_d17_workspace()
     mtd.add('dirWS', dirWS)
     illhelpers.add_slit_configuration_D17(dirWS, 0.03, 0.02)
     illhelpers.add_chopper_configuration_D17(dirWS)
     illhelpers.refl_create_beam_position_ws('dirBeamPosWS', dirWS, 0., 128)
     dirWS = illhelpers.refl_preprocess('dirWS', dirWS, 'dirBeamPosWS')
     dirFgdWS = illhelpers.refl_sum_foreground('dirFgdWS', 'SumInLambda', dirWS)
     reflWS = illhelpers.create_poor_mans_d17_workspace()
     illhelpers.add_chopper_configuration_D17(reflWS)
     illhelpers.add_slit_configuration_D17(reflWS, 0.03, 0.02)
     illhelpers.refl_rotate_detector(reflWS, 1.5)
     mtd.add('reflWS', reflWS)
     illhelpers.refl_create_beam_position_ws('reflBeamPosWS', reflWS, 1.5, 128)
     reflWS = illhelpers.refl_preprocess('reflWS', reflWS, 'reflBeamPosWS')
     fgdWS = illhelpers.refl_sum_foreground('fgdWS', 'SumInQ', reflWS, dirFgdWS, dirWS)
     args = {
         'InputWorkspace': fgdWS,
         'OutputWorkspace': 'inQ',
         'DirectForegroundWorkspace': dirFgdWS,
         'GroupingQFraction': 0.2,
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLConvertToQ', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEqual(outWS.getNumberHistograms(), 1)
     self.assertTrue(outWS.hasDx(0))
 def testAsymmetricForegroundRanges(self):
     inWSName = 'ReflectometryILLPreprocess_test_ws'
     self.create_sample_workspace(inWSName)
     ws = mtd[inWSName]
     # Add special background fitting zones around the exclude zones.
     foregroundIndices = [21, 22, 23, 24]
     for i in range(ws.getNumberHistograms()):
         ys = ws.dataY(i)
         es = ws.dataE(i)
         if i in foregroundIndices:
             ys.fill(1000.0)
             es.fill(numpy.sqrt(1000.0))
         else:
             ys.fill(-100)
             es.fill(numpy.sqrt(100))
     args = {
         'InputWorkspace': inWSName,
         'OutputWorkspace': 'unused_for_child',
         'BeamCentre': 23,
         'ForegroundHalfWidth': [2, 1],
         'FlatBackground': 'Background OFF',
         'FluxNormalisation': 'Normalisation OFF',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEquals(outWS.getNumberHistograms(), 100)
     logs = outWS.run()
     properties = ['foreground.first_workspace_index', 'foreground.centre_workspace_index', 'foreground.last_workspace_index']
     values = [21, 23, 24]
     for p, val in zip(properties, values):
         self.assertTrue(logs.hasProperty(p))
         self.assertEqual(logs.getProperty(p).value, val)
 def testWaterWorkspace(self):
     inWSName = 'ReflectometryILLPreprocess_test_ws'
     self.create_sample_workspace(inWSName)
     # Add a peak to the sample workspace.
     ws = mtd[inWSName]
     for i in range(ws.getNumberHistograms()):
         ys = ws.dataY(i)
         ys.fill(10.27)
     args = {
         'InputWorkspace': inWSName,
         'OutputWorkspace': 'unused_for_child',
         'WaterWorkspace': inWSName,
         'FluxNormalisation': 'Normalisation OFF',
         'FlatBackground': 'Background OFF',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEquals(outWS.getNumberHistograms(), 100)
     ysSize = outWS.blocksize()
     for i in range(outWS.getNumberHistograms()):
         ys = outWS.readY(i)
         numpy.testing.assert_equal(ys, [1.0] * ysSize)
     self.assertEquals(mtd.getObjectNames(), ['ReflectometryILLPreprocess_test_ws'])
Esempio n. 12
0
 def test_failure_X_out_of_bounds(self):
     ws, unused, unused = self._make_single_histogram_ws()
     X = sys.float_info.max
     params = self._make_algorithm_params(ws, X)
     algorithm = testhelpers.create_algorithm('BinWidthAtX', **params)
     self.assertRaises(RuntimeError, algorithm.execute)
     self.assertFalse(algorithm.isExecuted())
     DeleteWorkspace(ws)
Esempio n. 13
0
def refl_preprocess(outputWSName, ws):
    args = {
        'InputWorkspace': ws,
        'OutputWorkspace': outputWSName,
    }
    alg = create_algorithm('ReflectometryILLPreprocess', **args)
    alg.execute()
    return mtd[outputWSName]
 def _assert_run_algorithm_succeeds(self, args, expected):
     """Run the algorithm with the given args and check it succeeds, 
     and that the additional workspaces produced match the expected list.
     Clear these additional workspaces from the ADS"""
     alg = create_algorithm('ReflectometryISISLoadAndProcess', **args)
     assertRaisesNothing(self, alg.execute)
     actual = mtd.getObjectNames()
     self.assertEquals(set(actual), set(expected))
Esempio n. 15
0
 def test_value_member_returns_python_str_for_single_file(self):
     algorithm = create_algorithm('Load', Filename='LOQ48127.raw',OutputWorkspace='w',
                               SpectrumMin=1,SpectrumMax=1,child=True)
     prop = algorithm.getProperty("Filename")
     filenames = prop.value
     self.assertTrue(isinstance(filenames, list))
     self.assertTrue(isinstance(filenames[0], str))
     self.assertEquals(len(filenames), 1)
 def _assert_run_algorithm_throws(self, args = {}):
     """Run the algorithm with the given args and check it throws"""
     throws = False
     alg = create_algorithm('ReflectometryISISLoadAndProcess', **args)
     try:
         alg.execute()
     except:
         throws = True
     self.assertEquals(throws, True)
Esempio n. 17
0
def refl_preprocess_with_calibration(outputWSName, ws, directLineWS):
    args = {
        'InputWorkspace': ws,
        'DirectLineWorkspace': directLineWS,
        'OutputWorkspace': outputWSName,
    }
    alg = create_algorithm('ReflectometryILLPreprocess', **args)
    alg.execute()
    return mtd[outputWSName]
 def create_sample_workspace(self, name, NumMonitors=0):
     args = {
         'OutputWorkspace': name,
         'Function': 'Flat background',
         'NumMonitors': NumMonitors,
         'NumBanks': 1,
     }
     alg = create_algorithm('CreateSampleWorkspace', **args)
     alg.setLogging(False)
     alg.execute()
Esempio n. 19
0
def refl_sum_foreground(outputWSName, sumType, ws, dirFgdWS=None, dirWS=None):
    args = {
        'InputWorkspace': ws,
        'OutputWorkspace': outputWSName,
        'SummationType': sumType,
        'DirectForegroundWorkspace': dirFgdWS,
        'DirectBeamWorkspace': dirWS,
        'WavelengthRange': [0.1]
    }
    alg = create_algorithm('ReflectometryILLSumForeground', **args)
    alg.execute()
    return mtd[outputWSName]
 def testTwoInputFiles(self):
     outWSName = 'outWS'
     args = {
         'Run': 'ILL/D17/317369, ILL/D17/317370.nxs',
         'OutputWorkspace': outWSName,
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEquals(outWS.getAxis(0).getUnit().caption(), 'Wavelength')
Esempio n. 21
0
def refl_create_beam_position_ws(beamPosWSName, referenceWS, detectorAngle, beamCentre):
    args = {
        'OutputWorkspace': beamPosWSName
    }
    alg = create_algorithm('CreateEmptyTableWorkspace', **args)
    alg.execute()
    beamPos = mtd[beamPosWSName]
    beamPos.addColumn('double', 'DetectorAngle')
    beamPos.addColumn('double', 'DetectorDistance')
    beamPos.addColumn('double', 'PeakCentre')
    L2 = referenceWS.getInstrument().getComponentByName('detector').getPos().norm()
    beamPos.addRow((detectorAngle, L2, beamCentre))
    return beamPos
    def testCleanupOFF(self):
        # test if intermediate workspaces exist:
        # not tested: position tables
        # normalise_to_slits, normalise_to_monitor, '_normalised_to_time_','transposed_flat_background'
        workspace_name_suffix = ['_cloned_for_flat_bkg_', '_detectors_', '_flat_background_',
                                 '_flat_background_subtracted_', '_in_wavelength_',
                                 '_monitors_', '_transposed_clone_', '_water_calibrated_']
        outWSName = 'outWS'
        inWSName = 'inWS'
        self.create_sample_workspace(inWSName, NumMonitors=3)
        waterName = 'water'
        self.create_sample_workspace(waterName)

        arg = {'OutputWorkspace': 'peakTable'}
        alg = create_algorithm('CreateEmptyTableWorkspace', **arg)
        alg.execute()
        table = mtd['peakTable']
        table.addColumn('double', 'PeakCentre')
        table.addRow((3.0,))
        args = {
            'InputWorkspace': inWSName,
            'BeamPositionWorkspace': 'peakTable',
            'OutputWorkspace': outWSName,
            'Cleanup': 'Cleanup OFF',
            'WaterWorkspace': waterName,
            'ForegroundHalfWidth': [1],
            'LowAngleBkgOffset': 5,
            'LowAngleBkgWidth': 10,
            'HighAngleBkgOffset': 5,
            'HighAngleBkgWidth': 10,
            'FluxNormalisation': 'Normalisation OFF',
            'rethrow': True,
            'child': True
        }
        alg = create_algorithm('ReflectometryILLPreprocess', **args)
        assertRaisesNothing(self, alg.execute)
        for i in range(len(workspace_name_suffix)):
            wsName = outWSName + workspace_name_suffix[i]
            self.assertTrue(mtd.doesExist(wsName), wsName)
Esempio n. 23
0
    def test_that_a_histogram_workspace_is_returned_as_a_MatrixWorkspace_from_a_property(self):
        wsname = "MatrixWorkspaceTest_Property"
        AnalysisDataService.add(wsname, self._test_ws)

        alg = create_algorithm("Rebin", InputWorkspace=wsname)
        propValue = alg.getProperty("InputWorkspace").value
        # Is Workspace in the hierarchy of the value
        self.assertTrue(isinstance(propValue, Workspace))
        # Have got a MatrixWorkspace back and not just the generic interface
        self.assertTrue(isinstance(propValue, MatrixWorkspace))
        mem = propValue.getMemorySize()
        self.assertTrue((mem > 0))

        AnalysisDataService.remove(wsname)
 def testDirectBeamSummationExecutes(self):
     ws = illhelpers.create_poor_mans_d17_workspace()
     illhelpers.refl_rotate_detector(ws, 1.2)
     beamPosWS = illhelpers.refl_create_beam_position_ws('beamPosWS', ws, 1.2, 128)
     ws = illhelpers.refl_preprocess('ws', ws, beamPosWS)
     args = {
         'InputWorkspace': ws,
         'OutputWorkspace': 'foreground',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLSumForeground', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertTrue(alg.isExecuted())
 def testNotSummedDirectForegroundRaises(self):
     ws = illhelpers.create_poor_mans_d17_workspace()
     illhelpers.refl_rotate_detector(ws, 1.2)
     beamPosWS = illhelpers.refl_create_beam_position_ws('beamPosWS', ws, 1.2, 128)
     ws = illhelpers.refl_preprocess('ws', ws, beamPosWS)
     args = {
         'InputWorkspace': ws,
         'OutputWorkspace': 'foreground',
         'DirectForegroundWorkspace': ws,
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLSumForeground', **args)
     self.assertRaisesRegexp(RuntimeError, 'Some invalid Properties found', alg.execute)
     self.assertTrue(alg.isExecuted)
    def testDefaultRunFIGARO(self):
        args = {
            'Run': 'ILL/Figaro/000002.nxs',
            'OutputWorkspace': 'outWS',
            'rethrow': True,
            'child': True
        }
        alg = create_algorithm('ReflectometryILLPreprocess', **args)
        assertRaisesNothing(self, alg.execute)
        outWS = alg.getProperty('OutputWorkspace').value
        self.assertEquals(outWS.getAxis(0).getUnit().caption(), 'Wavelength')

        det122 = outWS.getDetector(122)
        twoTheta122 = outWS.detectorTwoTheta(det122)
        self.assertAlmostEquals(twoTheta122, 0.03060663990053301, delta=1.e-13)
        self.assertEquals(mtd.getObjectNames(), [])
 def testTwoThetaFit(self):
     args = {
         'Run': 'ILL/D17/317369',
         'OutputWorkspace': 'outWS',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertAlmostEquals(outWS.getRun().getProperty(common.SampleLogs.LINE_POSITION).value,
                             202.1773407538167,
                             delta=1.e-13)
     self.assertEquals(outWS.getRun().getProperty(common.SampleLogs.FOREGROUND_CENTRE).value, 202)
     self.assertEquals(outWS.getAxis(0).getUnit().caption(), 'Wavelength')
     print(mtd.getObjectNames())
 def testLinePositionTwoThetaInput(self):
     args = {
         'Run': 'ILL/D17/317369',
         'LinePosition': 10.23,
         'TwoTheta': 40.66,
         'OutputWorkspace': 'outWS',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEquals(outWS.getRun().getProperty(common.SampleLogs.LINE_POSITION).value, 10.23)
     self.assertEquals(outWS.getRun().getProperty(common.SampleLogs.FOREGROUND_CENTRE).value, 10)
     self.assertEquals(outWS.getRun().getProperty(common.SampleLogs.TWO_THETA).value, 1.5885926485061646)
     self.assertEquals(outWS.getAxis(0).getUnit().caption(), 'Wavelength')
     self.assertEquals(mtd.getObjectNames(), [])
 def testUnitConversion(self):
     args = {
         'Run': 'ILL/D17/317369',
         'OutputWorkspace': 'outWS',
         'FitRangeLower': 2.,
         'FitRangeUpper': 20.,
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertAlmostEquals(outWS.getRun().getProperty(common.SampleLogs.LINE_POSITION).value,
                             202.17752545515665,
                             delta=1.e-13)
     self.assertEquals(outWS.getRun().getProperty(common.SampleLogs.FOREGROUND_CENTRE).value, 202)
     self.assertEquals(outWS.getAxis(0).getUnit().caption(), 'Wavelength')
 def testExecutes(self):
     ws = illhelpers.create_poor_mans_d17_workspace()
     illhelpers.add_flipper_configuration_D17(ws, 1, 1)
     mtd.add('ws', ws)
     illhelpers.refl_create_beam_position_ws('beamPosWS', ws, 0., 128)
     ws = illhelpers.refl_preprocess('ws', ws, 'beamPosWS')
     ws = illhelpers.refl_sum_foreground('ws', 'SumInLambda', ws)
     args = {
         'InputWorkspaces': 'ws',
         'OutputWorkspace': 'corrected',
         'EfficiencyFile': 'ILL/D17/PolarizationFactors.txt',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPolarizationCor', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertTrue(mtd.doesExist('corrected_++'))
Esempio n. 31
0
 def testReflectedBeamSanAngleD17(self):
     args = {
         'Run': 'ILL/D17/317370.nxs',
         'Measurement': 'ReflectedBeam',
         'AngleOption': 'SampleAngle',
         'OutputWorkspace': 'outWS',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEqual(outWS.getAxis(0).getUnit().caption(), 'Wavelength')
     fgCentre = outWS.run().getProperty(common.SampleLogs.LINE_POSITION).value
     self.assertAlmostEqual(fgCentre, 201.674, delta=0.001)
     peakLeft = math.floor(fgCentre)
     peakRight = peakLeft + 1
     two_theta_fg = (outWS.spectrumInfo().twoTheta(peakLeft) + outWS.spectrumInfo().twoTheta(peakRight))/2.
     self.assertAlmostEqual(numpy.rad2deg(two_theta_fg), 1.6, delta=0.01)
Esempio n. 32
0
 def testDefaultRunFIGARO(self):
     args = {
         'Run': 'ILL/Figaro/000002.nxs',
         'OutputWorkspace': 'outWS',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEqual(outWS.getAxis(0).getUnit().caption(), 'Wavelength')
     fgCentre = outWS.run().getProperty(
         common.SampleLogs.LINE_POSITION).value
     self.assertAlmostEqual(fgCentre, 127.801, delta=0.001)
     peakLeft = math.floor(fgCentre)
     peakRight = peakLeft + 1
     two_theta_fg = (outWS.spectrumInfo().twoTheta(peakLeft) +
                     outWS.spectrumInfo().twoTheta(peakRight)) / 2.
     self.assertAlmostEqual(numpy.rad2deg(two_theta_fg), 0., delta=0.1)
 def testLinePositionFromSampleLogs(self):
     # We do not run the preprocess!
     ws = illhelpers.create_poor_mans_d17_workspace()
     illhelpers.refl_rotate_detector(ws, 1.2)
     ws.getAxis(0).setUnit('Wavelength')
     ws = illhelpers.refl_add_two_theta(ws, 5.5)
     ws = illhelpers.refl_add_line_position(ws, 120.6)
     ws.run().addProperty('reduction.foreground.first_workspace_index', int(140), True)
     ws.run().addProperty('reduction.foreground.centre_workspace_index', int(150), True)
     ws.run().addProperty('reduction.foreground.last_workspace_index', int(160), True)
     args = {
         'InputWorkspace': ws,
         'OutputWorkspace': 'foreground',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLSumForeground', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertTrue(alg.isExecuted())
 def testWavelengthRangeDefault(self):
     ws = illhelpers.create_poor_mans_d17_workspace()
     illhelpers.refl_rotate_detector(ws, 1.2)
     ws = illhelpers.refl_add_two_theta(ws, 5.5)
     ws = illhelpers.refl_preprocess('ws', ws)
     args = {
         'InputWorkspace': ws,
         'OutputWorkspace': 'foreground',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLSumForeground', **args)
     assertRaisesNothing(self, alg.execute)
     out = alg.getProperty('OutputWorkspace').value
     self.assertEqual(out.getNumberHistograms(), 1)
     Xs = out.readX(0)
     self.assertGreater(len(Xs), 1)
     self.assertGreater(Xs[0], 0.)
     self.assertLess(Xs[-1], 30.)
Esempio n. 35
0
 def testTwoThetaFit(self):
     args = {
         'Run': 'ILL/D17/317369',
         'OutputWorkspace': 'outWS',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertAlmostEquals(outWS.getRun().getProperty(
         common.SampleLogs.LINE_POSITION).value,
                             202.1773407538167,
                             delta=1.e-13)
     self.assertEqual(
         outWS.getRun().getProperty(
             common.SampleLogs.FOREGROUND_CENTRE).value, 202)
     self.assertEqual(outWS.getAxis(0).getUnit().caption(), 'Wavelength')
     print(mtd.getObjectNames())
Esempio n. 36
0
    def testDefaultValues(self):
        args = {
            'Run': '317370',
            'DirectRun': '317369',
            'OutputWorkspace': 'outWS',
            'rethrow': True
        }
        alg = create_algorithm('ReflectometryILLAutoProcess', **args)
        assertRaisesNothing(self, alg.execute)
        out = mtd['outWS'].getItem(0)
        self.assertEqual(out.getHistory().size(), 1)
        algH = out.getHistory().getAlgorithmHistory(0)

        from ReflectometryILLAutoProcess import PropertyNames
        from ReflectometryILLPreprocess import Prop
        self.assertEqual(algH.getPropertyValue('AngleOption'), 'DetectorAngle')
        self.assertEqual(algH.getPropertyValue(PropertyNames.LOW_BKG_OFFSET_DIRECT), '7')
        self.assertEqual(algH.getPropertyValue(PropertyNames.LOW_BKG_OFFSET), '7')
        self.assertEqual(algH.getPropertyValue(PropertyNames.LOW_BKG_WIDTH_DIRECT), '5')
        self.assertEqual(algH.getPropertyValue(PropertyNames.LOW_BKG_WIDTH), '5')
        self.assertEqual(algH.getPropertyValue(PropertyNames.HIGH_BKG_OFFSET_DIRECT), '7')
        self.assertEqual(algH.getPropertyValue(PropertyNames.HIGH_BKG_OFFSET), '7')
        self.assertEqual(algH.getPropertyValue(PropertyNames.HIGH_BKG_WIDTH_DIRECT), '5')
        self.assertEqual(algH.getPropertyValue(PropertyNames.HIGH_BKG_WIDTH), '5')
        self.assertEqual(algH.getPropertyValue(Prop.SUBALG_LOGGING), 'Logging OFF')
        self.assertEqual(algH.getPropertyValue(Prop.CLEANUP), 'Cleanup ON')
        self.assertEqual(algH.getPropertyValue(Prop.SLIT_NORM), 'Slit Normalisation AUTO')
        self.assertEqual(algH.getPropertyValue(Prop.FLUX_NORM_METHOD), 'Normalise To Time')
        self.assertEqual(algH.getPropertyValue(PropertyNames.CACHE_DIRECT_BEAM), '0')
        self.assertEqual(algH.getPropertyValue(PropertyNames.BKG_METHOD_DIRECT), 'Background Constant Fit')
        self.assertEqual(algH.getPropertyValue(PropertyNames.BKG_METHOD), 'Background Constant Fit')
        self.assertEqual(algH.getPropertyValue(PropertyNames.START_WS_INDEX_DIRECT), '0')
        self.assertEqual(algH.getPropertyValue(PropertyNames.START_WS_INDEX), '0')
        self.assertEqual(algH.getPropertyValue(PropertyNames.END_WS_INDEX_DIRECT), '255')
        self.assertEqual(algH.getPropertyValue(PropertyNames.END_WS_INDEX), '255')
        self.assertEqual(algH.getPropertyValue(PropertyNames.SUM_TYPE), 'Incoherent')
        self.assertEqual(algH.getPropertyValue(PropertyNames.WAVELENGTH_LOWER), '0')
        self.assertEqual(algH.getPropertyValue(PropertyNames.WAVELENGTH_UPPER), '35')
        self.assertEqual(algH.getPropertyValue(PropertyNames.LOW_FRG_HALF_WIDTH), '0')
        self.assertEqual(algH.getPropertyValue(PropertyNames.HIGH_FRG_HALF_WIDTH), '0')
        self.assertEqual(algH.getPropertyValue(PropertyNames.LOW_FRG_HALF_WIDTH_DIRECT), '0')
        self.assertEqual(algH.getPropertyValue(PropertyNames.HIGH_FRG_HALF_WIDTH_DIRECT), '0')
Esempio n. 37
0
 def testAsymmetricForegroundRanges(self):
     inWSName = 'ReflectometryILLPreprocess_test_ws'
     self.create_sample_workspace(inWSName)
     ws = mtd[inWSName]
     # Add special background fitting zones around the exclude zones.
     foregroundIndices = [21, 22, 23, 24]
     for i in range(ws.getNumberHistograms()):
         ys = ws.dataY(i)
         es = ws.dataE(i)
         if i in foregroundIndices:
             ys.fill(1000.0)
             es.fill(numpy.sqrt(1000.0))
         else:
             ys.fill(-100)
             es.fill(numpy.sqrt(100))
     args = {
         'InputWorkspace': inWSName,
         'OutputWorkspace': 'unused_for_child',
         'LinePosition': 23,
         'TwoTheta': 0.6,
         'ForegroundHalfWidth': [2, 1],
         'FlatBackground': 'Background OFF',
         'FluxNormalisation': 'Normalisation OFF',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEqual(outWS.getNumberHistograms(), 100)
     logs = outWS.run()
     properties = [
         common.SampleLogs.FOREGROUND_START,
         common.SampleLogs.FOREGROUND_CENTRE,
         common.SampleLogs.FOREGROUND_END
     ]
     values = [21, 23, 24]
     for p, val in zip(properties, values):
         self.assertTrue(logs.hasProperty(p))
         self.assertEqual(logs.getProperty(p).value, val)
     self.assertEqual(mtd.getObjectNames(),
                      ['ReflectometryILLPreprocess_test_ws'])
Esempio n. 38
0
 def testUnitConversion(self):
     args = {
         'Run': 'ILL/D17/317369',
         'OutputWorkspace': 'outWS',
         'FitRangeLower': 2.,
         'FitRangeUpper': 20.,
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertAlmostEquals(outWS.getRun().getProperty(
         common.SampleLogs.LINE_POSITION).value,
                             202.17752545515665,
                             delta=1.e-13)
     self.assertEqual(
         outWS.getRun().getProperty(
             common.SampleLogs.FOREGROUND_CENTRE).value, 202)
     self.assertEqual(outWS.getAxis(0).getUnit().caption(), 'Wavelength')
Esempio n. 39
0
    def test_requires_more_than_one_peak_workspace(self):
        peaks1 = CreatePeaksWorkspace(InstrumentWorkspace=self.ws,
                                      NumberOfPeaks=0,
                                      OutputWorkspace="SXD_peaks4")
        UB = np.diag([0.25, 0.25, 0.1])
        SetUB(peaks1, UB=UB)
        # Add some peaks
        add_peaksHKL([peaks1], range(0, 3), range(0, 3), 4)

        alg = create_algorithm('FindGlobalBMatrix',
                               PeakWorkspaces=[peaks1],
                               a=4.1,
                               b=4.2,
                               c=10,
                               alpha=88,
                               beta=88,
                               gamma=89,
                               Tolerance=0.15)

        with self.assertRaises(RuntimeError):
            alg.execute()
Esempio n. 40
0
 def testWavelengthRange(self):
     ws = illhelpers.create_poor_mans_d17_workspace()
     illhelpers.refl_rotate_detector(ws, 1.2)
     beamPosWS = illhelpers.refl_create_beam_position_ws('beamPosWS', ws, 1.2, 128)
     ws = illhelpers.refl_preprocess('ws', ws, beamPosWS)
     xMin = 2.3
     xMax = 4.2
     args = {
         'InputWorkspace': ws,
         'OutputWorkspace': 'foreground',
         'WavelengthRange': [xMin, xMax],
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLSumForeground', **args)
     assertRaisesNothing(self, alg.execute)
     ws = alg.getProperty('OutputWorkspace').value
     self.assertEquals(ws.getNumberHistograms(), 1)
     Xs = ws.readX(0)
     self.assertGreater(len(Xs), 1)
     self.assertGreater(Xs[0], xMin)
     self.assertLess(Xs[-1], xMax)
Esempio n. 41
0
 def testWavelengthRange(self):
     inWSName = 'ReflectometryILLPreprocess_test_ws'
     self.create_sample_workspace(inWSName)
     # Check range begin only.
     args = {
         'InputWorkspace': inWSName,
         'OutputWorkspace': 'unused_for_child',
         'BeamCentre': 50,
         'WavelengthRange': [2.0, 4.0],
         'ForegroundHalfWidth': 1,
         'FluxNormalisation': 'Normalisation OFF',
         'FlatBackground': 'Background OFF',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEquals(outWS.getNumberHistograms(), 100)
     Xs = outWS.extractX()
     numpy.testing.assert_array_less(2.0, Xs[:, 0])
     numpy.testing.assert_array_less(Xs[:, -1], 4.0)
Esempio n. 42
0
    def test_peak_workspaces_need_at_least_six_peaks_each(self):
        peaks1 = CreatePeaksWorkspace(InstrumentWorkspace=self.ws,
                                      NumberOfPeaks=0,
                                      OutputWorkspace="SXD_peaks5")
        UB = np.diag([0.25, 0.25, 0.1])
        SetUB(peaks1, UB=UB)
        # Add 5 peaks
        add_peaksHKL([peaks1], range(0, 5), [0], 4)
        peaks2 = CloneWorkspace(InputWorkspace=peaks1,
                                OutputWorkspace="SXD_peaks6")

        alg = create_algorithm('FindGlobalBMatrix',
                               PeakWorkspaces=[peaks1, peaks2],
                               a=4.1,
                               b=4.2,
                               c=10,
                               alpha=88,
                               beta=88,
                               gamma=89,
                               Tolerance=0.15)

        with self.assertRaises(RuntimeError):
            alg.execute()
 def testDisableFlatBackgroundSubtraction(self):
     inWSName = 'ReflectometryILLPreprocess_test_ws'
     self.create_sample_workspace(inWSName)
     # Add a peak to the sample workspace.
     ws = mtd[inWSName]
     bkgLevel = ws.readY(0)[0]
     self.assertGreater(bkgLevel, 0.1)
     args = {
         'InputWorkspace': inWSName,
         'OutputWorkspace': 'unused_for_child',
         'BeamCentre': 49,
         'FluxNormalisation': 'Normalisation OFF',
         'FlatBackground': 'Background OFF',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEquals(outWS.getNumberHistograms(), 100)
     for i in range(outWS.getNumberHistograms()):
         ys = outWS.readY(i)
         numpy.testing.assert_equal(ys, bkgLevel)
Esempio n. 44
0
 def testLinePositionTwoThetaInput(self):
     args = {
         'Run': 'ILL/D17/317369',
         'LinePosition': 10.23,
         'TwoTheta': 40.66,
         'OutputWorkspace': 'outWS',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEqual(
         outWS.getRun().getProperty(common.SampleLogs.LINE_POSITION).value,
         10.23)
     self.assertEqual(
         outWS.getRun().getProperty(
             common.SampleLogs.FOREGROUND_CENTRE).value, 10)
     self.assertEqual(
         outWS.getRun().getProperty(common.SampleLogs.TWO_THETA).value,
         1.5885926485061646)
     self.assertEqual(outWS.getAxis(0).getUnit().caption(), 'Wavelength')
     self.assertEqual(mtd.getObjectNames(), [])
 def testWaterWorkspace(self):
     inWSName = 'ReflectometryILLPreprocess_test_ws'
     self.create_sample_workspace(inWSName)
     # Add a peak to the sample workspace.
     ws = mtd[inWSName]
     for i in range(ws.getNumberHistograms()):
         ys = ws.dataY(i)
         ys.fill(10.27)
     args = {
         'InputWorkspace': inWSName,
         'OutputWorkspace': 'unused_for_child',
         'WaterWorkspace': inWSName,
         'FluxNormalisation': 'Normalisation OFF',
         'FlatBackground': 'Background OFF',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEquals(outWS.getNumberHistograms(), 100)
     for i in range(outWS.getNumberHistograms()):
         ys = outWS.readY(i)
         numpy.testing.assert_equal(ys, 1.0)
Esempio n. 46
0
    def testDefaultRunD17(self):
        args = {
            'Run': 'ILL/D17/317370.nxs',
            'OutputWorkspace': 'outWS',
            'rethrow': True,
            'child': True
        }
        alg = create_algorithm('ReflectometryILLPreprocess', **args)
        assertRaisesNothing(self, alg.execute)
        outWS = alg.getProperty('OutputWorkspace').value
        self.assertEqual(outWS.getAxis(0).getUnit().caption(), 'Wavelength')

        det122 = outWS.getDetector(122)
        twoTheta122 = outWS.detectorTwoTheta(det122)
        self.assertAlmostEqual(twoTheta122, 0.057659886309975004, delta=1.e-13)

        twoTheta = outWS.run().getProperty(common.SampleLogs.TWO_THETA).value
        self.assertAlmostEqual(twoTheta, 3.182191848754883, delta=1.e-13)

        peakPosition = outWS.run().getProperty(
            common.SampleLogs.FOREGROUND_CENTRE).value
        twoTheta2 = numpy.rad2deg(outWS.spectrumInfo().twoTheta(peakPosition))
        self.assertAlmostEqual(twoTheta2, 1.5371900428796088, delta=1.e-13)
        self.assertEqual(mtd.getObjectNames(), [])
Esempio n. 47
0
 def testCleanupOFF(self):
     # test if intermediate workspaces exist:
     # normalise_to_slits, normalise_to_monitor, '_normalised_to_time_','transposed_flat_background'
     outWSName = 'outWS'
     ws = illhelpers.create_poor_mans_d17_workspace()
     ws = illhelpers.refl_add_line_position(ws, 3.0)
     self.assertEqual(
         ws.run().getProperty(common.SampleLogs.LINE_POSITION).value, 3.0)
     # Add a peak to the workspace.
     for i in range(33, 100):
         ys = ws.dataY(i)
         ys += 10.0
     args = {
         'InputWorkspace': ws,
         'OutputWorkspace': outWSName,
         'TwoTheta': 0.6,
         'Cleanup': 'Cleanup OFF',
         'WaterWorkspace': ws,
         'ForegroundHalfWidth': [1, 2],
         'FluxNormalisation': 'Normalisation OFF',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     wsInADS = mtd.getObjectNames()
     self.assertEqual(len(wsInADS), 13)
     self.assertEqual(wsInADS, [
         'outWS_cloned_for_flat_bkg_', 'outWS_detectors_',
         'outWS_detectors_moved_', 'outWS_flat_background_',
         'outWS_flat_background_subtracted_', 'outWS_in_wavelength_',
         'outWS_monitors_', 'outWS_peak_', 'outWS_transposed_clone_',
         'outWS_transposed_flat_background_', 'outWS_water_calibrated_',
         'outWS_water_detectors_', 'outWS_water_rebinned_'
     ])
     mtd.clear()
Esempio n. 48
0
 def _assert_run_algorithm_succeeds(self, args):
     """Run the algorithm with the given args and check it succeeds"""
     alg = create_algorithm('ReflectometrySliceEventWorkspace', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertEqual(mtd.doesExist('output'), True)
     return mtd['output']
 def _run_algorithm_with_alternative_names(self):
     args = self._default_args
     args['GetLiveValueAlgorithm'] = 'GetFakeLiveInstrumentValueAlternativeNames'
     alg = create_algorithm('ReflectometryReductionOneLiveData', **args)
     assertRaisesNothing(self, alg.execute)
     return mtd['output']
Esempio n. 50
0
 def _assert_run_algorithm_throws(self, args={}):
     """Run the algorithm with the given args and check it throws"""
     alg = create_algorithm('ReflectometryBackgroundSubtraction', **args)
     with self.assertRaises(RuntimeError):
         alg.execute()
Esempio n. 51
0
 def _assert_run_algorithm_invalid_property(self, args={}):
     """Create the algorithm with the given args and check it fails"""
     with self.assertRaises(ValueError):
         create_algorithm('ReflectometryBackgroundSubtraction', **args)
Esempio n. 52
0
 def _assert_run_algorithm_fails(self, args):
     """Run the algorithm with the given args and check it fails to produce output"""
     alg = create_algorithm('ReflectometrySliceEventWorkspace', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertEqual(mtd.doesExist('output'), False)
 def _assert_run_algorithm_succeeds(self, args):
     """ Run the algorithm with the given args and check it succeeds """
     alg = create_algorithm('ReflectometryReductionOne', **args)
     assertRaisesNothing(self, alg.execute)
     self.assertTrue(mtd.doesExist('output'))
     return mtd['output']
Esempio n. 54
0
 def _run_algorithm(self, params):
     algorithm = testhelpers.create_algorithm('BinWidthAtX', **params)
     testhelpers.assertRaisesNothing(self, algorithm.execute)
     self.assertTrue(algorithm.isExecuted())
     return algorithm.getProperty('BinWidth').value
    def testReflectedBeamSumInLambdaDetectorMovingAndRotation(self):
        dirWS = illhelpers.create_poor_mans_d17_workspace()
        illhelpers.add_chopper_configuration_D17(dirWS)
        illhelpers.add_slit_configuration_D17(dirWS, 0.03, 0.02)
        dirWS = illhelpers.refl_add_two_theta(dirWS, 6.7)
        dirWS = illhelpers.refl_preprocess_lineposition('dirWS', dirWS, 50.9)
        self.assertEqual(
            dirWS.run().getProperty(common.SampleLogs.TWO_THETA).value, 6.7)
        self.assertEqual(
            dirWS.run().getProperty(common.SampleLogs.LINE_POSITION).value,
            50.9)
        args = {
            'InputWorkspace': dirWS,
            'OutputWorkspace': 'dirForeground',
            'rethrow': True,
            'child': True
        }
        alg = create_algorithm('ReflectometryILLSumForeground', **args)
        assertRaisesNothing(self, alg.execute)
        self.assertTrue(alg.isExecuted())
        dirForeground = alg.getProperty('OutputWorkspace').value
        self.assertEqual(
            dirForeground.run().getProperty(common.SampleLogs.TWO_THETA).value,
            6.7)
        self.assertEqual(
            dirForeground.run().getProperty(
                common.SampleLogs.LINE_POSITION).value, 50.9)
        self.assertEqual(dirForeground.spectrumInfo().size(), 1)
        self.assertAlmostEqual(dirForeground.spectrumInfo().l2(0),
                               3.101234371122588,
                               delta=1.e-15)
        self.assertAlmostEqual(numpy.degrees(
            dirForeground.spectrumInfo().twoTheta(0)),
                               8.3914043569830,
                               delta=1.e-13)

        reflWS = illhelpers.create_poor_mans_d17_workspace()
        illhelpers.refl_rotate_detector(reflWS, 1.2)
        illhelpers.add_chopper_configuration_D17(reflWS)
        illhelpers.add_slit_configuration_D17(reflWS, 0.03, 0.02)
        reflWS = illhelpers.refl_add_two_theta(reflWS, 40.2)
        reflWS = illhelpers.refl_preprocess_lineposition(
            'refWS', reflWS, 120.4)
        self.assertEqual(
            reflWS.run().getProperty(common.SampleLogs.TWO_THETA).value, 40.2)
        self.assertEqual(
            reflWS.run().getProperty(common.SampleLogs.LINE_POSITION).value,
            120.4)
        args = {
            'InputWorkspace': reflWS,
            'OutputWorkspace': 'foreground',
            'DirectForegroundWorkspace': dirForeground,
            'SummationType': 'SumInLambda',
            'DirectLineWorkspace': dirWS,
            'rethrow': True,
            'child': True
        }
        alg = create_algorithm('ReflectometryILLSumForeground', **args)
        assertRaisesNothing(self, alg.execute)
        out = alg.getProperty('OutputWorkspace').value
        self.assertEqual(
            out.run().getProperty(common.SampleLogs.TWO_THETA).value, 40.2)
        self.assertEqual(
            out.run().getProperty(common.SampleLogs.LINE_POSITION).value,
            120.4)
        self.assertEqual(out.spectrumInfo().size(), 1)
        self.assertAlmostEqual(out.spectrumInfo().l2(0),
                               3.0992766423566,
                               delta=1.e-13)
        self.assertAlmostEqual(numpy.degrees(out.spectrumInfo().twoTheta(0)),
                               40.3568485178340,
                               delta=1.e-13)
        self.assertTrue(alg.isExecuted())
Esempio n. 56
0
 def testForegroundBackgroundRanges(self):
     inWSName = 'ReflectometryILLPreprocess_test_ws'
     self.create_sample_workspace(inWSName)
     ws = mtd[inWSName]
     # Add special background fitting zones around the exclude zones.
     lowerBkgIndices = [26]
     for i in lowerBkgIndices:
         ys = ws.dataY(i)
         ys += 5.0
     # Add negative 'exclude zone' around the peak.
     lowerExclusionIndices = [27, 28]
     for i in lowerExclusionIndices:
         ys = ws.dataY(i)
         ys -= 1000.0
     # Add a peak to the sample workspace.
     foregroundIndices = [29, 30, 31]
     for i in foregroundIndices:
         ys = ws.dataY(i)
         ys += 1000.0
     # The second exclusion zone is wider.
     upperExclusionIndices = [32, 33, 34]
     for i in upperExclusionIndices:
         ys = ws.dataY(i)
         ys -= 1000.0
     # The second fitting zone is wider.
     upperBkgIndices = [35, 36]
     for i in upperBkgIndices:
         ys = ws.dataY(i)
         ys += 5.0
     args = {
         'InputWorkspace': inWSName,
         'OutputWorkspace': 'unused_for_child',
         'LinePosition': 30,
         'ForegroundHalfWidth': [1],
         'LowAngleBkgOffset': len(lowerExclusionIndices),
         'LowAngleBkgWidth': len(lowerBkgIndices),
         'HighAngleBkgOffset': len(upperExclusionIndices),
         'HighAngleBkgWidth': len(upperBkgIndices),
         'FluxNormalisation': 'Normalisation OFF',
         'rethrow': True,
         'child': True
     }
     alg = create_algorithm('ReflectometryILLPreprocess', **args)
     assertRaisesNothing(self, alg.execute)
     outWS = alg.getProperty('OutputWorkspace').value
     self.assertEqual(outWS.getNumberHistograms(), 100)
     ysSize = outWS.blocksize()
     for i in range(outWS.getNumberHistograms()):
         ys = outWS.readY(i)
         if i in lowerBkgIndices:
             numpy.testing.assert_equal(ys, [0.0] * ysSize)
         elif i in lowerExclusionIndices:
             numpy.testing.assert_equal(ys, [-1005.0] * ysSize)
         elif i in foregroundIndices:
             numpy.testing.assert_equal(ys, [995.0] * ysSize)
         elif i in upperExclusionIndices:
             numpy.testing.assert_equal(ys, [-1005.0] * ysSize)
         elif i in upperBkgIndices:
             numpy.testing.assert_equal(ys, [0.0] * ysSize)
         else:
             numpy.testing.assert_equal(ys, [-5.0] * ysSize)
     self.assertEqual(mtd.getObjectNames(),
                      ['ReflectometryILLPreprocess_test_ws'])
Esempio n. 57
0
 def _run_algorithm_with_defaults(self):
     alg = create_algorithm('ReflectometryReductionOneLiveData',
                            **self._default_args)
     assertRaisesNothing(self, alg.execute)
     return mtd['output']
Esempio n. 58
0
 def test_value_member_returns_python_str_for_single_file(self):
     algorithm = create_algorithm('Load', Filename='LOQ48127.raw',OutputWorkspace='w',
                               SpectrumMin=1,SpectrumMax=1,child=True)
     prop = algorithm.getProperty("Filename")
     self.assertTrue(isinstance(prop.value, str))