How to use the quantities.dimensionality.Dimensionality function in quantities

To help you get started, we’ve selected a few quantities examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-quantities / python-quantities / quantities / dimensionality.py View on Github external
def __div__(self, other):
            assert_isinstance(other, Dimensionality)
            return self.__truediv__(other)
github python-quantities / python-quantities / quantities / dimensionality.py View on Github external
def __pow__(self, other):
        try:
            assert np.isscalar(other)
        except AssertionError:
            raise TypeError('exponent must be a scalar, got %r' % other)
        if other == 0:
            return Dimensionality()
        new = Dimensionality(self)
        for i in new:
            new[i] *= other
        return new
github python-quantities / python-quantities / quantities / dimensionality.py View on Github external
def __truediv__(self, other):
        assert_isinstance(other, Dimensionality)
        new = Dimensionality(self)
        for unit, power in other.items():
            try:
                new[unit] -= power
                if new[unit] == 0:
                    new.pop(unit)
            except KeyError:
                new[unit] = -power
        return new
github python-quantities / python-quantities / quantities / dimensionality.py View on Github external
def __itruediv__(self, other):
        assert_isinstance(other, Dimensionality)
        for unit, power in other.items():
            try:
                self[unit] -= power
                if self[unit] == 0:
                    self.pop(unit)
            except KeyError:
                self[unit] = -power
        return self
github python-quantities / python-quantities / quantities / dimensionality.py View on Github external
def _d_trig(q1, out=None):
    try:
        assert q1.units == unit_registry['radian']
    except AssertionError:
        raise ValueError(
            'expected units of radians, got "%s"' % q1._dimensionality
        )
    return Dimensionality()
p_dict[np.sin] = _d_trig
github python-quantities / python-quantities / quantities / dimensionality.py View on Github external
def __pow__(self, other):
        try:
            assert np.isscalar(other)
        except AssertionError:
            raise TypeError('exponent must be a scalar, got %r' % other)
        if other == 0:
            return Dimensionality()
        new = Dimensionality(self)
        for i in new:
            new[i] *= other
        return new
github python-quantities / python-quantities / quantities / quantity.py View on Github external
def __array_finalize__(self, obj):
        self._dimensionality = getattr(obj, 'dimensionality', Dimensionality())
github scidash / sciunit / sciunit / comparators.py View on Github external
def dimensionless(value):
    """Test for dimensionlessness of input."""
    if type(value) is Quantity:
        if value.dimensionality == Dimensionality({}):
            value = value.base.item()
        else:
            raise TypeError("Score value %s must be dimensionless" % value)
    return value