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) dirWS = illhelpers.refl_add_line_position(dirWS, 128.0) dirWS = illhelpers.refl_add_two_theta(dirWS, 2.23) dirWS = illhelpers.refl_preprocess('dirWS', dirWS) 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) reflWS = illhelpers.refl_add_line_position(reflWS, 128.0) reflWS = illhelpers.refl_add_two_theta(reflWS, 6.7) reflWS = illhelpers.refl_preprocess('reflWS', reflWS) 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 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) dirWS = illhelpers.refl_add_line_position(dirWS, 128.0) dirWS = illhelpers.refl_add_two_theta(dirWS, 5.5) dirWS = illhelpers.refl_preprocess('dirWS', dirWS) 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) reflWS = illhelpers.refl_add_two_theta(reflWS, 6.7) reflWS = illhelpers.refl_preprocess('refWS', reflWS) args = { 'InputWorkspace': reflWS, 'OutputWorkspace': 'foreground', 'DirectForegroundWorkspace': dirForeground, 'SummationType': 'SumInQ', 'DirectLineWorkspace': dirWS, 'rethrow': True, 'child': True } alg = create_algorithm('ReflectometryILLSumForeground', **args) assertRaisesNothing(self, alg.execute) self.assertTrue(alg.isExecuted())
def testDirectBeamSummationExecutes(self): ws = illhelpers.create_poor_mans_d17_workspace() illhelpers.refl_rotate_detector(ws, 1.2) ws = illhelpers.refl_add_line_position(ws, 128.0) 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) self.assertTrue(alg.isExecuted())
def testNotSummedDirectForegroundRaises(self): ws = illhelpers.create_poor_mans_d17_workspace() illhelpers.refl_rotate_detector(ws, 1.2) ws = illhelpers.refl_add_line_position(ws, 128.0) ws = illhelpers.refl_add_two_theta(ws, 5.5) ws = illhelpers.refl_preprocess('ws', ws) 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 testExecutes(self): ws = illhelpers.create_poor_mans_d17_workspace() illhelpers.add_flipper_configuration_D17(ws, 1, 1) mtd.add('ws', ws) ws = illhelpers.refl_add_line_position(ws, 128.0) ws = illhelpers.refl_add_two_theta(ws, 6.6) ws = illhelpers.refl_preprocess('ws', 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_++'))
def testExecutes(self): ws = illhelpers.create_poor_mans_d17_workspace() illhelpers.add_flipper_configuration_D17(ws, 1, 1) mtd.add('ws', ws) ws = illhelpers.refl_add_line_position(ws, 128.0) ws = illhelpers.refl_add_two_theta(ws, 6.6) ws = illhelpers.refl_preprocess('ws', 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_++'))
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 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.assertEquals(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.assertEquals(len(wsInADS), 13) self.assertEquals(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()
def testWavelengthRangeDefault(self): ws = illhelpers.create_poor_mans_d17_workspace() illhelpers.refl_rotate_detector(ws, 1.2) ws = illhelpers.refl_add_line_position(ws, 128.0) 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.)
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()