Convert a quantity to this unit only in scale.
 @param [Phys::Quantity] quantity to be converted.
 @return [Phys::Quantity]
 @raise [UnitError] if unit conversion is failed.
558557
def convert_scale(quantity)
      if Quantity===quantity
        assert_same_dimension(quantity.unit)
        v = quantity.value * quantity.unit.conversion_factor
        v = v / self.conversion_factor
      else
        quantity / to_numeric
      end
    end
619900
def buy(self, quantity, **kwargs):
        
        self.parent.order("BUY", self, quantity=quantity, **kwargs)
1297148
def sub(self, quantity):
        
        newvalue = self._value - quantity
        self.set(newvalue.deg)
1084182
def flux_units(self, units):
        
        # Check that the units are valid
        dtypes = (q.core.PrefixUnit, q.quantity.Quantity, q.core.CompositeUnit)
        if not isinstance(units, dtypes):
            raise ValueError(units, "units not understood.")

        # Check that the units changed
        if units != self.flux_units:

            # Convert to new units
            sfd = q.spectral_density(self.wave_eff)
            self.zp = self.zp.to(units, equivalencies=sfd)

            # Store new units
            self._flux_units = units
715176
def convert(quantity)
      if Quantity===quantity
        assert_same_dimension(quantity.unit)
        v = quantity.unit.convert_value_to_base_unit(quantity.value)
        convert_value_from_base_unit(v)
      else
        quantity / to_numeric
      end
    end
2048
def _fix_quantities(tree):
    '''
    
    '''
    if isinstance(tree, dict):
        tree = {k: _fix_quantities(v) for k, v in tree.items()}
        if isinstance(tree.get('Items'), list):
            tree['Quantity'] = len(tree['Items'])
            if not tree['Items']:
                tree.pop('Items')  # Silly, but AWS requires it....
        return tree
    elif isinstance(tree, list):
        return [_fix_quantities(t) for t in tree]
    else:
        return tree
520836
def quantity(self):
        
        if not _has_astropy:
            raise ImportError("astropy must be installed for unit/quantity support")

        if self.unit is None:
            raise ValueError("unit is not set, cannot convert to quantity")

        return self.array * self.unit
460220
def scalar(magnitude = value)
      if special?
        unit.scalar(magnitude)
      else
        Number.rationalize(value) * Number.rationalize(unit.scalar)
      end
    end
200203
def convert(self, destination_units, *, convert_variables=False):
        
        if self.units is None and (destination_units is None or destination_units == "None"):
            return
        if not wt_units.is_valid_conversion(self.units, destination_units):
            valid = wt_units.get_valid_conversions(self.units)
            raise wt_exceptions.UnitsError(valid, destination_units)
        if convert_variables:
            for v in self.variables:
                v.convert(destination_units)
        self.units = destination_units
764566
def to_base_unit
      unit = @unit.base_unit
      val  = unit.convert(self)
      expr = unit.unit_string
      self.class.new( val, expr, unit )
    end
870268
def quantity=(quantity)
      if quantity.nil?
        fail ArgumentError, "quantity cannot be nil"
      end

      if quantity.to_s.length > 5
        fail ArgumentError, "invalid value for 'quantity', the character length must be smaller than or equal to 5."
      end

      if quantity.to_s.length < 1
        fail ArgumentError, "invalid value for 'quantity', the character length must be great than or equal to 1."
      end

      @quantity = quantity
    end
745513
def _validate_units(self, has_units, key, value):
        
        if has_units:
            if isinstance(self.test.units, dict):
                required_units = self.test.units[key]
            else:
                required_units = self.test.units
            if not isinstance(value, pq.quantity.Quantity):
                self._error(key, "Must be a python quantity")
            if not isinstance(value, pq.quantity.Quantity):
                self._error(key, "Must be a python quantity")
            provided_units = value.simplified.units
            if not isinstance(required_units, pq.Dimensionless):
                required_units = required_units.simplified.units
            if not required_units == provided_units:
                self._error(key,
                            "Must have units of '%s'" % self.test.units.name)
234087
def add(self, quantity):
        
        newvalue = self._value + quantity
        self.set(newvalue.deg)
1180795
def use_dimension
      return if @dim && @factor
      if @expr && @dim.nil?
        #puts "unit='#{@name}', parsing '#{@expr}'..." if Unit.debug
        unit = Unit.parse(@expr)
        case unit
        when Unit
          @dim = unit.dim
          @factor = unit.factor
          if @dim.nil? || @factor.nil?
            raise UnitError,"parse error : #{unit.inspect}"
          end
        when Numeric
          @factor = unit
          alloc_dim
        else
          raise UnitError,"parse error : #{self.inspect}"
        end
      else
        raise UnitError,"undefined unit?: #{self.inspect}"
      end
    end
1212198
def <<(item)
      item = ensure_type(Item, item)

      original_item = find_item(item)

      if original_item
        original_item.quantity += (item.quantity || 1)
      else
        store << item
      end
    end
243549
def assert_dimensionless(value):
    

    if isinstance(value, Quantity):
        value = value.simplified
        if value.dimensionality == Dimensionality({}):
            value = value.base.item()
        else:
            raise TypeError("Score value %s must be dimensionless" % value)
    return value
1009145
def value(self) -> Decimal:
        
        assert isinstance(self.price, Decimal)
        
        return self.quantity * self.price