RegionProcessor¶
- class nomenclature.RegionProcessor(*, input_data=None, input_meta=None, output_data=None, output_meta=None, fail_ok=False, region_codelist, variable_codelist, mappings)[source]¶
Region aggregation mappings for scenario processing
Methods
apply(df)Apply region processing
check_region_aggregation(df[, rtol_difference])Return region aggregation results and differences between aggregated and model native data
from_directory(path, dsd)Initialize a RegionProcessor from a directory of model-aggregation mappings.
Return a mapping from common region names to constituent countries for a model.
Return a mapping from (renamed) native region names to countries for a model.
- apply(df)[source]¶
Apply region processing
- Parameters:
- dfIamDataFrame
Input data that the region processing is applied to
- Returns:
- IamDataFrame:
Processed data
- Raises:
- ValueError
If df contains regions that are not listed in the model mapping, or
If the region-processing results in an empty IamDataFrame.
- check_region_aggregation(df, rtol_difference=0.01)[source]¶
Return region aggregation results and differences between aggregated and model native data
- Parameters:
- dfIamDataFrame
Input data
- rtol_differencefloat, optional
limit on the relative tolerance for differences, by default 0.01
- Returns:
- tuple[IamDataFrame, pd.DataFrame]
IamDataFrame containing aggregation results and pandas dataframe containing the differences
- classmethod from_directory(path, dsd)[source]¶
Initialize a RegionProcessor from a directory of model-aggregation mappings.
- Parameters:
- pathDirectoryPath
Directory which holds all the mappings.
- dsdDataStructureDefinition
Instance of DataStructureDefinition used for validation of mappings and region aggregation.
- Returns:
- RegionProcessor
The resulting region processor object.
- Raises:
- ValueError
Raised in case there are multiple mappings defined for the same model or there is an issue with region the RegionAggregationMapping
- AttributeError
Raised if the provided DataStructureDefinition does not contain the dimensions
regionandvariable.
- get_common_region_country_mapping(model)[source]¶
Return a mapping from common region names to constituent countries for a model.
- Parameters:
- modelstr
Name of the model.
- Returns:
- dict[str, list[str]]
Dictionary mapping each common region name to the aggregated list of countries from all of its constituent native regions.