Пример #1
0
    def decode(self, pv):
        """Decodes an epics PV object into a TaurusValue, and also updates other
         properties of the Attribute object
        """
        attr_value = TaurusAttrValue()
        if not pv.connected:
            attr_value.error = ChannelAccessException('PV "%s" not connected' %
                                                      pv.pvname)
            return attr_value
        v = pv.value
        # type
        try:
            self.type = Dbr2TaurusType[pv.ftype]
        except KeyError:
            raise ValueError('Unsupported epics type "%s"' % pv.type)
        # writable
        self.writable = pv.write_access
        # data_format
        if numpy.isscalar(v):
            self.data_format = DataFormat._0D
        else:
            self.data_format = DataFormat(len(numpy.shape(v)))
        # units and limits support
        if self.type in (DataType.Integer, DataType.Float):
            v = Quantity(v, pv.units)
            self._range = self.__decode_limit(pv.lower_ctrl_limit,
                                              pv.upper_ctrl_limit)
            self._alarm = self.__decode_limit(pv.lower_alarm_limit,
                                              pv.upper_alarm_limit)
            self._warning = self.__decode_limit(pv.lower_warning_limit,
                                                pv.upper_warning_limit)

        # rvalue
        attr_value.rvalue = v
        # wvalue
        if pv.write_access:
            attr_value.wvalue = v
        # time
        if pv.timestamp is None:
            attr_value.time = TaurusTimeVal.now()
        else:
            attr_value.time = TaurusTimeVal.fromtimestamp(pv.timestamp)
        # quality
        if pv.severity > 0:
            attr_value.quality = AttrQuality.ATTR_ALARM
        else:
            attr_value.quality = AttrQuality.ATTR_VALID
        return attr_value
Пример #2
0
    def decode(self, pv):
        """Decodes an epics PV object into a TaurusValue, and also updates other
         properties of the Attribute object
        """
        attr_value = TaurusAttrValue()
        if not pv.connected:
            attr_value.error = ChannelAccessException('PV "%s" not connected' %
                                                      pv.pvname)
            return attr_value
        v = pv.value
        # type
        try:
            self.type = Dbr2TaurusType[pv.ftype]
        except KeyError:
            raise ValueError('Unsupported epics type "%s"' % pv.type)
        # writable
        self.writable = pv.write_access
        # data_format
        if numpy.isscalar(v):
            self.data_format = DataFormat._0D
        else:
            self.data_format = DataFormat(len(numpy.shape(v)))
        # units and limits support
        if self.type in (DataType.Integer, DataType.Float):
            v = Quantity(v, pv.units)
            self._range = self.__decode_limit(pv.lower_ctrl_limit,
                                              pv.upper_ctrl_limit)
            self._alarm = self.__decode_limit(pv.lower_alarm_limit,
                                              pv.upper_alarm_limit)
            self._warning = self.__decode_limit(pv.lower_warning_limit,
                                                pv.upper_warning_limit)

        # rvalue
        attr_value.rvalue = v
        # wvalue
        if pv.write_access:
            attr_value.wvalue = v
        # time
        if pv.timestamp is None:
            attr_value.time = TaurusTimeVal.now()
        else:
            attr_value.time = TaurusTimeVal.fromtimestamp(pv.timestamp)
        # quality
        if pv.severity > 0:
            attr_value.quality = AttrQuality.ATTR_ALARM
        else:
            attr_value.quality = AttrQuality.ATTR_VALID
        return attr_value
Пример #3
0
 def applyTransformation(self):
     if self._transformation is None:
         return
     try:
         evaluator = self.getParentObj()
         rvalue = evaluator.eval(self._transformation)
         value_dimension = len(numpy.shape(rvalue))
         value_dformat = DataFormat(value_dimension)
         self.data_format = value_dformat
         self.type = self._encodeType(rvalue, value_dformat)
         if self.type is None:
             raise TypeError("Unsupported returned type, %r" % rvalue)
         if self.type in [DataType.Integer, DataType.Float] and\
                 not isinstance(rvalue, Quantity):
             self.debug("Transformation converted to Quantity")
             rvalue = Quantity(rvalue)
         elif self.type == DataType.Boolean and value_dimension > 1:
             self.debug("Transformation converted to numpy.array")
             rvalue = numpy.array(rvalue)
         self._value.rvalue = rvalue
         self._value.time = TaurusTimeVal.now()
         self._value.quality = AttrQuality.ATTR_VALID
     except Exception, e:
         self._value.quality = AttrQuality.ATTR_INVALID
         msg = " the function '%s' could not be evaluated. Reason: %s" \
             % (self._transformation, repr(e))
         self.warning(msg)
Пример #4
0
 def applyTransformation(self):
     if self._transformation is None:
         return
     try:
         evaluator = self.getParentObj()
         rvalue = evaluator.eval(self._transformation)
         value_dimension = len(numpy.shape(rvalue))
         value_dformat = DataFormat(value_dimension)
         self.data_format = value_dformat
         self.type = self._encodeType(rvalue, value_dformat)
         if self.type is None:
             raise TypeError("Unsupported returned type, %r" % rvalue)
         if self.type in [DataType.Integer, DataType.Float] and\
                 not isinstance(rvalue, Quantity):
             self.debug("Transformation converted to Quantity")
             rvalue = Quantity(rvalue)
         elif self.type == DataType.Boolean and value_dimension > 1:
             self.debug("Transformation converted to numpy.array")
             rvalue = numpy.array(rvalue)
         self._value.rvalue = rvalue
         self._value.time = TaurusTimeVal.now()
         self._value.quality = AttrQuality.ATTR_VALID
     except Exception, e:
         self._value.quality = AttrQuality.ATTR_INVALID
         msg = " the function '%s' could not be evaluated. Reason: %s" \
             % (self._transformation, repr(e))
         self.warning(msg)
Пример #5
0
 def read(self, cache=True):
     if cache and self._last_value is not None:
         return self._last_value
     dev = self.getParentObj()
     # each time we need to open and close the file, otherwise the
     # file content is not updated
     with h5py.File(dev.filename) as h5file:
         data = h5file.get(self._attr_name)
         if data is None:
             msg = "Object %s does not exist" % self._attr_name
             raise TaurusException(msg)
         # we need to decode and copy the data while the file is still opened
         rvalue = self.decode(data)
     value = TaurusAttrValue()
     value.rvalue = rvalue
     value.time = TaurusTimeVal.now()
     self._last_value = value
     return value
Пример #6
0
    def read(self, cache=True):
        """Returns the value of the attribute.

        :param cache: (bool) If True (default), the last calculated value will
                      be returned. If False, the referenced values will be re-
                      read.
        :return: TaurusAttrValue
        """
        if cache and self._last_value is not None:
            return self._last_value

        dev = self.getParentObj()
        self.handler.setFilename(dev.filename)

        data_frame = self.handler.parseAttrName(self._attr_name)

        value = TaurusAttrValue()
        value.rvalue = self.decode(data_frame)
        value.time = TaurusTimeVal.now()
        self._last_value = value

        return value
Пример #7
0
 def applyTransformation(self):
     if self._transformation is None:
         return
     try:
         evaluator = self.getParentObj()
         rvalue = evaluator.eval(self._transformation)
         # ---------------------------------------------------------
         # Workaround for https://github.com/hgrecco/pint/issues/509
         # The numpy.shape method over a Quantity mutates
         # the type of its magnitude.
         # TODO: remove "if" when the bug is solved in pint
         if hasattr(rvalue, "magnitude"):
             value_dimension = len(numpy.shape(rvalue.magnitude))
         else:
             value_dimension = len(numpy.shape(rvalue))
         # ---------------------------------------------------------
         value_dformat = DataFormat(value_dimension)
         self.data_format = value_dformat
         self.type = self._encodeType(rvalue, value_dformat)
         if self.type is None:
             raise TypeError("Unsupported returned type, %r" % rvalue)
         if self.type in [DataType.Integer, DataType.Float] and\
                 not isinstance(rvalue, Quantity):
             self.debug("Transformation converted to Quantity")
             rvalue = Quantity(rvalue)
         elif self.type == DataType.Boolean and value_dimension > 1:
             self.debug("Transformation converted to numpy.array")
             rvalue = numpy.array(rvalue)
         self._value.rvalue = rvalue
         self._value.time = TaurusTimeVal.now()
         self._value.quality = AttrQuality.ATTR_VALID
     except Exception as e:
         self._value.quality = AttrQuality.ATTR_INVALID
         msg = " the function '%s' could not be evaluated. Reason: %s" \
             % (self._transformation, repr(e))
         self.warning(msg)
Пример #8
0
    def _read(self):
        reader = self.parent.getReader()
        data = reader.get_attribute_values(self._tg_attr_name,
                                    self._start_date,
                                    self._end_date,
                                    decimate=True)
        t = TaurusTimeVal().now()
        self.type = self.getType()
        if len(data) > 0:
            times, values = zip(*data)
            self._arch_values.rvalue = self.encode(values)
            self._arch_timestamps.rvalue = Q_(times, 's')
        else:
            self._arch_values.rvalue = np.array([])
            self._arch_timestamps.rvalue = np.array([])
        self._arch_values.time = t
        self._arch_timestamps.time = t

        if self._return_timestamps is True:
            v = self._arch_timestamps
        else:
            v = self._arch_values

        return v