gcages.cmip7_scenariomip.pre_processing.pre_processor#
Definition of the pre-processor class
Classes:
| Name | Description |
|---|---|
CMIP7ScenarioMIPPreProcessingResult |
Result of pre-processing with CMIP7ScenarioMIPPreProcessor |
CMIP7ScenarioMIPPreProcessor |
Pre-processor for CMIP7's ScenarioMIP |
ReaggregatorLike |
Interface that can be used for re-aggregation |
Functions:
| Name | Description |
|---|---|
do_pre_processing |
Do the pre-processing for a given scenario |
guess_reaggregator |
Guess the re-aggregator to use with a given dataset |
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
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 #
do_pre_processing #
do_pre_processing(
indf: DataFrame,
reaggregator: ReaggregatorLike | None,
time_name: str,
run_checks: bool,
world_gridding_sectors: tuple[str, ...] = (
"Aircraft",
"International Shipping",
),
table: str = "Emissions",
level_separator: str = "|",
co2_fossil_sectors: tuple[
str, ...
] = CO2_FOSSIL_SECTORS_GRIDDING,
co2_biosphere_sectors: tuple[
str, ...
] = CO2_BIOSPHERE_SECTORS_GRIDDING,
co2_name: str = "CO2",
) -> CMIP7ScenarioMIPPreProcessingResult
Do the pre-processing for a given scenario
This only works on a single scenario at a time, to make verification and processing simpler.
Parameters#
indf Input data to process
reaggregator Re-aggregator to use during the processing
time_name
Name of the time axis in indf
run_checks Should checks be run during the processing?
If you know what you're doing, you can turn these off for speed.
world_gridding_sectors Sectors that should only be gridded at the world level
table Name of the 'table' for emissions
Used to process and create variable names
level_separator Separator between levels in the variable names
co2_fossil_sectors Sectors to assume have an origin in fossil CO2 reservoirs
These should be provided in the gridding naming convention
co2_biosphere_sectors Sectors to assume have an origin in biospheric CO2 reservoirs
These should be provided in the gridding naming convention
co2_name String that indicates emissions of CO2 in variable names
Returns#
: Results of the pre-processing
Source code in src/gcages/cmip7_scenariomip/pre_processing/pre_processor.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 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 | |
guess_reaggregator #
guess_reaggregator(
indf: DataFrame, region_level: str
) -> ReaggregatorLike
Guess the re-aggregator to use with a given dataset
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indf
|
DataFrame
|
Data for which to guess the re-aggregator |
required |
region_level
|
str
|
Region level in the data index |
required |
Returns:
| Type | Description |
|---|---|
ReaggregatorLike
|
Guessed re-aggregator |
Raises:
| Type | Description |
|---|---|
ValueError
|
Re-aggregator could not be guessed for |