API
data_disaggregation.vtypes
Type classes for data.
VT_Nominal
Bases: VariableType
Type class for nominal (categorical) data.
- Aggregation method: mode (most commonly used)
- Disaggregation method: keep value
- Examples: regional codes
VT_Numeric
Bases: VariableType
Type class for numerical, intensive data
An intensive variable is one which does not scale with the system size.
- Aggregation method: weighted average
- Disaggregation method: keep value
- Examples: temperature, density, pressure
VT_NumericExt
Bases: VT_Numeric
Type class for numerical, extensive data.
An extensive variable is one which does scale with the system size (assuming an equal distribution).
- Aggregation method: sum
- Disaggregation method: distribute by weights
- Examples: population, energy, total cost
VT_Ordinal
Bases: VT_Nominal
Type class for ordinal data (ranked categorical).
- Aggregation method: median
- Disaggregation method: keep value
- Examples: Level of agreement
VariableType
Bases: ABC
weighted_aggregate(data)
classmethod
aggregate data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Iterable
|
non empty list of (value, weight) pairs. weights must be numerical, positive, and sum up to 1.0. |
required |
Returns:
Type | Description |
---|---|
aggregated value
|
|
data_disaggregation.actions
Functions to perform data transformations.
transform(vtype, data, weight_map, weights_from=None, weights_to=None, weight_rel_threshold=0.0, validate=True)
(dis-)aggregate data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vtype
|
VariableType
|
Variable type of input data, determines the aggregation method. |
required |
data
|
Mapping[F, V]
|
Input data: mapping (usually dict) from any keys (any hashable) to values. |
required |
weight_map
|
Mapping[Tuple[F, T], float]
|
weights for combinations of input and output elements (must be positive). Keys must tuples from input/output key pairs. |
required |
weights_from
|
Mapping[F, float]
|
optional weights of input elements (must be positive).
If not specified, this will be calculated as a sum from |
None
|
weights_to
|
Mapping[T, float]
|
optional weights of output elements (must be positive).
If not specified, this will be calculated as a sum from |
None
|
weight_rel_threshold
|
float
|
optional value between 0 and 1: all mappings are dropped if the sum of input weights / output weight is smaller than this threshold. For example, you may want to set it to 0.5 for geographical mappings with extensive data. |
0.0
|
validate
|
bool
|
if True: run additional (but costly) validations of weights and data. |
True
|
Returns:
Type | Description |
---|---|
Mapping[T, V]
|
output data as a mapping from output keys (any hashable) to values. |
transform_pandas(vtype, data, weights, dim_in=None, dim_out=None, validate=True)
(dis-)aggregate data (pandas).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vtype
|
VariableType
|
Variable type of input data, determines the aggregation method. |
required |
data
|
Union[DataFrame, Series, float]
|
Input data. Indices must be unique and have unique level names |
required |
weights
|
Union[Index, Series, Tuple[Union[Index, Series]]]
|
weights for combinations of input and output elements (must be positive). |
required |
dim_in
|
Union[Index, Series]
|
TODO |
None
|
dim_out
|
Union[Index, Series]
|
TODO |
None
|
validate
|
bool
|
if True: run additional (but costly) validations of weights and data. |
True
|
Returns:
Type | Description |
---|---|
Union[DataFrame, Series, float]
|
output data |
options: members: - transform_pandas - transform