autorange
autorange.py
Scales numerical values by powers of 1000 to present engineering notation. Also scales metric prefixes to match.
AutoRange
Bases: object
numeral
property
report scaling factor as multiplicative numeral
Returns:
Type | Description |
---|---|
|
__init__(rng, bias=0, kg_to_t=True, disallow_prefix=None)
creates an object for computing auto-ranged values. The input argument should be the largest value that is expected to appear in the context. It will be ranged to fall between 0-1000 (absolute value); this can be adjusted with the 'bias' param: one order per integer value up (pos) or down (neg)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng |
either a scalar (abs) or an iterable (max(abs)) |
required | |
bias |
[0] default range is 0-1000. bias=1: 10-10,000; bias=-1: 0.1-100; etc; floats are operable |
0
|
|
kg_to_t |
[True] correct kg to t in cases where the results are scaled up example: with kg_to_t = True, a unit of 'kg' autoranged to 'Mg' or larger will be converted to 't', 'Gg' to 'kt', etc, but a unit of 'kg' or smaller will not with kg_to_t False, no alteration is performed |
True
|
|
disallow_prefix |
preifx(es) to add to DISALLOW ('MT', 'mol', 'PM'). can be string or iterable. |
None
|
adj_unit(unit)
This is the tricky, ad-hoc part. Assume the first character in the unit string is a prefix IF it is found in the metric prefixes dictionary. If it is not, assume it is unprefixed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit |
a unit string |
required |
Returns:
Type | Description |
---|---|
|