from_si#

module wntr.epanet.util

from_si(to_units, data, param, mass_units=MassUnits.mg, pressure_units=None, darcy_weisbach=False, reaction_order=0)[source]#

Convert an EPANET parameter from SI standard units back to internal units.

Note

See the Units page for details on the units for each HydParam or QualParam. 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:
  • to_units (FlowUnits) – The EPANET flow units (and therefore units system) to use for conversion

  • data (float, array-like, dict) – The data to be converted

  • param (HydParam or QualParam) – The parameter type for the data

  • mass_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 converted into EPANET internal units

Return type:

float, array-like, or dict

Examples

First, we convert an array of flows from SI (cubic meters per second) to GPM.

>>> from wntr.epanet.util import *
>>> flow_us = from_si(FlowUnits.GPM, [6.309019640000001e-06, 6.30901964e-05, 0.00027128784452], HydParam.Flow)
>>> print(flow_us)
[0.1, 1.0, 4.3]

Next, we show how to convert the quality parameter from kg/m3 to mg/L and then to ug/L.

>>> from_si(FlowUnits.GPM, 0.0046, QualParam.Quality)
4.6
>>> from_si(FlowUnits.GPM, 0.0046, QualParam.Quality, mass_units=MassUnits.ug)
4600.0

It is also possible to convert a dictionary of values.

>>> from_si(FlowUnits.GPM, {'node1': 3.9392568659127623, 'node2': 0.8441264712670206}, HydParam.Pressure)
{'node1': 5.6, 'node2': 1.2}

Finally, an example showing the conversion of 1000 cubic meters per second into the different flow units.

>>> from_si(FlowUnits.GPM, 1000.0, HydParam.Flow)  # to gallons per minute
15850323.141488904
>>> from_si(FlowUnits.LPS, 1000.0, HydParam.Flow)  # to liters per second
1000000.0
>>> from_si(FlowUnits.MGD, 1000.0, HydParam.Flow)  # to million gallons per day
22824.465323744018