to_si#
module wntr.epanet.util
- to_si(from_units, data, param, mass_units=MassUnits.mg, pressure_units=None, darcy_weisbach=False, reaction_order=0)[source]#
Convert an EPANET parameter from internal to SI standard units.
Note
See the Units page for details on the units for each
HydParam
orQualParam
. Other than for flows, most parameters only have one US and one metric unit that is used by EPANET. For example, even though flow might be specified in gallons, volumes would be specified in cubic feet for any US/English flow rates, and in cubic meters for all metric flow units; e.g., never liters for volumes even when flow is declared as LPS.Rememeber that internally, WNTR is always expecting the values for a parameter to be in true SI units – meters, kilograms, and seconds – unless explicitly stated otherwise (e.g., hours for control times).
- Parameters:
from_units (
FlowUnits
) – The EPANET flow units (and therefore units system) to use for conversionparam (
HydParam
orQualParam
) – The parameter type for the datamass_units (
MassUnits
, optional) – The EPANET mass units (mg or ug internal to EPANET)pressure_units (
PressureUnits
, optional) – The EPANET pressure units being used (based on flow_units, normally)darcy_weisbach (bool, optional) – For roughness coefficients, is this used in a Darcy-Weisbach formula?
reaction_order (int, optional) – For reaction coefficients, what is the reaction order?
- Returns:
The data values convert into SI standard units
- Return type:
Examples
First, we convert an array of flows from GPM to cubic meters per second (the SI units).
>>> from wntr.epanet.util import * >>> flow_si = to_si(FlowUnits.GPM, [0.1, 1.0, 4.3], HydParam.Flow) >>> print(flow_si) [6.309019640000001e-06, 6.30901964e-05, 0.00027128784452]
Next, we show how to convert the quality parameter from the EPANET units of mg/L to kg/m3. If that is not the mass units you prefer, it is possible to change them to ug/L, g/L, or kg/L, as shown in the second example.
>>> to_si(FlowUnits.GPM, 4.6, QualParam.Quality) 0.0046 >>> to_si(FlowUnits.GPM, 4.6, QualParam.Quality, mass_units=MassUnits.ug) 4.599999999999999e-06
It is also possible to convert a dictionary of values.
>>> to_si(FlowUnits.GPM, {'node1': 5.6, 'node2': 1.2}, HydParam.Pressure) {'node1': 3.9392568659127623, 'node2': 0.8441264712670206}
For certain coefficients, there are flags that will change how the conversion occurs. For example, reaction coefficients depend on the reaction order.
>>> to_si(FlowUnits.GPM, 0.45, QualParam.BulkReactionCoeff, reaction_order=0) 0.45 >>> to_si(FlowUnits.GPM, 0.45, QualParam.BulkReactionCoeff, reaction_order=1) 5.208333333333333e-06