Exemplo n.º 1
0
    def _set_link(self, link):
        if link is not None:
            if self._alwaysfrozen:
                raise ParameterErr('frozennolink', self.fullname)
            if not isinstance(link, Parameter):
                raise ParameterErr('notlink')

            # Short cycles produce error
            # e.g. par = 2*par+3
            if self in link:
                raise ParameterErr('linkcycle')

            # Correctly test for link cycles in long trees.
            cycle = False
            ll = link
            while isinstance(ll, Parameter):
                if ll == self or self in ll:
                    cycle = True
                ll = ll.link

            # Long cycles are overwritten BUG #12287
            if cycle and isinstance(link, Parameter):
                link.link = None

        self._link = link
Exemplo n.º 2
0
    def _set_limit(self, val):
        val = SherpaFloat(val)
        # Ensure that we don't try to set any value that is outside
        # the hard parameter limits.
        if val < self._hard_min:
            raise ParameterErr('edge', self.fullname,
                               'hard minimum', self._hard_min)
        if val > self._hard_max:
            raise ParameterErr('edge', self.fullname,
                               'hard maximum', self._hard_max)

        # Ensure that we don't try to set a parameter range, such that
        # the minimum will be greater than the current parameter value,
        # or that the maximum will be less than the current parameter value.

        # But we only want to do this check *after* parameter has been
        # created and fully initialized; we are doing this check some time
        # *later*, when the user is trying to reset a parameter range
        # such that the new range will leave the current value
        # *outside* the new range.  We want to warn against and disallow that.

        # Due to complaints about having to rewrite existing user scripts,
        # downgrade the ParameterErr issued here to mere warnings.  Also,
        # set the value to the appropriate soft limit.
        if hasattr(self, "_NoNewAttributesAfterInit__initialized") and \
           self._NoNewAttributesAfterInit__initialized:
            if name == "_min" and (val > self.val):
                self.val = val
                warning(('parameter %s less than new minimum; %s reset to %g') % (self.fullname, self.fullname, self.val))
            if name == "_max" and (val < self.val):
                self.val = val
                warning(('parameter %s greater than new maximum; %s reset to %g') % (self.fullname, self.fullname, self.val))

        setattr(self, name, val)
Exemplo n.º 3
0
    def _get_val(self):
        if hasattr(self, 'eval'):
            return self.eval()
        if self.link is None:
            return self._val

        val = self.link.val
        if val < self.min:
            raise ParameterErr('edge', self.fullname, 'minimum', self.min)
        if val > self.max:
            raise ParameterErr('edge', self.fullname, 'maximum', self.max)

        return val
Exemplo n.º 4
0
    def _set_default_val(self, default_val):
        if isinstance(default_val, Parameter):
            self.link = default_val
        else:
            # Reset link
            self.link = None

            # Validate new value
            default_val = SherpaFloat(default_val)
            if default_val < self.min:
                raise ParameterErr('edge', self.fullname, 'minimum', self.min)
            if default_val > self.max:
                raise ParameterErr('edge', self.fullname, 'maximum', self.max)

            self._default_val = default_val
Exemplo n.º 5
0
 def _set_frozen(self, val):
     val = bool(val)
     if self._alwaysfrozen and (not val):
         raise ParameterErr('alwaysfrozen', self.fullname)
     self._frozen = val