Refactor input and output units

master
Dan Howe 6 years ago
parent 1c3ca1849a
commit 6e15b63087

@ -9,18 +9,18 @@ TIME_EXPONENT = 1 / 2
MASS_EXPONENT = 3
def _convert(x, length_scale_factor, from_unit, to_unit):
def _convert(x, length_scale_factor, input_unit, target_unit):
# Calculate unit conversion factor
from_unit = UREG(from_unit)
to_unit = UREG(to_unit)
unit_conversion_factor = from_unit.to(to_unit).magnitude
input_unit = UREG(input_unit)
target_unit = UREG(target_unit)
unit_conversion_factor = input_unit.to(target_unit).magnitude
# Calculate Froude scaling factor
froude_scale_factor = length_scale_factor**(
from_unit.dimensionality['[length]'] * LENGTH_EXPONENT +
from_unit.dimensionality['[time]'] * TIME_EXPONENT +
from_unit.dimensionality['[mass]'] * MASS_EXPONENT)
input_unit.dimensionality['[length]'] * LENGTH_EXPONENT +
input_unit.dimensionality['[time]'] * TIME_EXPONENT +
input_unit.dimensionality['[mass]'] * MASS_EXPONENT)
# Scale values
x_scaled = x * froude_scale_factor
@ -37,14 +37,14 @@ def _convert(x, length_scale_factor, from_unit, to_unit):
return x_scaled
def proto_to_model(x_proto, length_scale, from_unit, to_unit):
def proto_to_model(x_proto, length_scale, input_unit, target_unit):
"""Convert prototype value(s) to model value(s) in specified units.
Args:
x_proto: prototype values (array_like, or pandas dataframe)
length_scale: ratio between prototype and model dimensions (float)
from_unit (str): unit of input value(s)
to_unit (str): unit of output value(s)
x_proto: prototype values (array_like, or pandas dataframe)
length_scale: ratio between prototype and model dimensions (float)
input_unit: unit of input (string)
target_unit: unit of output (string)
Returns:
input values in model scale
@ -52,17 +52,17 @@ def proto_to_model(x_proto, length_scale, from_unit, to_unit):
length_scale_factor = 1 / length_scale
return _convert(x_proto, length_scale_factor, from_unit, to_unit)
return _convert(x_proto, length_scale_factor, input_unit, target_unit)
def model_to_proto(x_model, length_scale, from_unit, to_unit):
def model_to_proto(x_model, length_scale, input_unit, target_unit):
"""Convert model value(s) to prototype value(s) in specified units.
Args:
x_model: model values (array_like, or pandas dataframe)
length_scale: ratio between prototype and model dimensions (float)
from_unit (str): unit of input value(s)
to_unit (str): unit of output value(s)
x_model: model values (array_like, or pandas dataframe)
length_scale: ratio between prototype and model dimensions (float)
input_unit: unit of input (string)
target_unit: unit of output (string)
Returns:
input values in prototype scale
@ -70,14 +70,14 @@ 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)
return _convert(x_model, length_scale_factor, input_unit, target_unit)
def dimensions(unit):
"""Get unit dimensions.
Args:
unit (str): unit name or symbol
unit: unit name or symbol (string)
Returns:
string containing unit dimensions
@ -101,7 +101,7 @@ def scaling_exponent(unit):
"""Convert prototype value(s) to model value(s) in specified units.
Args:
unit (str): unit of quantity to be scaled
unit: unit of quantity to be scaled (string)
Returns:
scaling factor

Loading…
Cancel
Save