Esempio n. 1
0
    def test_int_against_int(self):
        nm = NumberArrayMeta("int32")
        values = [1, 2, 3]
        response = nm.validate(values)

        for i, value in enumerate(response):
            assert values[i] == value
Esempio n. 2
0
    def test_float_against_float64(self):
        nm = NumberArrayMeta("float64")
        values = [1.2, 3.4, 5.6]
        response = nm.validate(values)

        for i, value in enumerate(response):
            assert values[i] == value
Esempio n. 3
0
    def test_float_against_float32(self):
        nm = NumberArrayMeta("float32")
        values = [1.2, 3.4, 5.6]
        response = nm.validate(values)

        for i, value in enumerate(response):
            self.assertAlmostEqual(values[i], response[i], places=5)
Esempio n. 4
0
    def test_numpy_array(self):
        nm = NumberArrayMeta("float64")
        values = np.array([1.2, 3.4, 5.6])
        response = nm.validate(values)

        for i, value in enumerate(response):
            assert values[i] == value
Esempio n. 5
0
    def __init__(
        self,
        name: util.APartName,
        description: util.AMetaDescription,
        pv: util.APv = "",
        rbv: util.ARbv = "",
        rbv_suffix: util.ARbvSuffix = "",
        min_delta: util.AMinDelta = 0.05,
        timeout: util.ATimeout = DEFAULT_TIMEOUT,
        sink_port: util.ASinkPort = None,
        widget: util.AWidget = None,
        group: util.AGroup = None,
        config: util.AConfig = True,
        display_from_pv: util.AGetLimits = True,
    ) -> None:
        super().__init__(name)
        self.display_from_pv = display_from_pv

        self.caa = util.CAAttribute(
            NumberArrayMeta("float64", description),
            util.catools.DBR_DOUBLE,
            pv,
            rbv,
            rbv_suffix,
            min_delta,
            timeout,
            sink_port,
            widget,
            group,
            config,
            on_connect=self._update_display,
        )
Esempio n. 6
0
 def __init__(
     self,
     name: util.APartName,
     description: util.AMetaDescription,
     pv: util.APv = "",
     rbv: util.ARbv = "",
     rbv_suffix: util.ARbvSuffix = "",
     min_delta: util.AMinDelta = 0.05,
     timeout: util.ATimeout = DEFAULT_TIMEOUT,
     sink_port: util.ASinkPort = None,
     widget: util.AWidget = None,
     group: util.AGroup = None,
     config: util.AConfig = True,
 ) -> None:
     super().__init__(name)
     self.caa = util.CAAttribute(
         NumberArrayMeta("int32", description),
         util.catools.DBR_LONG,
         pv,
         rbv,
         rbv_suffix,
         min_delta,
         timeout,
         sink_port,
         widget,
         group,
         config,
     )
Esempio n. 7
0
 def __init__(self, client, meta, block_name, field_name):
     # type: (AClient, AMeta, ABlockName, AFieldName) -> None
     # Fill in the meta object with the correct headers
     columns = OrderedDict()
     self.field_data = OrderedDict()
     fields = client.get_table_fields(block_name, field_name)
     if not fields:
         # Didn't put any metadata in, make some up
         fields["VALUE"] = TableFieldData(31, 0, "The Value", None)
     for column_name, field_data in fields.items():
         nbits = field_data.bits_hi - field_data.bits_lo + 1
         if nbits < 1:
             raise ValueError("Bad bits in %s" % (field_data, ))
         if field_data.labels:
             column_meta = ChoiceArrayMeta(choices=field_data.labels)
             widget = Widget.COMBO
         elif nbits == 1:
             column_meta = BooleanArrayMeta()
             widget = Widget.CHECKBOX
         else:
             if nbits <= 8:
                 dtype = "uint8"
             elif nbits <= 16:
                 dtype = "uint16"
             elif nbits <= 32:
                 dtype = "uint32"
             elif nbits <= 64:
                 dtype = "uint64"
             else:
                 raise ValueError("Bad bits in %s" % (field_data, ))
             column_meta = NumberArrayMeta(dtype)
             widget = Widget.TEXTINPUT
         column_name = snake_to_camel(column_name)
         column_meta.set_label(camel_to_title(column_name))
         column_meta.set_tags([widget.tag()])
         column_meta.set_description(field_data.description)
         column_meta.set_writeable(True)
         columns[column_name] = column_meta
         self.field_data[column_name] = field_data
     meta.set_elements(columns)
     # Superclass will make the attribute for us
     super(PandABlocksTablePart, self).__init__(client, meta, block_name,
                                                field_name)
Esempio n. 8
0
 def __init__(self,
              name,  # type: util.APartName
              description,  # type: util.AMetaDescription
              pv="",  # type: util.APv
              rbv="",  # type: util.ARbv
              rbv_suffix="",  # type: util.ARbvSuffix
              min_delta=0.05,  # type: util.AMinDelta
              timeout=DEFAULT_TIMEOUT,  # type: util.ATimeout
              sink_port=None,  # type: util.ASinkPort
              widget=None,  # type: util.AWidget
              group=None,  # type: util.AGroup
              config=True,  # type: util.AConfig
              ):
     # type: (...) -> None
     super(CADoubleArrayPart, self).__init__(name)
     self.caa = util.CAAttribute(
         NumberArrayMeta("float64", description), util.catools.DBR_DOUBLE,
         pv, rbv, rbv_suffix, min_delta, timeout, sink_port, widget, group,
         config)
Esempio n. 9
0
 def __init__(
     self,
     client: AClient,
     meta: AMeta,
     block_name: ABlockName,
     field_name: AFieldName,
 ) -> None:
     # Fill in the meta object with the correct headers
     columns = OrderedDict()
     self.field_data = OrderedDict()
     fields = client.get_table_fields(block_name, field_name)
     if not fields:
         # Didn't put any metadata in, make some up
         fields["VALUE"] = TableFieldData(31, 0, "The Value", None, True)
     for column_name, field_data in fields.items():
         nbits = field_data.bits_hi - field_data.bits_lo + 1
         if nbits < 1:
             raise ValueError("Bad bits in %s" % (field_data, ))
         if field_data.labels:
             column_meta = ChoiceArrayMeta(choices=field_data.labels)
             widget = Widget.COMBO
         elif nbits == 1:
             column_meta = BooleanArrayMeta()
             widget = Widget.CHECKBOX
         else:
             dtype = get_dtype(nbits, field_data.signed)
             column_meta = NumberArrayMeta(dtype)
             widget = Widget.TEXTINPUT
         column_name = snake_to_camel(column_name)
         column_meta.set_label(camel_to_title(column_name))
         column_meta.set_tags([widget.tag()])
         column_meta.set_description(field_data.description)
         column_meta.set_writeable(True)
         columns[column_name] = column_meta
         self.field_data[column_name] = field_data
     meta.set_elements(columns)
     # Work out how many ints per row
     # TODO: this should be in the block data
     max_bits_hi = max(f.bits_hi for f in self.field_data.values())
     self.ints_per_row = int((max_bits_hi + 31) / 32)
     # Superclass will make the attribute for us
     super().__init__(client, meta, block_name, field_name)
Esempio n. 10
0
 def __init__(
     self,
     name: util.APartName,
     description: util.AMetaDescription,
     pv_list: util.APvList = (),
     name_list: util.ANameList = (),
     min_delta: util.AMinDelta = 0.05,
     timeout: util.ATimeout = DEFAULT_TIMEOUT,
     widget: util.AWidget = Widget.PLOT,
     group: util.AGroup = None,
     config: util.AConfig = True,
     display_from_pv: util.AGetLimits = True,
 ) -> None:
     if len(pv_list) != len(name_list):
         raise BadValueError(
             "List of PVs must be same length as list of names!")
     super().__init__(name)
     self.display_from_pv = display_from_pv
     elements = {}
     for name in name_list:
         elements[name] = NumberArrayMeta("float64",
                                          name,
                                          tags=[Widget.TEXTUPDATE.tag()])
     self.name_list = name_list
     self.pv_list = pv_list
     self.caa = util.WaveformTableAttribute(
         TableMeta(description, writeable=False, elements=elements),
         util.catools.DBR_DOUBLE,
         pv_list,
         name_list,
         min_delta,
         timeout,
         widget,
         group,
         config,
         on_connect=self._update_display,
     )
Esempio n. 11
0
 def test_none_validates(self):
     nm = NumberArrayMeta("int32")
     assert list(nm.validate(None)) == []
Esempio n. 12
0
 def test_null_element_zero(self):
     nm = NumberArrayMeta("float64")
     actual = nm.validate([1.2, None, 1.3])
     assert actual[0] == 1.2
     assert np.isnan(actual[1])
     assert actual[2] == 1.3
Esempio n. 13
0
 def test_float_against_int_floors(self):
     nm = NumberArrayMeta("int32")
     actual = list(nm.validate([1.2, 34, 56]))
     expected = [1, 34, 56]
     assert actual == expected
Esempio n. 14
0
    def test_numpy_array_wrong_number_type_raises(self):
        nm = NumberArrayMeta("int32")
        values = np.array([1.2, 3.4, 5.6])

        with self.assertRaises(AssertionError):
            nm.validate(values)
Esempio n. 15
0
    def test_numpy_array_wrong_type_raises(self):
        nm = NumberArrayMeta("float64")
        values = "[1.2, 3.4, 5.6]"

        with self.assertRaises(ValueError):
            nm.validate(values)