def setUp(self):
     self._facility = config['default.facility']
     self._data_search_dirs = config.getDataSearchDirs()
     config.appendDataSearchSubDir('ILL/D11/')
     config.appendDataSearchSubDir('ILL/D33/')
     config.setFacility("ILL")
     SANSILLReduction(Run='010569', ProcessAs='Sample', OutputWorkspace='sample')
 def tearDown(self):
     config.setFacility(self._facility)
     config.setDataSearchDirs(self._data_search_dirs)
     mtd.clear()
    def runTest(self):
        """ This is the old way to do MDNorm to sample, background and finally clean background from sample
        Now it serves as a benchmark to generate expected result for enhanced MDNorm

        Current status: To task 88 no accumulation
        Next   status:  To task 89 no accumulation
                        To task 88 with accumulation
                        To task 89 with accumulation
        """
        # Set facility that load data
        config.setFacility('SNS')
        Load(Filename='HYS_13656', OutputWorkspace='sum')
        SetGoniometer(Workspace='sum', Axis0='s1,0,1,0,1')

        # prepare sample MD: in test must between 10 and 12 to match the gold data
        dgs_red_group_name1 = self.prepare_md(input_ws_name='sum',
                                              merged_md_name='merged1',
                                              min_log_value=10,
                                              max_log_value=12,
                                              log_step=LOG_VALUE_STEP,
                                              prefix='step1')

        # 1-1 Existing method (but to keep)
        benchmark = self.run_old_solution('merged1',
                                          f'{dgs_red_group_name1}_1',
                                          'oldstep1')
        self._old_clean = str(benchmark.cleaned)

        # Prepare background workspace
        self.prepare_single_exp_info_background(
            input_md_name=f'{dgs_red_group_name1}_1',
            output_md_name='bkgd_md1',
            target_qframe='Q_lab')

        # Test new solutions
        r = MDNorm(InputWorkspace='merged1',
                   BackgroundWorkspace='bkgd_md1',
                   Dimension0Name='QDimension1',
                   Dimension0Binning='-5,0.05,5',
                   Dimension1Name='QDimension2',
                   Dimension1Binning='-5,0.05,5',
                   Dimension2Name='DeltaE',
                   Dimension2Binning='-2,2',
                   Dimension3Name='QDimension0',
                   Dimension3Binning='-0.5,0.5',
                   SymmetryOperations=SYMMETRY_OPERATION,
                   OutputWorkspace='clean_data',
                   OutputDataWorkspace='dataMD',
                   OutputNormalizationWorkspace='normMD',
                   OutputBackgroundDataWorkspace='background_dataMD',
                   OutputBackgroundNormalizationWorkspace='background_normMD')
        # Test solution
        assert hasattr(r, 'OutputBackgroundNormalizationWorkspace'
                       ), 'MDNorm does not execute.'
        # Compare workspaces: binned background data workspace
        rc = CompareMDWorkspaces(Workspace1=benchmark.bkgd_data,
                                 Workspace2='background_dataMD')
        assert rc.Equals, f'Error message: {rc.Result}'
        # Compare workspaces: background normalization workspace
        r89 = CompareMDWorkspaces(Workspace1=benchmark.bkgd_norm,
                                  Workspace2='background_normMD',
                                  Tolerance=1E-9)
        assert r89.Equals, f'Incompatible background normalization workspaces: {r89.Result}'
        # Compare the cleaned MD
        r_out = CompareMDWorkspaces(Workspace1=benchmark.cleaned,
                                    Workspace2='clean_data',
                                    Tolerance=1E-16)
        if not r_out.Equals:
            raise ValueError(
                f'Sample output data does not match: {r_out.Result}')

        # Round 2: Test accumulation mode
        dgs_red_group_name1 = self.prepare_md(input_ws_name='sum',
                                              merged_md_name='merged2',
                                              min_log_value=13,
                                              max_log_value=15,
                                              log_step=LOG_VALUE_STEP,
                                              prefix='step2')
        # Old solution
        benchmark2 = self.run_old_solution('merged2',
                                           f'{dgs_red_group_name1}_2',
                                           'oldstep2', benchmark)
        # 1-2 Test new solutions
        self.prepare_single_exp_info_background(
            input_md_name=f'{dgs_red_group_name1}_2',
            output_md_name='bkgd_md2',
            target_qframe='Q_lab')
        r = MDNorm(
            InputWorkspace='merged2',
            BackgroundWorkspace='bkgd_md2',
            TemporaryDataWorkspace='dataMD',
            TemporaryNormalizationWorkspace='normMD',
            TemporaryBackgroundDataWorkspace='background_dataMD',
            TemporaryBackgroundNormalizationWorkspace='background_normMD',
            Dimension0Name='QDimension1',
            Dimension0Binning='-5,0.05,5',
            Dimension1Name='QDimension2',
            Dimension1Binning='-5,0.05,5',
            Dimension2Name='DeltaE',
            Dimension2Binning='-2,2',
            Dimension3Name='QDimension0',
            Dimension3Binning='-0.5,0.5',
            SymmetryOperations=SYMMETRY_OPERATION,
            OutputWorkspace='clean_data_2',
            OutputDataWorkspace='dataMD2',
            OutputNormalizationWorkspace='normMD2',
            OutputBackgroundDataWorkspace='background_dataMD2',
            OutputBackgroundNormalizationWorkspace='background_normMD2')

        # Compare data workspace
        r_sd = CompareMDWorkspaces(Workspace1=benchmark2.sample_data,
                                   Workspace2='dataMD',
                                   Tolerance=1E-7)
        assert r_sd.Equals, f'Sample binned data MD not equal: {r_sd.Result}'

        # Compare gold (old solution) and new: passed test in #88
        r = CompareMDWorkspaces(Workspace1=benchmark2.bkgd_data,
                                Workspace2='background_dataMD2')
        if not r.Equals:
            raise ValueError(
                f'Accumulation mode: Background binned data MD: {r.Result}')

        # Compare gold (old solution) and new: passed test in #88
        r_bn = CompareMDWorkspaces(Workspace1=benchmark2.bkgd_norm,
                                   Workspace2='background_normMD2',
                                   Tolerance=1E-9)
        if not r_bn.Equals:
            raise ValueError(
                f'Accumulation mode: Background normalization MD: {r_bn.Result}'
            )

        # Test MDNorm's checking on inputs
        # Note that this test must be put after all the tests because
        # it will modify some workspaces and thus mess some experimental data set up to verify
        self.test_property_setup('merged1', f'{dgs_red_group_name1}_1')
Пример #4
0
    def __init__(self, *args):
        # set previous
        config.setFacility('SNS')

        unittest.TestCase.__init__(self, *args)