Index
frequenz.quantities ¤
Types for holding quantities with units.
This library provide types for holding quantities with units. The main goal is to avoid mistakes while working with different types of quantities, for example avoiding adding a length to a time.
It also prevents mistakes when operating between the same quantity but in different units, like adding a power in Joules to a power in Watts without converting one of them.
Quantities store the value in a base unit, and then provide methods to get that quantity
as a particular unit. They can only be constructed using special constructors with the
form Quantity.from_<unit>
, for example
Power.from_watts(10.0)
.
Internally quantities store values as float
s, so regular float issues and limitations
apply, although some of them are
tried to be mitigated.
Quantities are also immutable, so operations between quantities return a new instance of the quantity.
This library provides the following types:
- Current: A quantity representing an electric current.
- Energy: A quantity representing energy.
- Frequency: A quantity representing frequency.
- Percentage: A quantity representing a percentage.
- Power: A quantity representing power.
- Temperature: A quantity representing temperature.
- Voltage: A quantity representing electric voltage.
Additionally, for each of those types, there is a corresponding marshmallow field that can be used to serialize and deserialize the quantities using the QuantitySchema schema.
There is also the unitless Quantity class. All
quantities are subclasses of this class and it can be used as a base to create new
quantities. Using the Quantity
class directly is discouraged, as it doesn't provide
any unit conversion methods.
Example
from datetime import timedelta
from frequenz.quantities import Power, Voltage, Current, Energy
# Create a power quantity
power = Power.from_watts(230.0)
# Printing uses a unit to make the string as short as possible
print(f"Power: {power}") # Power: 230.0 W
# The precision can be changed
print(f"Power: {power:0.3}") # Power: 230.000 W
# The conversion methods can be used to get the value in a particular unit
print(f"Power in MW: {power.as_megawatt()}") # Power in MW: 0.00023 MW
# Create a voltage quantity
voltage = Voltage.from_volts(230.0)
# Calculate the current
current = power / voltage
assert isinstance(current, Current)
print(f"Current: {current}") # Current: 1.0 A
assert current.isclose(Current.from_amperes(1.0))
# Calculate the energy
energy = power * timedelta(hours=1)
assert isinstance(energy, Energy)
print(f"Energy: {energy}") # Energy: 230.0 Wh
print(f"Energy in kWh: {energy.as_kilowatt_hours()}") # Energy in kWh: 0.23
# Invalid operations are not permitted
# (when using a type hinting linter like mypy, this will be caught at linting time)
try:
power + voltage
except TypeError as e:
print(f"Error: {e}") # Error: unsupported operand type(s) for +: 'Power' and 'Voltage'
Classes¤
frequenz.quantities.ApparentPower ¤
Bases: Quantity
A apparent power quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in frequenz/quantities/_apparent_power.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
Attributes¤
base_unit
property
¤
base_unit: str | None
Return the base unit of this quantity.
None if this quantity has no unit.
RETURNS | DESCRIPTION |
---|---|
str | None
|
The base unit of this quantity. |
base_value
property
¤
base_value: float
Return the value of this quantity in the base unit.
RETURNS | DESCRIPTION |
---|---|
float
|
The value of this quantity in the base unit. |
Functions¤
__abs__ ¤
__abs__() -> Self
Return the absolute value of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The absolute value of this quantity. |
Source code in frequenz/quantities/_quantity.py
__add__ ¤
Return the sum of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The sum of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__eq__ ¤
Return whether this quantity is equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is equal to another. |
Source code in frequenz/quantities/_quantity.py
__format__ ¤
Return a formatted string representation of this quantity.
If specified, must be of this form: [0].{precision}
. If a 0 is not given, the
trailing zeros will be omitted. If no precision is given, the default is 3.
The returned string will use the unit that will result in the maximum precision, based on the magnitude of the value.
Example
PARAMETER | DESCRIPTION |
---|---|
__format_spec
|
The format specifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given format specifier is invalid. |
Source code in frequenz/quantities/_quantity.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__ge__ ¤
Return whether this quantity is greater than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__gt__ ¤
__init__ ¤
__init_subclass__ ¤
Initialize a new subclass of Quantity.
PARAMETER | DESCRIPTION |
---|---|
exponent_unit_map
|
A mapping from the exponent of the base unit to the unit symbol. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given exponent_unit_map does not contain a base unit (exponent 0). |
Source code in frequenz/quantities/_quantity.py
__le__ ¤
Return whether this quantity is less than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__lt__ ¤
__mod__ ¤
__mul__ ¤
__mul__(percent: Percentage) -> Self
__mul__(other: float | Percentage) -> Self
Return a power or energy from multiplying this power by the given value.
PARAMETER | DESCRIPTION |
---|---|
other
|
The scalar, percentage or duration to multiply by.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A power or energy. |
Source code in frequenz/quantities/_apparent_power.py
__neg__ ¤
__neg__() -> Self
Return the negation of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The negation of this quantity. |
__repr__ ¤
__repr__() -> str
Return a representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A representation of this quantity. |
__round__ ¤
__str__ ¤
__str__() -> str
Return a string representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
__sub__ ¤
Return the difference of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The difference of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__truediv__ ¤
Return a current or voltage from dividing this power by the given value.
PARAMETER | DESCRIPTION |
---|---|
other
|
The scalar, power, current or voltage to divide by. |
RETURNS | DESCRIPTION |
---|---|
Self | float | Voltage | Current
|
A current or voltage from dividing this power by the given value. |
Source code in frequenz/quantities/_apparent_power.py
as_kilo_volt_amperes ¤
as_kilo_volt_amperes() -> float
Return the apparent power in kilovolt-amperes (kVA).
RETURNS | DESCRIPTION |
---|---|
float
|
The apparent power in kilovolt-amperes (kVA). |
as_mega_volt_amperes ¤
as_mega_volt_amperes() -> float
Return the apparent power in megavolt-amperes (MVA).
RETURNS | DESCRIPTION |
---|---|
float
|
The apparent power in megavolt-amperes (MVA). |
as_milli_volt_amperes ¤
as_milli_volt_amperes() -> float
Return the apparent power in millivolt-amperes (mVA).
RETURNS | DESCRIPTION |
---|---|
float
|
The apparent power in millivolt-amperes (mVA). |
as_volt_amperes ¤
as_volt_amperes() -> float
Return the apparent power in volt-amperes (VA).
RETURNS | DESCRIPTION |
---|---|
float
|
The apparent power in volt-amperes (VA). |
from_kilo_volt_amperes
classmethod
¤
from_mega_volt_amperes
classmethod
¤
from_milli_volt_amperes
classmethod
¤
from_string
classmethod
¤
Return a quantity from a string representation.
PARAMETER | DESCRIPTION |
---|---|
string
|
The string representation of the quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A quantity object with the value given in the string. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the string does not match the expected format. |
Source code in frequenz/quantities/_quantity.py
from_volt_amperes
classmethod
¤
isclose ¤
Return whether this quantity is close to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The quantity to compare to.
TYPE:
|
rel_tol
|
The relative tolerance.
TYPE:
|
abs_tol
|
The absolute tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is close to another. |
Source code in frequenz/quantities/_quantity.py
isinf ¤
isinf() -> bool
Return whether this quantity is infinite.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is infinite. |
isnan ¤
isnan() -> bool
Return whether this quantity is NaN.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is NaN. |
frequenz.quantities.Current ¤
Bases: Quantity
A current quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in frequenz/quantities/_current.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
Attributes¤
base_unit
property
¤
base_unit: str | None
Return the base unit of this quantity.
None if this quantity has no unit.
RETURNS | DESCRIPTION |
---|---|
str | None
|
The base unit of this quantity. |
base_value
property
¤
base_value: float
Return the value of this quantity in the base unit.
RETURNS | DESCRIPTION |
---|---|
float
|
The value of this quantity in the base unit. |
Functions¤
__abs__ ¤
__abs__() -> Self
Return the absolute value of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The absolute value of this quantity. |
Source code in frequenz/quantities/_quantity.py
__add__ ¤
Return the sum of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The sum of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__eq__ ¤
Return whether this quantity is equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is equal to another. |
Source code in frequenz/quantities/_quantity.py
__format__ ¤
Return a formatted string representation of this quantity.
If specified, must be of this form: [0].{precision}
. If a 0 is not given, the
trailing zeros will be omitted. If no precision is given, the default is 3.
The returned string will use the unit that will result in the maximum precision, based on the magnitude of the value.
Example
PARAMETER | DESCRIPTION |
---|---|
__format_spec
|
The format specifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given format specifier is invalid. |
Source code in frequenz/quantities/_quantity.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__ge__ ¤
Return whether this quantity is greater than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__gt__ ¤
__init__ ¤
__init_subclass__ ¤
Initialize a new subclass of Quantity.
PARAMETER | DESCRIPTION |
---|---|
exponent_unit_map
|
A mapping from the exponent of the base unit to the unit symbol. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given exponent_unit_map does not contain a base unit (exponent 0). |
Source code in frequenz/quantities/_quantity.py
__le__ ¤
Return whether this quantity is less than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__lt__ ¤
__mod__ ¤
__mul__ ¤
__mul__(percent: Percentage) -> Self
__mul__(
other: float | Percentage | Voltage,
) -> Self | Power
Return a current or power from multiplying this current by the given value.
PARAMETER | DESCRIPTION |
---|---|
other
|
The scalar, percentage or voltage to multiply by.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self | Power
|
A current or power. |
Source code in frequenz/quantities/_current.py
__neg__ ¤
__neg__() -> Self
Return the negation of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The negation of this quantity. |
__repr__ ¤
__repr__() -> str
Return a representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A representation of this quantity. |
__round__ ¤
__str__ ¤
__str__() -> str
Return a string representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
__sub__ ¤
Return the difference of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The difference of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__truediv__ ¤
Divide this quantity by a scalar or another quantity.
PARAMETER | DESCRIPTION |
---|---|
value
|
The scalar or quantity to divide this quantity by. |
RETURNS | DESCRIPTION |
---|---|
Self | float
|
The divided quantity or the ratio of this quantity to another. |
Source code in frequenz/quantities/_quantity.py
as_milliamperes ¤
as_milliamperes() -> float
Return the current in milliamperes.
RETURNS | DESCRIPTION |
---|---|
float
|
The current in milliamperes. |
from_amperes
classmethod
¤
from_milliamperes
classmethod
¤
from_string
classmethod
¤
Return a quantity from a string representation.
PARAMETER | DESCRIPTION |
---|---|
string
|
The string representation of the quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A quantity object with the value given in the string. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the string does not match the expected format. |
Source code in frequenz/quantities/_quantity.py
isclose ¤
Return whether this quantity is close to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The quantity to compare to.
TYPE:
|
rel_tol
|
The relative tolerance.
TYPE:
|
abs_tol
|
The absolute tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is close to another. |
Source code in frequenz/quantities/_quantity.py
isinf ¤
isinf() -> bool
Return whether this quantity is infinite.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is infinite. |
isnan ¤
isnan() -> bool
Return whether this quantity is NaN.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is NaN. |
frequenz.quantities.Energy ¤
Bases: Quantity
An energy quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in frequenz/quantities/_energy.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
|
Attributes¤
base_unit
property
¤
base_unit: str | None
Return the base unit of this quantity.
None if this quantity has no unit.
RETURNS | DESCRIPTION |
---|---|
str | None
|
The base unit of this quantity. |
base_value
property
¤
base_value: float
Return the value of this quantity in the base unit.
RETURNS | DESCRIPTION |
---|---|
float
|
The value of this quantity in the base unit. |
Functions¤
__abs__ ¤
__abs__() -> Self
Return the absolute value of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The absolute value of this quantity. |
Source code in frequenz/quantities/_quantity.py
__add__ ¤
Return the sum of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The sum of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__eq__ ¤
Return whether this quantity is equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is equal to another. |
Source code in frequenz/quantities/_quantity.py
__format__ ¤
Return a formatted string representation of this quantity.
If specified, must be of this form: [0].{precision}
. If a 0 is not given, the
trailing zeros will be omitted. If no precision is given, the default is 3.
The returned string will use the unit that will result in the maximum precision, based on the magnitude of the value.
Example
PARAMETER | DESCRIPTION |
---|---|
__format_spec
|
The format specifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given format specifier is invalid. |
Source code in frequenz/quantities/_quantity.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__ge__ ¤
Return whether this quantity is greater than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__gt__ ¤
__init__ ¤
__init_subclass__ ¤
Initialize a new subclass of Quantity.
PARAMETER | DESCRIPTION |
---|---|
exponent_unit_map
|
A mapping from the exponent of the base unit to the unit symbol. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given exponent_unit_map does not contain a base unit (exponent 0). |
Source code in frequenz/quantities/_quantity.py
__le__ ¤
Return whether this quantity is less than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__lt__ ¤
__mod__ ¤
__mul__ ¤
__mul__(other: float | Percentage) -> Self
Scale this energy by a percentage.
PARAMETER | DESCRIPTION |
---|---|
other
|
The percentage by which to scale this energy.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The scaled energy. |
Source code in frequenz/quantities/_energy.py
__neg__ ¤
__neg__() -> Self
Return the negation of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The negation of this quantity. |
__repr__ ¤
__repr__() -> str
Return a representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A representation of this quantity. |
__round__ ¤
__str__ ¤
__str__() -> str
Return a string representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
__sub__ ¤
Return the difference of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The difference of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__truediv__ ¤
Return a power or duration from dividing this energy by the given value.
PARAMETER | DESCRIPTION |
---|---|
other
|
The scalar, energy, power or duration to divide by. |
RETURNS | DESCRIPTION |
---|---|
Self | float | Power | timedelta
|
A power or duration from dividing this energy by the given value. |
Source code in frequenz/quantities/_energy.py
as_kilowatt_hours ¤
as_kilowatt_hours() -> float
Return the energy in kilowatt hours.
RETURNS | DESCRIPTION |
---|---|
float
|
The energy in kilowatt hours. |
as_megawatt_hours ¤
as_megawatt_hours() -> float
Return the energy in megawatt hours.
RETURNS | DESCRIPTION |
---|---|
float
|
The energy in megawatt hours. |
from_kilowatt_hours
classmethod
¤
from_megawatt_hours
classmethod
¤
from_string
classmethod
¤
Return a quantity from a string representation.
PARAMETER | DESCRIPTION |
---|---|
string
|
The string representation of the quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A quantity object with the value given in the string. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the string does not match the expected format. |
Source code in frequenz/quantities/_quantity.py
from_watt_hours
classmethod
¤
isclose ¤
Return whether this quantity is close to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The quantity to compare to.
TYPE:
|
rel_tol
|
The relative tolerance.
TYPE:
|
abs_tol
|
The absolute tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is close to another. |
Source code in frequenz/quantities/_quantity.py
isinf ¤
isinf() -> bool
Return whether this quantity is infinite.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is infinite. |
isnan ¤
isnan() -> bool
Return whether this quantity is NaN.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is NaN. |
frequenz.quantities.Frequency ¤
Bases: Quantity
A frequency quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in frequenz/quantities/_frequency.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
Attributes¤
base_unit
property
¤
base_unit: str | None
Return the base unit of this quantity.
None if this quantity has no unit.
RETURNS | DESCRIPTION |
---|---|
str | None
|
The base unit of this quantity. |
base_value
property
¤
base_value: float
Return the value of this quantity in the base unit.
RETURNS | DESCRIPTION |
---|---|
float
|
The value of this quantity in the base unit. |
Functions¤
__abs__ ¤
__abs__() -> Self
Return the absolute value of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The absolute value of this quantity. |
Source code in frequenz/quantities/_quantity.py
__add__ ¤
Return the sum of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The sum of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__eq__ ¤
Return whether this quantity is equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is equal to another. |
Source code in frequenz/quantities/_quantity.py
__format__ ¤
Return a formatted string representation of this quantity.
If specified, must be of this form: [0].{precision}
. If a 0 is not given, the
trailing zeros will be omitted. If no precision is given, the default is 3.
The returned string will use the unit that will result in the maximum precision, based on the magnitude of the value.
Example
PARAMETER | DESCRIPTION |
---|---|
__format_spec
|
The format specifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given format specifier is invalid. |
Source code in frequenz/quantities/_quantity.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__ge__ ¤
Return whether this quantity is greater than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__gt__ ¤
__init__ ¤
__init_subclass__ ¤
Initialize a new subclass of Quantity.
PARAMETER | DESCRIPTION |
---|---|
exponent_unit_map
|
A mapping from the exponent of the base unit to the unit symbol. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given exponent_unit_map does not contain a base unit (exponent 0). |
Source code in frequenz/quantities/_quantity.py
__le__ ¤
Return whether this quantity is less than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__lt__ ¤
__mod__ ¤
__mul__ ¤
__mul__(percent: Percentage) -> Self
__mul__(value: float | Percentage) -> Self
Scale this quantity by a scalar or percentage.
PARAMETER | DESCRIPTION |
---|---|
value
|
The scalar or percentage by which to scale this quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The scaled quantity. |
Source code in frequenz/quantities/_quantity.py
__neg__ ¤
__neg__() -> Self
Return the negation of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The negation of this quantity. |
__repr__ ¤
__repr__() -> str
Return a representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A representation of this quantity. |
__round__ ¤
__str__ ¤
__str__() -> str
Return a string representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
__sub__ ¤
Return the difference of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The difference of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__truediv__ ¤
Divide this quantity by a scalar or another quantity.
PARAMETER | DESCRIPTION |
---|---|
value
|
The scalar or quantity to divide this quantity by. |
RETURNS | DESCRIPTION |
---|---|
Self | float
|
The divided quantity or the ratio of this quantity to another. |
Source code in frequenz/quantities/_quantity.py
as_gigahertz ¤
as_gigahertz() -> float
Return the frequency in gigahertz.
RETURNS | DESCRIPTION |
---|---|
float
|
The frequency in gigahertz. |
from_gigahertz
classmethod
¤
from_hertz
classmethod
¤
from_kilohertz
classmethod
¤
from_megahertz
classmethod
¤
from_string
classmethod
¤
Return a quantity from a string representation.
PARAMETER | DESCRIPTION |
---|---|
string
|
The string representation of the quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A quantity object with the value given in the string. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the string does not match the expected format. |
Source code in frequenz/quantities/_quantity.py
isclose ¤
Return whether this quantity is close to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The quantity to compare to.
TYPE:
|
rel_tol
|
The relative tolerance.
TYPE:
|
abs_tol
|
The absolute tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is close to another. |
Source code in frequenz/quantities/_quantity.py
isinf ¤
isinf() -> bool
Return whether this quantity is infinite.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is infinite. |
isnan ¤
isnan() -> bool
Return whether this quantity is NaN.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is NaN. |
period ¤
period() -> timedelta
Return the period of the frequency.
RETURNS | DESCRIPTION |
---|---|
timedelta
|
The period of the frequency. |
frequenz.quantities.Percentage ¤
Bases: Quantity
A percentage quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in frequenz/quantities/_percentage.py
Attributes¤
base_unit
property
¤
base_unit: str | None
Return the base unit of this quantity.
None if this quantity has no unit.
RETURNS | DESCRIPTION |
---|---|
str | None
|
The base unit of this quantity. |
base_value
property
¤
base_value: float
Return the value of this quantity in the base unit.
RETURNS | DESCRIPTION |
---|---|
float
|
The value of this quantity in the base unit. |
Functions¤
__abs__ ¤
__abs__() -> Self
Return the absolute value of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The absolute value of this quantity. |
Source code in frequenz/quantities/_quantity.py
__add__ ¤
Return the sum of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The sum of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__eq__ ¤
Return whether this quantity is equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is equal to another. |
Source code in frequenz/quantities/_quantity.py
__format__ ¤
Return a formatted string representation of this quantity.
If specified, must be of this form: [0].{precision}
. If a 0 is not given, the
trailing zeros will be omitted. If no precision is given, the default is 3.
The returned string will use the unit that will result in the maximum precision, based on the magnitude of the value.
Example
PARAMETER | DESCRIPTION |
---|---|
__format_spec
|
The format specifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given format specifier is invalid. |
Source code in frequenz/quantities/_quantity.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__ge__ ¤
Return whether this quantity is greater than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__gt__ ¤
__init__ ¤
__init_subclass__ ¤
Initialize a new subclass of Quantity.
PARAMETER | DESCRIPTION |
---|---|
exponent_unit_map
|
A mapping from the exponent of the base unit to the unit symbol. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given exponent_unit_map does not contain a base unit (exponent 0). |
Source code in frequenz/quantities/_quantity.py
__le__ ¤
Return whether this quantity is less than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__lt__ ¤
__mod__ ¤
__mul__ ¤
__mul__(percent: Percentage) -> Self
__mul__(value: float | Percentage) -> Self
Scale this quantity by a scalar or percentage.
PARAMETER | DESCRIPTION |
---|---|
value
|
The scalar or percentage by which to scale this quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The scaled quantity. |
Source code in frequenz/quantities/_quantity.py
__neg__ ¤
__neg__() -> Self
Return the negation of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The negation of this quantity. |
__repr__ ¤
__repr__() -> str
Return a representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A representation of this quantity. |
__round__ ¤
__str__ ¤
__str__() -> str
Return a string representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
__sub__ ¤
Return the difference of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The difference of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__truediv__ ¤
Divide this quantity by a scalar or another quantity.
PARAMETER | DESCRIPTION |
---|---|
value
|
The scalar or quantity to divide this quantity by. |
RETURNS | DESCRIPTION |
---|---|
Self | float
|
The divided quantity or the ratio of this quantity to another. |
Source code in frequenz/quantities/_quantity.py
as_fraction ¤
as_fraction() -> float
Return this quantity as a fraction.
RETURNS | DESCRIPTION |
---|---|
float
|
This quantity as a fraction. |
as_percent ¤
as_percent() -> float
Return this quantity as a percentage.
RETURNS | DESCRIPTION |
---|---|
float
|
This quantity as a percentage. |
from_fraction
classmethod
¤
from_percent
classmethod
¤
from_string
classmethod
¤
Return a quantity from a string representation.
PARAMETER | DESCRIPTION |
---|---|
string
|
The string representation of the quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A quantity object with the value given in the string. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the string does not match the expected format. |
Source code in frequenz/quantities/_quantity.py
isclose ¤
Return whether this quantity is close to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The quantity to compare to.
TYPE:
|
rel_tol
|
The relative tolerance.
TYPE:
|
abs_tol
|
The absolute tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is close to another. |
Source code in frequenz/quantities/_quantity.py
isinf ¤
isinf() -> bool
Return whether this quantity is infinite.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is infinite. |
isnan ¤
isnan() -> bool
Return whether this quantity is NaN.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is NaN. |
frequenz.quantities.Power ¤
Bases: Quantity
A power quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in frequenz/quantities/_power.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
Attributes¤
base_unit
property
¤
base_unit: str | None
Return the base unit of this quantity.
None if this quantity has no unit.
RETURNS | DESCRIPTION |
---|---|
str | None
|
The base unit of this quantity. |
base_value
property
¤
base_value: float
Return the value of this quantity in the base unit.
RETURNS | DESCRIPTION |
---|---|
float
|
The value of this quantity in the base unit. |
Functions¤
__abs__ ¤
__abs__() -> Self
Return the absolute value of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The absolute value of this quantity. |
Source code in frequenz/quantities/_quantity.py
__add__ ¤
Return the sum of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The sum of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__eq__ ¤
Return whether this quantity is equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is equal to another. |
Source code in frequenz/quantities/_quantity.py
__format__ ¤
Return a formatted string representation of this quantity.
If specified, must be of this form: [0].{precision}
. If a 0 is not given, the
trailing zeros will be omitted. If no precision is given, the default is 3.
The returned string will use the unit that will result in the maximum precision, based on the magnitude of the value.
Example
PARAMETER | DESCRIPTION |
---|---|
__format_spec
|
The format specifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given format specifier is invalid. |
Source code in frequenz/quantities/_quantity.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__ge__ ¤
Return whether this quantity is greater than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__gt__ ¤
__init__ ¤
__init_subclass__ ¤
Initialize a new subclass of Quantity.
PARAMETER | DESCRIPTION |
---|---|
exponent_unit_map
|
A mapping from the exponent of the base unit to the unit symbol. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given exponent_unit_map does not contain a base unit (exponent 0). |
Source code in frequenz/quantities/_quantity.py
__le__ ¤
Return whether this quantity is less than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__lt__ ¤
__mod__ ¤
__mul__ ¤
__mul__(percent: Percentage) -> Self
__mul__(
other: float | Percentage | timedelta,
) -> Self | Energy
Return a power or energy from multiplying this power by the given value.
PARAMETER | DESCRIPTION |
---|---|
other
|
The scalar, percentage or duration to multiply by.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self | Energy
|
A power or energy. |
Source code in frequenz/quantities/_power.py
__neg__ ¤
__neg__() -> Self
Return the negation of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The negation of this quantity. |
__repr__ ¤
__repr__() -> str
Return a representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A representation of this quantity. |
__round__ ¤
__str__ ¤
__str__() -> str
Return a string representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
__sub__ ¤
Return the difference of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The difference of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__truediv__ ¤
Return a current or voltage from dividing this power by the given value.
PARAMETER | DESCRIPTION |
---|---|
other
|
The scalar, power, current or voltage to divide by. |
RETURNS | DESCRIPTION |
---|---|
Self | float | Voltage | Current
|
A current or voltage from dividing this power by the given value. |
Source code in frequenz/quantities/_power.py
from_kilowatts
classmethod
¤
from_megawatts
classmethod
¤
from_milliwatts
classmethod
¤
from_string
classmethod
¤
Return a quantity from a string representation.
PARAMETER | DESCRIPTION |
---|---|
string
|
The string representation of the quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A quantity object with the value given in the string. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the string does not match the expected format. |
Source code in frequenz/quantities/_quantity.py
from_watts
classmethod
¤
isclose ¤
Return whether this quantity is close to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The quantity to compare to.
TYPE:
|
rel_tol
|
The relative tolerance.
TYPE:
|
abs_tol
|
The absolute tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is close to another. |
Source code in frequenz/quantities/_quantity.py
isinf ¤
isinf() -> bool
Return whether this quantity is infinite.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is infinite. |
isnan ¤
isnan() -> bool
Return whether this quantity is NaN.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is NaN. |
frequenz.quantities.Quantity ¤
A quantity with a unit.
Quantities try to behave like float and are also immutable.
Source code in frequenz/quantities/_quantity.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
|
Attributes¤
base_unit
property
¤
base_unit: str | None
Return the base unit of this quantity.
None if this quantity has no unit.
RETURNS | DESCRIPTION |
---|---|
str | None
|
The base unit of this quantity. |
base_value
property
¤
base_value: float
Return the value of this quantity in the base unit.
RETURNS | DESCRIPTION |
---|---|
float
|
The value of this quantity in the base unit. |
Functions¤
__abs__ ¤
__abs__() -> Self
Return the absolute value of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The absolute value of this quantity. |
Source code in frequenz/quantities/_quantity.py
__add__ ¤
Return the sum of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The sum of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__eq__ ¤
Return whether this quantity is equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is equal to another. |
Source code in frequenz/quantities/_quantity.py
__format__ ¤
Return a formatted string representation of this quantity.
If specified, must be of this form: [0].{precision}
. If a 0 is not given, the
trailing zeros will be omitted. If no precision is given, the default is 3.
The returned string will use the unit that will result in the maximum precision, based on the magnitude of the value.
Example
PARAMETER | DESCRIPTION |
---|---|
__format_spec
|
The format specifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given format specifier is invalid. |
Source code in frequenz/quantities/_quantity.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__ge__ ¤
Return whether this quantity is greater than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__gt__ ¤
__init__ ¤
__init_subclass__ ¤
Initialize a new subclass of Quantity.
PARAMETER | DESCRIPTION |
---|---|
exponent_unit_map
|
A mapping from the exponent of the base unit to the unit symbol. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given exponent_unit_map does not contain a base unit (exponent 0). |
Source code in frequenz/quantities/_quantity.py
__le__ ¤
Return whether this quantity is less than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__lt__ ¤
__mod__ ¤
__mul__ ¤
__mul__(percent: Percentage) -> Self
__mul__(value: float | Percentage) -> Self
Scale this quantity by a scalar or percentage.
PARAMETER | DESCRIPTION |
---|---|
value
|
The scalar or percentage by which to scale this quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The scaled quantity. |
Source code in frequenz/quantities/_quantity.py
__neg__ ¤
__neg__() -> Self
Return the negation of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The negation of this quantity. |
__repr__ ¤
__repr__() -> str
Return a representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A representation of this quantity. |
__round__ ¤
__str__ ¤
__str__() -> str
Return a string representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
__sub__ ¤
Return the difference of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The difference of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__truediv__ ¤
Divide this quantity by a scalar or another quantity.
PARAMETER | DESCRIPTION |
---|---|
value
|
The scalar or quantity to divide this quantity by. |
RETURNS | DESCRIPTION |
---|---|
Self | float
|
The divided quantity or the ratio of this quantity to another. |
Source code in frequenz/quantities/_quantity.py
from_string
classmethod
¤
Return a quantity from a string representation.
PARAMETER | DESCRIPTION |
---|---|
string
|
The string representation of the quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A quantity object with the value given in the string. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the string does not match the expected format. |
Source code in frequenz/quantities/_quantity.py
isclose ¤
Return whether this quantity is close to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The quantity to compare to.
TYPE:
|
rel_tol
|
The relative tolerance.
TYPE:
|
abs_tol
|
The absolute tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is close to another. |
Source code in frequenz/quantities/_quantity.py
isinf ¤
isinf() -> bool
Return whether this quantity is infinite.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is infinite. |
isnan ¤
isnan() -> bool
Return whether this quantity is NaN.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is NaN. |
frequenz.quantities.ReactivePower ¤
Bases: Quantity
A reactive power quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in frequenz/quantities/_reactive_power.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
Attributes¤
base_unit
property
¤
base_unit: str | None
Return the base unit of this quantity.
None if this quantity has no unit.
RETURNS | DESCRIPTION |
---|---|
str | None
|
The base unit of this quantity. |
base_value
property
¤
base_value: float
Return the value of this quantity in the base unit.
RETURNS | DESCRIPTION |
---|---|
float
|
The value of this quantity in the base unit. |
Functions¤
__abs__ ¤
__abs__() -> Self
Return the absolute value of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The absolute value of this quantity. |
Source code in frequenz/quantities/_quantity.py
__add__ ¤
Return the sum of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The sum of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__eq__ ¤
Return whether this quantity is equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is equal to another. |
Source code in frequenz/quantities/_quantity.py
__format__ ¤
Return a formatted string representation of this quantity.
If specified, must be of this form: [0].{precision}
. If a 0 is not given, the
trailing zeros will be omitted. If no precision is given, the default is 3.
The returned string will use the unit that will result in the maximum precision, based on the magnitude of the value.
Example
PARAMETER | DESCRIPTION |
---|---|
__format_spec
|
The format specifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given format specifier is invalid. |
Source code in frequenz/quantities/_quantity.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__ge__ ¤
Return whether this quantity is greater than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__gt__ ¤
__init__ ¤
__init_subclass__ ¤
Initialize a new subclass of Quantity.
PARAMETER | DESCRIPTION |
---|---|
exponent_unit_map
|
A mapping from the exponent of the base unit to the unit symbol. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given exponent_unit_map does not contain a base unit (exponent 0). |
Source code in frequenz/quantities/_quantity.py
__le__ ¤
Return whether this quantity is less than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__lt__ ¤
__mod__ ¤
__mul__ ¤
__mul__(percent: Percentage) -> Self
__mul__(other: float | Percentage) -> Self
Return a power or energy from multiplying this power by the given value.
PARAMETER | DESCRIPTION |
---|---|
other
|
The scalar, percentage or duration to multiply by.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A power or energy. |
Source code in frequenz/quantities/_reactive_power.py
__neg__ ¤
__neg__() -> Self
Return the negation of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The negation of this quantity. |
__repr__ ¤
__repr__() -> str
Return a representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A representation of this quantity. |
__round__ ¤
__str__ ¤
__str__() -> str
Return a string representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
__sub__ ¤
Return the difference of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The difference of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__truediv__ ¤
Return a current or voltage from dividing this power by the given value.
PARAMETER | DESCRIPTION |
---|---|
other
|
The scalar, power, current or voltage to divide by. |
RETURNS | DESCRIPTION |
---|---|
Self | float | Voltage | Current
|
A current or voltage from dividing this power by the given value. |
Source code in frequenz/quantities/_reactive_power.py
as_kilo_volt_amperes_reactive ¤
as_kilo_volt_amperes_reactive() -> float
Return the reactive power in kilovolt-amperes reactive (kVAR).
RETURNS | DESCRIPTION |
---|---|
float
|
The reactive power in kilovolt-amperes reactive (kVAR). |
as_mega_volt_amperes_reactive ¤
as_mega_volt_amperes_reactive() -> float
Return the reactive power in megavolt-amperes reactive (MVAR).
RETURNS | DESCRIPTION |
---|---|
float
|
The reactive power in megavolt-amperes reactive (MVAR). |
as_milli_volt_amperes_reactive ¤
as_milli_volt_amperes_reactive() -> float
Return the reactive power in millivolt-amperes reactive (mVAR).
RETURNS | DESCRIPTION |
---|---|
float
|
The reactive power in millivolt-amperes reactive (mVAR). |
as_volt_amperes_reactive ¤
as_volt_amperes_reactive() -> float
Return the reactive power in volt-amperes reactive (VAR).
RETURNS | DESCRIPTION |
---|---|
float
|
The reactive power in volt-amperes reactive (VAR). |
from_kilo_volt_amperes_reactive
classmethod
¤
from_mega_volt_amperes_reactive
classmethod
¤
from_milli_volt_amperes_reactive
classmethod
¤
from_string
classmethod
¤
Return a quantity from a string representation.
PARAMETER | DESCRIPTION |
---|---|
string
|
The string representation of the quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A quantity object with the value given in the string. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the string does not match the expected format. |
Source code in frequenz/quantities/_quantity.py
from_volt_amperes_reactive
classmethod
¤
isclose ¤
Return whether this quantity is close to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The quantity to compare to.
TYPE:
|
rel_tol
|
The relative tolerance.
TYPE:
|
abs_tol
|
The absolute tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is close to another. |
Source code in frequenz/quantities/_quantity.py
isinf ¤
isinf() -> bool
Return whether this quantity is infinite.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is infinite. |
isnan ¤
isnan() -> bool
Return whether this quantity is NaN.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is NaN. |
frequenz.quantities.Temperature ¤
Bases: Quantity
A temperature quantity (in degrees Celsius).
Source code in frequenz/quantities/_temperature.py
Attributes¤
base_unit
property
¤
base_unit: str | None
Return the base unit of this quantity.
None if this quantity has no unit.
RETURNS | DESCRIPTION |
---|---|
str | None
|
The base unit of this quantity. |
base_value
property
¤
base_value: float
Return the value of this quantity in the base unit.
RETURNS | DESCRIPTION |
---|---|
float
|
The value of this quantity in the base unit. |
Functions¤
__abs__ ¤
__abs__() -> Self
Return the absolute value of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The absolute value of this quantity. |
Source code in frequenz/quantities/_quantity.py
__add__ ¤
Return the sum of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The sum of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__eq__ ¤
Return whether this quantity is equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is equal to another. |
Source code in frequenz/quantities/_quantity.py
__format__ ¤
Return a formatted string representation of this quantity.
If specified, must be of this form: [0].{precision}
. If a 0 is not given, the
trailing zeros will be omitted. If no precision is given, the default is 3.
The returned string will use the unit that will result in the maximum precision, based on the magnitude of the value.
Example
PARAMETER | DESCRIPTION |
---|---|
__format_spec
|
The format specifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given format specifier is invalid. |
Source code in frequenz/quantities/_quantity.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__ge__ ¤
Return whether this quantity is greater than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__gt__ ¤
__init__ ¤
__init_subclass__ ¤
Initialize a new subclass of Quantity.
PARAMETER | DESCRIPTION |
---|---|
exponent_unit_map
|
A mapping from the exponent of the base unit to the unit symbol. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given exponent_unit_map does not contain a base unit (exponent 0). |
Source code in frequenz/quantities/_quantity.py
__le__ ¤
Return whether this quantity is less than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__lt__ ¤
__mod__ ¤
__mul__ ¤
__mul__(percent: Percentage) -> Self
__mul__(value: float | Percentage) -> Self
Scale this quantity by a scalar or percentage.
PARAMETER | DESCRIPTION |
---|---|
value
|
The scalar or percentage by which to scale this quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The scaled quantity. |
Source code in frequenz/quantities/_quantity.py
__neg__ ¤
__neg__() -> Self
Return the negation of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The negation of this quantity. |
__repr__ ¤
__repr__() -> str
Return a representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A representation of this quantity. |
__round__ ¤
__str__ ¤
__str__() -> str
Return a string representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
__sub__ ¤
Return the difference of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The difference of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__truediv__ ¤
Divide this quantity by a scalar or another quantity.
PARAMETER | DESCRIPTION |
---|---|
value
|
The scalar or quantity to divide this quantity by. |
RETURNS | DESCRIPTION |
---|---|
Self | float
|
The divided quantity or the ratio of this quantity to another. |
Source code in frequenz/quantities/_quantity.py
as_celsius ¤
as_celsius() -> float
Return the temperature in degrees Celsius.
RETURNS | DESCRIPTION |
---|---|
float
|
The temperature in degrees Celsius. |
from_celsius
classmethod
¤
from_string
classmethod
¤
Return a quantity from a string representation.
PARAMETER | DESCRIPTION |
---|---|
string
|
The string representation of the quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A quantity object with the value given in the string. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the string does not match the expected format. |
Source code in frequenz/quantities/_quantity.py
isclose ¤
Return whether this quantity is close to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The quantity to compare to.
TYPE:
|
rel_tol
|
The relative tolerance.
TYPE:
|
abs_tol
|
The absolute tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is close to another. |
Source code in frequenz/quantities/_quantity.py
isinf ¤
isinf() -> bool
Return whether this quantity is infinite.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is infinite. |
isnan ¤
isnan() -> bool
Return whether this quantity is NaN.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is NaN. |
frequenz.quantities.Voltage ¤
Bases: Quantity
A voltage quantity.
Objects of this type are wrappers around float
values and are immutable.
The constructors accept a single float
value, the as_*()
methods return a
float
value, and each of the arithmetic operators supported by this type are
actually implemented using floating-point arithmetic.
So all considerations about floating-point arithmetic apply to this type as well.
Source code in frequenz/quantities/_voltage.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
Attributes¤
base_unit
property
¤
base_unit: str | None
Return the base unit of this quantity.
None if this quantity has no unit.
RETURNS | DESCRIPTION |
---|---|
str | None
|
The base unit of this quantity. |
base_value
property
¤
base_value: float
Return the value of this quantity in the base unit.
RETURNS | DESCRIPTION |
---|---|
float
|
The value of this quantity in the base unit. |
Functions¤
__abs__ ¤
__abs__() -> Self
Return the absolute value of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The absolute value of this quantity. |
Source code in frequenz/quantities/_quantity.py
__add__ ¤
Return the sum of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The sum of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__eq__ ¤
Return whether this quantity is equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is equal to another. |
Source code in frequenz/quantities/_quantity.py
__format__ ¤
Return a formatted string representation of this quantity.
If specified, must be of this form: [0].{precision}
. If a 0 is not given, the
trailing zeros will be omitted. If no precision is given, the default is 3.
The returned string will use the unit that will result in the maximum precision, based on the magnitude of the value.
Example
PARAMETER | DESCRIPTION |
---|---|
__format_spec
|
The format specifier.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given format specifier is invalid. |
Source code in frequenz/quantities/_quantity.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
|
__ge__ ¤
Return whether this quantity is greater than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is greater than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__gt__ ¤
__init__ ¤
__init_subclass__ ¤
Initialize a new subclass of Quantity.
PARAMETER | DESCRIPTION |
---|---|
exponent_unit_map
|
A mapping from the exponent of the base unit to the unit symbol. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the given exponent_unit_map does not contain a base unit (exponent 0). |
Source code in frequenz/quantities/_quantity.py
__le__ ¤
Return whether this quantity is less than or equal to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is less than or equal to another. |
Source code in frequenz/quantities/_quantity.py
__lt__ ¤
__mod__ ¤
__mul__ ¤
__mul__(percent: Percentage) -> Self
__mul__(
other: float | Percentage | Current,
) -> Self | Power
Return a voltage or power from multiplying this voltage by the given value.
PARAMETER | DESCRIPTION |
---|---|
other
|
The scalar, percentage or current to multiply by.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self | Power
|
The calculated voltage or power. |
Source code in frequenz/quantities/_voltage.py
__neg__ ¤
__neg__() -> Self
Return the negation of this quantity.
RETURNS | DESCRIPTION |
---|---|
Self
|
The negation of this quantity. |
__repr__ ¤
__repr__() -> str
Return a representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A representation of this quantity. |
__round__ ¤
__str__ ¤
__str__() -> str
Return a string representation of this quantity.
RETURNS | DESCRIPTION |
---|---|
str
|
A string representation of this quantity. |
__sub__ ¤
Return the difference of this quantity and another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The other quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
The difference of this quantity and another. |
Source code in frequenz/quantities/_quantity.py
__truediv__ ¤
Divide this quantity by a scalar or another quantity.
PARAMETER | DESCRIPTION |
---|---|
value
|
The scalar or quantity to divide this quantity by. |
RETURNS | DESCRIPTION |
---|---|
Self | float
|
The divided quantity or the ratio of this quantity to another. |
Source code in frequenz/quantities/_quantity.py
from_kilovolts
classmethod
¤
from_millivolts
classmethod
¤
from_string
classmethod
¤
Return a quantity from a string representation.
PARAMETER | DESCRIPTION |
---|---|
string
|
The string representation of the quantity.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Self
|
A quantity object with the value given in the string. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the string does not match the expected format. |
Source code in frequenz/quantities/_quantity.py
from_volts
classmethod
¤
isclose ¤
Return whether this quantity is close to another.
PARAMETER | DESCRIPTION |
---|---|
other
|
The quantity to compare to.
TYPE:
|
rel_tol
|
The relative tolerance.
TYPE:
|
abs_tol
|
The absolute tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is close to another. |
Source code in frequenz/quantities/_quantity.py
isinf ¤
isinf() -> bool
Return whether this quantity is infinite.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is infinite. |
isnan ¤
isnan() -> bool
Return whether this quantity is NaN.
RETURNS | DESCRIPTION |
---|---|
bool
|
Whether this quantity is NaN. |