primap2.csg.PriorityDefinition#
- class primap2.csg.PriorityDefinition(*, priority_dimensions: list[Hashable], priorities: list[dict[Hashable, str | list[str] | Not]], exclude_input: list[dict[Hashable, str | list[str]]] = [], exclude_result: list[dict[Hashable, str | list[str]]] = [])[source]#
Defines source priorities for composing a full dataset or a single timeseries.
- Attributes:
- priority_dimensions
List of dimensions from which source timeseries are selected. Each priority has to specify all priority dimensions.
- priorities
List of priority selections. Higher priority selections come first. Each selection consists of a dict which maps dimension names to values. Each selection has to specify all priority_dimensions, but may specify additional dimensions (fixed dimensions) to limit the selection to specific cases. You can use primap2.Not as a value for fixed dimensions to easily specify negative selections in the priorities. This should generally only be used if you want to change the priority of a source in specific circumstances. If you want to avoid using a source completely in specific cases, use exclude_input instead.
- exclude_input
Set of selections from the input dataset to exclude from processing. Each selection consists of a dict which maps dimension names to values. Each selection can specify any number of priority dimensions or additional dimensions (fixed dimensions) to limit the selection. All input timeseries which match any selection will be skipped in processing. Note that after the exclusions, there still must be at least one applicable source for each result timeseries, otherwise errors will be raised. If you want to exclude timeseries from the result without raising errors, use exclude_result instead.
- exclude_result
Set of selections from the result to exclude from all processing. Each selection consists of a dict which maps dimension names to values. Each selection can specify any number of additional dimensions (fixed dimensions) to limit the selection. Because it excludes timeseries from the result not from the input, it may not contain priority_dimensions. All timeseries which match any selection will be excluded entirely from processing and will be all-NaN in the result.
Methods
check_dimensions
()Raise an error if priorities or exclusions use wrong dimensions.
excludes_input
(ts)Check if a selected input timeseries is excluded from processing.
excludes_result
(ts)Check if a selected result timeseries is excluded from processing.
limit
(dim, value)Remove one fixed dimension by limiting to a single value.
Examples
priorities:
[{"area (ISO3)": ["MEX", "COL"], "source": "A"}, {"source": "B"}]
would select source “A” as highest-priority source and source “B” as lower-priority source for Columbia and Mexico, but source “B” as highest-priority (and only) source for all other countries.
- __init__(*, priority_dimensions: list[Hashable], priorities: list[dict[Hashable, str | list[str] | Not]], exclude_input: list[dict[Hashable, str | list[str]]] = [], exclude_result: list[dict[Hashable, str | list[str]]] = []) None #
Method generated by attrs for class PriorityDefinition.
Methods
__init__
(*, priority_dimensions, priorities)Method generated by attrs for class PriorityDefinition.
check_dimensions
()Raise an error if priorities or exclusions use wrong dimensions.
excludes_input
(ts)Check if a selected input timeseries is excluded from processing.
excludes_result
(ts)Check if a selected result timeseries is excluded from processing.
limit
(dim, value)Remove one fixed dimension by limiting to a single value.
Attributes
priority_dimensions
priorities
exclude_input
exclude_result