|
19 | 19 |
|
20 | 20 | """ |
21 | 21 |
|
22 | | -import copy |
23 | | -from itertools import groupby |
24 | | -from unittest import TestCase |
25 | | - |
26 | | -import geopandas as gpd |
27 | 22 | import numpy as np |
28 | 23 | import pandas as pd |
29 | 24 | import pytest |
30 | 25 |
|
31 | 26 | from climada.engine.impact_calc import ImpactCalc |
32 | 27 | from climada.entity.disc_rates.base import DiscRates |
33 | | -from climada.entity.exposures.base import Exposures |
34 | | -from climada.entity.impact_funcs.base import ImpactFunc |
35 | | -from climada.entity.impact_funcs.impact_func_set import ImpactFuncSet |
36 | | -from climada.hazard.base import Hazard |
37 | | -from climada.test.conftest import ( |
38 | | - CATEGORIES, |
39 | | - DATES, |
40 | | - EVENT_IDS, |
41 | | - EVENT_NAMES, |
42 | | - EXPOSURE_REF_YEAR, |
43 | | - FREQUENCY, |
44 | | - FREQUENCY_UNIT, |
45 | | - HAZARD_MAX_INTENSITY, |
46 | | - HAZARD_TYPE, |
47 | | - HAZARD_UNIT, |
48 | | - IMPF_ID, |
49 | | - IMPF_NAME, |
50 | | -) |
| 28 | +from climada.test.conftest import CATEGORIES, EXPOSURE_REF_YEAR |
51 | 29 | from climada.trajectories import InterpolatedRiskTrajectory, StaticRiskTrajectory |
52 | 30 | from climada.trajectories.constants import ( |
53 | 31 | AAI_METRIC_NAME, |
54 | | - AAI_PER_GROUP_METRIC_NAME, |
55 | 32 | CONTRIBUTION_BASE_RISK_NAME, |
56 | 33 | CONTRIBUTION_EXPOSURE_NAME, |
57 | 34 | CONTRIBUTION_HAZARD_NAME, |
58 | 35 | CONTRIBUTION_INTERACTION_TERM_NAME, |
59 | 36 | CONTRIBUTION_VULNERABILITY_NAME, |
60 | | - COORD_ID_COL_NAME, |
61 | 37 | DATE_COL_NAME, |
62 | | - EAI_METRIC_NAME, |
63 | 38 | GROUP_COL_NAME, |
64 | 39 | MEASURE_COL_NAME, |
65 | 40 | METRIC_COL_NAME, |
66 | 41 | NO_MEASURE_VALUE, |
67 | 42 | PERIOD_COL_NAME, |
68 | | - RETURN_PERIOD_METRIC_NAME, |
69 | 43 | RISK_COL_NAME, |
70 | | - RP_VALUE_PREFIX, |
71 | 44 | UNIT_COL_NAME, |
72 | 45 | ) |
73 | 46 | from climada.trajectories.snapshot import Snapshot |
74 | 47 | from climada.trajectories.trajectory import DEFAULT_RP |
75 | 48 |
|
76 | 49 | EXPOSURE_FUTURE_YEAR = 2040 |
77 | 50 |
|
78 | | -from climada.trajectories.snapshot import Snapshot |
79 | | - |
80 | 51 |
|
81 | 52 | @pytest.fixture(scope="session") |
82 | 53 | def snapshot_factory( |
@@ -509,21 +480,21 @@ def expected_interp_metrics(): |
509 | 480 | return pd.DataFrame.from_dict( |
510 | 481 | {'index': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], |
511 | 482 | 'columns': [DATE_COL_NAME, GROUP_COL_NAME, MEASURE_COL_NAME, METRIC_COL_NAME, UNIT_COL_NAME, RISK_COL_NAME], |
512 | | - 'data': [[ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 18.0], |
513 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 94.5], |
| 483 | + 'data': [[ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 18.0], |
| 484 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 94.5], |
514 | 485 | # Above should indeed not be 216+18 / 2 and slightly |
515 | 486 | # because as we interpolate each contributor separately, |
516 | 487 | # the interaction term grows slower. |
517 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 216.0], |
518 | | - [ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
519 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
520 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
521 | | - [ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 500.0], |
522 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 2625.0], |
523 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 6000.0], |
524 | | - [ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'rp_250', 'USD', 3750.0], |
525 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'rp_250', 'USD', 19687.5], |
526 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'rp_250', 'USD', 45000.0]], |
| 488 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 216.0], |
| 489 | + [ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
| 490 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
| 491 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
| 492 | + [ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 500.0], |
| 493 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 2625.0], |
| 494 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 6000.0], |
| 495 | + [ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'rp_250', 'USD', 3750.0], |
| 496 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'rp_250', 'USD', 19687.5], |
| 497 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'rp_250', 'USD', 45000.0]], |
527 | 498 | 'index_names': [None], |
528 | 499 | 'column_names': [None] |
529 | 500 | }, |
@@ -612,21 +583,21 @@ def expected_interp_metrics_rpchange(): |
612 | 583 | return pd.DataFrame.from_dict( |
613 | 584 | {'index': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], |
614 | 585 | 'columns': [DATE_COL_NAME, GROUP_COL_NAME, MEASURE_COL_NAME, METRIC_COL_NAME, UNIT_COL_NAME, RISK_COL_NAME], |
615 | | - 'data': [[ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 18.0], |
616 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 94.5], |
| 586 | + 'data': [[ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 18.0], |
| 587 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 94.5], |
617 | 588 | # Above should indeed not be 216+18 / 2 and slightly |
618 | 589 | # because as we interpolate each contributor separately, |
619 | 590 | # the interaction term grows slower. |
620 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 216.0], |
621 | | - [ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
622 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
623 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
624 | | - [ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
625 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
626 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
627 | | - [ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'rp_500', 'USD', 3750.0], |
628 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'rp_500', 'USD', 19687.5], |
629 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'rp_500', 'USD', 45000.0]], |
| 591 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 216.0], |
| 592 | + [ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
| 593 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
| 594 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
| 595 | + [ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
| 596 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
| 597 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
| 598 | + [ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'rp_500', 'USD', 3750.0], |
| 599 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'rp_500', 'USD', 19687.5], |
| 600 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'rp_500', 'USD', 45000.0]], |
630 | 601 | 'index_names': [None], |
631 | 602 | 'column_names': [None] |
632 | 603 | }, |
@@ -659,21 +630,21 @@ def expected_interp_metrics_ratechange(): |
659 | 630 | return pd.DataFrame.from_dict( |
660 | 631 | {'index': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], |
661 | 632 | 'columns': [DATE_COL_NAME, GROUP_COL_NAME, MEASURE_COL_NAME, METRIC_COL_NAME, UNIT_COL_NAME, RISK_COL_NAME], |
662 | | - 'data': [[ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 18.0], |
663 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 90.0], |
| 633 | + 'data': [[ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 18.0], |
| 634 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 90.0], |
664 | 635 | # Above should indeed not be 216+18 / 2 and slightly |
665 | 636 | # because as we interpolate each contributor separately, |
666 | 637 | # the interaction term grows slower. |
667 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 195.9183673469], |
668 | | - [ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
669 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
670 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
671 | | - [ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
672 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
673 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
674 | | - [ pd.Period(2020), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 500.0], |
675 | | - [ pd.Period(2021), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 2500.0], |
676 | | - [ pd.Period(2022), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 5442.176870]], |
| 638 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'aai', 'USD', 195.9183673469], |
| 639 | + [ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
| 640 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
| 641 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'rp_20', 'USD', 0.0], |
| 642 | + [ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
| 643 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
| 644 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'rp_50', 'USD', 0.0], |
| 645 | + [ pd.Period("2020"), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 500.0], |
| 646 | + [ pd.Period("2021"), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 2500.0], |
| 647 | + [ pd.Period("2022"), 'All',NO_MEASURE_VALUE, 'rp_100', 'USD', 5442.176870]], |
677 | 648 | 'index_names': [None], |
678 | 649 | 'column_names': [None] |
679 | 650 | }, |
|
0 commit comments