exerpy.units

Units of the values in ExerPy’s input, converted to SI with pint.

A value is stored next to its unit, as "T": 15.0, "T_unit": "degC". Before an analysis, every key of SI_UNITS is converted to its SI unit, wherever it appears: in the ambient conditions, in a connection, in a component, its parameters or its exergy_results, and in the system_results. A value without a unit is taken as SI. Keys ExerPy does not read keep their value and unit. An export writes the unit of every value, in SI or in the units asked for.

Units are read by pint, e.g. "degC", "bar", "kJ / kg", "t / h" or "kilogram / second"; "m2", "m3", "kgK" and "-" are understood as well, and so are the spellings of the simulators, e.g. "C", "kJ/kg-K" or "cum/sec". convert_to_SI() converts a value a simulator reports to the SI unit of its key. convert() converts a value between any two units, convert_cost() a cost in the currency of an exergoeconomic analysis.

exerpy.units.SI_UNITS = {'A': 'm2', 'E': 'W', 'E_CH': 'W', 'E_D': 'W', 'E_F': 'W', 'E_L': 'W', 'E_M': 'W', 'E_P': 'W', 'E_PH': 'W', 'E_T': 'W', 'P': 'W', 'Q': 'W', 'QEFF': 'W', 'Q_Solar': 'W', 'RQINC': 'W', 'T': 'K', 'T_cold': 'K', 'T_hot': 'K', 'Tamb': 'K', 'VM': 'm3 / s', 'e_CH': 'J / kg', 'e_M': 'J / kg', 'e_PH': 'J / kg', 'e_T': 'J / kg', 'energy_flow': 'W', 'epsilon': 'dimensionless', 'eta_cc': 'dimensionless', 'eta_el': 'dimensionless', 'eta_mech': 'dimensionless', 'eta_s': 'dimensionless', 'h': 'J / kg', 'kA': 'W / K', 'lamb': 'dimensionless', 'm': 'kg / s', 'n': 'mol / s', 'p': 'Pa', 'pamb': 'Pa', 's': 'J / kgK', 'v': 'm3 / s', 'x': 'dimensionless', 'y': 'dimensionless', 'y_star': 'dimensionless'}

SI unit of each key ExerPy reads or writes.

exerpy.units.add_units(data)[source]

Return a copy of a document in SI units in which every value of SI_UNITS has its unit.

exerpy.units.check_unit(unit, to_unit)[source]

Raise ValueError if unit is not a string, unknown or not convertible to to_unit.

exerpy.units.convert(value, from_unit, to_unit)[source]

Convert value from from_unit to to_unit; raise ValueError for a bad unit.

>>> round(convert(15.0, "degC", "K"), 2), convert(2e5, "Pa", "bar")
(288.15, 2.0)
exerpy.units.convert_cost(value, from_unit, to_unit, currency)[source]

Convert a cost between two units in currency, e.g. from "EUR / MWh" to "EUR / GJ".

Only the part per time or per energy is converted, never one currency into another. A cost per day or longer is not converted, since a cost rate per operating hour depends on the operating hours.

>>> convert_cost(36.0, "EUR / MWh", "EUR / GJ", "EUR")
10.0
exerpy.units.convert_to_SI(key, value, unit)[source]

Convert a value a simulator reports in unit to the SI unit of key, see SI_UNITS.

None stays None. A value whose unit the simulator does not report ("Unknown") is returned as it is, with a warning.

>>> convert_to_SI("T", 15.0, "C"), convert_to_SI("s", 1.0, "kJ/kg-K")
(288.15, 1000.0)
exerpy.units.entries(data)[source]

Yield every dictionary of values in a document, with its JSONPath-like path.

exerpy.units.from_SI(data, units)[source]

Return a copy of a document in SI units with the keys of units in the units given.

Parameters:
  • data (dict) – A document in SI units, as exerpy.ExergyAnalysis.export_to_json() writes it.

  • units (dict) – Unit of each key, e.g. {"T": "degC", "p": "bar", "E_D": "kW"}; the keys are those of SI_UNITS.

Raises:

ValueError – If a key has no SI unit, or a unit is unknown or of the wrong kind.

exerpy.units.registry()[source]

The pint unit registry, created on first use.

exerpy.units.to_SI(data)[source]

Return a copy of an input document with the values of SI_UNITS in SI units.

Returns:

tuple – The converted document and a list of (path, message) for every unit that is unknown or of the wrong kind.