Exemplo n.º 1
0
 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.assertEqual(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.assertEqual(mtd.getObjectNames(),
                      ['ReflectometryILLPreprocess_test_ws'])
 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'])
Exemplo n.º 3
0
 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.assertEqual(mtd.getObjectNames(), [name])
Exemplo n.º 4
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.assertAlmostEquals(twoTheta122,
                                0.057659886309975004,
                                delta=1.e-13)

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

        peakPosition = outWS.run().getProperty(
            common.SampleLogs.FOREGROUND_CENTRE).value
        twoTheta2 = numpy.rad2deg(outWS.spectrumInfo().twoTheta(peakPosition))
        self.assertAlmostEquals(twoTheta2, 1.5371900428796088, delta=1.e-13)
        self.assertEqual(mtd.getObjectNames(), [])
 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])
Exemplo n.º 6
0
    def test_load_valid_added_event_data_and_monitor_file_produces_group_ws(self):
        # Arrange
        names = ['event_data', 'monitor']
        file_names = self._prepare_workspaces(names = names)
        self._cleanup_workspaces(names = names)

        # Act
        group_ws_name = 'g_ws'
        output_group_file_name = su.bundle_added_event_data_as_group(file_names[0], file_names[1])

        Load(Filename = output_group_file_name, OutputWorkspace = group_ws_name)
        group_ws = mtd[group_ws_name]

        # Assert
        self.assertTrue(isinstance(group_ws, WorkspaceGroup))
        self.assertEqual(group_ws.size(), 2)
        self.assertTrue(os.path.exists(file_names[0])) # File for group workspace exists
        self.assertFalse(os.path.exists(file_names[1]))  # File for monitors is deleted

        # Clean up
        ws_names_to_delete = []
        for ws_name in mtd.getObjectNames():
            if ws_name != group_ws_name:
                ws_names_to_delete.append(str(ws_name))
        self._cleanup_workspaces(names = ws_names_to_delete)

        if os.path.exists(file_names[0]):
            os.remove(file_names[0])
Exemplo n.º 7
0
 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',
         'LinePosition': 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.assertEqual(outWS.getNumberHistograms(), 100)
     for i in range(outWS.getNumberHistograms()):
         ys = outWS.readY(i)
         numpy.testing.assert_equal(ys, bkgLevel)
     self.assertEqual(mtd.getObjectNames(),
                      ['ReflectometryILLPreprocess_test_ws'])
 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'])
Exemplo n.º 9
0
 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.assertEqual(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.assertEqual(mtd.getObjectNames(),
                      ['ReflectometryILLPreprocess_test_ws'])
Exemplo n.º 10
0
    def test_monitors_are_renamed_correctly(self):
        #Arrange
        ws_1 = CreateSampleWorkspace()
        ws_2 = CreateSampleWorkspace()
        ws_3 = CreateSampleWorkspace()

        ws_mon_1 = CreateSampleWorkspace()
        ws_mon_2 = CreateSampleWorkspace()
        ws_mon_3 = CreateSampleWorkspace()

        ws_group = GroupWorkspaces(InputWorkspaces=[ws_1, ws_2, ws_3])
        ws_mon_group = GroupWorkspaces(InputWorkspaces=[ws_mon_1, ws_mon_2, ws_mon_3])

        # Act
        su.rename_monitors_for_multiperiod_event_data(ws_mon_group, ws_group, self.monitor_appendix)

        # Assert
        self.assertTrue(ws_mon_1.name() == ws_1.name() + self.monitor_appendix, "Monitors should be renamed to xxxx_monitors")
        self.assertTrue(ws_mon_2.name() == ws_2.name() + self.monitor_appendix, "Monitors should be renamed to xxxx_monitors")
        self.assertTrue(ws_mon_3.name() == ws_3.name() + self.monitor_appendix, "Monitors should be renamed to xxxx_monitors")

        # Clean up
        for element in mtd.getObjectNames():
            if element in mtd:
                DeleteWorkspace(element)
 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))
Exemplo n.º 12
0
 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))
 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')
     self.assertEquals(mtd.getObjectNames(), [])
Exemplo n.º 14
0
 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.assertEqual(outWS.getAxis(0).getUnit().caption(), 'Wavelength')
     self.assertEqual(mtd.getObjectNames(), [])
    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(), [])
Exemplo n.º 16
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')

        det122 = outWS.getDetector(122)
        twoTheta122 = outWS.detectorTwoTheta(det122)
        self.assertAlmostEquals(twoTheta122, 0.03060663990053301, delta=1.e-13)
        self.assertEqual(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(), [])
Exemplo n.º 19
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())
Exemplo n.º 20
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'])
 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()
Exemplo n.º 22
0
    def test_expection_is_raised_when_workspaec_and_monitor_mismatch(self):
        #Arrange
        ws_1 = CreateSampleWorkspace()
        ws_2 = CreateSampleWorkspace()
        ws_3 = CreateSampleWorkspace()

        ws_mon_1 = CreateSampleWorkspace()
        ws_mon_2 = CreateSampleWorkspace()

        ws_group = GroupWorkspaces(InputWorkspaces=[ws_1, ws_2, ws_3])
        ws_mon_group = GroupWorkspaces(InputWorkspaces=[ws_mon_1, ws_mon_2])

        # Act + Assert
        args = {'monitor_worksapce': ws_mon_group, 'workspace':ws_group, 'appendix':self.monitor_appendix}
        self.assertRaises(RuntimeError, su.rename_monitors_for_multiperiod_event_data, *args)

        # Clean up
        for element in mtd.getObjectNames():
            if element in mtd:
                DeleteWorkspace(element)
Exemplo n.º 23
0
    def exec_command_refresh(self):
        """ Refresh workspace in the memory
        :return:
        """
        workspace_names = mtd.getObjectNames()

        self.ui.tableWidget_dataStructure.remove_all_rows()
        error_message = ''
        for ws_name in workspace_names:
            try:
                # get workspace and its type
                workspace = mtd.retrieve(ws_name)
                ws_type = workspace.id()
                # find out workspace information
                ws_info = ''
                if ws_type == 'EventWorkspace':
                    num_events = workspace.getNumberEvents()
                    num_hist = workspace.getNumberHistograms()
                    num_bins = len(workspace.readY(0))
                    ws_info = '{}/{}/{}'.format(num_events, num_hist, num_bins)
                elif ws_type == 'Workspace2D':
                    num_hist = workspace.getNumberHistograms()
                    num_bins = len(workspace.readY(0))
                    ws_info = '{}/{}'.format(num_hist, num_bins)
                elif ws_type == 'TableWorkspace':
                    num_rows = workspace.rowCount()
                    num_cols = workspace.columnCount()
                    ws_info = '{}/{}'.format(num_rows, num_cols)
                self.ui.tableWidget_dataStructure.add_workspace(ws_name, ws_type, ws_info)
            except Exception as ex:
                error_message += 'Unable to add %s to table due to %s.\n' % (ws_name, str(ex))
        # END-FOR

        # switch to table tab
        self.ui.tabWidget_table_view.setCurrentIndex(0)

        if len(error_message) == 0:
            return True, ''

        return False, error_message
 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.assertEquals(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.assertEquals(mtd.getObjectNames(), ['ReflectometryILLPreprocess_test_ws'])
    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.assertEquals(outWS.getAxis(0).getUnit().caption(), 'Wavelength')

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

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

        peakPosition = outWS.run().getProperty(common.SampleLogs.FOREGROUND_CENTRE).value
        twoTheta2 = numpy.rad2deg(outWS.spectrumInfo().twoTheta(peakPosition))
        self.assertAlmostEquals(twoTheta2, 1.5371900428796088, delta=1.e-13)
        self.assertEquals(mtd.getObjectNames(), [])
Exemplo n.º 26
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 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',
         'LinePosition': 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)
     self.assertEquals(mtd.getObjectNames(), ['ReflectometryILLPreprocess_test_ws'])
Exemplo n.º 28
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()
Exemplo n.º 29
0
 def tearDown(self):
     for wsName in mtd.getObjectNames():
         if wsName.startswith(self.prefix):
             mtd.remove(wsName)
 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.assertEquals(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.assertEquals(mtd.getObjectNames(), ['ReflectometryILLPreprocess_test_ws'])
Exemplo n.º 31
0
def analyse(data_table,
            masks,
            output_file,
            show_fits=False,
            show_quality=False):
    """

    Analyse a set of combined Sans and Semsans measurements.
    The result will be a set of workspaces with the Semsans data
    and a csv file that can be loaded into the batch sans interface
    to load the sans data.

    Parameters
    ----------
    data_table
      The name of WorkspaceTable with the runs that need to be analysed.  This
      table should be generated by the get_log function.
    masks
      A list of strings containing the filenames of the masks for the
      individual tubes used in the semsans polarisation calculation
    output_file
      Where to save the CSV file that will generate the SANS runs
    show_fits
      Whether to show the individual tube fits used to calculate the spin echo
      length.  Defaults to False
    show_quality
      Whether to show the quality of the linear fit of the precession
      frequencies used to calculate the spin echo length.  Defaults to False

    """
    if "Full_Blank" not in mtd.getObjectNames():
        int3samples(table_to_run(mtd["metadata_Full_Blank_runs"]),
                    "Full_Blank", masks)
    const = sel_const(
        [mtd["Full_Blank_{}".format(tube)] for tube, _ in enumerate(masks)],
        show_fits=show_fits,
        show_quality=show_quality)

    k = data_table[9:-5]
    runs = table_to_run(mtd[data_table])
    for run in runs:
        get_shimed(run.number, dirname(output_file))
        get_shimed(run.trans, dirname(output_file))
        get_shimed(run.csans, dirname(output_file))
        get_shimed(run.ctrans, dirname(output_file))
        get_shimed(run.direct, dirname(output_file))
        semsans_ws = "{}_hours_{:0.02f}".format(
            k, (run.start - runs[0].start).seconds / 3600.0)
        int3samples([run], semsans_ws, masks)
        # DeleteWorkspace("{}_sans_nxs".format(run.number))
        norm(semsans_ws, "Full_Blank", masks)
        sel(semsans_ws + "_norm", const)
        DeleteWorkspaces([semsans_ws, semsans_ws + "_Norm"])
    with open(output_file, "w") as outfile:
        framework = "sample_sans,{}-add," \
                    "sample_trans,{}-add," \
                    "sample_direct_beam,{}-add,"\
                    "can_sans,{}-add,"\
                    "can_trans,{}-add,"\
                    "can_direct_beam,{}-add,"\
                    "output_as,{}_hours_{:0.2f}\n"
        for idx, run in enumerate(runs):
            outfile.write(
                framework.format(run.number, run.trans, run.direct, run.csans,
                                 run.ctrans, run.direct, k,
                                 (run.start - runs[0].start).seconds / 3600.0))

    import sans.command_interface.ISISCommandInterface as ici
    ici.Clean()
    ici.LARMOR()
    ici.MaskFile(
        r"\\isis\inst$\NDXLARMOR\User\Users\Masks\USER_Edler_171B_a2_8mm_SEMSANS_r20287.txt"
    )
    ici.BatchReduce(output_file, format=".nxs", verbose=True)
Exemplo n.º 32
0
 def _clean_up(self,names):
     for name in names:
         if name in mtd.getObjectNames():
             DeleteWorkspace(name)
Exemplo n.º 33
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'])