table: utilities for operations with tables
Code author: Peter Kraus
Provides convenience functions for operating with tables, including
combine_namespaces()
for combining ->
-separated
namespaces of values or chemicals into a single namespace;
combine_columns()
for combining individual columns
into a single column; and set_uncertainty()
for
stripping or replacing uncertainties from data.
Functions
|
Combines two namespaces into one. |
|
Combines two columns into one. |
|
Allows for stripping or replacing uncertainties using absolute and relative values. |
- dgpost.transform.table.combine_namespaces(a, b, conflicts='sum', output=None, fillnan=True, chemicals=False, _inp={})
Combines two namespaces into one. Unit checks are performed, with the resulting units corresponding to the units in namespace
a
. By default, the output namespace is set toa
. Optionally, the keys in each namespace can be treated as chemicals.- Parameters:
a (
dict
[str
,Quantity
]) – Namespacea
.b (
dict
[str
,Quantity
]) – Namespaceb
.conflicts (
str
) – Name resolution scheme. Can be either"sum"
where conflicts are summed, or"replace"
, where conflicting values ina
are overwritten byb
.fillnan (
bool
) – Toggle whetherNaN
values within the columns ought to be treated as zeroes or asNaN
. Default isTrue
.chemicals (
bool
) – Treat keys withina
andb
as chemicals, and combine them accordingly. Default isFalse
.output (
Optional
[str
]) – Namespace of the returned dictionary. Defaults to the namespace ofa
.
- Return type:
dict
[str
,Quantity
]
- dgpost.transform.table.combine_columns(a, b, fillnan=True, output=None, _inp={})
Combines two columns into one. Unit checks are performed, with the resulting units corresponding to the units in column
a
. By default, the output column is set toa
.- Parameters:
a (
Quantity
) – Columna
.b (
Quantity
) – Columnb
.fillnan (
bool
) – Toggle whetherNaN
values within the columns ought to be treated as zeroes or asNaN
. Default isTrue
.output (
Optional
[str
]) – Namespace of the returned dictionary. By defaults to the name of columna
.
- Return type:
dict
[str
,Quantity
]
- dgpost.transform.table.set_uncertainty(namespace=None, column=None, abs=None, rel=None, _inp={})
Allows for stripping or replacing uncertainties using absolute and relative values. Can target either namespaces, or individual columns. If both
abs
andrel
uncertainty is provided, the higher of the two values is set. If neitherabs
norrel
are provided, the uncertainties are stripped.- Parameters:
namespace (
Optional
[dict
[str
,Quantity
]]) – The prefix of the namespace for which uncertainties are to be replaced or stripped. Cannot be supplied along withcolumn
.column (
Optional
[Quantity
]) – The name of the column for which uncertainties are to be replaced or stripped. Cannot be supplied along withnamespace
abs (
Union
[Quantity
,float
,None
]) – The absolute value of the uncertainty. If units are not supplied, the units of the column/namespace will be used. If bothabs
andrel
areNone
, the existing uncertainties will be stripped.rel (
Union
[Quantity
,float
,None
]) – The relative value of the uncertainty, should be in dimensionless units. If bothabs
andrel
areNone
, the existing uncertainties will be stripped.
- Return type:
dict
[str
,Quantity
]