Esempio n. 1
0
    def set_spectrum_range_on_detector(self, spectrum_range_start, spectrum_range_stop):
        """
        An unusual setter in the state framework. We cannot just call an automatic setter, since we have to decide
        on which detector the spectrum range lives.

        :param spectrum_range_start: a list of start spectra which we need to set on the right detector
        :param spectrum_range_stop: a list of stop spectra which we need to set on the right detector
        """
        instrument = self._data.instrument
        for start, stop in zip(spectrum_range_start, spectrum_range_stop):
            detector_bank_start = get_bank_for_spectrum_number(start, instrument)
            detector_bank_stop = get_bank_for_spectrum_number(stop, instrument)
            if detector_bank_start != detector_bank_stop:
                raise ValueError("The specified spectrum mask range S{0}{1} has spectra on more than one detector. "
                                 "Make sure that all spectra in the range are on a single detector".format(start, stop))
            else:
                detector_mask_state = self.state.detectors[DetectorType.to_string(detector_bank_start)]
                spec_range_start = detector_mask_state.spectrum_range_start
                spec_range_stop = detector_mask_state.spectrum_range_stop
                # Set the start spectrum range
                if spec_range_start is not None:
                    spec_range_start.append(start)
                else:
                    self.state.detectors[DetectorType.to_string(detector_bank_start)].spectrum_range_start = [start]

                # Set the stop spectrum range
                if spec_range_stop is not None:
                    spec_range_stop.append(stop)
                else:
                    self.state.detectors[DetectorType.to_string(detector_bank_start)].spectrum_range_stop = [stop]
Esempio n. 2
0
    def set_spectrum_range_on_detector(self, spectrum_range_start, spectrum_range_stop):
        """
        An unusual setter in the state framework. We cannot just call an automatic setter, since we have to decide
        on which detector the spectrum range lives.

        :param spectrum_range_start: a list of start spectra which we need to set on the right detector
        :param spectrum_range_stop: a list of stop spectra which we need to set on the right detector
        """
        instrument = self._data.instrument
        for start, stop in zip(spectrum_range_start, spectrum_range_stop):
            detector_bank_start = get_bank_for_spectrum_number(start, instrument)
            detector_bank_stop = get_bank_for_spectrum_number(stop, instrument)
            if detector_bank_start != detector_bank_stop:
                raise ValueError("The specified spectrum mask range S{0}{1} has spectra on more than one detector. "
                                 "Make sure that all spectra in the range are on a single detector".format(start, stop))
            else:
                detector_mask_state = self.state.detectors[detector_bank_start.value]
                spec_range_start = detector_mask_state.spectrum_range_start
                spec_range_stop = detector_mask_state.spectrum_range_stop
                # Set the start spectrum range
                if spec_range_start is not None:
                    spec_range_start.append(start)
                else:
                    self.state.detectors[detector_bank_start.value].spectrum_range_start = [start]

                # Set the stop spectrum range
                if spec_range_stop is not None:
                    spec_range_stop.append(stop)
                else:
                    self.state.detectors[detector_bank_start.value].spectrum_range_stop = [stop]
Esempio n. 3
0
def is_spectrum_range_all_on_one_detector(start, stop, invalid_dict, start_name, stop_name, instrument):
    for a, b in zip(start, stop):
        detector_a = get_bank_for_spectrum_number(a, instrument)
        detector_b = get_bank_for_spectrum_number(b, instrument)
        if detector_a is not detector_b:
            entry = validation_message("The lower and the upper bounds of the specified spectrum range S{0}{1} are on "
                                       "two different banks. They have to be on the same bank.".format(a, b),
                                       {start_name: start,
                                        stop_name: stop})
            invalid_dict.update(entry)
            return
    return invalid_dict
Esempio n. 4
0
def is_spectrum_range_all_on_one_detector(start, stop, invalid_dict, start_name, stop_name, instrument):
    for a, b in zip(start, stop):
        detector_a = get_bank_for_spectrum_number(a, instrument)
        detector_b = get_bank_for_spectrum_number(b, instrument)
        if detector_a is not detector_b:
            entry = validation_message("The lower and the upper bounds of the specified spectrum range S{0}{1} are on "
                                       "two different banks. They have to be on the same bank.".format(a, b),
                                       {start_name: start,
                                        stop_name: stop})
            invalid_dict.update(entry)
            return
    return invalid_dict
Esempio n. 5
0
    def set_single_spectra_on_detector(self, single_spectra):
        """
        An unusual setter in the state framework. We cannot just call an automatic setter, since we have to decide
        on which detector the spectrum lives.

        :param single_spectra: a list of spectra which we need to set on the right detector
        """
        instrument = self._data.instrument
        for spectrum in single_spectra:
            detector = get_bank_for_spectrum_number(spectrum, instrument)
            detector_mask_state = self.state.detectors[DetectorType.to_string(detector)]
            spectra = detector_mask_state.single_spectra
            if spectra is not None:
                spectra.append(spectrum)
            else:
                self.state.detectors[DetectorType.to_string(detector)].single_spectra = [spectrum]
Esempio n. 6
0
    def set_single_spectra_on_detector(self, single_spectra):
        """
        An unusual setter in the state framework. We cannot just call an automatic setter, since we have to decide
        on which detector the spectrum lives.

        :param single_spectra: a list of spectra which we need to set on the right detector
        """
        instrument = self._data.instrument
        for spectrum in single_spectra:
            detector = get_bank_for_spectrum_number(spectrum, instrument)
            detector_mask_state = self.state.detectors[detector.value]
            spectra = detector_mask_state.single_spectra
            if spectra is not None:
                spectra.append(spectrum)
            else:
                self.state.detectors[detector.value].single_spectra = [spectrum]
Esempio n. 7
0
    def _parse_mask(self):
        mask_dict = self._get_val("mask")
        self.mask.beam_stop_arm_angle = self._get_val(
            ["beamstop_shadow", "angle"], mask_dict)
        self.mask.beam_stop_arm_width = self._get_val(
            ["beamstop_shadow", "width"], mask_dict)

        prompt_peak_vals = self._get_val("prompt_peak", mask_dict)
        self.calculate_transmission.prompt_peak_correction_enabled = bool(
            prompt_peak_vals)
        self.normalize_to_monitor.prompt_peak_correction_enabled = bool(
            prompt_peak_vals)
        if prompt_peak_vals:
            pp_min = self._get_val("start", prompt_peak_vals)
            pp_max = self._get_val("stop", prompt_peak_vals)
            self.calculate_transmission.prompt_peak_correction_min = pp_min
            self.calculate_transmission.prompt_peak_correction_max = pp_max
            self.normalize_to_monitor.prompt_peak_correction_min = pp_min
            self.normalize_to_monitor.prompt_peak_correction_max = pp_max

        mask_files = self._get_val("mask_files", mask_dict)
        if mask_files:
            self.mask.mask_files.extend(mask_files)

        mask_pixels = self._get_val("mask_pixels", mask_dict)
        if mask_pixels:
            for pixel in mask_pixels:
                # TODO we shouldn't be trying to guess which bank each pixel belongs to
                bank = get_bank_for_spectrum_number(pixel,
                                                    instrument=self.instrument)
                self.mask.detectors[bank.value].single_spectra.append(pixel)

        tof_masks = self._get_val(["time", "tof"], mask_dict)
        if tof_masks:
            for mask_pair in tof_masks:
                self.mask.bin_mask_general_start.append(mask_pair["start"])
                self.mask.bin_mask_general_stop.append(mask_pair["stop"])

        phi_mask = self._get_val(["phi"], mask_dict)
        if phi_mask:
            if "mirror" in phi_mask:
                self.mask.use_mask_phi_mirror = phi_mask["mirror"]
            if "start" in phi_mask:
                self.mask.phi_min = phi_mask["start"]
            if "stop" in phi_mask:
                self.mask.phi_max = phi_mask["stop"]
Esempio n. 8
0
    def _parse_spatial_masks(self):
        spatial_dict = self.get_val(["mask", "spatial"])

        def parse_mask_dict(spatial_dict, bank_type):
            mask_detectors = self.mask.detectors[bank_type.value]
            assert isinstance(mask_detectors, StateMaskDetectors)

            individual_cols = self.get_val("detector_columns", spatial_dict)
            if individual_cols:
                mask_detectors.single_vertical_strip_mask.extend(
                    individual_cols)

            individual_rows = self.get_val("detector_rows", spatial_dict)
            if individual_rows:
                mask_detectors.single_horizontal_strip_mask.extend(
                    individual_rows)

            col_ranges = self.get_val("detector_column_ranges",
                                      spatial_dict,
                                      default=[])
            row_ranges = self.get_val("detector_row_ranges",
                                      spatial_dict,
                                      default=[])
            for pair in col_ranges:
                assert isinstance(
                    pair, list
                ), "Ranges should be entered as lists of lists, e.g. [[1, 10]]"
                assert len(
                    pair
                ) == 2, "A start and end value must exist for each pair"
                mask_detectors.range_vertical_strip_start.append(pair[0])
                mask_detectors.range_vertical_strip_stop.append(pair[1])

            for pair in row_ranges:
                assert isinstance(
                    pair, list
                ), "Ranges should be entered as lists of lists, e.g. [[1, 10]]"
                assert len(
                    pair
                ) == 2, "A start and end value must exist for each pair"
                mask_detectors.range_horizontal_strip_start.append(pair[0])
                mask_detectors.range_horizontal_strip_stop.append(pair[1])

        rear_dict = self.get_val("rear", spatial_dict)
        if rear_dict:
            parse_mask_dict(rear_dict, DetectorType.LAB)

        front_dict = self.get_val("front", spatial_dict)
        if front_dict:
            parse_mask_dict(front_dict, DetectorType.HAB)

        self.mask.beam_stop_arm_angle = self.get_val(
            ["beamstop_shadow", "angle"], spatial_dict)
        self.mask.beam_stop_arm_width = self.get_val(
            ["beamstop_shadow", "width"], spatial_dict)
        self.mask.beam_stop_arm_pos1 = self.get_val(
            ["beamstop_shadow", "x_pos"], spatial_dict, 0.0)
        self.mask.beam_stop_arm_pos2 = self.get_val(
            ["beamstop_shadow", "y_pos"], spatial_dict, 0.0)

        mask_pixels = self.get_val("mask_pixels", spatial_dict)
        if mask_pixels:
            for pixel in mask_pixels:
                # TODO we shouldn't be trying to guess which bank each pixel belongs to
                bank = get_bank_for_spectrum_number(pixel,
                                                    instrument=self.instrument)
                self.mask.detectors[bank.value].single_spectra.append(pixel)