UnitsStringManager
- class PlasmaCalcs.units.units_manager.UnitsStringManager
Bases:
dictmanages string of units; keys are unit symbol bases, values are exponents.
Methods
__eq__(other)tells whether self equals another UnitsStringManager.
__mul__(other)multiply self by other UnitsStringManager; adds values where keys match.
__pow__(exp)raise self to exponent; multiplies each value in self by exp.
__str__()convert self into units string.
clean()return result of deleting all keys with value == 0.
clear()copy()return copy of self.
evaluate(values_dict)evaluates self based on values_dict, returning a numerical value.
evaluate_iteratively(values_dict)evaluates all the parts of self which can be evaluated based on values_dict,
evaluate_partial(values_dict)evaluates all the parts of self which can be evaluated based on values_dict.
expand(*[, bases, known])returns result of expanding repeatedly until all keys are si base units.
expand_once(*[, bases, known])returns result of replacing all keys other than bases with their known conversions.
from_string(string_of_units, *[, bases, known])new UnitsStringManager from a string of units; just gets the symbols & exponents.
fromkeys([value])Create a new dictionary with keys from iterable and values set to value.
get(key[, default])Return the value for key if key is in the dictionary, else default.
items()keys()pop(k[,d])If key is not found, default is returned if given, otherwise KeyError is raised
popitem()Remove and return a (key, value) pair as a 2-tuple.
setdefault(key[, default])Insert key with a value of default if key is not in the dictionary.
update([E, ]**F)If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
values()_get_bases_and_known([bases, known])return bases & known, using value from self if None is entered
_new(dict_)create new instance of self given this dict.
Attributes
basesknown- __eq__(other)
tells whether self equals another UnitsStringManager.
- __mul__(other)
multiply self by other UnitsStringManager; adds values where keys match.
- __pow__(exp)
raise self to exponent; multiplies each value in self by exp.
- __str__()
convert self into units string.
- _get_bases_and_known(bases=None, known=None)
return bases & known, using value from self if None is entered
- _new(dict_)
create new instance of self given this dict.
- clean()
return result of deleting all keys with value == 0.
- clear() None. Remove all items from D.
- copy()
return copy of self.
- evaluate(values_dict)
evaluates self based on values_dict, returning a numerical value.
if any units are not in values_dict, raises UnitsError.Equivalent to self.evaluate_partial(values_dict)[0], when all units are in values_dict.
- evaluate_iteratively(values_dict)
evaluates all the parts of self which can be evaluated based on values_dict,
and also calling result[1].expand_once() after each incomplete evaluation attempt.returns numerical value.raises UnitsError if any units are not in values_dict after expanding as many times as possible.
- evaluate_partial(values_dict)
evaluates all the parts of self which can be evaluated based on values_dict.
returns (numerical value, UnitsStringManager with still-unevaluated units)if no keys in self are also in values_dict, result[0] will be 1.if all keys in self are also in values_dict, len(result[1]) will be 0.if values_dict provides any relevant key with value None, returns (None, {})
- expand(*, bases=None, known=None)
returns result of expanding repeatedly until all keys are si base units.
- expand_once(*, bases=None, known=None)
returns result of replacing all keys other than bases with their known conversions.
- classmethod from_string(string_of_units, *, bases=None, known=None)
new UnitsStringManager from a string of units; just gets the symbols & exponents.
- fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- pop(k[, d]) v, remove specified key and return the corresponding value.
If key is not found, default is returned if given, otherwise KeyError is raised
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order.
Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from dict/iterable E and F.
If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = vIn either case, this is followed by: for k in F: D[k] = F[k]
- values() an object providing a view on D's values