Пример #1
0
    def test_generate_run_numbers(self):
        # Mantid handles most of this for us

        # First check it can handle int types
        test_int_input = 123
        int_input_return = common.generate_run_numbers(run_number_string=test_int_input)
        # Expect the returned type is a list
        self.assertEqual(int_input_return, [test_int_input])

        # Check it can handle 10-12 and is inclusive
        input_string = "10-12"
        expected_values = [10, 11, 12]
        returned_values = common.generate_run_numbers(run_number_string=input_string)
        self.assertEqual(expected_values, returned_values)

        # Check that the underscore syntax used by older pearl_routines scripts is handled
        input_string = "10_12"
        returned_values = common.generate_run_numbers(run_number_string=input_string)
        self.assertEqual(expected_values, returned_values)

        # Check that the comma notation is working
        input_string = "20, 22, 24"
        expected_values = [20, 22, 24]
        returned_values = common.generate_run_numbers(run_number_string=input_string)
        self.assertEqual(expected_values, returned_values)

        # Check we can use a combination of both
        input_string = "30-33, 36, 38-39"
        expected_values = [30, 31, 32, 33, 36, 38, 39]
        returned_values = common.generate_run_numbers(run_number_string=input_string)
        self.assertEqual(expected_values, returned_values)
Пример #2
0
    def test_generate_run_numbers(self):
        # Mantid handles most of this for us

        # First check it can handle int types
        test_int_input = 123
        int_input_return = common.generate_run_numbers(run_number_string=test_int_input)
        # Expect the returned type is a list
        self.assertEqual(int_input_return, [test_int_input])

        # Check it can handle 10-12 and is inclusive
        input_string = "10-12"
        expected_values = [10, 11, 12]
        returned_values = common.generate_run_numbers(run_number_string=input_string)
        self.assertEqual(expected_values, returned_values)

        # Check that the underscore syntax used by older pearl_routines scripts is handled
        input_string = "10_12"
        returned_values = common.generate_run_numbers(run_number_string=input_string)
        self.assertEqual(expected_values, returned_values)

        # Check that the comma notation is working
        input_string = "20, 22, 24"
        expected_values = [20, 22, 24]
        returned_values = common.generate_run_numbers(run_number_string=input_string)
        self.assertEqual(expected_values, returned_values)

        # Check we can use a combination of both
        input_string = "30-33, 36, 38-39"
        expected_values = [30, 31, 32, 33, 36, 38, 39]
        returned_values = common.generate_run_numbers(run_number_string=input_string)
        self.assertEqual(expected_values, returned_values)
Пример #3
0
    def test_generate_run_numbers_fails(self):
        run_input_sting = "text-string"

        with assertRaisesRegex(self, ValueError, "Could not generate run numbers from this input"):
            common.generate_run_numbers(run_number_string=run_input_sting)

        # Check it says what the actual string was
        with assertRaisesRegex(self, ValueError, run_input_sting):
            common.generate_run_numbers(run_number_string=run_input_sting)
Пример #4
0
    def test_generate_run_numbers_fails(self):
        run_input_sting = "text-string"

        with assertRaisesRegex(self, ValueError, "Could not generate run numbers from this input"):
            common.generate_run_numbers(run_number_string=run_input_sting)

        # Check it says what the actual string was
        with assertRaisesRegex(self, ValueError, run_input_sting):
            common.generate_run_numbers(run_number_string=run_input_sting)
Пример #5
0
    def _generate_input_file_name(run_number, file_ext=""):
        polaris_old_name = "POL"
        polaris_new_name = "POLARIS"
        first_run_new_name = 96912

        if isinstance(run_number, list):
            # Lists use recursion to deal with individual entries
            updated_list = []
            for run in run_number:
                updated_list.append(
                    Polaris._generate_input_file_name(run_number=run))
            return updated_list
        else:
            # Select between old and new prefix
            # Test if it can be converted to an int or if we need to ask Mantid to do it for us
            if isinstance(run_number, str) and not run_number.isdigit():
                # Convert using Mantid and take the first element which is most likely to be the lowest digit
                use_new_name = int(common.generate_run_numbers(run_number)
                                   [0]) >= first_run_new_name
            else:
                use_new_name = int(run_number) >= first_run_new_name

            prefix = polaris_new_name if use_new_name else polaris_old_name

            return prefix + str(run_number) + file_ext
Пример #6
0
def _individual_run_focusing(instrument, perform_vanadium_norm, run_number,
                             absorb, sample_details):
    # Load and process one by one
    run_numbers = common.generate_run_numbers(run_number_string=run_number)
    run_details = instrument._get_run_details(run_number_string=run_number)
    vanadium_splines = None
    van = "van_{}".format(run_details.vanadium_run_numbers)
    if perform_vanadium_norm:
        if van not in mantid.mtd:
            vanadium_splines = mantid.LoadNexus(
                Filename=run_details.splined_vanadium_file_path,
                OutputWorkspace=van)
        else:
            vanadium_splines = mantid.mtd[van]

    output = None
    for run in run_numbers:
        ws = common.load_current_normalised_ws_list(run_number_string=run,
                                                    instrument=instrument)
        output = _focus_one_ws(input_workspace=ws[0],
                               run_number=run,
                               instrument=instrument,
                               absorb=absorb,
                               perform_vanadium_norm=perform_vanadium_norm,
                               sample_details=sample_details,
                               vanadium_path=vanadium_splines)
    return output
Пример #7
0
def _individual_run_focusing(instrument, perform_vanadium_norm, run_number, absorb, sample_details):
    # Load and process one by one
    run_numbers = common.generate_run_numbers(run_number_string=run_number)
    output = None
    for run in run_numbers:
        ws = common.load_current_normalised_ws_list(run_number_string=run, instrument=instrument)
        output = _focus_one_ws(input_workspace=ws[0], run_number=run, instrument=instrument, absorb=absorb,
                               perform_vanadium_norm=perform_vanadium_norm, sample_details=sample_details)
    return output
Пример #8
0
def _individual_run_focusing(instrument, perform_vanadium_norm, run_number, absorb, sample_details):
    # Load and process one by one
    run_numbers = common.generate_run_numbers(run_number_string=run_number)
    output = None
    for run in run_numbers:
        ws = common.load_current_normalised_ws_list(run_number_string=run, instrument=instrument)
        output = _focus_one_ws(input_workspace=ws[0], run_number=run, instrument=instrument, absorb=absorb,
                               perform_vanadium_norm=perform_vanadium_norm, sample_details=sample_details)
    return output
Пример #9
0
def _find_dictionary_key(dict_to_search, run_number):
    for key in dict_to_search:
        if is_run_range_key_unbounded(key):  # Have an unbounded run don't generate numbers
            split_key = str(key).split('-')
            lower_key_bound = int(split_key[-2])
            if run_number >= lower_key_bound:
                return key
        else:
            try:
                generated_runs = common.generate_run_numbers(run_number_string=key)
            except RuntimeError:
                raise ValueError("Could not parse '" + str(key) + "'\n"
                                 "This should be a range of runs in the mapping file."
                                 " Please check your indentation and YAML syntax is correct.")

            if run_number in generated_runs:
                return key

    return None
Пример #10
0
def _find_dictionary_key(dict_to_search, run_number):
    for key in dict_to_search:
        if is_run_range_key_unbounded(key):  # Have an unbounded run don't generate numbers
            split_key = str(key).split('-')
            lower_key_bound = int(split_key[-2])
            if run_number >= lower_key_bound:
                return key
        else:
            try:
                generated_runs = common.generate_run_numbers(run_number_string=key)
            except RuntimeError:
                raise ValueError("Could not parse '" + str(key) + "'\n"
                                 "This should be a range of runs in the mapping file."
                                 " Please check your indentation and YAML syntax is correct.")

            if run_number in generated_runs:
                return key

    return None
Пример #11
0
def _individual_run_focusing(instrument, perform_vanadium_norm, run_number, absorb, sample_details):
    # Load and process one by one
    run_numbers = common.generate_run_numbers(run_number_string=run_number)
    run_details = instrument._get_run_details(run_number_string=run_number)
    vanadium_splines = None
    van = "van_{}".format(run_details.vanadium_run_numbers)
    if perform_vanadium_norm:
        if van not in mantid.mtd:
            vanadium_splines = mantid.LoadNexus(Filename=run_details.splined_vanadium_file_path,
                                                OutputWorkspace=van)
        else:
            vanadium_splines = mantid.mtd[van]

    output = None
    for run in run_numbers:
        ws = common.load_current_normalised_ws_list(run_number_string=run, instrument=instrument)
        output = _focus_one_ws(input_workspace=ws[0], run_number=run, instrument=instrument, absorb=absorb,
                               perform_vanadium_norm=perform_vanadium_norm, sample_details=sample_details,
                               vanadium_path=vanadium_splines)
    return output
Пример #12
0
    def _get_run_details(self, run_number):
        if self._run_details_last_run_number == run_number:
            return self._run_details_cached_obj

        input_run_number_list = common.generate_run_numbers(run_number_string=run_number)
        configuration = polaris_calib_parser.get_calibration_dict(run_number=input_run_number_list[0])

        if self._chopper_on:
            chopper_config = configuration["chopper_on"]
        else:
            chopper_config = configuration["chopper_off"]

        empty_runs = chopper_config["empty_run_numbers"]
        vanadium_runs = chopper_config["vanadium_run_numbers"]
        solid_angle_file_name = self._generate_solid_angle_file_name(vanadium_run_string=vanadium_runs)
        splined_vanadium_name = self._generate_splined_van_name(vanadium_run_string=vanadium_runs)
        cycle = configuration["label"]

        calibration_dir = os.path.join(self.calibration_dir, cycle)
        calibration_full_path = os.path.join(calibration_dir, configuration["offset_file_name"])
        grouping_full_path = os.path.join(calibration_dir, configuration["offset_file_name"])
        solid_angle_file_path = os.path.join(calibration_dir, solid_angle_file_name)
        splined_vanadium = os.path.join(calibration_dir, splined_vanadium_name)

        calibration_details = RunDetails(calibration_path=calibration_full_path, grouping_path=grouping_full_path,
                                         vanadium_runs=vanadium_runs, run_number=run_number)
        calibration_details.label = cycle
        calibration_details.sample_empty = empty_runs
        calibration_details.splined_vanadium = splined_vanadium
        calibration_details.solid_angle_corr = solid_angle_file_path

        # Hold obj in case same run range is requested
        self._run_details_last_run_number = run_number
        self._run_details_cached_obj = calibration_details

        return calibration_details