Add dimensions() function

master
Dan Howe 6 years ago
parent 7405ccdd19
commit 61ceb7f224

@ -71,3 +71,27 @@ def model_to_proto(x_model, length_scale, from_unit, to_unit):
length_scale_factor = length_scale
return _convert(x_model, length_scale_factor, from_unit, to_unit)
def dimensions(unit):
"""Get unit dimensions.
Args:
unit (str): unit name or symbol
Returns:
string containing unit dimensions
"""
# Get dimensions of unit
dims = UREG(unit).dimensionality
dim_data = {'L': '[length]', 'M': '[mass]', 'T': '[time]'}
s = ''
for symbol, key in dim_data.items():
exponent = dims[key]
if exponent != 0:
s += '{}^{:g} '.format(symbol, exponent)
return s.strip()

@ -9,3 +9,6 @@ def test_froude_length():
def test_froude_force():
assert froude.model_to_proto(1, 10, 'N', 'N') == 1000
def test_unit_dimensions():
assert froude.dimensions('N') == 'L^1 M^1 T^-2'

Loading…
Cancel
Save