From 7405ccdd19d275d78cf9c67e3f992daa482c1e78 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Mon, 10 Sep 2018 19:04:28 +1000 Subject: [PATCH] Make Froude definitions into global variables --- scaling/froude.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scaling/froude.py b/scaling/froude.py index 6d17682..9b2fc68 100644 --- a/scaling/froude.py +++ b/scaling/froude.py @@ -1,26 +1,26 @@ import pint +# Initialise unit definitions +UREG = pint.UnitRegistry() + +# Define Froude scaling relationships +LENGTH_EXPONENT = 1 +TIME_EXPONENT = 1 / 2 +MASS_EXPONENT = 3 -def _convert(x, length_scale_factor, from_unit, to_unit): - # Initialise unit definitions - ureg = pint.UnitRegistry() +def _convert(x, length_scale_factor, from_unit, to_unit): # Calculate unit conversion factor - from_unit = ureg(from_unit) - to_unit = ureg(to_unit) + from_unit = UREG(from_unit) + to_unit = UREG(to_unit) unit_conversion_factor = from_unit.to(to_unit).magnitude - # Define Froude scaling relationships - froude_l_exponent = 1 - froude_t_exponent = 1 / 2 - froude_m_exponent = 3 - # Calculate Froude scaling factor froude_scale_factor = length_scale_factor**( - from_unit.dimensionality['[length]'] * froude_l_exponent + - from_unit.dimensionality['[time]'] * froude_t_exponent + - from_unit.dimensionality['[mass]'] * froude_m_exponent) + from_unit.dimensionality['[length]'] * LENGTH_EXPONENT + + from_unit.dimensionality['[time]'] * TIME_EXPONENT + + from_unit.dimensionality['[mass]'] * MASS_EXPONENT) # Scale values x_scaled = x * froude_scale_factor @@ -30,7 +30,7 @@ def _convert(x, length_scale_factor, from_unit, to_unit): # Scale time (dataframe or series only) try: - x_scaled.index *= length_scale_factor**froude_t_exponent + x_scaled.index *= length_scale_factor**TIME_EXPONENT except (AttributeError, TypeError): pass