Пример #1
0
class StateWavelengthAndPixelAdjustment(StateBase):
    wavelength_low = PositiveFloatParameter()
    wavelength_high = PositiveFloatParameter()
    wavelength_step = PositiveFloatParameter()
    wavelength_step_type = ClassTypeParameter(RangeStepType)

    adjustment_files = DictParameter()

    idf_path = StringParameter()

    def __init__(self):
        super(StateWavelengthAndPixelAdjustment, self).__init__()
        self.adjustment_files = {
            DetectorType.to_string(DetectorType.LAB): StateAdjustmentFiles(),
            DetectorType.to_string(DetectorType.HAB): StateAdjustmentFiles()
        }

    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)))
Пример #2
0
class StateReductionMode(StateReductionBase, StateBase):
    reduction_mode = ClassTypeParameter(ReductionMode)
    reduction_dimensionality = ClassTypeParameter(ReductionDimensionality)

    # Fitting
    merge_fit_mode = ClassTypeParameter(FitModeForMerge)
    merge_shift = FloatParameter()
    merge_scale = FloatParameter()
    merge_range_min = FloatWithNoneParameter()
    merge_range_max = FloatWithNoneParameter()

    # Map from detector type to detector name
    detector_names = DictParameter()

    def __init__(self):
        super(StateReductionMode, self).__init__()
        self.reduction_mode = ISISReductionMode.LAB
        self.reduction_dimensionality = ReductionDimensionality.OneDim

        # Set the shifts to defaults which essentially don't do anything.
        self.merge_shift = 0.0
        self.merge_scale = 1.0
        self.merge_fit_mode = FitModeForMerge.NoFit
        self.merge_range_min = None
        self.merge_range_max = None

        # Set the detector names to empty strings
        self.detector_names = {
            DetectorType.to_string(DetectorType.LAB): "",
            DetectorType.to_string(DetectorType.HAB): ""
        }

    def get_merge_strategy(self):
        return [ISISReductionMode.LAB, ISISReductionMode.HAB]

    def get_all_reduction_modes(self):
        return [ISISReductionMode.LAB, ISISReductionMode.HAB]

    def get_detector_name_for_reduction_mode(self, reduction_mode):
        if reduction_mode is ISISReductionMode.LAB:
            bank_type = DetectorType.to_string(DetectorType.LAB)
        elif reduction_mode is ISISReductionMode.HAB:
            bank_type = DetectorType.to_string(DetectorType.HAB)
        else:
            raise RuntimeError(
                "SANStateReductionISIS: There is no detector available for the"
                " reduction mode {0}.".format(reduction_mode))
        return self.detector_names[bank_type]

    def validate(self):
        pass
Пример #3
0
class StateMove(StateBase):
    sample_offset = FloatParameter()
    sample_offset_direction = ClassTypeParameter(Coordinates)
    detectors = DictParameter()
    monitor_names = DictParameter()

    def __init__(self):
        super(StateMove, self).__init__()

        # Setup the sample offset
        self.sample_offset = 0.0

        # The sample offset direction is Z for the ISIS instruments
        self.sample_offset_direction = CanonicalCoordinates.Z

    def validate(self):
        # No validation of the descriptors on this level, let potential exceptions from detectors "bubble" up
        for key in self.detectors:
            self.detectors[key].validate()

        # If the detectors are empty, then we raise
        if not self.detectors:
            raise ValueError("No detectors have been set.")
Пример #4
0
class ComplexState(StateBase):
    float_parameter = FloatParameter()
    positive_float_with_none_parameter = PositiveFloatWithNoneParameter()
    sub_state_1 = TypedParameter(SimpleState, validator_sub_state)
    dict_parameter = DictParameter()

    def __init__(self):
        super(ComplexState, self).__init__()
        self.float_parameter = 23.
        self.positive_float_with_none_parameter = 234.
        self.sub_state_1 = SimpleState()
        self.dict_parameter = {"A": SimpleState(), "B": SimpleState()}

    def validate(self):
        pass
Пример #5
0
class StateBaseTestClass(StateBase):
    string_parameter = StringParameter()
    bool_parameter = BoolParameter()
    float_parameter = FloatParameter()
    positive_float_parameter = PositiveFloatParameter()
    positive_integer_parameter = PositiveIntegerParameter()
    dict_parameter = DictParameter()
    float_with_none_parameter = FloatWithNoneParameter()
    positive_float_with_none_parameter = PositiveFloatWithNoneParameter()
    float_list_parameter = FloatListParameter()
    string_list_parameter = StringListParameter()
    positive_integer_list_parameter = PositiveIntegerListParameter()
    class_type_parameter = ClassTypeParameter(TestType)
    class_type_list_parameter = ClassTypeListParameter(TestType)

    def __init__(self):
        super(StateBaseTestClass, self).__init__()

    def validate(self):
        pass
Пример #6
0
class SimpleState(StateBase):
    string_parameter = StringParameter()
    bool_parameter = BoolParameter()
    float_parameter = FloatParameter()
    positive_float_parameter = PositiveFloatParameter()
    positive_integer_parameter = PositiveIntegerParameter()
    dict_parameter = DictParameter()
    float_with_none_parameter = FloatWithNoneParameter()
    positive_float_with_none_parameter = PositiveFloatWithNoneParameter()
    float_list_parameter = FloatListParameter()
    string_list_parameter = StringListParameter()
    positive_integer_list_parameter = PositiveIntegerListParameter()
    class_type_parameter = ClassTypeParameter(TestType)
    class_type_list_parameter = ClassTypeListParameter(TestType)

    sub_state_very_simple = TypedParameter(VerySimpleState,
                                           validator_sub_state)

    def __init__(self):
        super(SimpleState, self).__init__()
        self.string_parameter = "String_in_SimpleState"
        self.bool_parameter = False
        # We explicitly leave out the float_parameter
        self.positive_float_parameter = 1.
        self.positive_integer_parameter = 6
        self.dict_parameter = {"1": 123, "2": "test"}
        self.float_with_none_parameter = 325.
        # We expliclty leave out the positive_float_with_none_parameter
        self.float_list_parameter = [123., 234.]
        self.string_list_parameter = ["test1", "test2"]
        self.positive_integer_list_parameter = [1, 2, 3]
        self.class_type_parameter = TestType.TypeA
        self.class_type_list_parameter = [TestType.TypeA, TestType.TypeB]
        self.sub_state_very_simple = VerySimpleState()

    def validate(self):
        pass
Пример #7
0
class StateNormalizeToMonitor(StateBase):
    prompt_peak_correction_min = PositiveFloatWithNoneParameter()
    prompt_peak_correction_max = PositiveFloatWithNoneParameter()
    prompt_peak_correction_enabled = BoolParameter()

    rebin_type = ClassTypeParameter(RebinType)
    wavelength_low = PositiveFloatListParameter()
    wavelength_high = PositiveFloatListParameter()
    wavelength_step = PositiveFloatParameter()
    wavelength_step_type = ClassTypeParameter(RangeStepType)

    background_TOF_general_start = FloatParameter()
    background_TOF_general_stop = FloatParameter()
    background_TOF_monitor_start = DictParameter()
    background_TOF_monitor_stop = DictParameter()

    incident_monitor = PositiveIntegerParameter()

    def __init__(self):
        super(StateNormalizeToMonitor, self).__init__()
        self.background_TOF_monitor_start = {}
        self.background_TOF_monitor_stop = {}
        self.prompt_peak_correction_enabled = False

        # Default rebin type is a standard Rebin
        self.rebin_type = RebinType.Rebin

    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)))
Пример #8
0
class StateMask(StateBase):
    # Radius Mask
    radius_min = FloatParameter()
    radius_max = FloatParameter()

    # Bin mask
    bin_mask_general_start = FloatListParameter()
    bin_mask_general_stop = FloatListParameter()

    # Mask files
    mask_files = StringListParameter()

    # Angle masking
    phi_min = FloatParameter()
    phi_max = FloatParameter()
    use_mask_phi_mirror = BoolParameter()

    # Beam stop
    beam_stop_arm_width = PositiveFloatParameter()
    beam_stop_arm_angle = FloatParameter()
    beam_stop_arm_pos1 = FloatParameter()
    beam_stop_arm_pos2 = FloatParameter()

    # Clear commands
    clear = BoolParameter()
    clear_time = BoolParameter()

    # The detector dependent masks
    detectors = DictParameter()

    # The idf path of the instrument
    idf_path = StringParameter()

    def __init__(self):
        super(StateMask, self).__init__()
        # Setup the detectors
        self.detectors = {
            DetectorType.to_string(DetectorType.LAB): StateMaskDetector(),
            DetectorType.to_string(DetectorType.HAB): StateMaskDetector()
        }

        # IDF Path
        self.idf_path = ""

    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)))
Пример #9
0
class StateReductionMode(StateReductionBase, StateBase):
    reduction_mode = ClassTypeParameter(ReductionMode)
    reduction_dimensionality = ClassTypeParameter(ReductionDimensionality)
    merge_max = FloatWithNoneParameter()
    merge_min = FloatWithNoneParameter()
    merge_mask = BoolParameter()

    # Fitting
    merge_fit_mode = ClassTypeParameter(FitModeForMerge)
    merge_shift = FloatParameter()
    merge_scale = FloatParameter()
    merge_range_min = FloatWithNoneParameter()
    merge_range_max = FloatWithNoneParameter()

    # Map from detector type to detector name
    detector_names = DictParameter()

    def __init__(self):
        super(StateReductionMode, self).__init__()
        self.reduction_mode = ISISReductionMode.LAB
        self.reduction_dimensionality = ReductionDimensionality.OneDim

        # Set the shifts to defaults which essentially don't do anything.
        self.merge_shift = 0.0
        self.merge_scale = 1.0
        self.merge_fit_mode = FitModeForMerge.NoFit
        self.merge_range_min = None
        self.merge_range_max = None
        self.merge_max = None
        self.merge_min = None
        self.merge_mask = False

        # Set the detector names to empty strings
        self.detector_names = {
            DetectorType.to_string(DetectorType.LAB): "",
            DetectorType.to_string(DetectorType.HAB): ""
        }

    def get_merge_strategy(self):
        return [ISISReductionMode.LAB, ISISReductionMode.HAB]

    def get_all_reduction_modes(self):
        return [ISISReductionMode.LAB, ISISReductionMode.HAB]

    def get_detector_name_for_reduction_mode(self, reduction_mode):
        if reduction_mode is ISISReductionMode.LAB:
            bank_type = DetectorType.to_string(DetectorType.LAB)
        elif reduction_mode is ISISReductionMode.HAB:
            bank_type = DetectorType.to_string(DetectorType.HAB)
        else:
            raise RuntimeError(
                "SANStateReductionISIS: There is no detector available for the"
                " reduction mode {0}.".format(reduction_mode))
        return self.detector_names[bank_type]

    def validate(self):
        is_invalid = {}
        if self.merge_max and self.merge_min:
            if self.merge_min > self.merge_max:
                is_invalid.update({
                    "StateReduction":
                    "The minimum of the merge region is greater than the maximum."
                })

        if is_invalid:
            raise ValueError(
                "StateReduction: The provided inputs are illegal. "
                "Please see: {0}".format(json.dumps(is_invalid)))
class StateCalculateTransmission(StateBase):
    # -----------------------
    # Transmission
    # -----------------------
    transmission_radius_on_detector = PositiveFloatParameter()
    transmission_roi_files = StringListParameter()
    transmission_mask_files = StringListParameter()

    default_transmission_monitor = PositiveIntegerParameter()
    transmission_monitor = PositiveIntegerParameter()

    default_incident_monitor = PositiveIntegerParameter()
    incident_monitor = PositiveIntegerParameter()

    # ----------------------
    # Prompt peak correction
    # ----------------------
    prompt_peak_correction_min = PositiveFloatParameter()
    prompt_peak_correction_max = PositiveFloatParameter()
    prompt_peak_correction_enabled = BoolParameter()

    # ----------------
    # Wavelength rebin
    # ----------------
    rebin_type = ClassTypeParameter(RebinType)
    wavelength_low = PositiveFloatParameter()
    wavelength_high = PositiveFloatParameter()
    wavelength_step = PositiveFloatParameter()
    wavelength_step_type = ClassTypeParameter(RangeStepType)

    use_full_wavelength_range = BoolParameter()
    wavelength_full_range_low = PositiveFloatParameter()
    wavelength_full_range_high = PositiveFloatParameter()

    # -----------------------
    # Background correction
    # ----------------------
    background_TOF_general_start = FloatParameter()
    background_TOF_general_stop = FloatParameter()
    background_TOF_monitor_start = DictParameter()
    background_TOF_monitor_stop = DictParameter()
    background_TOF_roi_start = FloatParameter()
    background_TOF_roi_stop = FloatParameter()

    # -----------------------
    # Fit
    # ----------------------
    fit = DictParameter()

    def __init__(self):
        super(StateCalculateTransmission, self).__init__()
        # The keys of this dictionaries are the spectrum number of the monitors (as a string)
        self.background_TOF_monitor_start = {}
        self.background_TOF_monitor_stop = {}

        self.fit = {DataType.to_string(DataType.Sample): StateTransmissionFit(),
                    DataType.to_string(DataType.Can): StateTransmissionFit()}
        self.use_full_wavelength_range = False

        # Default rebin type is a standard Rebin
        self.rebin_type = RebinType.Rebin

        self.prompt_peak_correction_enabled = False

    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)))