Exemple #1
0
 def setUpClass(cls):
     cls.workspaces_temporary = list(
     )  # workspaces to be deleted at tear-down
     # Load a CORELLI file containing data for bank number 20 (16 tubes)
     config.appendDataSearchSubDir('CORELLI/calibration')
     for directory in config.getDataSearchDirs():
         if 'UnitTest' in directory:
             data_dir = path.join(directory, 'CORELLI', 'calibration')
             break
     wire_positions_pixels = [
         0.03043, 0.04544, 0.06045, 0.07546, 0.09047, 0.10548, 0.12049,
         0.13550, 0.15052, 0.16553, 0.18054, 0.19555, 0.21056, 0.22557
     ]  # in mili-meters, 14 wires
     workspace = 'CORELLI_123455_bank20'
     LoadNexusProcessed(Filename=path.join(data_dir, workspace + '.nxs'),
                        OutputWorkspace=workspace)
     cls.workspaces_temporary.append(
         workspace)  # delete workspace at tear-down
     wire_positions_pixels = wire_positions(units='pixels')[1:-1]
     wire_count = len(wire_positions_pixels)
     fit_parameters = TubeCalibFitParams(wire_positions_pixels,
                                         height=-1000,
                                         width=4,
                                         margin=7)
     fit_parameters.setAutomatic(True)
     cls.corelli = {
         'workspace': workspace,
         'bank_name': 'bank20',
         'wire_positions': wire_positions(units='meters')[1:-1],
         'peaks_form': [1] *
         wire_count,  # signals we'll be fitting dips (peaks with negative heights)
         'fit_parameters': fit_parameters,
     }
    def setUpClass(
            cls):  # called only before running all tests in the test case
        cls.workspaces_temporary = list(
        )  # workspaces to be deleted at tear-down

        # Single tube data. Tube dimensions appropriate for a CORELLI tube
        def y_quad(n: float) -> float:
            r"""
            Example quadratic function, returning the Y-coordinate (meters) versus pixel index `i

            y_quad(n) = c0 + c1 * n + c2 * n^2.
            Coefficients c0, c1, and c2 obtained by solving the following equations:
                y(0) = -0.502
                y(128) = 0.001
                y(255) = 0.393  # assume a tube with 256 pixels
            Obtaining:
                c0 = -0.502
                c1 = 0.00435287724834028
                c2 = -3.306169908908442e-06

            :param n: pixel coordinate
            """
            return -0.502 + 0.00435287724834028 * n - 3.306169908908442e-06 * n * n

        # assume 11 slits(wires) casting 11 peaks(shadows) onto the tube at the following pixel numbers
        tube_points = np.linspace(5, 245, 11,
                                  endpoint=True)  # 5, 29, 53,...,221, 245
        # assume the Y-coordinates of the peaks(shadows) given by our quadratic example function
        ideal_tube_coordinates = [y_quad(n) for n in tube_points]
        cls.y_quad_data = {
            'detector_count': 256,
            'peak_count': 11,
            'y_quad': y_quad,
            'coefficients': {
                'A0': -0.502,
                'A1': 0.00435287724834028,
                'A2': -3.306169908908442e-06
            },
            'tube_points': tube_points,
            'ideal_tube_coordinates': ideal_tube_coordinates
        }

        # Load a CORELLI file containing data for bank number 20 (16 tubes)
        config.appendDataSearchSubDir('CORELLI/calibration')
        for directory in config.getDataSearchDirs():
            if 'UnitTest' in directory:
                data_dir = path.join(directory, 'CORELLI', 'calibration')
                break
        workspace = 'CORELLI_123455_bank20'
        LoadNexusProcessed(Filename=path.join(data_dir, workspace + '.nxs'),
                           OutputWorkspace=workspace)
        assert AnalysisDataService.doesExist(workspace)
        cls.workspaces_temporary.append(
            workspace)  # delete workspace at tear-down
        cls.corelli = {
            'tube_length': 0.900466,  # in meters
            'pixels_per_tube': 256,
            'workspace': workspace
        }
Exemple #3
0
 def search_user_dirs(self):
     """ Finds all files for the run number provided """
     files = []
     for user_dir in config.getDataSearchDirs():
         path = os.path.join(user_dir,
                             "ral{}.rooth*.dat".format(self.pad_run()))
         files.extend([file for file in glob.iglob(path)])
         if files:
             self.setProperty("Directory", user_dir)
             return files
Exemple #4
0
def findFile(fileName):
    """ Simple search within Mantid data search directories for
        a file which is not a run file
    """

    if os.path.exists(fileName):
        return os.path.abspath(fileName)
    fbase = os.path.basename(fileName)
    search_path = config.getDataSearchDirs()
    for path in search_path:
        fname = os.path.join(path, fbase)
        if os.path.exists(fname):
            return fname
    return ''
Exemple #5
0
def findFile(fileName):
    """ Simple search within Mantid data search directories for
        a file which is not a run file
    """

    if os.path.exists(fileName):
        return os.path.abspath(fileName)
    fbase = os.path.basename(fileName)
    search_path = config.getDataSearchDirs()
    for path in search_path:
        fname = os.path.join(path,fbase)
        if os.path.exists(fname):
            return fname
    return ''
    def test_validate_settings(self):
        dsp = config.getDataSearchDirs()
        # clear all not to find any files
        config.setDataSearchDirs('')

        red = mr.ReduceMARI()
        ok,level,errors = red.validate_settings()

        self.assertFalse(ok)
        self.assertEqual(level,2)
        self.assertEqual(len(errors),7)


 

        # this run should be in data search directory for basic Mantid
        red.reducer.wb_run       = 11001
        red.reducer.det_cal_file = '11001'
        red.reducer.monovan_run = None
        red.reducer.hard_mask_file = None
        red.reducer.map_file = None
        red.reducer.save_format = 'nxspe'

        path = []
        for item in dsp:
            path.append(item)
        config.setDataSearchDirs(path)


        # hack -- let's pretend we are running from webservices 
        # but web var are empty (not to overwrite values above)
        red._run_from_web = True
        red._wvs.standard_vars={}
        red._wvs.advanced_vars={}
        ok,level,errors = red.validate_settings()
        if not ok:
            print("Errors found at level",level)
            print(errors)

        self.assertTrue(ok)
        self.assertEqual(level,0)
        self.assertEqual(len(errors),0)

        # this is how we set it up from web
        red._wvs.advanced_vars={'save_format':''}
        ok,level,errors = red.validate_settings()

        self.assertFalse(ok)
        self.assertEqual(level,1)
        self.assertEqual(len(errors),1)
Exemple #7
0
 def setUpClass(cls) -> None:
     r"""
     Load the tests cases for calibrate_bank, consisting of data for only one bank
     CORELLI_124023_bank10, tube 13 has shadows at pixel numbers quite different from the rest
     """
     config.appendDataSearchSubDir('CORELLI/calibration')
     for directory in config.getDataSearchDirs():
         if 'UnitTest' in directory:
             data_dir = path.join(directory, 'CORELLI', 'calibration')
             break
     cls.workspaces_temporary = list()
     cls.cases = dict()
     for bank_case in ('124016_bank10', '123454_bank58', '124023_bank10', '124023_banks_14_15'):
         workspace = 'CORELLI_' + bank_case
         LoadNexusProcessed(Filename=path.join(data_dir, workspace + '.nxs'), OutputWorkspace=workspace)
         cls.cases[bank_case] = workspace
         cls.workspaces_temporary.append(workspace)
Exemple #8
0
 def test_load_banks(self):
     # loading a non-existing file
     with self.assertRaises(AssertionError) as exception_info:
         load_banks('I_am_no_here', '58', output_workspace='jambalaya')
     assert 'File I_am_no_here does not exist' in str(
         exception_info.exception)
     # loading an event nexus file will take too much time, so it's left as a system test.
     # loading a nexus processed file
     for directory in config.getDataSearchDirs():
         if 'UnitTest' in directory:
             data_dir = path.join(directory, 'CORELLI', 'calibration')
             config.appendDataSearchDir(
                 path.join(directory, 'CORELLI', 'calibration'))
             break
     workspace = load_banks(path.join(data_dir,
                                      'CORELLI_123454_bank58.nxs'),
                            '58',
                            output_workspace='jambalaya')
     self.assertAlmostEqual(workspace.readY(42)[0], 13297.0)
     DeleteWorkspaces(['jambalaya'])
Exemple #9
0
 def setUpClass(cls):
     for directory in config.getDataSearchDirs():
         if 'UnitTest' in directory:
             cls.base_path = path.join(directory, 'project_load',
                                       'Mantidplot')
             break
     cls.project_with_multiple_workspaces = path.join(
         cls.base_path, "mantidplot_project_multiple_workspaces.mantid")
     cls.project_with_workspace_group = path.join(
         cls.base_path, "mantidplot_project_workspace_group.mantid")
     cls.project_with_simple_1d_plot = path.join(
         cls.base_path, "mantidplot_project_simple_plot.mantid")
     cls.project_with_multiple_1d_plots = path.join(
         cls.base_path, "mantidplot_project_multiple_plots.mantid")
     cls.project_plot_with_multiple_lines = path.join(
         cls.base_path,
         "mantidplot_project_plot_with_multiple_lines.mantid")
     cls.project_with_tiled_lots = path.join(
         cls.base_path, "mantidplot_project_tiled_plots.mantid")
     cls.project_with_errorbars = path.join(
         cls.base_path, "mantidplot_project_errorbar_plots.mantid")
     cls.project_with_logscale = path.join(
         cls.base_path, "mantidplot_project_logscale_plots.mantid")
Exemple #10
0
    def setUpClass(cls):
        r"""
        Load the tests cases for calibrate_bank, consisting of data for only one bank
        CORELLI_123455_bank20, control bank, it has no problems
        CORELLI_123454_bank58, beam center intensity spills over adjacent tubes, tube15 and tube16
        CORELLI_124018_bank45, tube11 is not working at all
        CORELLI_123555_bank20, insufficient intensity for all tubes in the bank
        CORELLI_124023_bank10, tube 13 has shadows at pixel numbers quite different from the rest
        CORELLI_124023_bank14, wire shadows very faint, only slightly larger than fluctuations of the background
        CORELLI_124023_bank15, one spurious shadow in tube14
        Load the test case for calibrate_banks, consisting of data for two banks
        CORELLI_124023_banks_14_15
        """
        config.appendDataSearchSubDir('CORELLI/calibration')
        for directory in config.getDataSearchDirs():
            if 'UnitTest' in directory:
                data_dir = path.join(directory, 'CORELLI', 'calibration')
                break
        cls.cases = dict()
        for bank_case in ('123454_bank58', '124018_bank45', '123555_bank20', '123455_bank20',
                          '124023_bank10', '124023_bank14', '124023_bank15', '124023_banks_14_15'):
            workspace = 'CORELLI_' + bank_case
            LoadNexusProcessed(Filename=path.join(data_dir, workspace + '.nxs'), OutputWorkspace=workspace)
            cls.cases[bank_case] = workspace

        def assert_missing_tube(cls_other, calibration_table, tube_number):
            r"""Check detector ID's from a failing tube are not in the calibration table"""
            table = mtd[str(calibration_table)]
            first = table.cell('Detector ID', 0)  # first detector ID
            # Would-be first and last detectors ID's for the failing tube
            begin, end = first + (tube_number - 1) * 256, first + tube_number * 256 - 1
            detectors_ids = table.column(0)
            assert begin not in detectors_ids
            assert end not in detectors_ids
        # sneak in a class method, make sure it's loaded before any tests is executed
        cls.assert_missing_tube = assert_missing_tube