def modify(self, symbol, base_value): """ Change the base value of a unit symbol. Useful for adjusting code units after parsing parameters. Parameters ---------- symbol : str The name of the symbol to modify base_value : float The new base_value for the symbol. """ self._unit_system_id = None if symbol not in self.lut: raise SymbolNotFoundError( "Tried to modify the symbol '%s', but it does not exist " "in this registry." % symbol ) if hasattr(base_value, "in_base"): new_dimensions = base_value.units.dimensions base_value = base_value.in_base("mks") base_value = base_value.value else: new_dimensions = self.lut[symbol][1] self.lut[symbol] = (float(base_value), new_dimensions) + self.lut[symbol][2:]
def __getitem__(self, key): try: ret = self.lut[key] except KeyError: raise SymbolNotFoundError( "The symbol '%s' does not exist in this registry." % key) return ret
def __getitem__(self, key): try: ret = self.lut[str(key)] except KeyError: try: _lookup_unit_symbol(str(key), self.lut) ret = self.lut[str(key)] except UnitParseError: raise SymbolNotFoundError( "The symbol '%s' does not exist in this registry." % key) return ret
def remove(self, symbol): """ Remove the entry for the unit matching `symbol`. """ self._unit_system_id = None if symbol not in self.lut: raise SymbolNotFoundError( "Tried to remove the symbol '%s', but it does not exist " "in this registry." % symbol) del self.lut[symbol]