gcages.cmip7_scenariomip.pre_processing#
Pre-processing part of the workflow
This is extremely fiddly because of the way the data is reported, which is frankly, a mess because of how it blends data that is a regional-sum with data that has regional detail and how the variable name is a blend of different bits of information (species, sectoral information etc.) with no easy way to decode what is what using a machine (you have to hardcode lots of edge cases e.g. Emissions|CO2|Energy is "Emissions", then the species then the sector but Emissions|HFC|HFC245 is "Emissions" then the "HFC" string then the species, i.e. completely different information is provided after each "|").
This module implements the logic for this processing. The complexity comes in the re-aggregation (gcages.cmip7_scenariomip.pre_processing.reaggregation), which has to handle converting from whatever is reported (and a huge amount of different possibilities have to be supported) to the sectors used for gridding. From there, the workflow can be standardised (as is done in pre_processor.do_pre_processing).
Modules:
| Name | Description |
|---|---|
pre_processor |
Definition of the pre-processor class |
reaggregation |
Reaggregation of timeseries from raw reporting to sectors needed for gridding |
Classes:
| Name | Description |
|---|---|
CMIP7ScenarioMIPPreProcessingResult |
Result of pre-processing with CMIP7ScenarioMIPPreProcessor |
CMIP7ScenarioMIPPreProcessor |
Pre-processor for CMIP7's ScenarioMIP |
ReaggregatorBasic |
Reaggregator that follows this module's logic |
ReaggregatorLike |
Interface that can be used for re-aggregation |
ToCompleteResult |
Result of calling |
CMIP7ScenarioMIPPreProcessingResult #
Result of pre-processing with CMIP7ScenarioMIPPreProcessor
This has more components than normal, because we need to support both the 'normal' global path and harmonising at the region-sector level.
Attributes:
| Name | Type | Description |
|---|---|---|
assumed_zero_emissions |
DataFrame | None
|
Emissions that were asssumed to be zero during the processing |
global_workflow_emissions |
DataFrame
|
Emissions that can be used with the 'normal' global workflow |
global_workflow_emissions_raw_names |
DataFrame
|
Emissions consistent with those that can be used with the 'normal' global workflow |
gridding_workflow_emissions |
DataFrame
|
Emissions that can be used with the gridding workflow |
Source code in src/gcages/cmip7_scenariomip/pre_processing/pre_processor.py
assumed_zero_emissions
instance-attribute
#
assumed_zero_emissions: DataFrame | None
Emissions that were asssumed to be zero during the processing
global_workflow_emissions
instance-attribute
#
global_workflow_emissions: DataFrame
Emissions that can be used with the 'normal' global workflow
global_workflow_emissions_raw_names
instance-attribute
#
global_workflow_emissions_raw_names: DataFrame
Emissions consistent with those that can be used with the 'normal' global workflow
The difference is that these are reported with CMIP7 ScenarioMIP naming, which isn't compatible with our SCM runners (for example), so is probably not what you want to use, but perhaps helpful for plotting and direct comparisons.
CMIP7ScenarioMIPPreProcessor #
Pre-processor for CMIP7's ScenarioMIP
For more details of the logic, see gcages.cmip7_scenariomip.pre_processing.
Methods:
| Name | Description |
|---|---|
__call__ |
Pre-process |
Attributes:
| Name | Type | Description |
|---|---|---|
co2_biosphere_sectors |
tuple[str, ...]
|
Gridding sectors that are assumed to come from the biosphere CO2 reservoir |
co2_fossil_sectors |
tuple[str, ...]
|
Gridding sectors that are assumed to come from the fossil CO2 reservoir |
co2_name |
str
|
Name used for CO2 in variable names |
level_separator |
str
|
The separator between levels in variable names |
n_processes |
int | None
|
Number of processes to use for parallel processing. |
progress |
bool
|
Should progress bars be shown? |
reaggregator |
ReaggregatorLike | None
|
Re-aggregator to use when converting raw data to gridding sectors |
run_checks |
bool
|
If |
table |
str
|
The value used for the top level of variable names |
world_gridding_sectors |
tuple[str, ...]
|
Sectors that are only used for gridding at the world (i.e. regional sum) level |
Source code in src/gcages/cmip7_scenariomip/pre_processing/pre_processor.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 | |
co2_biosphere_sectors
class-attribute
instance-attribute
#
co2_biosphere_sectors: tuple[str, ...] = (
CO2_BIOSPHERE_SECTORS_GRIDDING
)
Gridding sectors that are assumed to come from the biosphere CO2 reservoir
co2_fossil_sectors
class-attribute
instance-attribute
#
co2_fossil_sectors: tuple[str, ...] = (
CO2_FOSSIL_SECTORS_GRIDDING
)
Gridding sectors that are assumed to come from the fossil CO2 reservoir
co2_name
class-attribute
instance-attribute
#
co2_name: str = 'CO2'
Name used for CO2 in variable names
level_separator
class-attribute
instance-attribute
#
level_separator: str = '|'
The separator between levels in variable names
n_processes
class-attribute
instance-attribute
#
Number of processes to use for parallel processing.
Set to None to process in serial.
reaggregator
class-attribute
instance-attribute
#
reaggregator: ReaggregatorLike | None = None
Re-aggregator to use when converting raw data to gridding sectors
If not supplied, we guess the re-aggregator during processing
run_checks
class-attribute
instance-attribute
#
run_checks: bool = True
If True, run checks on both input and output data
If you are sure about your workflow, you can disable the checks to speed things up (but we don't recommend this unless you really are confident about what you're doing).
table
class-attribute
instance-attribute
#
table: str = 'Emissions'
The value used for the top level of variable names
world_gridding_sectors
class-attribute
instance-attribute
#
Sectors that are only used for gridding at the world (i.e. regional sum) level
__call__ #
__call__(
in_emissions: DataFrame,
) -> CMIP7ScenarioMIPPreProcessingResult
Pre-process
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_emissions
|
DataFrame
|
Emissions to pre-process |
required |
Returns:
| Type | Description |
|---|---|
CMIP7ScenarioMIPPreProcessingResult
|
Pre-processed emissions |
Source code in src/gcages/cmip7_scenariomip/pre_processing/pre_processor.py
ReaggregatorBasic #
Reaggregator that follows this module's logic
Methods:
| Name | Description |
|---|---|
assert_has_all_required_timeseries |
Assert that the data has all the required timeseries |
assert_is_internally_consistent |
Assert that the data is internally consistent |
default_tols_internal_consistency |
Get default tolerances for internal consistency checks |
get_internal_consistency_checking_index |
Get the index which selects only data relevant for checking internal consistency |
to_complete |
Convert the raw data to complete data |
to_gridding_sectors |
Re-aggregate data to the sectors used for gridding |
Attributes:
| Name | Type | Description |
|---|---|---|
internal_consistency_tolerances |
Mapping[str, Mapping[str, float]] | Mapping[str, Mapping[str, PINT_SCALAR]]
|
Tolerances to apply when checking the internal consistency of the data |
model_regions |
tuple[str, ...]
|
Model regions to use while reaggregating |
region_level |
str
|
Region level in the data index |
unit_level |
str
|
Unit level in the data index |
variable_level |
str
|
Variable level in the data index |
world_region |
str
|
The value used when the data represents the sum over all regions |
Source code in src/gcages/cmip7_scenariomip/pre_processing/reaggregation/basic.py
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 | |
internal_consistency_tolerances
class-attribute
instance-attribute
#
internal_consistency_tolerances: (
Mapping[str, Mapping[str, float]]
| Mapping[str, Mapping[str, PINT_SCALAR]]
) = field()
Tolerances to apply when checking the internal consistency of the data
model_regions
instance-attribute
#
Model regions to use while reaggregating
region_level
class-attribute
instance-attribute
#
region_level: str = 'region'
Region level in the data index
unit_level
class-attribute
instance-attribute
#
unit_level: str = 'unit'
Unit level in the data index
variable_level
class-attribute
instance-attribute
#
variable_level: str = 'variable'
Variable level in the data index
world_region
class-attribute
instance-attribute
#
world_region: str = 'World'
The value used when the data represents the sum over all regions
(Having a value for this is odd, there should really just be no region level when data is the sum, but this is the data format used so we have to follow this convention.)
assert_has_all_required_timeseries #
assert_has_all_required_timeseries(indf: DataFrame) -> None
Assert that the data has all the required timeseries
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indf
|
DataFrame
|
Data to check |
required |
Raises:
| Type | Description |
|---|---|
NotCompleteError
|
|
Source code in src/gcages/cmip7_scenariomip/pre_processing/reaggregation/basic.py
assert_is_internally_consistent #
assert_is_internally_consistent(indf: DataFrame) -> None
Assert that the data is internally consistent
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indf
|
DataFrame
|
Data to check |
required |
Raises:
| Type | Description |
|---|---|
InternalConsistencyError
|
The data is not internally consistent |
Source code in src/gcages/cmip7_scenariomip/pre_processing/reaggregation/basic.py
default_tols_internal_consistency #
default_tols_internal_consistency() -> (
Mapping[str, Mapping[str, float]]
| Mapping[str, Mapping[str, PINT_SCALAR]]
)
Get default tolerances for internal consistency checks
Source code in src/gcages/cmip7_scenariomip/pre_processing/reaggregation/basic.py
get_internal_consistency_checking_index #
get_internal_consistency_checking_index() -> MultiIndex
Get the index which selects only data relevant for checking internal consistency
Returns:
| Type | Description |
|---|---|
MultiIndex
|
Internal consistency checking index |
Source code in src/gcages/cmip7_scenariomip/pre_processing/reaggregation/basic.py
to_complete #
to_complete(raw: DataFrame) -> ToCompleteResult
Convert the raw data to complete data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Raw data |
required |
Returns:
| Type | Description |
|---|---|
ToCompleteResult
|
To complete result |
Source code in src/gcages/cmip7_scenariomip/pre_processing/reaggregation/basic.py
to_gridding_sectors #
Re-aggregate data to the sectors used for gridding
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indf
|
DataFrame
|
Data to re-aggregate |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Data re-aggregated to the gridding sectors |
Source code in src/gcages/cmip7_scenariomip/pre_processing/reaggregation/basic.py
ReaggregatorLike #
Bases: Protocol
Interface that can be used for re-aggregation
Methods:
| Name | Description |
|---|---|
assert_has_all_required_timeseries |
Assert that the data has all the required timeseries |
assert_is_internally_consistent |
Assert that the data is internally consistent |
get_internal_consistency_checking_index |
Get the index which selects only data relevant for checking internal consistency |
to_complete |
Convert the raw data to complete data |
to_gridding_sectors |
Re-aggregate data to the sectors used for gridding |
Attributes:
| Name | Type | Description |
|---|---|---|
model_regions |
tuple[str, ...]
|
Model regions to use while reaggregating |
region_level |
str
|
Region level in the data index |
unit_level |
str
|
Unit level in the data index |
variable_level |
str
|
Variable level in the data index |
world_region |
str
|
The value used when the data represents the sum over all regions |
Source code in src/gcages/cmip7_scenariomip/pre_processing/pre_processor.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | |
model_regions
instance-attribute
#
Model regions to use while reaggregating
world_region
instance-attribute
#
world_region: str
The value used when the data represents the sum over all regions
(Having a value for this is odd, there should really just be no region level when data is the sum, but this is the data format used so we have to follow this convention.)
assert_has_all_required_timeseries #
assert_has_all_required_timeseries(indf: DataFrame) -> None
Assert that the data has all the required timeseries
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indf
|
DataFrame
|
Data to check |
required |
Raises:
| Type | Description |
|---|---|
NotCompleteError
|
|
Source code in src/gcages/cmip7_scenariomip/pre_processing/pre_processor.py
assert_is_internally_consistent #
assert_is_internally_consistent(indf: DataFrame) -> None
Assert that the data is internally consistent
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indf
|
DataFrame
|
Data to check |
required |
Raises:
| Type | Description |
|---|---|
InternalConsistencyError
|
The data is not internally consistent |
Source code in src/gcages/cmip7_scenariomip/pre_processing/pre_processor.py
get_internal_consistency_checking_index #
get_internal_consistency_checking_index() -> MultiIndex
Get the index which selects only data relevant for checking internal consistency
Returns:
| Type | Description |
|---|---|
MultiIndex
|
Internal consistency checking index |
Source code in src/gcages/cmip7_scenariomip/pre_processing/pre_processor.py
to_complete #
to_complete(raw: DataFrame) -> ToCompleteResult
Convert the raw data to complete data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw
|
DataFrame
|
Raw data |
required |
Returns:
| Type | Description |
|---|---|
ToCompleteResult
|
To complete result |
Source code in src/gcages/cmip7_scenariomip/pre_processing/pre_processor.py
to_gridding_sectors #
ToCompleteResult #
Result of calling to_complete on a reaggregator
Attributes:
| Name | Type | Description |
|---|---|---|
assumed_zero |
DataFrame | None
|
The timeseries that were assumed to be zero to make |
complete |
DataFrame
|
Complete pd.DataFrame |