def validate(self):
        is_invalid = {}

        if one_is_none([self.wavelength_low, self.wavelength_high, self.wavelength_step, self.wavelength_step_type]):
            entry = validation_message("A wavelength entry has not been set.",
                                       "Make sure that all entries are set.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high,
                                        "wavelength_step": self.wavelength_step,
                                        "wavelength_step_type": self.wavelength_step_type})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.wavelength_low, self.wavelength_high]):
            entry = validation_message("Incorrect wavelength bounds.",
                                       "Make sure that lower wavelength bound is smaller then upper bound.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high})
            is_invalid.update(entry)

        try:
            self.adjustment_files[DetectorType.to_string(DetectorType.LAB)].validate()
            self.adjustment_files[DetectorType.to_string(DetectorType.HAB)].validate()
        except ValueError as e:
            is_invalid.update({"adjustment_files": str(e)})

        if is_invalid:
            raise ValueError("StateWavelengthAndPixelAdjustment: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
    def validate(self):
        is_invalid = dict()
        if one_is_none(
            [self.wavelength_low, self.wavelength_high, self.wavelength_step]):
            entry = validation_message(
                "A wavelength entry has not been set.",
                "Make sure that all entries for the wavelength are set.", {
                    "wavelength_low": self.wavelength_low,
                    "wavelength_high": self.wavelength_high,
                    "wavelength_step": self.wavelength_step
                })
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second(
            [self.wavelength_low, self.wavelength_high]):
            entry = validation_message(
                "Incorrect wavelength bounds.",
                "Make sure that lower wavelength bound is smaller then upper bound.",
                {
                    "wavelength_low": self.wavelength_low,
                    "wavelength_high": self.wavelength_high
                })
            is_invalid.update(entry)

        if is_invalid:
            raise ValueError(
                "StateWavelength: The provided inputs are illegal. "
                "Please see: {0}".format(json.dumps(is_invalid, indent=4)))
    def validate(self):  # noqa
        is_invalid = {}
        if self.fit_type is FitType.Polynomial and self.polynomial_order == 0:
            entry = validation_message("You can only select a polynomial fit if you set a polynomial order (2 to 6).",
                                       "Make sure that you select a polynomial order.",
                                       {"fit_type": self.fit_type,
                                        "polynomial_order": self.polynomial_order})
            is_invalid.update(entry)

        if not is_pure_none_or_not_none([self.wavelength_low, self.wavelength_high]):
            entry = validation_message("Inconsistent wavelength setting.",
                                       "Make sure that you have specified both wavelength bounds (or none).",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.wavelength_low, self.wavelength_high]):
            entry = validation_message("Incorrect wavelength bounds.",
                                       "Make sure that lower wavelength bound is smaller then upper bound.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high})
            is_invalid.update(entry)
        if is_invalid:
            raise ValueError("StateTransmissionFit: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
    def validate(self):
        is_invalid = {}

        if one_is_none([self.wavelength_interval, self.wavelength_step_type]):
            entry = validation_message("A wavelength entry has not been set.",
                                       "Make sure that all entries are set.",
                                       {"wavelength_low": self.wavelength_interval,
                                        "wavelength_step_type": self.wavelength_step_type})
            is_invalid.update(entry)

        if self.wavelength_step_type is RangeStepType.NOT_SET:
            entry = validation_message("A wavelength entry has not been set.",
                                       "Make sure that all entries are set.",
                                       {"wavelength_step_type": self.wavelength_step_type})
            is_invalid.update(entry)

        try:
            self.adjustment_files[DetectorType.LAB.value].validate()
            self.adjustment_files[DetectorType.HAB.value].validate()
        except ValueError as e:
            is_invalid.update({"adjustment_files": str(e)})

        if is_invalid:
            raise ValueError("StateWavelengthAndPixelAdjustment: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #5
0
    def validate(self):  # noqa
        is_invalid = {}
        if self.fit_type is not FitType.Polynomial and self.polynomial_order != 0:
            entry = validation_message("You can only set a polynomial order of you selected polynomial fitting.",
                                       "Make sure that you select polynomial fitting.",
                                       {"fit_type": self.fit_type,
                                        "polynomial_order": self.polynomial_order})
            is_invalid.update(entry)

        if not is_pure_none_or_not_none([self.wavelength_low, self.wavelength_high]):
            entry = validation_message("Inconsistent wavelength setting.",
                                       "Make sure that you have specified both wavelength bounds (or none).",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.wavelength_low, self.wavelength_high]):
            entry = validation_message("Incorrect wavelength bounds.",
                                       "Make sure that lower wavelength bound is smaller then upper bound.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high})
            is_invalid.update(entry)
        if is_invalid:
            raise ValueError("StateTransmissionFit: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #6
0
    def validate(self):
        is_invalid = {}
        # --------------------
        # Vertical strip mask
        # --------------------
        range_check(self.range_vertical_strip_start,
                    self.range_vertical_strip_stop, is_invalid,
                    "range_vertical_strip_start", "range_vertical_strip_stop",
                    "range_vertical_strip")

        # --------------------
        # Horizontal strip mask
        # --------------------
        range_check(self.range_horizontal_strip_start,
                    self.range_horizontal_strip_stop, is_invalid,
                    "range_horizontal_strip_start",
                    "range_horizontal_strip_stop", "range_horizontal_strip")

        # --------------------
        # Block mask
        # --------------------
        range_check(self.block_horizontal_start, self.block_horizontal_stop,
                    is_invalid, "block_horizontal_start",
                    "block_horizontal_stop", "block_horizontal")
        range_check(self.block_vertical_start, self.block_vertical_stop,
                    is_invalid, "block_vertical_start", "block_vertical_stop",
                    "block_vertical")

        # --------------------
        # Time/Bin mask
        # --------------------
        range_check(self.bin_mask_start, self.bin_mask_stop, is_invalid,
                    "bin_mask_start", "bin_mask_stop", "bin_mask")

        if not self.detector_name:
            entry = validation_message(
                "Missing detector name.",
                "Make sure that the detector names are set.",
                {"detector_name": self.detector_name})
            is_invalid.update(entry)
        if not self.detector_name_short:
            entry = validation_message(
                "Missing short detector name.",
                "Make sure that the short detector names are set.",
                {"detector_name_short": self.detector_name_short})
            is_invalid.update(entry)

        # --------------------
        # Spectrum Range
        # --------------------
        range_check(self.spectrum_range_start, self.spectrum_range_stop,
                    is_invalid, "spectrum_range_start", "spectrum_range_stop",
                    "spectrum_range")

        if is_invalid:
            raise ValueError(
                "StateMoveDetectorISIS: The provided inputs are illegal. "
                "Please see: {0}".format(json.dumps(is_invalid)))
    def validate(self):
        is_invalid = dict()

        if not is_pure_none_or_not_none([self.start_time, self.end_time]):
            entry = validation_message(
                "Missing slice times",
                "Makes sure that either both or none are set.", {
                    "start_time": self.start_time,
                    "end_time": self.end_time
                })
            is_invalid.update(entry)

        if self.start_time and self.end_time:
            # The length of start_time and end_time needs to be identical
            if len(self.start_time) != len(self.end_time):
                entry = validation_message(
                    "Bad relation of start and end",
                    "Makes sure that the start time is smaller than the end time.",
                    {
                        "start_time": self.start_time,
                        "end_time": self.end_time
                    })
                is_invalid.update(entry)

            # Each entry in start_time and end_time must be a float
            if len(self.start_time) == len(
                    self.end_time) and len(self.start_time) > 0:
                for item in range(0, len(self.start_time)):
                    for element1, element2 in zip(self.start_time,
                                                  self.end_time):
                        if not isinstance(element1, float) or not isinstance(
                                element2, float):
                            entry = validation_message(
                                "Bad relation of start and end time entries",
                                "The elements need to be floats.", {
                                    "start_time": self.start_time,
                                    "end_time": self.end_time
                                })
                            is_invalid.update(entry)

            # Check that end_time is not smaller than start_time
            if not is_smaller(self.start_time, self.end_time):
                entry = validation_message(
                    "Start time larger than end time.",
                    "Make sure that the start time is not smaller than the end time.",
                    {
                        "start_time": self.start_time,
                        "end_time": self.end_time
                    })
                is_invalid.update(entry)

        if is_invalid:
            raise ValueError(
                "StateSliceEvent: The provided inputs are illegal. "
                "Please see: {}".format(json.dumps(is_invalid)))
Exemple #8
0
    def validate(self):
        is_invalid = dict()

        # A sample scatter must be specified
        if self.sample_scatter is None:
            entry = validation_message(
                "Sample scatter was not specified.",
                "Make sure that the sample scatter file is specified.",
                {"sample_scatter": self.sample_scatter})
            is_invalid.update(entry)

        # If the sample transmission/direct was specified, then a sample direct/transmission is required
        if not is_pure_none_or_not_none(
            [self.sample_transmission, self.sample_direct]):
            entry = validation_message(
                "If the sample transmission is specified then, the direct run needs to be "
                "specified too.",
                "Make sure that the transmission and direct runs are both specified (or none).",
                {
                    "sample_transmission": self.sample_transmission,
                    "sample_direct": self.sample_direct
                })
            is_invalid.update(entry)

        # If the can transmission/direct was specified, then this requires the can scatter
        if (self.can_direct
                or self.can_transmission) and (not self.can_scatter):
            entry = validation_message(
                "If the can transmission is specified then the can scatter run needs to be "
                "specified too.",
                "Make sure that the can scatter file is set.", {
                    "can_scatter": self.can_scatter,
                    "can_transmission": self.can_transmission,
                    "can_direct": self.can_direct
                })
            is_invalid.update(entry)

        # If a can transmission/direct was specified, then the other can entries need to be specified as well.
        if self.can_scatter and not is_pure_none_or_not_none(
            [self.can_transmission, self.can_direct]):
            entry = validation_message(
                "Inconsistent can transmission setting.",
                "Make sure that the can transmission and can direct runs are set (or none of"
                " them).", {
                    "can_transmission": self.can_transmission,
                    "can_direct": self.can_direct
                })
            is_invalid.update(entry)

        if is_invalid:
            raise ValueError("StateData: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #9
0
 def validate(self):
     is_invalid = {}
     if self.detector_name == "" or self.detector_name is None:
         entry = validation_message("Missing detector name",
                                    "Make sure that a detector name was specified.",
                                    {"detector_name": self.detector_name})
         is_invalid.update(entry)
     if self.detector_name_short == "" or self.detector_name_short is None:
         entry = validation_message("Missing short detector name",
                                    "Make sure that a short detector name was specified.",
                                    {"detector_name_short": self.detector_name_short})
         is_invalid.update(entry)
     if is_invalid:
         raise ValueError("StateMoveDetectorISIS: The provided inputs are illegal. "
                          "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #10
0
 def validate(self):
     is_invalid = {}
     if self.detector_name == "" or self.detector_name is None:
         entry = validation_message("Missing detector name",
                                    "Make sure that a detector name was specified.",
                                    {"detector_name": self.detector_name})
         is_invalid.update(entry)
     if self.detector_name_short == "" or self.detector_name_short is None:
         entry = validation_message("Missing short detector name",
                                    "Make sure that a short detector name was specified.",
                                    {"detector_name_short": self.detector_name_short})
         is_invalid.update(entry)
     if is_invalid:
         raise ValueError("StateMoveDetectorISIS: The provided inputs are illegal. "
                          "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #11
0
    def validate(self):
        is_invalid = dict()

        # --------------------
        # Radius Mask
        # --------------------
        # Radius mask rule: the min radius must be less or equal to the max radius
        if self.radius_max is not None and self.radius_min is not None and\
           self.radius_max != -1 and self.radius_min != -1:  # noqa
            if self.radius_min > 0 and self.radius_max > 0 and (
                    self.radius_min > self.radius_max):
                entry = validation_message(
                    "Incorrect radius bounds.",
                    "Makes sure that the lower radius bound is smaller than the"
                    " upper radius bound.", {
                        "radius_min": self.radius_min,
                        "radius_max": self.radius_max
                    })
                is_invalid.update(entry)

        # --------------------
        # General bin mask
        # --------------------
        range_check(self.bin_mask_general_start, self.bin_mask_general_stop,
                    is_invalid, "bin_mask_general_start",
                    "bin_mask_general_stop", "bin_mask_general")

        # --------------------
        # Mask files
        # --------------------
        if self.mask_files:
            for mask_file in self.mask_files:
                if not find_full_file_path(mask_file):
                    entry = validation_message(
                        "Mask file not found.",
                        "Makes sure that the mask file is in your path",
                        {"mask_file": self.mask_files})
                    is_invalid.update(entry)

        # --------------------
        # Detectors
        # --------------------
        for _, value in list(self.detectors.items()):
            value.validate()

        if is_invalid:
            raise ValueError("StateMask: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #12
0
    def validate(self):
        is_invalid = {}
        # --------------------
        # Vertical strip mask
        # --------------------
        range_check(self.range_vertical_strip_start, self.range_vertical_strip_stop,
                    is_invalid, "range_vertical_strip_start", "range_vertical_strip_stop", "range_vertical_strip")

        # --------------------
        # Horizontal strip mask
        # --------------------
        range_check(self.range_horizontal_strip_start, self.range_horizontal_strip_stop,
                    is_invalid, "range_horizontal_strip_start", "range_horizontal_strip_stop", "range_horizontal_strip")

        # --------------------
        # Block mask
        # --------------------
        range_check(self.block_horizontal_start, self.block_horizontal_stop,
                    is_invalid, "block_horizontal_start", "block_horizontal_stop", "block_horizontal")
        range_check(self.block_vertical_start, self.block_vertical_stop,
                    is_invalid, "block_vertical_start", "block_vertical_stop", "block_vertical")

        # --------------------
        # Time/Bin mask
        # --------------------
        range_check(self.bin_mask_start, self.bin_mask_stop,
                    is_invalid, "bin_mask_start", "bin_mask_stop", "bin_mask")

        if not self.detector_name:
            entry = validation_message("Missing detector name.",
                                       "Make sure that the detector names are set.",
                                       {"detector_name": self.detector_name})
            is_invalid.update(entry)
        if not self.detector_name_short:
            entry = validation_message("Missing short detector name.",
                                       "Make sure that the short detector names are set.",
                                       {"detector_name_short": self.detector_name_short})
            is_invalid.update(entry)

        # --------------------
        # Spectrum Range
        # --------------------
        range_check(self.spectrum_range_start, self.spectrum_range_stop,
                    is_invalid, "spectrum_range_start", "spectrum_range_stop", "spectrum_range")

        if is_invalid:
            raise ValueError("StateMaskDetector: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #13
0
def range_check(start,
                stop,
                invalid_dict,
                start_name,
                stop_name,
                general_name=None):
    """
    Checks a start container against a stop container

    :param start: The start container
    :param stop:  the stop container
    :param invalid_dict: The invalid dict to which we write our error messages
    :param start_name: The name of the start container
    :param stop_name: The name of the stop container
    :param general_name: The general name of this container family
    :return: A (potentially) updated invalid_dict
    """
    if not is_pure_none_or_not_none([start, stop]):
        entry = validation_message("A range element has not been set.",
                                   "Make sure that all entries are set.", {
                                       start_name: start,
                                       stop_name: stop
                                   })
        invalid_dict.update(entry)

    if start is not None and stop is not None:
        # Start and stop need to have the same length
        if len(start) != len(stop):
            entry = validation_message(
                "Start and stop ranges have different lengths.",
                "Make sure that all entries for {0} he same length.".format(
                    general_name), {
                        start_name: start,
                        stop_name: stop
                    })
            invalid_dict.update(entry)
        # Start values need to be smaller than the stop values
        for a, b in zip(start, stop):
            if a > b:
                entry = validation_message(
                    "Incorrect start-stop bounds.",
                    "Make sure the lower bound is smaller than the upper bound for {0}."
                    "".format(general_name), {
                        start_name: start,
                        stop_name: stop
                    })
                invalid_dict.update(entry)
    return invalid_dict
Exemple #14
0
    def validate(self):
        is_invalid = {}

        if one_is_none([
                self.wavelength_low, self.wavelength_high,
                self.wavelength_step, self.wavelength_step_type
        ]):
            entry = validation_message(
                "A wavelength entry has not been set.",
                "Make sure that all entries are set.", {
                    "wavelength_low": self.wavelength_low,
                    "wavelength_high": self.wavelength_high,
                    "wavelength_step": self.wavelength_step,
                    "wavelength_step_type": self.wavelength_step_type
                })
            is_invalid.update(entry)

        if self.wavelength_step_type is RangeStepType.NOT_SET:
            entry = validation_message(
                "A wavelength entry has not been set.",
                "Make sure that all entries are set.",
                {"wavelength_step_type": self.wavelength_step_type})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second(
            [self.wavelength_low, self.wavelength_high]):
            entry = validation_message(
                "Incorrect wavelength bounds.",
                "Make sure that lower wavelength bound is smaller then upper bound.",
                {
                    "wavelength_low": self.wavelength_low,
                    "wavelength_high": self.wavelength_high
                })
            is_invalid.update(entry)

        try:
            self.adjustment_files[DetectorType.LAB.value].validate()
            self.adjustment_files[DetectorType.HAB.value].validate()
        except ValueError as e:
            is_invalid.update({"adjustment_files": str(e)})

        if is_invalid:
            raise ValueError(
                "StateWavelengthAndPixelAdjustment: The provided inputs are illegal. "
                "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #15
0
    def validate(self):
        is_invalid = dict()

        # --------------------
        # Radius Mask
        # --------------------
        # Radius mask rule: the min radius must be less or equal to the max radius
        if self.radius_max is not None and self.radius_min is not None and\
           self.radius_max != -1 and self.radius_min != -1:  # noqa
            if self.radius_min > 0 and self.radius_max > 0 and (self.radius_min > self.radius_max):
                entry = validation_message("Incorrect radius bounds.",
                                           "Makes sure that the lower radius bound is smaller than the"
                                           " upper radius bound.",
                                           {"radius_min": self.radius_min,
                                            "radius_max": self.radius_max})
                is_invalid.update(entry)

        # --------------------
        # General bin mask
        # --------------------
        range_check(self.bin_mask_general_start, self.bin_mask_general_stop,
                    is_invalid, "bin_mask_general_start", "bin_mask_general_stop", "bin_mask_general")

        # --------------------
        # Mask files
        # --------------------
        if self.mask_files:
            for mask_file in self.mask_files:
                if not find_full_file_path(mask_file):
                    entry = validation_message("Mask file not found.",
                                               "Makes sure that the mask file is in your path",
                                               {"mask_file": self.mask_files})
                    is_invalid.update(entry)

        # --------------------
        # Detectors
        # --------------------
        for _, value in list(self.detectors.items()):
            value.validate()

        if is_invalid:
            raise ValueError("StateMask: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #16
0
    def validate(self):
        is_invalid = dict()
        if one_is_none([self.wavelength_low, self.wavelength_high, self.wavelength_step]):
            entry = validation_message("A wavelength entry has not been set.",
                                       "Make sure that all entries for the wavelength are set.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high,
                                        "wavelength_step": self.wavelength_step})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.wavelength_low, self.wavelength_high]):
            entry = validation_message("Incorrect wavelength bounds.",
                                       "Make sure that lower wavelength bound is smaller then upper bound.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high})
            is_invalid.update(entry)

        if is_invalid:
            raise ValueError("StateWavelength: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid, indent=4)))
Exemple #17
0
    def validate(self):
        is_invalid = dict()

        if not is_pure_none_or_not_none([self.start_time, self.end_time]):
            entry = validation_message("Missing slice times",
                                       "Makes sure that either both or none are set.",
                                       {"start_time": self.start_time,
                                        "end_time": self.end_time})
            is_invalid.update(entry)

        if self.start_time and self.end_time:
            # The length of start_time and end_time needs to be identical
            if len(self.start_time) != len(self.end_time):
                entry = validation_message("Bad relation of start and end",
                                           "Makes sure that the start time is smaller than the end time.",
                                           {"start_time": self.start_time,
                                            "end_time": self.end_time})
                is_invalid.update(entry)

            # Each entry in start_time and end_time must be a float
            if len(self.start_time) == len(self.end_time) and len(self.start_time) > 0:
                for item in range(0, len(self.start_time)):
                    for element1, element2 in zip(self.start_time, self.end_time):
                        if not isinstance(element1, float) or not isinstance(element2, float):
                            entry = validation_message("Bad relation of start and end time entries",
                                                       "The elements need to be floats.",
                                                       {"start_time": self.start_time,
                                                        "end_time": self.end_time})
                            is_invalid.update(entry)

            # Check that end_time is not smaller than start_time
            if not is_smaller(self.start_time, self.end_time):
                entry = validation_message("Start time larger than end time.",
                                           "Make sure that the start time is not smaller than the end time.",
                                           {"start_time": self.start_time,
                                            "end_time": self.end_time})
                is_invalid.update(entry)

        if is_invalid:
            raise ValueError("StateSliceEvent: The provided inputs are illegal. "
                             "Please see: {}".format(json.dumps(is_invalid)))
Exemple #18
0
    def validate(self):
        is_invalid = dict()

        # A sample scatter must be specified
        if not self.sample_scatter:
            entry = validation_message("Sample scatter was not specified.",
                                       "Make sure that the sample scatter file is specified.",
                                       {"sample_scatter": self.sample_scatter})
            is_invalid.update(entry)

        # If the sample transmission/direct was specified, then a sample direct/transmission is required
        if not is_pure_none_or_not_none([self.sample_transmission, self.sample_direct]):
            entry = validation_message("If the sample transmission is specified then, the direct run needs to be "
                                       "specified too.",
                                       "Make sure that the transmission and direct runs are both specified (or none).",
                                       {"sample_transmission": self.sample_transmission,
                                        "sample_direct": self.sample_direct})
            is_invalid.update(entry)

        # If the can transmission/direct was specified, then this requires the can scatter
        if (self.can_direct or self.can_transmission) and (not self.can_scatter):
            entry = validation_message("If the can transmission is specified then the can scatter run needs to be "
                                       "specified too.",
                                       "Make sure that the can scatter file is set.",
                                       {"can_scatter": self.can_scatter,
                                        "can_transmission": self.can_transmission,
                                        "can_direct": self.can_direct})
            is_invalid.update(entry)

        # If a can transmission/direct was specified, then the other can entries need to be specified as well.
        if self.can_scatter and not is_pure_none_or_not_none([self.can_transmission, self.can_direct]):
            entry = validation_message("Inconsistent can transmission setting.",
                                       "Make sure that the can transmission and can direct runs are set (or none of"
                                       " them).",
                                       {"can_transmission": self.can_transmission,
                                        "can_direct": self.can_direct})
            is_invalid.update(entry)

        if is_invalid:
            raise ValueError("StateData: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
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
Exemple #20
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
Exemple #21
0
    def validate(self):
        is_invalid = dict()
        if one_is_none([self.wavelength_interval]):
            entry = validation_message(
                "A wavelength entry has not been set.",
                "Make sure that all entries for the wavelength are set.",
                {"wavelength_binning": self.wavelength_interval})
            is_invalid.update(entry)

        if is_invalid:
            raise ValueError(
                "StateWavelength: The provided inputs are illegal. "
                "Please see: {0}".format(json.dumps(is_invalid, indent=4)))
 def test_that_produces_correct_validation_message(self):
     # Arrange
     error_message = "test message."
     instruction = "do this."
     variables = {"var1": 12, "var2": "test"}
     # Act
     val_message = validation_message(error_message, instruction, variables)
     # Assert
     expected_text = "var1: 12\n" \
                     "var2: test\n" \
                     "" + instruction
     self.assertTrue(list(val_message.keys())[0] == error_message)
     self.assertTrue(val_message[error_message] == expected_text)
Exemple #23
0
 def test_that_produces_correct_validation_message(self):
     # Arrange
     error_message = "test message."
     instruction = "do this."
     variables = {"var1": 12,
                  "var2": "test"}
     # Act
     val_message = validation_message(error_message, instruction, variables)
     # Assert
     expected_text = "var1: 12\n" \
                     "var2: test\n" \
                     "" + instruction
     self.assertTrue(val_message.keys()[0] == error_message)
     self.assertTrue(val_message[error_message] == expected_text)
Exemple #24
0
def range_check(start, stop, invalid_dict, start_name, stop_name, general_name=None):
    """
    Checks a start container against a stop container

    :param start: The start container
    :param stop:  the stop container
    :param invalid_dict: The invalid dict to which we write our error messages
    :param start_name: The name of the start container
    :param stop_name: The name of the stop container
    :param general_name: The general name of this container family
    :return: A (potentially) updated invalid_dict
    """
    if not is_pure_none_or_not_none([start, stop]):
        entry = validation_message("A range element has not been set.",
                                   "Make sure that all entries are set.",
                                   {start_name: start,
                                    stop_name: stop})
        invalid_dict.update(entry)

    if start is not None and stop is not None:
        # Start and stop need to have the same length
        if len(start) != len(stop):
            entry = validation_message("Start and stop ranges have different lengths.",
                                       "Make sure that all entries for {0} he same length.".format(general_name),
                                       {start_name: start,
                                        stop_name: stop})
            invalid_dict.update(entry)
        # Start values need to be smaller than the stop values
        for a, b in zip(start, stop):
            if a > b:
                entry = validation_message("Incorrect start-stop bounds.",
                                           "Make sure the lower bound is smaller than the upper bound for {0}."
                                           "".format(general_name),
                                           {start_name: start,
                                            stop_name: stop})
                invalid_dict.update(entry)
    return invalid_dict
Exemple #25
0
    def validate(self):
        is_invalid = {}
        # -----------------
        # incident Monitor
        # -----------------
        if self.incident_monitor is None:
            is_invalid.update(
                {"incident_monitor": "An incident monitor must be specified."})

        # -----------------
        # Prompt peak
        # -----------------
        if not is_pure_none_or_not_none(
            [self.prompt_peak_correction_min, self.prompt_peak_correction_max
             ]):
            entry = validation_message(
                "A prompt peak correction entry has not been set.",
                "Make sure that either all prompt peak entries have been set or none.",
                {
                    "prompt_peak_correction_min":
                    self.prompt_peak_correction_min,
                    "prompt_peak_correction_max":
                    self.prompt_peak_correction_max
                })
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second(
            [self.prompt_peak_correction_min,
             self.prompt_peak_correction_max]):
            entry = validation_message(
                "Incorrect prompt peak correction bounds.",
                "Make sure that lower prompt peak time bound is smaller then upper bound.",
                {
                    "prompt_peak_correction_min":
                    self.prompt_peak_correction_min,
                    "prompt_peak_correction_max":
                    self.prompt_peak_correction_max
                })
            is_invalid.update(entry)

        # -----------------
        # Wavelength rebin
        # -----------------
        if one_is_none([
                self.wavelength_low, self.wavelength_high,
                self.wavelength_step, self.wavelength_step_type
        ]):
            entry = validation_message(
                "A wavelength entry has not been set.",
                "Make sure that all entries are set.", {
                    "wavelength_low": self.wavelength_low,
                    "wavelength_high": self.wavelength_high,
                    "wavelength_step": self.wavelength_step,
                    "wavelength_step_type": self.wavelength_step_type
                })
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second(
            [self.wavelength_low, self.wavelength_high]):
            entry = validation_message(
                "Incorrect wavelength bounds.",
                "Make sure that lower wavelength bound is smaller then upper bound.",
                {
                    "wavelength_low": self.wavelength_low,
                    "wavelength_high": self.wavelength_high
                })
            is_invalid.update(entry)

        # ----------------------
        # Background correction
        # ----------------------
        if not is_pure_none_or_not_none([
                self.background_TOF_general_start,
                self.background_TOF_general_stop
        ]):
            entry = validation_message(
                "A general background TOF entry has not been set.",
                "Make sure that either all general background TOF entries are set or none.",
                {
                    "background_TOF_general_start":
                    self.background_TOF_general_start,
                    "background_TOF_general_stop":
                    self.background_TOF_general_stop
                })
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([
                self.background_TOF_general_start,
                self.background_TOF_general_stop
        ]):
            entry = validation_message(
                "Incorrect general background TOF bounds.",
                "Make sure that lower general background TOF bound is smaller then upper bound.",
                {
                    "background_TOF_general_start":
                    self.background_TOF_general_start,
                    "background_TOF_general_stop":
                    self.background_TOF_general_stop
                })
            is_invalid.update(entry)

        if not is_pure_none_or_not_none([
                self.background_TOF_monitor_start,
                self.background_TOF_monitor_stop
        ]):
            entry = validation_message(
                "A monitor background TOF entry has not been set.",
                "Make sure that either all monitor background TOF entries are set or none.",
                {
                    "background_TOF_monitor_start":
                    self.background_TOF_monitor_start,
                    "background_TOF_monitor_stop":
                    self.background_TOF_monitor_stop
                })
            is_invalid.update(entry)

        if self.background_TOF_monitor_start is not None and self.background_TOF_monitor_stop is not None:
            if len(self.background_TOF_monitor_start) != len(
                    self.background_TOF_monitor_stop):
                entry = validation_message(
                    "The monitor background TOF entries have a length mismatch.",
                    "Make sure that all monitor background TOF entries have the same length.",
                    {
                        "background_TOF_monitor_start":
                        self.background_TOF_monitor_start,
                        "background_TOF_monitor_stop":
                        self.background_TOF_monitor_stop
                    })
                is_invalid.update(entry)
            for key_start, value_start in list(
                    self.background_TOF_monitor_start.items()):
                if key_start not in self.background_TOF_monitor_stop:
                    entry = validation_message(
                        "The monitor background TOF had spectrum number mismatch.",
                        "Make sure that all monitors have entries for start and stop.",
                        {
                            "background_TOF_monitor_start":
                            self.background_TOF_monitor_start,
                            "background_TOF_monitor_stop":
                            self.background_TOF_monitor_stop
                        })
                    is_invalid.update(entry)
                else:
                    value_stop = self.background_TOF_monitor_stop[key_start]
                    if value_start > value_stop:
                        entry = validation_message(
                            "Incorrect monitor background TOF bounds.",
                            "Make sure that lower monitor background TOF bound is"
                            " smaller then upper bound.", {
                                "background_TOF_monitor_start":
                                self.background_TOF_monitor_start,
                                "background_TOF_monitor_stop":
                                self.background_TOF_monitor_stop
                            })
                        is_invalid.update(entry)

        if is_invalid:
            raise ValueError(
                "StateMoveDetector: The provided inputs are illegal. "
                "Please see: {0}".format(json.dumps(is_invalid)))
    def validate(self):  # noqa
        is_invalid = {}
        # -----------------
        # Incident monitor
        # -----------------
        if self.incident_monitor is None and self.default_incident_monitor is None:
            entry = validation_message("No incident monitor was specified.",
                                       "Make sure that incident monitor has been specified.",
                                       {"incident_monitor": self.incident_monitor,
                                        "default_incident_monitor": self.default_incident_monitor})
            is_invalid.update(entry)

        # --------------
        # Transmission, either we need some ROI (ie radius, roi files /mask files) or a transmission monitor
        # --------------
        has_no_transmission_monitor_setting = self.transmission_monitor is None and\
                                              self.default_transmission_monitor is None  # noqa
        has_no_transmission_roi_setting = self.transmission_radius_on_detector is None and\
                                          self.transmission_roi_files is None  # noqa
        if has_no_transmission_monitor_setting and has_no_transmission_roi_setting:
            entry = validation_message("No transmission settings were specified.",
                                       "Make sure that transmission settings are specified.",
                                       {"transmission_monitor": self.transmission_monitor,
                                        "default_transmission_monitor": self.default_transmission_monitor,
                                        "transmission_radius_on_detector": self.transmission_radius_on_detector,
                                        "transmission_roi_files": self.transmission_roi_files})
            is_invalid.update(entry)

        # -----------------
        # Prompt peak
        # -----------------
        if not is_pure_none_or_not_none([self.prompt_peak_correction_min, self.prompt_peak_correction_max]):
            entry = validation_message("Inconsistent prompt peak setting.",
                                       "Make sure that you have specified both prompt peak bounds (or none).",
                                       {"prompt_peak_correction_min": self.prompt_peak_correction_min,
                                        "prompt_peak_correction_max": self.prompt_peak_correction_max})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.prompt_peak_correction_min, self.prompt_peak_correction_max]):
            entry = validation_message("Incorrect prompt peak bounds.",
                                       "Make sure that lower prompt peak bound is smaller then upper bound.",
                                       {"prompt_peak_correction_min": self.prompt_peak_correction_min,
                                        "prompt_peak_correction_max": self.prompt_peak_correction_max})
            is_invalid.update(entry)

        # -----------------
        # Wavelength rebin
        # -----------------
        if one_is_none([self.wavelength_low, self.wavelength_high, self.wavelength_step, self.wavelength_step_type,
                        self.wavelength_step_type, self.rebin_type]):
            entry = validation_message("A wavelength entry has not been set.",
                                       "Make sure that all entries are set.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high,
                                        "wavelength_step": self.wavelength_step,
                                        "wavelength_step_type": self.wavelength_step_type,
                                        "rebin_type": self.rebin_type})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.wavelength_low, self.wavelength_high]):
            entry = validation_message("Incorrect wavelength bounds.",
                                       "Make sure that lower wavelength bound is smaller then upper bound.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high})
            is_invalid.update(entry)

        if self.use_full_wavelength_range:
            if self.wavelength_full_range_low is None or self.wavelength_full_range_high is None:
                entry = validation_message("Incorrect full wavelength settings.",
                                           "Make sure that both full wavelength entries have been set.",
                                           {"wavelength_full_range_low": self.wavelength_full_range_low,
                                            "wavelength_full_range_high": self.wavelength_full_range_high})
                is_invalid.update(entry)
            if is_not_none_and_first_larger_than_second([self.wavelength_full_range_low,
                                                         self.wavelength_full_range_high]):
                entry = validation_message("Incorrect wavelength bounds.",
                                           "Make sure that lower full wavelength bound is smaller then upper bound.",
                                           {"wavelength_full_range_low": self.wavelength_full_range_low,
                                            "wavelength_full_range_high": self.wavelength_full_range_high})
                is_invalid.update(entry)

        # ----------------------
        # Background correction
        # ----------------------
        if not is_pure_none_or_not_none([self.background_TOF_general_start, self.background_TOF_general_stop]):
            entry = validation_message("A general background TOF entry has not been set.",
                                       "Make sure that either all general background TOF entries are set or none.",
                                       {"background_TOF_general_start": self.background_TOF_general_start,
                                        "background_TOF_general_stop": self.background_TOF_general_stop})
            is_invalid.update(entry)
        if is_not_none_and_first_larger_than_second([self.background_TOF_general_start,
                                                     self.background_TOF_general_stop]):
            entry = validation_message("Incorrect general background TOF bounds.",
                                       "Make sure that lower general background TOF bound is smaller then upper bound.",
                                       {"background_TOF_general_start": self.background_TOF_general_start,
                                        "background_TOF_general_stop": self.background_TOF_general_stop})
            is_invalid.update(entry)

        if not is_pure_none_or_not_none([self.background_TOF_roi_start, self.background_TOF_roi_stop]):
            entry = validation_message("A ROI background TOF entry has not been set.",
                                       "Make sure that either all ROI background TOF entries are set or none.",
                                       {"background_TOF_roi_start": self.background_TOF_roi_start,
                                        "background_TOF_roi_stop": self.background_TOF_roi_stop})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.background_TOF_roi_start,
                                                     self.background_TOF_roi_stop]):
            entry = validation_message("Incorrect ROI background TOF bounds.",
                                       "Make sure that lower ROI background TOF bound is smaller then upper bound.",
                                       {"background_TOF_roi_start": self.background_TOF_roi_start,
                                        "background_TOF_roi_stop": self.background_TOF_roi_stop})
            is_invalid.update(entry)

        if not is_pure_none_or_not_none([self.background_TOF_monitor_start, self.background_TOF_monitor_stop]):
            entry = validation_message("A monitor background TOF entry has not been set.",
                                       "Make sure that either all monitor background TOF entries are set or none.",
                                       {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                        "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
            is_invalid.update(entry)

        if self.background_TOF_monitor_start is not None and self.background_TOF_monitor_stop is not None:
            if len(self.background_TOF_monitor_start) != len(self.background_TOF_monitor_stop):
                entry = validation_message("The monitor background TOF entries have a length mismatch.",
                                           "Make sure that all monitor background TOF entries have the same length.",
                                           {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                            "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
                is_invalid.update(entry)
            for key_start, value_start in list(self.background_TOF_monitor_start.items()):
                if key_start not in self.background_TOF_monitor_stop:
                    entry = validation_message("The monitor background TOF had spectrum number mismatch.",
                                               "Make sure that all monitors have entries for start and stop.",
                                               {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                                "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
                    is_invalid.update(entry)
                else:
                    value_stop = self.background_TOF_monitor_stop[key_start]
                    if value_start > value_stop:
                        entry = validation_message("Incorrect monitor background TOF bounds.",
                                                   "Make sure that lower monitor background TOF bound is"
                                                   " smaller then upper bound.",
                                                   {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                                    "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
                        is_invalid.update(entry)

        # -----
        # Fit
        # -----
        self.fit[DataType.to_string(DataType.Sample)].validate()
        self.fit[DataType.to_string(DataType.Can)].validate()

        if is_invalid:
            raise ValueError("StateCalculateTransmission: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #27
0
    def validate(self):
        is_invalid = {}

        # 1D Q settings
        if not is_pure_none_or_not_none([self.q_min, self.q_max]):
            entry = validation_message("The q boundaries for the 1D reduction are inconsistent.",
                                       "Make sure that both q boundaries are set (or none).",
                                       {"q_min": self.q_min,
                                        "q_max": self.q_max})
            is_invalid.update(entry)
        if is_not_none_and_first_larger_than_second([self.q_min, self.q_max]):
            entry = validation_message("Incorrect q bounds for 1D reduction.",
                                       "Make sure that the lower q bound is smaller than the upper q bound.",
                                       {"q_min": self.q_min,
                                        "q_max": self.q_max})
            is_invalid.update(entry)

        if self.reduction_dimensionality is ReductionDimensionality.OneDim:
            if self.q_min is None or self.q_max is None:
                entry = validation_message("Q bounds not set for 1D reduction.",
                                           "Make sure to set the q boundaries when using a 1D reduction.",
                                           {"q_min": self.q_min,
                                            "q_max": self.q_max})
                is_invalid.update(entry)

        if self.q_1d_rebin_string is not None:
            if self.q_1d_rebin_string == "":
                entry = validation_message("Q rebin string does not seem to be valid.",
                                           "Make sure to provide a valid rebin string",
                                           {"q_1d_rebin_string": self.q_1d_rebin_string})
                is_invalid.update(entry)
            elif not is_valid_rebin_string(self.q_1d_rebin_string):
                entry = validation_message("Q rebin string does not seem to be valid.",
                                           "Make sure to provide a valid rebin string",
                                           {"q_1d_rebin_string": self.q_1d_rebin_string})
                is_invalid.update(entry)

        # QXY settings
        if self.reduction_dimensionality is ReductionDimensionality.TwoDim:
            if self.q_xy_max is None or self.q_xy_step is None:
                entry = validation_message("Q bounds not set for 2D reduction.",
                                           "Make sure that the q_max value bound and the step for the 2D reduction.",
                                           {"q_xy_max": self.q_xy_max,
                                            "q_xy_step": self.q_xy_step})
                is_invalid.update(entry)

        # Q Resolution settings
        if self.use_q_resolution:
            if not is_pure_none_or_not_none([self.q_resolution_a1, self.q_resolution_a2]):
                entry = validation_message("Inconsistent circular geometry.",
                                           "Make sure that both diameters for the circular apertures are set.",
                                           {"q_resolution_a1": self.q_resolution_a1,
                                            "q_resolution_a2": self.q_resolution_a2})
                is_invalid.update(entry)
            if not is_pure_none_or_not_none([self.q_resolution_h1, self.q_resolution_h2, self.q_resolution_w1,
                                             self.q_resolution_w2]):
                entry = validation_message("Inconsistent rectangular geometry.",
                                           "Make sure that both diameters for the circular apertures are set.",
                                           {"q_resolution_h1": self.q_resolution_h1,
                                            "q_resolution_h2": self.q_resolution_h2,
                                            "q_resolution_w1": self.q_resolution_w1,
                                            "q_resolution_w2": self.q_resolution_w2})
                is_invalid.update(entry)

            if all(element is None for element in [self.q_resolution_a1, self.q_resolution_a2, self.q_resolution_w1,
                                                   self.q_resolution_w2, self.q_resolution_h1, self.q_resolution_h2]):
                entry = validation_message("Aperture is undefined.",
                                           "Make sure that you set the geometry for a circular or a "
                                           "rectangular aperture.",
                                           {"q_resolution_a1": self.q_resolution_a1,
                                            "q_resolution_a2": self.q_resolution_a2,
                                            "q_resolution_h1": self.q_resolution_h1,
                                            "q_resolution_h2": self.q_resolution_h2,
                                            "q_resolution_w1": self.q_resolution_w1,
                                            "q_resolution_w2": self.q_resolution_w2})
                is_invalid.update(entry)
            if self.moderator_file is None:
                entry = validation_message("Missing moderator file.",
                                           "Make sure to specify a moderator file when using q resolution.",
                                           {"moderator_file": self.moderator_file})
                is_invalid.update(entry)
                is_invalid.update({"moderator_file": "A moderator file is required for the q resolution calculation."})

        if is_invalid:
            raise ValueError("StateMoveDetectorISIS: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #28
0
    def validate(self):
        is_invalid = {}

        # 1D Q settings
        if not is_pure_none_or_not_none([self.q_min, self.q_max]):
            entry = validation_message(
                "The q boundaries for the 1D reduction are inconsistent.",
                "Make sure that both q boundaries are set (or none).", {
                    "q_min": self.q_min,
                    "q_max": self.q_max
                })
            is_invalid.update(entry)
        if is_not_none_and_first_larger_than_second([self.q_min, self.q_max]):
            entry = validation_message(
                "Incorrect q bounds for 1D reduction.",
                "Make sure that the lower q bound is smaller than the upper q bound.",
                {
                    "q_min": self.q_min,
                    "q_max": self.q_max
                })
            is_invalid.update(entry)

        if self.reduction_dimensionality is ReductionDimensionality.ONE_DIM:
            if self.q_min is None or self.q_max is None:
                entry = validation_message(
                    "Q bounds not set for 1D reduction.",
                    "Make sure to set the q boundaries when using a 1D reduction.",
                    {
                        "q_min": self.q_min,
                        "q_max": self.q_max
                    })
                is_invalid.update(entry)

        if self.q_1d_rebin_string is not None:
            if self.q_1d_rebin_string == "":
                entry = validation_message(
                    "Q rebin string does not seem to be valid.",
                    "Make sure to provide a valid rebin string",
                    {"q_1d_rebin_string": self.q_1d_rebin_string})
                is_invalid.update(entry)
            elif not is_valid_rebin_string(self.q_1d_rebin_string):
                entry = validation_message(
                    "Q rebin string does not seem to be valid.",
                    "Make sure to provide a valid rebin string",
                    {"q_1d_rebin_string": self.q_1d_rebin_string})
                is_invalid.update(entry)

        # QXY settings
        if self.reduction_dimensionality is ReductionDimensionality.TWO_DIM:
            if self.q_xy_max is None or self.q_xy_step is None:
                entry = validation_message(
                    "Q bounds not set for 2D reduction.",
                    "Make sure that the q_max value bound and the step for the 2D reduction.",
                    {
                        "q_xy_max": self.q_xy_max,
                        "q_xy_step": self.q_xy_step
                    })
                is_invalid.update(entry)

        # Q Resolution settings
        if self.use_q_resolution:
            if not is_pure_none_or_not_none(
                [self.q_resolution_a1, self.q_resolution_a2]):
                entry = validation_message(
                    "Inconsistent circular geometry.",
                    "Make sure that both diameters for the circular apertures are set.",
                    {
                        "q_resolution_a1": self.q_resolution_a1,
                        "q_resolution_a2": self.q_resolution_a2
                    })
                is_invalid.update(entry)
            if not is_pure_none_or_not_none([
                    self.q_resolution_h1, self.q_resolution_h2,
                    self.q_resolution_w1, self.q_resolution_w2
            ]):
                entry = validation_message(
                    "Inconsistent rectangular geometry.",
                    "Make sure that both diameters for the circular apertures are set.",
                    {
                        "q_resolution_h1": self.q_resolution_h1,
                        "q_resolution_h2": self.q_resolution_h2,
                        "q_resolution_w1": self.q_resolution_w1,
                        "q_resolution_w2": self.q_resolution_w2
                    })
                is_invalid.update(entry)

            if all(element is None for element in [
                    self.q_resolution_a1, self.q_resolution_a2,
                    self.q_resolution_w1, self.q_resolution_w2,
                    self.q_resolution_h1, self.q_resolution_h2
            ]):
                entry = validation_message(
                    "Aperture is undefined.",
                    "Make sure that you set the geometry for a circular or a "
                    "rectangular aperture.", {
                        "q_resolution_a1": self.q_resolution_a1,
                        "q_resolution_a2": self.q_resolution_a2,
                        "q_resolution_h1": self.q_resolution_h1,
                        "q_resolution_h2": self.q_resolution_h2,
                        "q_resolution_w1": self.q_resolution_w1,
                        "q_resolution_w2": self.q_resolution_w2
                    })
                is_invalid.update(entry)
            if self.moderator_file is None:
                entry = validation_message(
                    "Missing moderator file.",
                    "Make sure to specify a moderator file when using q resolution.",
                    {"moderator_file": self.moderator_file})
                is_invalid.update(entry)
                is_invalid.update({
                    "moderator_file":
                    "A moderator file is required for the q resolution calculation."
                })

        if is_invalid:
            raise ValueError(
                "StateMoveDetectorISIS: The provided inputs are illegal. "
                "Please see: {0}".format(json.dumps(is_invalid)))
Exemple #29
0
    def validate(self):  # noqa
        is_invalid = {}
        # -----------------
        # Incident monitor
        # -----------------
        if self.incident_monitor is None and self.default_incident_monitor is None:
            entry = validation_message("No incident monitor was specified.",
                                       "Make sure that incident monitor has been specified.",
                                       {"incident_monitor": self.incident_monitor,
                                        "default_incident_monitor": self.default_incident_monitor})
            is_invalid.update(entry)

        # --------------
        # Transmission, either we need some ROI (ie radius, roi files /mask files) or a transmission monitor
        # --------------
        has_no_transmission_monitor_setting = self.transmission_monitor is None and\
                                              self.default_transmission_monitor is None  # noqa
        has_no_transmission_roi_setting = self.transmission_radius_on_detector is None and\
                                          self.transmission_roi_files is None  # noqa
        if has_no_transmission_monitor_setting and has_no_transmission_roi_setting:
            entry = validation_message("No transmission settings were specified.",
                                       "Make sure that transmission settings are specified.",
                                       {"transmission_monitor": self.transmission_monitor,
                                        "default_transmission_monitor": self.default_transmission_monitor,
                                        "transmission_radius_on_detector": self.transmission_radius_on_detector,
                                        "transmission_roi_files": self.transmission_roi_files})
            is_invalid.update(entry)

        # -----------------
        # Prompt peak
        # -----------------
        if not is_pure_none_or_not_none([self.prompt_peak_correction_min, self.prompt_peak_correction_max]):
            entry = validation_message("Inconsistent prompt peak setting.",
                                       "Make sure that you have specified both prompt peak bounds (or none).",
                                       {"prompt_peak_correction_min": self.prompt_peak_correction_min,
                                        "prompt_peak_correction_max": self.prompt_peak_correction_max})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.prompt_peak_correction_min, self.prompt_peak_correction_max]):
            entry = validation_message("Incorrect prompt peak bounds.",
                                       "Make sure that lower prompt peak bound is smaller then upper bound.",
                                       {"prompt_peak_correction_min": self.prompt_peak_correction_min,
                                        "prompt_peak_correction_max": self.prompt_peak_correction_max})
            is_invalid.update(entry)

        # -----------------
        # Wavelength rebin
        # -----------------
        if one_is_none([self.wavelength_low, self.wavelength_high, self.wavelength_step, self.wavelength_step_type,
                        self.rebin_type]):
            entry = validation_message("A wavelength entry has not been set.",
                                       "Make sure that all entries are set.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high,
                                        "wavelength_step": self.wavelength_step,
                                        "wavelength_step_type": self.wavelength_step_type,
                                        "rebin_type": self.rebin_type})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.wavelength_low, self.wavelength_high]):
            entry = validation_message("Incorrect wavelength bounds.",
                                       "Make sure that lower wavelength bound is smaller then upper bound.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high})
            is_invalid.update(entry)

        if self.use_full_wavelength_range:
            if self.wavelength_full_range_low is None or self.wavelength_full_range_high is None:
                entry = validation_message("Incorrect full wavelength settings.",
                                           "Make sure that both full wavelength entries have been set.",
                                           {"wavelength_full_range_low": self.wavelength_full_range_low,
                                            "wavelength_full_range_high": self.wavelength_full_range_high})
                is_invalid.update(entry)
            if is_not_none_and_first_larger_than_second([self.wavelength_full_range_low,
                                                         self.wavelength_full_range_high]):
                entry = validation_message("Incorrect wavelength bounds.",
                                           "Make sure that lower full wavelength bound is smaller then upper bound.",
                                           {"wavelength_full_range_low": self.wavelength_full_range_low,
                                            "wavelength_full_range_high": self.wavelength_full_range_high})
                is_invalid.update(entry)

        # ----------------------
        # Background correction
        # ----------------------
        if not is_pure_none_or_not_none([self.background_TOF_general_start, self.background_TOF_general_stop]):
            entry = validation_message("A general background TOF entry has not been set.",
                                       "Make sure that either all general background TOF entries are set or none.",
                                       {"background_TOF_general_start": self.background_TOF_general_start,
                                        "background_TOF_general_stop": self.background_TOF_general_stop})
            is_invalid.update(entry)
        if is_not_none_and_first_larger_than_second([self.background_TOF_general_start,
                                                     self.background_TOF_general_stop]):
            entry = validation_message("Incorrect general background TOF bounds.",
                                       "Make sure that lower general background TOF bound is smaller then upper bound.",
                                       {"background_TOF_general_start": self.background_TOF_general_start,
                                        "background_TOF_general_stop": self.background_TOF_general_stop})
            is_invalid.update(entry)

        if not is_pure_none_or_not_none([self.background_TOF_roi_start, self.background_TOF_roi_stop]):
            entry = validation_message("A ROI background TOF entry has not been set.",
                                       "Make sure that either all ROI background TOF entries are set or none.",
                                       {"background_TOF_roi_start": self.background_TOF_roi_start,
                                        "background_TOF_roi_stop": self.background_TOF_roi_stop})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.background_TOF_roi_start,
                                                     self.background_TOF_roi_stop]):
            entry = validation_message("Incorrect ROI background TOF bounds.",
                                       "Make sure that lower ROI background TOF bound is smaller then upper bound.",
                                       {"background_TOF_roi_start": self.background_TOF_roi_start,
                                        "background_TOF_roi_stop": self.background_TOF_roi_stop})
            is_invalid.update(entry)

        if not is_pure_none_or_not_none([self.background_TOF_monitor_start, self.background_TOF_monitor_stop]):
            entry = validation_message("A monitor background TOF entry has not been set.",
                                       "Make sure that either all monitor background TOF entries are set or none.",
                                       {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                        "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
            is_invalid.update(entry)

        if self.background_TOF_monitor_start is not None and self.background_TOF_monitor_stop is not None:
            if len(self.background_TOF_monitor_start) != len(self.background_TOF_monitor_stop):
                entry = validation_message("The monitor background TOF entries have a length mismatch.",
                                           "Make sure that all monitor background TOF entries have the same length.",
                                           {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                            "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
                is_invalid.update(entry)
            for key_start, value_start in self.background_TOF_monitor_start.items():
                if key_start not in self.background_TOF_monitor_stop:
                    entry = validation_message("The monitor background TOF had spectrum number mismatch.",
                                               "Make sure that all monitors have entries for start and stop.",
                                               {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                                "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
                    is_invalid.update(entry)
                else:
                    value_stop = self.background_TOF_monitor_stop[key_start]
                    if value_start > value_stop:
                        entry = validation_message("Incorrect monitor background TOF bounds.",
                                                   "Make sure that lower monitor background TOF bound is"
                                                   " smaller then upper bound.",
                                                   {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                                    "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
                        is_invalid.update(entry)

        # -----
        # Fit
        # -----
        self.fit[DataType.to_string(DataType.Sample)].validate()
        self.fit[DataType.to_string(DataType.Can)].validate()

        if is_invalid:
            raise ValueError("StateCalculateTransmission: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))
    def validate(self):
        is_invalid = {}
        # -----------------
        # incident Monitor
        # -----------------
        if self.incident_monitor is None:
            is_invalid.update({"incident_monitor": "An incident monitor must be specified."})

        # -----------------
        # Prompt peak
        # -----------------
        if not is_pure_none_or_not_none([self.prompt_peak_correction_min, self.prompt_peak_correction_max]):
            entry = validation_message("A prompt peak correction entry has not been set.",
                                       "Make sure that either all prompt peak entries have been set or none.",
                                       {"prompt_peak_correction_min": self.prompt_peak_correction_min,
                                        "prompt_peak_correction_max": self.prompt_peak_correction_max})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.prompt_peak_correction_min, self.prompt_peak_correction_max]):
            entry = validation_message("Incorrect prompt peak correction bounds.",
                                       "Make sure that lower prompt peak time bound is smaller then upper bound.",
                                       {"prompt_peak_correction_min": self.prompt_peak_correction_min,
                                        "prompt_peak_correction_max": self.prompt_peak_correction_max})
            is_invalid.update(entry)

        # -----------------
        # Wavelength rebin
        # -----------------
        if one_is_none([self.wavelength_low, self.wavelength_high, self.wavelength_step, self.wavelength_step_type]):
            entry = validation_message("A wavelength entry has not been set.",
                                       "Make sure that all entries are set.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high,
                                        "wavelength_step": self.wavelength_step,
                                        "wavelength_step_type": self.wavelength_step_type})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.wavelength_low, self.wavelength_high]):
            entry = validation_message("Incorrect wavelength bounds.",
                                       "Make sure that lower wavelength bound is smaller then upper bound.",
                                       {"wavelength_low": self.wavelength_low,
                                        "wavelength_high": self.wavelength_high})
            is_invalid.update(entry)

        # ----------------------
        # Background correction
        # ----------------------
        if not is_pure_none_or_not_none([self.background_TOF_general_start, self.background_TOF_general_stop]):
            entry = validation_message("A general background TOF entry has not been set.",
                                       "Make sure that either all general background TOF entries are set or none.",
                                       {"background_TOF_general_start": self.background_TOF_general_start,
                                        "background_TOF_general_stop": self.background_TOF_general_stop})
            is_invalid.update(entry)

        if is_not_none_and_first_larger_than_second([self.background_TOF_general_start,
                                                     self.background_TOF_general_stop]):
            entry = validation_message("Incorrect general background TOF bounds.",
                                       "Make sure that lower general background TOF bound is smaller then upper bound.",
                                       {"background_TOF_general_start": self.background_TOF_general_start,
                                        "background_TOF_general_stop": self.background_TOF_general_stop})
            is_invalid.update(entry)

        if not is_pure_none_or_not_none([self.background_TOF_monitor_start, self.background_TOF_monitor_stop]):
            entry = validation_message("A monitor background TOF entry has not been set.",
                                       "Make sure that either all monitor background TOF entries are set or none.",
                                       {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                        "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
            is_invalid.update(entry)

        if self.background_TOF_monitor_start is not None and self.background_TOF_monitor_stop is not None:
            if len(self.background_TOF_monitor_start) != len(self.background_TOF_monitor_stop):
                entry = validation_message("The monitor background TOF entries have a length mismatch.",
                                           "Make sure that all monitor background TOF entries have the same length.",
                                           {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                            "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
                is_invalid.update(entry)
            for key_start, value_start in list(self.background_TOF_monitor_start.items()):
                if key_start not in self.background_TOF_monitor_stop:
                    entry = validation_message("The monitor background TOF had spectrum number mismatch.",
                                               "Make sure that all monitors have entries for start and stop.",
                                               {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                                "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
                    is_invalid.update(entry)
                else:
                    value_stop = self.background_TOF_monitor_stop[key_start]
                    if value_start > value_stop:
                        entry = validation_message("Incorrect monitor background TOF bounds.",
                                                   "Make sure that lower monitor background TOF bound is"
                                                   " smaller then upper bound.",
                                                   {"background_TOF_monitor_start": self.background_TOF_monitor_start,
                                                    "background_TOF_monitor_stop": self.background_TOF_monitor_stop})
                        is_invalid.update(entry)

        if is_invalid:
            raise ValueError("StateMoveDetector: The provided inputs are illegal. "
                             "Please see: {0}".format(json.dumps(is_invalid)))