Skip to content

Commit e3da3ec

Browse files
Merge branch 'cross-calibrate-impact-functions' of github.com:CLIMADA-project/climada_python into cross-calibrate-impact-functions
2 parents 373dbbc + 51630a6 commit e3da3ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+4942
-2045
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
-
4848
name: Install CLIMADA
4949
run: |
50-
python -m pip install ".[test]"
50+
python -m pip install "./[dev]"
5151
-
5252
name: Run Unit Tests
5353
run: |

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,5 @@ results/
183183
!.pylintrc
184184
!.readthedocs.yml
185185
!.github
186+
climada_petals/
187+
climada_python/

.zenodo.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
},
120120
{
121121
"name": "Valentin Gebhart"
122+
},
123+
{
124+
"name": "Dahyann Araya"
122125
}
123126
]
124127
}

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@
3636
* Luca Severino
3737
* Samuel Juhel
3838
* Valentin Gebhart
39+
* Dahyann Araya

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ Code freeze date: YYYY-MM-DD
1010

1111
### Dependency Changes
1212

13+
Added:
14+
15+
- `fiona` >=1.10
16+
17+
Updated:
18+
19+
- `geopandas` >=0.14,<1.0 → >=0.14
20+
- `pandas` >=2.1,<2.2 → >=2.1
21+
1322
Removed:
1423

1524
- `pandas-datareader`
1625

1726
### Added
27+
1828
- Added optional parameter to `geo_im_from_array`, `plot_from_gdf`, `plot_rp_imp`, `plot_rp_intensity`,
1929
`plot_intensity`, `plot_fraction`, `_event_plot` to mask plotting when regions are too far from data points [#1047](https://github.com/CLIMADA-project/climada_python/pull/1047). To recreate previous plots (no masking), the parameter can be set to None.
2030
- Added instructions to install Climada petals on Euler cluster in `doc.guide.Guide_Euler.ipynb` [#1029](https://github.com/CLIMADA-project/climada_python/pull/1029)
@@ -23,11 +33,14 @@ Removed:
2333

2434
### Changed
2535

36+
- Changed the default mask_distance in `util.plot.geo_im_from_array` to 0.03 to avoid white gaps in gridded hazard data with comparably low resolution (>80 centroids per axis) [#1073](https://github.com/CLIMADA-project/climada_python/pull/1073)
37+
- Increased speed of `util.plot.add_shapes` by avoiding for loops, substantially speeding up `Hazard.plot_intensity` and other functions. [#1073](https://github.com/CLIMADA-project/climada_python/pull/1073)
2638
- `Hazard.local_exceedance_intensity`, `Hazard.local_return_period` and `Impact.local_exceedance_impact`, `Impact.local_return_period`, using the `climada.util.interpolation` module: New default (no binning), binning on decimals, and faster implementation [#1012](https://github.com/CLIMADA-project/climada_python/pull/1012)
2739
- World Bank indicator data is now downloaded directly from their API via the function `download_world_bank_indicator`, instead of relying on the `pandas-datareader` package [#1033](https://github.com/CLIMADA-project/climada_python/pull/1033)
2840
- `Exposures.write_hdf5` pickles geometry data in WKB format, which is faster and more sustainable. [#1051](https://github.com/CLIMADA-project/climada_python/pull/1051)
2941
- The online documentation has been completely overhauled, now uses PyData theme: [#977](https://github.com/CLIMADA-project/climada_python/pull/977)
3042
- `Input` to impact function calibration tasks now supports adding weights to the data [#1048](https://github.com/CLIMADA-project/climada_python/pull/1048)
43+
- Add `climada.hazard.xarray` module with helper structures for reading Hazard objects from `xarray` data [#1063](https://github.com/CLIMADA-project/climada_python/pull/1063)
3144

3245
### Fixed
3346

@@ -36,9 +49,13 @@ Removed:
3649

3750
### Deprecated
3851

52+
- `Hazard.from_xarray_raster_file`. Use `Hazard.from_xarray_raster` and pass the file path as `data` argument [#1063](https://github.com/CLIMADA-project/climada_python/pull/1063)
53+
3954
### Removed
4055

4156
- `climada.util.interpolation.round_to_sig_digits` [#1012](https://github.com/CLIMADA-project/climada_python/pull/1012)
57+
- `intensity_thres` of `Hazard`, `StormEurope`, and `TropCyclones` object [#1065](https://github.com/CLIMADA-project/climada_python/pull/1065)
58+
- Deprecated method `climada.hazard.trop_cyclone.trop_cyclone.TropCyclone.set_from_tracks` [#1065](https://github.com/CLIMADA-project/climada_python/pull/1065)
4259

4360
## 6.0.1
4461

@@ -208,6 +225,7 @@ CLIMADA tutorials. [#872](https://github.com/CLIMADA-project/climada_python/pull
208225
- `Impact.write_hdf5` now throws an error if `event_name` is does not contain strings exclusively [#894](https://github.com/CLIMADA-project/climada_python/pull/894)
209226
- Split `climada.hazard.trop_cyclone` module into smaller submodules without affecting module usage [#911](https://github.com/CLIMADA-project/climada_python/pull/911)
210227
- `yearly_steps` parameter of `TropCyclone.apply_climate_scenario_knu` has been made explicit [#991](https://github.com/CLIMADA-project/climada_python/pull/991)
228+
- `Hazard.write_hdf5` writes centroids as x,y columns (or as wkb in case of polygons) at a compression level of 9, not as pickled `Shapely` objects anymore, which reduces the size of the files significantly.
211229

212230
### Fixed
213231

climada/engine/cost_benefit.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,9 +1079,7 @@ def _calc_impact_measures(
10791079
# compute impact for each measure
10801080
for measure in meas_set.get_measure(hazard.haz_type):
10811081
LOGGER.debug("%s impact of measure %s.", when, measure.name)
1082-
imp_tmp, risk_transf = measure.calc_impact(
1083-
exposures, imp_fun_set, hazard, assign_centroids=False
1084-
)
1082+
imp_tmp, risk_transf = measure.calc_impact(exposures, imp_fun_set, hazard)
10851083
impact_meas[measure.name] = dict()
10861084
impact_meas[measure.name]["cost"] = (
10871085
measure.cost,

climada/engine/impact.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ def plot_rp_imp(
11781178
return_periods=(25, 50, 100, 250),
11791179
log10_scale=True,
11801180
axis=None,
1181-
mask_distance=0.01,
1181+
mask_distance=0.03,
11821182
kwargs_local_exceedance_impact=None,
11831183
**kwargs,
11841184
):
@@ -1198,8 +1198,8 @@ def plot_rp_imp(
11981198
mask_distance: float, optional
11991199
Only regions are plotted that are closer to any of the data points than this distance,
12001200
relative to overall plot size. For instance, to only plot values
1201-
at the centroids, use mask_distance=0.01. If None, the plot is not masked.
1202-
Default is 0.01.
1201+
at the centroids, use mask_distance=0.03. If None, the plot is not masked.
1202+
Default is 0.03.
12031203
kwargs_local_exceedance_impact: dict
12041204
Dictionary of keyword arguments for the method impact.local_exceedance_impact.
12051205
kwargs : dict, optional

climada/engine/impact_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ def clean_emdat_df(
774774
df_data["Start Day"] = np.array(day_list, dtype="int")
775775
df_data["Start Year"] = np.array(year_list, dtype="int")
776776
for var in ["Disaster Subtype", "Disaster Type", "Country"]:
777-
df_data[VARNAMES_EMDAT[target_version][var]].fillna("None", inplace=True)
777+
df_data.fillna({VARNAMES_EMDAT[target_version][var]: "None"}, inplace=True)
778778

779779
# (3) Filter by countries, year range, and disaster type
780780
# (3.1) Countries:

climada/engine/test/test_cost_benefit.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
)
3636
from climada.entity.disc_rates import DiscRates
3737
from climada.entity.entity_def import Entity
38+
from climada.entity.measures import Measure
39+
from climada.entity.measures.base import LOGGER as ILOG
3840
from climada.hazard.base import Hazard
3941
from climada.test import get_test_file
4042
from climada.util.api_client import Client
@@ -1119,6 +1121,66 @@ def test_remove_measure(self):
11191121
self.assertEqual(len(cost_ben.cost_ben_ratio), 3)
11201122
self.assertEqual(len(cost_ben.benefit), 3)
11211123

1124+
def test_measure_exposure_no_centroids(self):
1125+
"""Test centroids assigned if no centroids were assigned in Measure Exposures object"""
1126+
hazard = Hazard.from_hdf5(HAZ_TEST_TC)
1127+
entity = Entity.from_excel(ENT_DEMO_TODAY)
1128+
entity.check()
1129+
entity.exposures.ref_year = 2018
1130+
1131+
# test that warning is not raised when centroid are assigned
1132+
try:
1133+
with self.assertLogs(ILOG, level="WARNING") as logs:
1134+
cost_ben = CostBenefit()
1135+
cost_ben.calc(
1136+
hazard,
1137+
entity,
1138+
future_year=2040,
1139+
risk_func=risk_aai_agg,
1140+
imp_time_depen=None,
1141+
save_imp=True,
1142+
)
1143+
for log in logs.output:
1144+
self.assertNotIn(
1145+
"No assigned hazard centroids in exposure object after",
1146+
log,
1147+
"Centroids are already assinged in Measure Exposure object"
1148+
"and should not be reassigned.",
1149+
)
1150+
except AssertionError as e:
1151+
if "no logs" in str(e).lower():
1152+
pass
1153+
else:
1154+
raise
1155+
1156+
# add measure with exposure without assigned centroids
1157+
exp_no_assigned_centroids = entity.exposures.copy()
1158+
exp_no_assigned_centroids.data = entity.exposures.data.drop(
1159+
columns=["centr_TC"]
1160+
)
1161+
entity.measures.append(
1162+
Measure(
1163+
name="no centroids",
1164+
haz_type="TC",
1165+
exposures_set=exp_no_assigned_centroids,
1166+
)
1167+
)
1168+
1169+
# test if warning is raised
1170+
with self.assertLogs(ILOG, level="WARNING") as logs:
1171+
cost_ben = CostBenefit()
1172+
cost_ben.calc(
1173+
hazard,
1174+
entity,
1175+
future_year=2040,
1176+
risk_func=risk_aai_agg,
1177+
imp_time_depen=None,
1178+
save_imp=True,
1179+
)
1180+
self.assertIn(
1181+
"No assigned hazard centroids in exposure object after", logs.output[0]
1182+
)
1183+
11221184

11231185
class TestCalc(unittest.TestCase):
11241186
"""Test calc"""

climada/engine/unsequa/calc_cost_benefit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def _map_costben_calc(
398398
ent_future=ent_fut,
399399
save_imp=False,
400400
assign_centroids=False,
401-
**cost_benefit_kwargs
401+
**cost_benefit_kwargs,
402402
)
403403
# Extract from climada.impact the chosen metrics
404404
uncertainty_values.append(

0 commit comments

Comments
 (0)