Пример #1
0
    def _update_wavelength(self, min_value=None, max_value=None, step=None, step_type=None, wavelength_range=None):
        if LimitsId.wavelength in self._user_file_items:
            settings = self._user_file_items[LimitsId.wavelength]
        else:
            # If the entry does not already exist, then add it. The -1. is an illegal input which should get overridden
            # and if not we want it to fail.
            settings = [simple_range(start=-1., stop=-1., step=-1., step_type=RangeStepType.Lin)]

        new_settings = []
        for setting in settings:
            new_min = min_value if min_value else setting.start
            new_max = max_value if max_value else setting.stop
            new_step = step if step else setting.step
            new_step_type = step_type if step_type else setting.step_type
            new_setting = simple_range(start=new_min, stop=new_max, step=new_step, step_type=new_step_type)
            new_settings.append(new_setting)
        self._user_file_items.update({LimitsId.wavelength: new_settings})

        if wavelength_range:
            if OtherId.wavelength_range in self._user_file_items:
                settings = self._user_file_items[OtherId.wavelength_range]
            else:
                settings = [""]

            new_settings = []
            for setting in settings:
                new_range = wavelength_range if wavelength_range else setting
                new_settings.append(new_range)
            self._user_file_items.update({OtherId.wavelength_range: new_settings})
Пример #2
0
    def _set_q_xy_limits(self, stop_value=None, step_value=None, step_type_value=None):
        element_id = LimitsId.qxy
        if element_id in self._user_file_items:
            settings = self._user_file_items[element_id]
        else:
            settings = [simple_range(start=None, stop=None, step=None, step_type=None)]

        # At this point we have settings with the desired detector type
        new_settings = []
        for setting in settings:
            new_stop = stop_value if stop_value is not None else setting.stop
            new_step = step_value if step_value is not None else setting.step
            new_step_type_value = step_type_value if step_type_value is not None else setting.step_type
            new_settings.append(simple_range(start=None, stop=new_stop, step=new_step, step_type=new_step_type_value))
        self._user_file_items.update({element_id: new_settings})
Пример #3
0
    def _set_q_xy_limits(self, stop_value=None, step_value=None, step_type_value=None):
        element_id = LimitsId.qxy
        if element_id in self._user_file_items:
            settings = self._user_file_items[element_id]
        else:
            settings = [simple_range(start=None, stop=None, step=None, step_type=None)]

        # At this point we have settings with the desired detector type
        new_settings = []
        for setting in settings:
            new_stop = stop_value if stop_value is not None else setting.stop
            new_step = step_value if step_value is not None else setting.step
            new_step_type_value = step_type_value if step_type_value is not None else setting.step_type
            new_settings.append(simple_range(start=None, stop=new_stop, step=new_step, step_type=new_step_type_value))
        self._user_file_items.update({element_id: new_settings})
 def _process_qxy_limit(self, command):
     q_min = command.values[0]
     q_max = command.values[1]
     q_step = command.values[2]
     q_step_type = command.values[3]
     new_state_entries = {LimitsId.qxy: simple_range(start=q_min, stop=q_max, step=q_step, step_type=q_step_type)}
     self.add_to_processed_state_settings(new_state_entries)
    def _process_wavrange(self, command):
        wavelength_low = command.values[0]
        wavelength_high = command.values[1]
        full_wavelength_range = command.values[2]
        reduction_mode = command.values[3]

        # Update the lower and the upper wavelength values. Note that this is considered an incomplete setting, since
        # not step or step type have been specified. This means we need to update one of the processed commands, which
        # is not nice but the command interface forces us to do so. We take a copy of the last LimitsId.wavelength
        # entry, we copy it and then change the desired settings. This means it has to be set at this point, else
        # something is wrong
        if LimitsId.wavelength in self._processed_state_settings:
            last_entry = self._processed_state_settings[LimitsId.wavelength][-1]

            new_wavelength_low = wavelength_low if wavelength_low is not None else last_entry.start
            new_wavelength_high = wavelength_high if wavelength_high is not None else last_entry.stop
            new_range = simple_range(start=new_wavelength_low, stop=new_wavelength_high, step=last_entry.step,
                                     step_type=last_entry.step_type)

            if wavelength_low is not None or wavelength_high is not None:
                copied_entry = {LimitsId.wavelength: new_range}
                self.add_to_processed_state_settings(copied_entry)
        else:
            raise RuntimeError("CommandInterfaceStateDirector: Setting the lower and upper wavelength bounds is not"
                               " possible. We require also a step and step range")

        if full_wavelength_range is not None:
            full_wavelength_range_entry = {OtherId.use_full_wavelength_range: full_wavelength_range}
            self.add_to_processed_state_settings(full_wavelength_range_entry)

        if reduction_mode is not None:
            reduction_mode_entry = {DetectorId.reduction_mode: reduction_mode}
            self.add_to_processed_state_settings(reduction_mode_entry)
 def _process_wavelength_limit(self, command):
     wavelength_low = command.values[0]
     wavelength_high = command.values[1]
     wavelength_step = command.values[2]
     wavelength_step_type = command.values[3]
     new_state_entries = {LimitsId.wavelength: simple_range(start=wavelength_low, stop=wavelength_high,
                                                            step=wavelength_step, step_type=wavelength_step_type)}
     self.add_to_processed_state_settings(new_state_entries)
Пример #7
0
    def _update_wavelength(self, min_value=None, max_value=None, step=None, step_type=None):
        if LimitsId.wavelength in self._user_file_items:
            settings = self._user_file_items[LimitsId.wavelength]
        else:
            # If the entry does not already exist, then add it. The -1. is an illegal input which should get overriden
            # and if not we want it to fail.
            settings = [simple_range(start=-1., stop=-1., step=-1., step_type=RangeStepType.Lin)]

        new_settings = []
        for setting in settings:
            new_min = min_value if min_value else setting.start
            new_max = max_value if max_value else setting.stop
            new_step = step if step else setting.step
            new_step_type = step_type if step_type else setting.step_type
            new_setting = simple_range(start=new_min, stop=new_max, step=new_step, step_type=new_step_type)
            new_settings.append(new_setting)
        self._user_file_items.update({LimitsId.wavelength: new_settings})
    def _process_wavrange(self, command):
        wav_min = command.values[0]
        wav_max = command.values[1]
        full_wavelength_range = command.values[2]
        reduction_mode = command.values[3]

        # Update the lower and the upper wavelength values. Note that this is considered an incomplete setting, since
        # not step or step type have been specified. This means we need to update one of the processed commands, which
        # is not nice but the command interface forces us to do so. We take a copy of the last LimitsId.wavelength
        # entry, we copy it and then change the desired settings. This means it has to be set at this point, else
        # something is wrong
        if self._processed_state_obj and self._processed_state_obj.wavelength:
            existing_wavelength = self._processed_state_obj.wavelength
            new_wav_min = wav_min if wav_min else existing_wavelength.wavelength_interval.wavelength_full_range[
                0]
            new_wav_max = wav_max if wav_max else existing_wavelength.wavelength_interval.wavelength_full_range[
                1]
            new_range = simple_range(
                start=new_wav_min,
                stop=new_wav_max,
                step=existing_wavelength.wavelength_interval.wavelength_step,
                step_type=existing_wavelength.wavelength_step_type)

            if wav_min is not None or wav_max is not None:
                copied_entry = {LimitsId.WAVELENGTH: new_range}
                self.add_to_processed_state_settings(copied_entry)
        else:
            raise RuntimeError(
                "CommandInterfaceStateDirector: Setting the lower and upper wavelength bounds is not"
                " possible. We require also a step and step range")

        if full_wavelength_range is not None:
            full_wavelength_range_entry = {
                OtherId.USE_FULL_WAVELENGTH_RANGE: full_wavelength_range
            }
            self.add_to_processed_state_settings(full_wavelength_range_entry)

        if reduction_mode is not None:
            reduction_mode_entry = {DetectorId.REDUCTION_MODE: reduction_mode}
            self.add_to_processed_state_settings(reduction_mode_entry)
Пример #9
0
    def test_that_can_read_user_file(self):
        # Arrange
        user_file_path = create_user_file(sample_user_file)
        reader = UserFileReader(user_file_path)

        # Act
        output = reader.read_user_file()

        # Assert
        expected_values = {LimitsId.wavelength: [simple_range(start=1.5, stop=12.5, step=0.125,
                                                              step_type=RangeStepType.Lin)],
                           LimitsId.q: [q_rebin_values(min=.001, max=.2, rebin_string="0.001,0.001,0.0126,-0.08,0.2")],
                           LimitsId.qxy: [simple_range(0, 0.05, 0.001, RangeStepType.Lin)],
                           BackId.single_monitors: [back_single_monitor_entry(1, 35000, 65000),
                                                    back_single_monitor_entry(2, 85000, 98000)],
                           DetectorId.reduction_mode: [ISISReductionMode.LAB],
                           GravityId.on_off: [True],
                           FitId.general: [fit_general(start=1.5, stop=12.5, fit_type=FitType.Logarithmic,
                                                       data_type=None, polynomial_order=0)],
                           MaskId.vertical_single_strip_mask: [single_entry_with_detector(191, DetectorType.LAB),
                                                               single_entry_with_detector(191, DetectorType.HAB),
                                                               single_entry_with_detector(0, DetectorType.LAB),
                                                               single_entry_with_detector(0, DetectorType.HAB)],
                           MaskId.horizontal_single_strip_mask: [single_entry_with_detector(0, DetectorType.LAB),
                                                                 single_entry_with_detector(0, DetectorType.HAB)],
                           MaskId.horizontal_range_strip_mask: [range_entry_with_detector(190, 191, DetectorType.LAB),
                                                                range_entry_with_detector(167, 172, DetectorType.LAB),
                                                                range_entry_with_detector(190, 191, DetectorType.HAB),
                                                                range_entry_with_detector(156, 159, DetectorType.HAB)
                                                                ],
                           MaskId.time: [range_entry_with_detector(17500, 22000, None)],
                           MonId.direct: [monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat", DetectorType.LAB),
                                          monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat", DetectorType.HAB)],
                           MonId.spectrum: [monitor_spectrum(1, True, True), monitor_spectrum(1, False, True)],
                           SetId.centre: [position_entry(155.45, -169.6, DetectorType.LAB)],
                           SetId.scales: [set_scales_entry(0.074, 1.0, 1.0, 1.0, 1.0)],
                           SampleId.offset: [53.0],
                           DetectorId.correction_x: [single_entry_with_detector(-16.0, DetectorType.LAB),
                                                     single_entry_with_detector(-44.0, DetectorType.HAB)],
                           DetectorId.correction_y: [single_entry_with_detector(-20.0, DetectorType.HAB)],
                           DetectorId.correction_z: [single_entry_with_detector(47.0, DetectorType.LAB),
                                                     single_entry_with_detector(47.0, DetectorType.HAB)],
                           DetectorId.correction_rotation: [single_entry_with_detector(0.0, DetectorType.HAB)],
                           LimitsId.events_binning: ["7000.0,500.0,60000.0"],
                           MaskId.clear_detector_mask: [True],
                           MaskId.clear_time_mask: [True],
                           LimitsId.radius: [range_entry(12, 15)],
                           TransId.spec_shift: [-70.],
                           PrintId.print_line: ["for changer"],
                           BackId.all_monitors: [range_entry(start=3500, stop=4500)],
                           FitId.monitor_times: [range_entry(start=1000, stop=2000)],
                           TransId.spec: [4],
                           BackId.trans: [range_entry(start=123, stop=466)],
                           TransId.radius: [7.0],
                           TransId.roi: ["test.xml", "test2.xml"],
                           TransId.mask: ["test3.xml", "test4.xml"],
                           SampleId.path: [True],
                           LimitsId.radius_cut: [200.0],
                           LimitsId.wavelength_cut: [8.0],
                           QResolutionId.on: [True],
                           QResolutionId.delta_r: [11.],
                           QResolutionId.collimation_length: [12.],
                           QResolutionId.a1: [13.],
                           QResolutionId.a2: [14.],
                           QResolutionId.moderator: ["moderator_rkh_file.txt"],
                           TubeCalibrationFileId.file: ["TUBE_SANS2D_BOTH_31681_25Sept15.nxs"]}

        self.assertEqual(len(expected_values), len(output))
        for key, value in list(expected_values.items()):
            self.assertTrue(key in output)
            self.assertEqual(len(output[key]), len(value))
            elements = output[key]
            # Make sure that the different entries are sorted
            UserFileReaderTest._sort_list(elements)
            UserFileReaderTest._sort_list(value)
            self.assertEqual(elements, value, "{} is not {}".format(elements, value))

        # clean up
        if os.path.exists(user_file_path):
            os.remove(user_file_path)
Пример #10
0
    def test_that_can_read_user_file(self):
        # Arrange
        user_file_path = create_user_file(sample_user_file)
        reader = UserFileReader(user_file_path)

        # Act
        output = reader.read_user_file()

        # Assert
        expected_values = {
            LimitsId.wavelength: [
                simple_range(start=1.5,
                             stop=12.5,
                             step=0.125,
                             step_type=RangeStepType.Lin)
            ],
            LimitsId.q: [
                q_rebin_values(min=.001,
                               max=.2,
                               rebin_string="0.001,0.001,0.0126,-0.08,0.2")
            ],
            LimitsId.qxy: [simple_range(0, 0.05, 0.001, RangeStepType.Lin)],
            BackId.single_monitors: [
                back_single_monitor_entry(1, 35000, 65000),
                back_single_monitor_entry(2, 85000, 98000)
            ],
            DetectorId.reduction_mode: [ISISReductionMode.LAB],
            GravityId.on_off: [True],
            FitId.general: [
                fit_general(start=1.5,
                            stop=12.5,
                            fit_type=FitType.Logarithmic,
                            data_type=None,
                            polynomial_order=0)
            ],
            MaskId.vertical_single_strip_mask: [
                single_entry_with_detector(191, DetectorType.LAB),
                single_entry_with_detector(191, DetectorType.HAB),
                single_entry_with_detector(0, DetectorType.LAB),
                single_entry_with_detector(0, DetectorType.HAB)
            ],
            MaskId.horizontal_single_strip_mask: [
                single_entry_with_detector(0, DetectorType.LAB),
                single_entry_with_detector(0, DetectorType.HAB)
            ],
            MaskId.horizontal_range_strip_mask: [
                range_entry_with_detector(190, 191, DetectorType.LAB),
                range_entry_with_detector(167, 172, DetectorType.LAB),
                range_entry_with_detector(190, 191, DetectorType.HAB),
                range_entry_with_detector(156, 159, DetectorType.HAB)
            ],
            MaskId.time: [range_entry_with_detector(17500, 22000, None)],
            MonId.direct: [
                monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat",
                             DetectorType.LAB),
                monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat",
                             DetectorType.HAB)
            ],
            MonId.spectrum: [
                monitor_spectrum(1, True, True),
                monitor_spectrum(1, False, True)
            ],
            SetId.centre: [position_entry(155.45, -169.6, DetectorType.LAB)],
            SetId.scales: [set_scales_entry(0.074, 1.0, 1.0, 1.0, 1.0)],
            SampleId.offset: [53.0],
            DetectorId.correction_x: [
                single_entry_with_detector(-16.0, DetectorType.LAB),
                single_entry_with_detector(-44.0, DetectorType.HAB)
            ],
            DetectorId.correction_y:
            [single_entry_with_detector(-20.0, DetectorType.HAB)],
            DetectorId.correction_z: [
                single_entry_with_detector(47.0, DetectorType.LAB),
                single_entry_with_detector(47.0, DetectorType.HAB)
            ],
            DetectorId.correction_rotation:
            [single_entry_with_detector(0.0, DetectorType.HAB)],
            LimitsId.events_binning: ["7000.0,500.0,60000.0"],
            MaskId.clear_detector_mask: [True],
            MaskId.clear_time_mask: [True],
            LimitsId.radius: [range_entry(12, 15)],
            TransId.spec_shift: [-70.],
            PrintId.print_line: ["for changer"],
            BackId.all_monitors: [range_entry(start=3500, stop=4500)],
            FitId.monitor_times: [range_entry(start=1000, stop=2000)],
            TransId.spec: [4],
            BackId.trans: [range_entry(start=123, stop=466)],
            TransId.radius: [7.0],
            TransId.roi: ["test.xml", "test2.xml"],
            TransId.mask: ["test3.xml", "test4.xml"],
            SampleId.path: [True],
            LimitsId.radius_cut: [200.0],
            LimitsId.wavelength_cut: [8.0],
            QResolutionId.on: [True],
            QResolutionId.delta_r: [11.],
            QResolutionId.collimation_length: [12.],
            QResolutionId.a1: [13.],
            QResolutionId.a2: [14.],
            QResolutionId.moderator: ["moderator_rkh_file.txt"],
            TubeCalibrationFileId.file:
            ["TUBE_SANS2D_BOTH_31681_25Sept15.nxs"]
        }

        self.assertTrue(len(expected_values) == len(output))
        for key, value in list(expected_values.items()):
            self.assertTrue(key in output)
            self.assertTrue(len(output[key]) == len(value))
            elements = output[key]
            # Make sure that the different entries are sorted
            UserFileReaderTest._sort_list(elements)
            UserFileReaderTest._sort_list(value)
            self.assertTrue(elements == value)

        # clean up
        if os.path.exists(user_file_path):
            os.remove(user_file_path)
Пример #11
0
    def test_that_can_read_user_file(self):
        # Arrange
        user_file_path = create_user_file(sample_user_file)
        reader = UserFileReader(user_file_path)

        # Act
        output = reader.read_user_file()

        # Assert
        expected_values = {
            LimitsId.WAVELENGTH: [
                simple_range(start=1.5,
                             stop=12.5,
                             step=0.125,
                             step_type=RangeStepType.LIN)
            ],
            LimitsId.Q: [
                q_rebin_values(min=.001,
                               max=.2,
                               rebin_string="0.001,0.001,0.0126,-0.08,0.2")
            ],
            LimitsId.QXY: [simple_range(0, 0.05, 0.001, RangeStepType.LIN)],
            BackId.SINGLE_MONITORS: [
                back_single_monitor_entry(1, 35000, 65000),
                back_single_monitor_entry(2, 85000, 98000)
            ],
            DetectorId.REDUCTION_MODE: [ReductionMode.LAB],
            GravityId.ON_OFF: [True],
            FitId.GENERAL: [
                fit_general(start=1.5,
                            stop=12.5,
                            fit_type=FitType.LOGARITHMIC,
                            data_type=None,
                            polynomial_order=0)
            ],
            MaskId.VERTICAL_SINGLE_STRIP_MASK: [
                single_entry_with_detector(191, DetectorType.LAB),
                single_entry_with_detector(191, DetectorType.HAB),
                single_entry_with_detector(0, DetectorType.LAB),
                single_entry_with_detector(0, DetectorType.HAB)
            ],
            MaskId.HORIZONTAL_SINGLE_STRIP_MASK: [
                single_entry_with_detector(0, DetectorType.LAB),
                single_entry_with_detector(0, DetectorType.HAB)
            ],
            MaskId.HORIZONTAL_RANGE_STRIP_MASK: [
                range_entry_with_detector(190, 191, DetectorType.LAB),
                range_entry_with_detector(167, 172, DetectorType.LAB),
                range_entry_with_detector(190, 191, DetectorType.HAB),
                range_entry_with_detector(156, 159, DetectorType.HAB)
            ],
            MaskId.TIME: [range_entry_with_detector(17500, 22000, None)],
            MonId.DIRECT: [
                monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat",
                             DetectorType.LAB),
                monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat",
                             DetectorType.HAB)
            ],
            MonId.SPECTRUM: [
                monitor_spectrum(1, True, True),
                monitor_spectrum(1, False, True)
            ],
            SetId.CENTRE: [position_entry(155.45, -169.6, DetectorType.LAB)],
            SetId.SCALES: [set_scales_entry(0.074, 1.0, 1.0, 1.0, 1.0)],
            SampleId.OFFSET: [53.0],
            DetectorId.CORRECTION_X: [
                single_entry_with_detector(-16.0, DetectorType.LAB),
                single_entry_with_detector(-44.0, DetectorType.HAB)
            ],
            DetectorId.CORRECTION_Y:
            [single_entry_with_detector(-20.0, DetectorType.HAB)],
            DetectorId.CORRECTION_Z: [
                single_entry_with_detector(47.0, DetectorType.LAB),
                single_entry_with_detector(47.0, DetectorType.HAB)
            ],
            DetectorId.CORRECTION_ROTATION:
            [single_entry_with_detector(0.0, DetectorType.HAB)],
            LimitsId.EVENTS_BINNING: ["7000.0,500.0,60000.0"],
            MaskId.CLEAR_DETECTOR_MASK: [True],
            MaskId.CLEAR_TIME_MASK: [True],
            LimitsId.RADIUS: [range_entry(12, 15)],
            TransId.SPEC_4_SHIFT: [-70.],
            PrintId.PRINT_LINE: ["for changer"],
            BackId.ALL_MONITORS: [range_entry(start=3500, stop=4500)],
            FitId.MONITOR_TIMES: [range_entry(start=1000, stop=2000)],
            TransId.SPEC: [4],
            BackId.TRANS: [range_entry(start=123, stop=466)],
            TransId.RADIUS: [7.0],
            TransId.ROI: ["test.xml", "test2.xml"],
            TransId.MASK: ["test3.xml", "test4.xml"],
            SampleId.PATH: [True],
            LimitsId.RADIUS_CUT: [200.0],
            LimitsId.WAVELENGTH_CUT: [8.0],
            QResolutionId.ON: [True],
            QResolutionId.DELTA_R: [11.],
            QResolutionId.COLLIMATION_LENGTH: [12.],
            QResolutionId.A1: [13.],
            QResolutionId.A2: [14.],
            QResolutionId.MODERATOR: ["moderator_rkh_file.txt"],
            TubeCalibrationFileId.FILE:
            ["TUBE_SANS2D_BOTH_31681_25Sept15.nxs"]
        }

        self.assertEqual(len(expected_values), len(output))
        for key, value in list(expected_values.items()):
            self.assertTrue(key in output)
            self.assertEqual(len(output[key]), len(value))
            elements = output[key]
            # Make sure that the different entries are sorted
            UserFileReaderTest._sort_list(elements)
            UserFileReaderTest._sort_list(value)
            self.assertEqual(elements, value,
                             "{} is not {}".format(elements, value))

        # clean up
        if os.path.exists(user_file_path):
            os.remove(user_file_path)