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

combine_namespaces(a, b[, conflicts, ...])

Combines two namespaces into one.

combine_columns(a, b[, fillnan, output, _inp])

Combines two columns into one.

set_uncertainty([namespace, column, abs, ...])

Allows for stripping or replacing uncertainties using absolute and relative values.

dgpost.transform.table.combine_namespaces(a: dict[str, Quantity], b: dict[str, Quantity], conflicts: str = 'sum', output: str = None, fillnan: bool = True, chemicals: bool = False, _inp: dict = {}) dict[str, Quantity]

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 to a. Optionally, the keys in each namespace can be treated as chemicals.

Parameters:
  • a – Namespace a.

  • b – Namespace b.

  • conflicts – Name resolution scheme. Can be either "sum" where conflicts are summed, or "replace", where conflicting values in a are overwritten by b.

  • fillnan – Toggle whether NaN values within the columns ought to be treated as zeroes or as NaN. Default is True.

  • chemicals – Treat keys within a and b as chemicals, and combine them accordingly. Default is False.

  • output – Namespace of the returned dictionary. Defaults to the namespace of a.

dgpost.transform.table.combine_columns(a: Quantity, b: Quantity, fillnan: bool = True, output: str = None, _inp: dict = {}) dict[str, Quantity]

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 to a.

Parameters:
  • a – Column a.

  • b – Column b.

  • fillnan – Toggle whether NaN values within the columns ought to be treated as zeroes or as NaN. Default is True.

  • output – Namespace of the returned dictionary. By defaults to the name of column a.

dgpost.transform.table.set_uncertainty(namespace: dict[str, Quantity] = None, column: Quantity = None, abs: Quantity | float = None, rel: Quantity | float = None, _inp: dict = {}) dict[str, Quantity]

Allows for stripping or replacing uncertainties using absolute and relative values. Can target either namespaces, or individual columns. If both abs and rel uncertainty is provided, the higher of the two values is set. If neither abs nor rel are provided, the uncertainties are stripped.

Parameters:
  • namespace – The prefix of the namespace for which uncertainties are to be replaced or stripped. Cannot be supplied along with column.

  • column – The name of the column for which uncertainties are to be replaced or stripped. Cannot be supplied along with namespace

  • abs – The absolute value of the uncertainty. If units are not supplied, the units of the column/namespace will be used. If both abs and rel are None, the existing uncertainties will be stripped.

  • rel – The relative value of the uncertainty, should be in dimensionless units. If both abs and rel are None, the existing uncertainties will be stripped.