Ejemplo n.º 1
0
class StateTransmissionFit(StateBase):
    fit_type = ClassTypeParameter(FitType)
    polynomial_order = PositiveIntegerParameter()
    wavelength_low = PositiveFloatWithNoneParameter()
    wavelength_high = PositiveFloatWithNoneParameter()

    def __init__(self):
        super(StateTransmissionFit, self).__init__()
        self.fit_type = FitType.Log
        self.polynomial_order = 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)))
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 4
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
Ejemplo n.º 5
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)))