wellcast.units¶
units ¶
Unit conversions for oilfield quantities.
Every unit belongs to a physical quantity (pressure, temperature, volume rate and so on) and is defined by an affine map to the base unit of that quantity::
base = value * scale + offset
Only temperature units use a non-zero offset. Conversions between units of
different quantities raise wellcast.exceptions.UnitError.
Standard-condition volumes (stb, scf, sm3) are treated as plain
volumes. The small difference between oilfield standard conditions (60 degF,
14.696 psia) and metric standard conditions (15 degC, 101.325 kPa) is ignored,
as is common practice in production reporting.
Unit
dataclass
¶
A unit defined by an affine map to the base unit of its quantity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Canonical symbol, for example |
required |
quantity
|
str
|
Physical quantity, for example |
required |
scale
|
float
|
Multiplier to the base unit. |
required |
offset
|
float
|
Additive term applied after scaling (temperatures only). |
0.0
|
register_unit ¶
register_unit(name: str, quantity: str, scale: float, offset: float = 0.0, *, overwrite: bool = False) -> Unit
Add a unit to the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unit symbol. Lookup is case-insensitive and ignores spaces. |
required |
quantity
|
str
|
Physical quantity the unit measures. |
required |
scale
|
float
|
Multiplier from this unit to the base unit of |
required |
offset
|
float
|
Additive term applied after scaling. Default 0. |
0.0
|
overwrite
|
bool
|
Allow replacing an existing unit. Default False. |
False
|
Returns:
| Type | Description |
|---|---|
Unit
|
The registered unit. |
Raises:
| Type | Description |
|---|---|
UnitError
|
If the unit exists and |
Examples:
get_unit ¶
list_units ¶
Return registered unit symbols, optionally for one quantity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quantity
|
str
|
Restrict the list to this quantity, for example |
None
|
Returns:
| Type | Description |
|---|---|
list of str
|
Sorted unit symbols. |
Examples:
convert ¶
Convert a value between two units of the same quantity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
(float, ndarray, Series or DataFrame)
|
Value(s) to convert. The container type is preserved. |
required |
from_unit
|
str
|
Unit of |
required |
to_unit
|
str
|
Target unit. |
required |
Returns:
| Type | Description |
|---|---|
(float, ndarray, Series or DataFrame)
|
Converted value(s) in |
Raises:
| Type | Description |
|---|---|
UnitError
|
If a unit is unknown or the units measure different quantities. |
Notes
With base = value * scale + offset for each unit, the conversion is
(value * s_from + o_from - o_to) / s_to.
Examples: