Exemple #1
0
    def set_calibrators(self, parameter, calibrators):
        """
        Apply an ordered set of calibrators for the specified parameter.
        This replaces existing calibrators (if any).

        Each calibrator may have a context, which indicates when it its
        effects may be applied. Only the first matching calibrator is
        applied.

        A calibrator with context ``None`` is the *default* calibrator.
        There can be only one such calibrator, and is always applied at
        the end when no other contextual calibrator was applicable.

        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        :param .Calibrator[] calibrators: List of calibrators (either contextual or not)
        """
        req = mdb_pb2.ChangeParameterRequest()
        req.action = mdb_pb2.ChangeParameterRequest.SET_CALIBRATORS
        for c in calibrators:
            if c.context:
                context_calib = req.contextCalibrator.add()
                context_calib.context = rs.context
                calib_info = context_calib.calibrator
            else:
                calib_info = req.defaultCalibrator

            _add_calib(calib_info, c.type, c.data)

        url = '/mdb/{}/{}/parameters/{}'.format(self._instance,
                                                self._processor, parameter)
        response = self._client.post_proto(url, data=req.SerializeToString())
        pti = mdb_pb2.ParameterTypeInfo()
Exemple #2
0
    def reset_alarm_ranges(self, parameter):
        """
        Reset all alarm limits for the specified parameter to their original MDB value.
        """
        req = mdb_pb2.ChangeParameterRequest()
        req.action = mdb_pb2.ChangeParameterRequest.RESET_ALARMS

        url = '/mdb/{}/{}/parameters/{}'.format(self._instance,
                                                self._processor, parameter)
        response = self._client.post_proto(url, data=req.SerializeToString())
Exemple #3
0
 def reset_calibrators(self, parameter):
     """
     Reset all calibrators for the specified parameter to their original MDB value.
     """
     req = mdb_pb2.ChangeParameterRequest()
     req.action = mdb_pb2.ChangeParameterRequest.RESET_CALIBRATORS
     calib_info = req.defaultCalibrator
     url = '/mdb/{}/{}/parameters/{}'.format(self._instance,
                                             self._processor, parameter)
     response = self._client.post_proto(url, data=req.SerializeToString())
Exemple #4
0
    def set_default_alarm_ranges(self,
                                 parameter,
                                 watch=None,
                                 warning=None,
                                 distress=None,
                                 critical=None,
                                 severe=None,
                                 min_violations=1):
        """
        Generate out-of-limit alarms for a parameter using the specified
        alarm ranges.

        This replaces any previous default alarms on this parameter.

        .. note::

            Contextual range sets take precedence over the default alarm
            ranges. See :meth:`set_alarm_range_sets` for setting contextual
            range sets.

        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        :param (float,float) watch: Range expressed as a tuple ``(lo, hi)``
                                where lo and hi are assumed exclusive.
        :param (float,float) warning: Range expressed as a tuple ``(lo, hi)``
                                  where lo and hi are assumed exclusive.
        :param (float,float) distress: Range expressed as a tuple ``(lo, hi)``
                                   where lo and hi are assumed exclusive.
        :param (float,float) critical: Range expressed as a tuple ``(lo, hi)``
                                   where lo and hi are assumed exclusive.
        :param (float,float) severe: Range expressed as a tuple ``(lo, hi)``
                                 where lo and hi are assumed exclusive.
        :param int min_violations: Minimum violations before an alarm is
                                   generated.
        """
        req = mdb_pb2.ChangeParameterRequest()
        req.action = mdb_pb2.ChangeParameterRequest.SET_DEFAULT_ALARMS
        if watch or warning or distress or critical or severe:
            _add_alarms(req.defaultAlarm, watch, warning, distress, critical,
                        severe, min_violations)

        parameter = adapt_name_for_rest(parameter)
        url = '/mdb/{}/{}/parameters{}'.format(self._instance, self._processor,
                                               parameter)
        self._client.post_proto(url, data=req.SerializeToString())
Exemple #5
0
    def set_alarm_range_sets(self, parameter, sets):
        """
        Apply an ordered list of alarm range sets for the specified parameter.
        This replaces existing alarm sets (if any).

        Each RangeSet may have a context, which indicates when
        its effects may be applied. Only the first matching set is
        applied.

        A RangeSet with context ``None`` represents the *default* set of
        alarm ranges.  There can be only one such set, and it is always
        applied at the end when no other set of contextual ranges is
        applicable.

        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        :param .RangeSet[] sets: List of range sets (either contextual or not)
        """
        req = mdb_pb2.ChangeParameterRequest()
        req.action = mdb_pb2.ChangeParameterRequest.SET_ALARMS
        for rs in sets:
            if rs.context:
                context_alarm = req.contextAlarm.add()
                context_alarm.context = rs.context
                alarm_info = context_alarm.alarm
            else:
                alarm_info = req.defaultAlarm

            _add_alarms(alarm_info, rs.watch, rs.warning, rs.distress,
                        rs.critical, rs.severe, rs.min_violations)

        parameter = adapt_name_for_rest(parameter)
        url = '/mdb/{}/{}/parameters{}'.format(self._instance, self._processor,
                                               parameter)
        response = self._client.post_proto(url, data=req.SerializeToString())
        pti = mdb_pb2.ParameterTypeInfo()
        pti.ParseFromString(response.content)
        print(pti)
Exemple #6
0
    def set_default_calibrator(self, parameter, type, data):  # pylint: disable=W0622
        """
        Apply a calibrator while processing raw values of the specified
        parameter. If there is already a default calibrator associated
        to this parameter, that calibrator gets replaced.

        .. note::

            Contextual calibrators take precedence over the default calibrator
            See :meth:`set_calibrators` for setting contextual calibrators.

        Two types of calibrators can be applied:

        * Polynomial calibrators apply a polynomial expression of the form:
          `y = a + bx + cx^2 + ...`.

          The `data` argument must be an array of floats ``[a, b, c, ...]``.

        * Spline calibrators interpolate the raw value between a set of points
          which represent a linear curve.

          The `data` argument must be an array of ``[x, y]`` points.

        :param str parameter: Either a fully-qualified XTCE name or an alias
                              in the format ``NAMESPACE/NAME``.
        :param str type: One of ``polynomial`` or ``spline``.
        :param data: Calibration definition for the selected type.
        """
        req = mdb_pb2.ChangeParameterRequest()
        req.action = mdb_pb2.ChangeParameterRequest.SET_DEFAULT_CALIBRATOR
        if type:
            _add_calib(req.defaultCalibrator, type, data)

        parameter = adapt_name_for_rest(parameter)
        url = '/mdb/{}/{}/parameters{}'.format(self._instance, self._processor,
                                               parameter)
        self._client.post_proto(url, data=req.SerializeToString())