Пример #1
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
Пример #2
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
Пример #3
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)))
Пример #4
0
class StateMaskDetector(StateBase):
    # Vertical strip masks
    single_vertical_strip_mask = PositiveIntegerListParameter()
    range_vertical_strip_start = PositiveIntegerListParameter()
    range_vertical_strip_stop = PositiveIntegerListParameter()

    # Horizontal strip masks
    single_horizontal_strip_mask = PositiveIntegerListParameter()
    range_horizontal_strip_start = PositiveIntegerListParameter()
    range_horizontal_strip_stop = PositiveIntegerListParameter()

    # Spectrum Block
    block_horizontal_start = PositiveIntegerListParameter()
    block_horizontal_stop = PositiveIntegerListParameter()
    block_vertical_start = PositiveIntegerListParameter()
    block_vertical_stop = PositiveIntegerListParameter()

    # Spectrum block cross
    block_cross_horizontal = PositiveIntegerListParameter()
    block_cross_vertical = PositiveIntegerListParameter()

    # Time/Bin mask
    bin_mask_start = FloatListParameter()
    bin_mask_stop = FloatListParameter()

    # Name of the detector
    detector_name = StringParameter()
    detector_name_short = StringParameter()

    # Single Spectra
    single_spectra = PositiveIntegerListParameter()

    # Spectrum Range
    spectrum_range_start = PositiveIntegerListParameter()
    spectrum_range_stop = PositiveIntegerListParameter()

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

    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)))
Пример #5
0
class StateSliceEvent(StateBase):
    start_time = FloatListParameter()
    end_time = FloatListParameter()

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

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