gcages.ar6.pre_processing#
Pre-processing part of the workflow
Classes:
| Name | Description |
|---|---|
AR6PreProcessor |
Pre-processor that follows the same logic as was used in AR6 |
Functions:
| Name | Description |
|---|---|
add_conditional_sums |
Add sums to a pd.DataFrame if all components are present |
condtionally_remove_variables |
Conditionally remove variables |
drop_variables_if_identical |
Drop variables if they are identical to another variable |
reclassify_variables |
Reclassify variables |
run_parallel_pre_processing |
Run a pre-processing step in parallel |
AR6PreProcessor #
Pre-processor that follows the same logic as was used in AR6
If you want exactly the same behaviour as in AR6,
initialise using from_ar6_config
Methods:
| Name | Description |
|---|---|
__call__ |
Pre-process |
from_ar6_config |
Initialise from config that was used in AR6 |
Attributes:
| Name | Type | Description |
|---|---|---|
conditional_removals |
tuple[tuple[str, tuple[str, ...]], ...] | None
|
Specification for variables that can be removed if other variables are present |
conditional_sums |
tuple[tuple[str, tuple[str, ...]], ...] | None
|
Specification for variables that can be created from other variables |
drop_if_identical |
tuple[tuple[str, str], ...] | None
|
Variables that can be dropped if they are idential to another variable |
emissions_out |
tuple[str, ...]
|
Names of emissions that can be included in the result of pre-processing |
n_processes |
int | None
|
Number of processes to use for parallel processing. |
negative_value_not_small_threshold |
float
|
Threshold which defines when a negative value is not small |
progress |
bool
|
Should progress bars be shown for each operation? |
reclassifications |
Mapping[str, tuple[str, ...]] | None
|
Variables that should be reclassified as being part of another variable |
run_checks |
bool
|
If |
Source code in src/gcages/ar6/pre_processing.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 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 489 490 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 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 | |
conditional_removals
class-attribute
instance-attribute
#
conditional_sums
class-attribute
instance-attribute
#
drop_if_identical
class-attribute
instance-attribute
#
emissions_out
instance-attribute
#
Names of emissions that can be included in the result of pre-processing
Not all these emissions need to be there, but any names which are not in this list will be removed as part of pre-processing.
n_processes
class-attribute
instance-attribute
#
Number of processes to use for parallel processing.
Set to None to process in serial.
negative_value_not_small_threshold
instance-attribute
#
negative_value_not_small_threshold: float
Threshold which defines when a negative value is not small
Non-CO2 emissions less than this that are negative are not automatically set to zero.
progress
class-attribute
instance-attribute
#
progress: bool = True
Should progress bars be shown for each operation?
reclassifications
class-attribute
instance-attribute
#
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).
__call__ #
Pre-process
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_emissions
|
DataFrame
|
Emissions to pre-process |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Pre-processed emissions |
Source code in src/gcages/ar6/pre_processing.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 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 | |
from_ar6_config
classmethod
#
from_ar6_config(
run_checks: bool = True,
progress: bool = True,
n_processes: int | None = cpu_count(),
) -> AR6PreProcessor
Initialise from config that was used in AR6
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_checks
|
bool
|
Should checks of the input and output data be performed? If this is turned off, things are faster, but error messages are much less clear if things go wrong. |
True
|
progress
|
bool
|
Should a progress bar be shown for each operation? |
True
|
n_processes
|
int | None
|
Number of processes to use for parallel processing. Set to |
cpu_count()
|
Returns:
| Type | Description |
|---|---|
AR6PreProcessor
|
Initialised Pre-processor |
Source code in src/gcages/ar6/pre_processing.py
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 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 | |
add_conditional_sums #
add_conditional_sums(
indf: DataFrame,
conditional_sums: tuple[
tuple[str, tuple[str, ...]], ...
],
copy_on_entry: bool = True,
) -> DataFrame
Add sums to a pd.DataFrame if all components are present
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indf
|
DataFrame
|
Data to add sums to |
required |
conditional_sums
|
tuple[tuple[str, tuple[str, ...]], ...]
|
Definition of the conditional sums. The first element of each sub-tuple is the name of the variable to add. The second element are its components. If the variable is added, all the sub-components are dropped. All components must be present for the variable to be added. If the variable is already there, the sum is not re-calculated or checked. |
required |
copy_on_entry
|
bool
|
Should the data be copied on entry? |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Source code in src/gcages/ar6/pre_processing.py
condtionally_remove_variables #
condtionally_remove_variables(
indf: DataFrame,
conditional_removals: tuple[
tuple[str, tuple[str, ...]], ...
],
copy_on_entry: bool = True,
) -> DataFrame
Conditionally remove variables
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indf
|
DataFrame
|
Data to add sums to |
required |
conditional_removals
|
tuple[tuple[str, tuple[str, ...]], ...]
|
Definition of the conditional removals. For each tuple, the first element defines the variable that can be removed.
This variable will be removed if all variables in the tuple's second element
are present in |
required |
copy_on_entry
|
bool
|
Should the data be copied on entry? |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Source code in src/gcages/ar6/pre_processing.py
drop_variables_if_identical #
drop_variables_if_identical(
indf: DataFrame,
drop_if_identical: tuple[tuple[str, str], ...],
copy_on_entry: bool = True,
) -> DataFrame
Drop variables if they are identical to another variable
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indf
|
DataFrame
|
Data to add sums to |
required |
drop_if_identical
|
tuple[tuple[str, str], ...]
|
Definition of the variables that can be dropped. For each tuple, the first element defines the variable that can be removed and the second element defines the variable to compare it to. If the variable to drop has the same values as the variable to compare to, it is dropped. |
required |
copy_on_entry
|
bool
|
Should the data be copied on entry? |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Source code in src/gcages/ar6/pre_processing.py
reclassify_variables #
reclassify_variables(
indf: DataFrame,
reclassifications: Mapping[str, tuple[str, ...]],
copy_on_entry: bool = True,
) -> DataFrame
Reclassify variables
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indf
|
DataFrame
|
Data to add sums to |
required |
reclassifications
|
Mapping[str, tuple[str, ...]]
|
Definition of the reclassifications. For each variable (key) in For example, if then if "var_b" or "var_c" (or both) is in |
required |
copy_on_entry
|
bool
|
Should the data be copied on entry? |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Source code in src/gcages/ar6/pre_processing.py
run_parallel_pre_processing #
run_parallel_pre_processing(
indf: DataFrame,
func_to_call: Callable[
Concatenate[DataFrame, P], DataFrame
],
groups: tuple[str, ...] = ("model", "scenario"),
progress: bool = True,
progress_bar_desc: str | None = None,
n_processes: int | None = cpu_count(),
*args: args,
**kwargs: kwargs,
) -> DataFrame
Run a pre-processing step in parallel
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indf
|
DataFrame
|
Input data to process |
required |
func_to_call
|
Callable[Concatenate[DataFrame, P], DataFrame]
|
Function to apply to each group in |
required |
groups
|
tuple[str, ...]
|
Columns to use to group the data in |
('model', 'scenario')
|
progress
|
bool
|
Should a progress bar be displayed? |
True
|
progress_bar_desc
|
str | None
|
If If not supplied, we use a default description. |
None
|
n_processes
|
int | None
|
Number of parallel processes to use |
cpu_count()
|
**kwargs
|
kwargs
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Result of calling |