Skip to content

Commit f8b5c07

Browse files
Merge branch 'develop'
# Conflicts: # climada/_version.py # setup.py
2 parents 71fe94a + 8905cd2 commit f8b5c07

File tree

98 files changed

+8828
-2398
lines changed

Some content is hidden

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

98 files changed

+8828
-2398
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ climada/hazard/test/data/tc_tracks_nc/*
6060
climada/hazard/test/data/tc_tracks.h5
6161
climada/hazard/test/data/test_centr.h5
6262
climada/hazard/test/data/test_haz.h5
63+
climada/hazard/test/data/test_unsupported.h5
6364
climada/test/data/1988234N13299.nc
6465
climada/test/data/exposure_buildings_default_47_7.h5
6566
climada/test/data/exposure_high_47_8.h5

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,26 @@ Follow the [tutorial](https://climada-python.readthedocs.io/en/latest/tutorial/1
2626

2727
Documentation is available on Read the Docs:
2828

29+
Note that all the documentations has two versions,'latest' and 'stable', and explicit version numbers, such as 'v3.1.1', in the url path. 'latest' is created from the 'develop' branch and has the latest changes by developers, 'stable' from the latest release. For more details about documentation versions, please have a look at [here](https://readthedocs.org/projects/climada-python/versions/).
30+
31+
CLIMADA python:
2932
* [online (recommended)](https://climada-python.readthedocs.io/en/latest/)
3033
* [PDF file](https://climada-python.readthedocs.io/_/downloads/en/stable/pdf/)
3134

35+
CLIMADA petals:
36+
* [online (recommended)](https://climada-petals.readthedocs.io/en/latest/)
37+
* [PDF file](https://climada-petals.readthedocs.io/_/downloads/en/stable/pdf/)
38+
* [petals Tutorials on GitHub](https://github.com/CLIMADA-project/climada_petals/tree/main/doc/tutorial)
39+
40+
3241
## Citing CLIMADA
3342

3443
If you use CLIMADA please cite (in general, in particular for academic work) :
3544

45+
The [used version](https://zenodo.org/search?page=1&size=20&q=climada)
46+
47+
and/or the following published articles:
48+
3649
Aznar-Siguan, G. and Bresch, D. N., 2019: CLIMADA v1: a global weather and climate risk assessment platform, Geosci. Model Dev., 12, 3085–3097, https://doi.org/10.5194/gmd-12-3085-2019
3750

3851
Bresch, D. N. and Aznar-Siguan, G., 2021: CLIMADA v1.4.1: towards a globally consistent adaptation options appraisal tool, Geosci. Model Dev., 14, 351-363, https://doi.org/10.5194/gmd-14-351-2021

climada.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
"util": {
2424
"test_data": "{test_directory}/util/test/data"
2525
},
26+
"data_api": {
27+
"supported_exposures_types": ["litpop", "crop_production", "base"]
28+
},
2629
"log_level": "INFO"
2730
}

climada/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
HAZ_DEMO_H5,
5959
TC_ANDREW_FL,
6060
DEMO_DIR.joinpath('demo_emdat_impact_data_2020.csv'),
61+
DEMO_DIR.joinpath('nl_rails.gpkg'),
6162
] + WS_DEMO_NC
6263
}
6364

@@ -68,9 +69,9 @@ def test_installation():
6869
"""
6970
from unittest import TestLoader, TextTestRunner
7071
suite = TestLoader().discover(start_dir='climada.engine.test',
71-
pattern='test_cost_benefit.py')
72+
pattern='test_cost_benefit.py')
7273
suite.addTest(TestLoader().discover(start_dir='climada.engine.test',
73-
pattern='test_impact.py'))
74+
pattern='test_impact.py'))
7475
TextTestRunner(verbosity=2).run(suite)
7576

7677

climada/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '3.1.3'
1+
__version__ = '3.2.0'

climada/conf/climada.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
"hazard": {
4545
"relative_cropyield": {
46-
"local_data": "{exposures.crop_production.local_data}",
46+
"local_data": "{local_data.system}/ISIMIP_crop",
4747
"filename_wheat_mask": "mask_winter_and_spring_wheat_areas_phase3.nc4"
4848
},
4949
"trop_cyclone": {
@@ -65,6 +65,8 @@
6565
"url": "https://climada.ethz.ch/data-api/v1/",
6666
"chunk_size": 8192,
6767
"cache_db": "{local_data.system}/.downloads.db",
68+
"cache_enabled": true,
69+
"cache_dir": "{local_data.system}/.apicache",
6870
"supported_hazard_types": ["river_flood", "tropical_cyclone", "storm_europe", "relative_cropyield"],
6971
"supported_exposures_types": ["litpop", "crop_production"]
7072
}

climada/engine/calibration_opt.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
Optimization and manual calibration
2121
"""
2222

23-
import numpy as np
24-
import pandas as pd
2523
import datetime as dt
2624
import copy
25+
import itertools
26+
import logging
27+
import numpy as np
28+
import pandas as pd
2729
from scipy import interpolate
2830
from scipy.optimize import minimize
29-
import itertools
3031

3132
from climada.engine import Impact
3233
from climada.entity import ImpactFuncSet, ImpfTropCyclone, impact_funcs
3334
from climada.engine.impact_data import emdat_impact_yearlysum, emdat_impact_event
3435

35-
import logging
3636
LOGGER = logging.getLogger(__name__)
3737

3838

@@ -111,7 +111,7 @@ def calib_instance(hazard, exposure, impact_func, df_out=pd.DataFrame(),
111111
raise ValueError('adding simulated impacts to reported impacts not'
112112
' yet implemented. use yearly_impact=True or run'
113113
' without init_impact_data.')
114-
if not return_cost == 'False':
114+
if return_cost != 'False':
115115
df_out = calib_cost_calc(df_out, return_cost)
116116
return df_out
117117

climada/engine/cost_benefit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ def combine_measures(self, in_meas_names, new_name, new_color, disc_rates,
265265
-------
266266
climada.CostBenefit
267267
"""
268+
# pylint: disable=protected-access
268269
new_cb = CostBenefit()
269270
new_cb.present_year = self.present_year
270271
new_cb.future_year = self.future_year

climada/engine/forecast.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import logging
2626
import datetime as dt
27-
from pathlib import Path
2827
import numpy as np
2928
import matplotlib.pyplot as plt
3029
from matplotlib.patches import Patch
@@ -340,8 +339,8 @@ def plot_imp_map(
340339
figure size for plt.subplots, width, height in inches
341340
The default is (9, 13)
342341
adapt_fontsize : bool, optional
343-
If set to true, the size of the fonts will be adapted to the size of the figure. Otherwise
344-
the default matplotlib font size is used. Default is True.
342+
If set to true, the size of the fonts will be adapted to the size of the figure.
343+
Otherwise the default matplotlib font size is used. Default is True.
345344
346345
Returns
347346
-------
@@ -397,6 +396,7 @@ def _plot_imp_map(
397396
adapt_fontsize=True,
398397
):
399398
# select hazard with run_datetime
399+
# pylint: disable=protected-access
400400
if run_datetime is None:
401401
run_datetime = self.run_datetime[0]
402402
haz_ind = np.argwhere(np.isin(self.run_datetime, run_datetime))[0][0]
@@ -729,8 +729,8 @@ def plot_exceedence_prob(
729729
figure size for plt.subplots, width, height in inches
730730
The default is (9, 13)
731731
adapt_fontsize : bool, optional
732-
If set to true, the size of the fonts will be adapted to the size of the figure. Otherwise
733-
the default matplotlib font size is used. Default is True.
732+
If set to true, the size of the fonts will be adapted to the size of the figure.
733+
Otherwise the default matplotlib font size is used. Default is True.
734734
735735
Returns
736736
-------
@@ -794,6 +794,7 @@ def _plot_exc_prob(
794794
):
795795
"""plot the probability of reaching a threshold"""
796796
# select hazard with run_datetime
797+
# pylint: disable=protected-access
797798
if run_datetime is None:
798799
run_datetime = self.run_datetime[0]
799800
haz_ind = np.argwhere(np.isin(self.run_datetime, run_datetime))[0][0]
@@ -962,8 +963,8 @@ def plot_warn_map(
962963
close_fig : bool, optional
963964
Figure is not drawn if True. The default is False.
964965
adapt_fontsize : bool, optional
965-
If set to true, the size of the fonts will be adapted to the size of the figure. Otherwise
966-
the default matplotlib font size is used. Default is True.
966+
If set to true, the size of the fonts will be adapted to the size of the figure.
967+
Otherwise the default matplotlib font size is used. Default is True.
967968
968969
Returns
969970
-------
@@ -1027,6 +1028,7 @@ def _plot_warn(
10271028
):
10281029
"""plotting the warning level of each warning region based on thresholds"""
10291030
# select hazard with run_datetime
1031+
# pylint: disable=protected-access
10301032
if run_datetime is None:
10311033
run_datetime = self.run_datetime[0]
10321034
haz_ind = np.argwhere(np.isin(self.run_datetime, run_datetime))[0][0]

climada/engine/impact.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def calc_freq_curve(self, return_per=None):
111111
112112
Returns
113113
-------
114-
ImpactFreqCurve
114+
climada.engine.impact.ImpactFreqCurve
115115
"""
116116
ifc = ImpactFreqCurve()
117117
ifc.tag = self.tag
@@ -251,7 +251,7 @@ def calc_risk_transfer(self, attachment, cover):
251251
252252
Returns
253253
-------
254-
climada.engine.Impact
254+
climada.engine.impact.Impact
255255
"""
256256
new_imp = copy.deepcopy(self)
257257
if attachment or cover:
@@ -270,7 +270,7 @@ def calc_risk_transfer(self, attachment, cover):
270270

271271
return new_imp, Impact()
272272

273-
def plot_hexbin_eai_exposure(self, mask=None, ignore_zero=True,
273+
def plot_hexbin_eai_exposure(self, mask=None, ignore_zero=False,
274274
pop_name=True, buffer=0.0, extend='neither',
275275
axis=None, adapt_fontsize=True, **kwargs):
276276
"""Plot hexbin expected annual impact of each exposure.
@@ -308,7 +308,7 @@ def plot_hexbin_eai_exposure(self, mask=None, ignore_zero=True,
308308
axis.set_title('Expected annual impact')
309309
return axis
310310

311-
def plot_scatter_eai_exposure(self, mask=None, ignore_zero=True,
311+
def plot_scatter_eai_exposure(self, mask=None, ignore_zero=False,
312312
pop_name=True, buffer=0.0, extend='neither',
313313
axis=None, adapt_fontsize=True, **kwargs):
314314
"""Plot scatter expected annual impact of each exposure.
@@ -331,8 +331,8 @@ def plot_scatter_eai_exposure(self, mask=None, ignore_zero=True,
331331
axis : matplotlib.axes._subplots.AxesSubplot, optional
332332
axis to use
333333
adapt_fontsize : bool, optional
334-
If set to true, the size of the fonts will be adapted to the size of the figure. Otherwise
335-
the default matplotlib font size is used. Default is True.
334+
If set to true, the size of the fonts will be adapted to the size of the figure.
335+
Otherwise the default matplotlib font size is used. Default is True.
336336
kwargs : optional
337337
arguments for hexbin matplotlib function
338338
@@ -371,8 +371,8 @@ def plot_raster_eai_exposure(self, res=None, raster_res=None, save_tiff=None,
371371
axis : matplotlib.axes._subplots.AxesSubplot, optional
372372
axis to use
373373
adapt_fontsize : bool, optional
374-
If set to true, the size of the fonts will be adapted to the size of the figure. Otherwise
375-
the default matplotlib font size is used. Default is True.
374+
If set to true, the size of the fonts will be adapted to the size of the figure.
375+
Otherwise the default matplotlib font size is used. Default is True.
376376
kwargs : optional
377377
arguments for imshow matplotlib function
378378
@@ -428,7 +428,7 @@ def plot_basemap_eai_exposure(self, mask=None, ignore_zero=False, pop_name=True,
428428
axis.set_title('Expected annual impact')
429429
return axis
430430

431-
def plot_hexbin_impact_exposure(self, event_id=1, mask=None, ignore_zero=True,
431+
def plot_hexbin_impact_exposure(self, event_id=1, mask=None, ignore_zero=False,
432432
pop_name=True, buffer=0.0, extend='neither',
433433
axis=None, adapt_fontsize=True, **kwargs):
434434
"""Plot hexbin impact of an event at each exposure.
@@ -457,8 +457,8 @@ def plot_hexbin_impact_exposure(self, event_id=1, mask=None, ignore_zero=True,
457457
axis : matplotlib.axes._subplots.AxesSubplot
458458
optional axis to use
459459
adapt_fontsize : bool, optional
460-
If set to true, the size of the fonts will be adapted to the size of the figure. Otherwise
461-
the default matplotlib font size is used. Default is True.
460+
If set to true, the size of the fonts will be adapted to the size of the figure.
461+
Otherwise the default matplotlib font size is used. Default is True.
462462
463463
Returns
464464
--------
@@ -471,12 +471,13 @@ def plot_hexbin_impact_exposure(self, event_id=1, mask=None, ignore_zero=True,
471471
kwargs['cmap'] = CMAP_IMPACT
472472
impact_at_events_exp = self._build_exp_event(event_id)
473473
axis = impact_at_events_exp.plot_hexbin(mask, ignore_zero, pop_name,
474-
buffer, extend, axis=axis, adapt_fontsize=adapt_fontsize,
474+
buffer, extend, axis=axis,
475+
adapt_fontsize=adapt_fontsize,
475476
**kwargs)
476477

477478
return axis
478479

479-
def plot_basemap_impact_exposure(self, event_id=1, mask=None, ignore_zero=True,
480+
def plot_basemap_impact_exposure(self, event_id=1, mask=None, ignore_zero=False,
480481
pop_name=True, buffer=0.0, extend='neither', zoom=10,
481482
url='http://tile.stamen.com/terrain/tileZ/tileX/tileY.png',
482483
axis=None, **kwargs):
@@ -619,7 +620,8 @@ def calc_impact_year_set(self, all_years=True, year_range=None):
619620
620621
Returns
621622
-------
622-
Impact year set of type numpy.ndarray with summed impact per year.
623+
yearset : numpy.ndarray
624+
Impact year set of type numpy.ndarray with summed impact per year.
623625
"""
624626
if year_range is None:
625627
year_range = []
@@ -851,16 +853,17 @@ def read_excel(self, *args, **kwargs):
851853
@staticmethod
852854
def video_direct_impact(exp, impf_set, haz_list, file_name='',
853855
writer=animation.PillowWriter(bitrate=500),
854-
imp_thresh=0, args_exp=None, args_imp=None):
856+
imp_thresh=0, args_exp=None, args_imp=None,
857+
ignore_zero=False, pop_name=False):
855858
"""
856859
Computes and generates video of accumulated impact per input events
857860
over exposure.
858861
859862
Parameters
860863
----------
861-
exp : Exposures
864+
exp : climada.entity.Exposures
862865
exposures instance, constant during all video
863-
impf_set : ImpactFuncSet
866+
impf_set : climada.entity.ImpactFuncSet
864867
impact functions
865868
haz_list : (list(Hazard))
866869
every Hazard contains an event; all hazards
@@ -877,6 +880,12 @@ def video_direct_impact(exp, impf_set, haz_list, file_name='',
877880
args_imp : optional
878881
arguments for scatter (points) or hexbin (raster)
879882
matplotlib function used in impact
883+
ignore_zero : bool, optional
884+
flag to indicate if zero and negative
885+
values are ignored in plot. Default: False
886+
pop_name : bool, optional
887+
add names of the populated places
888+
The default is False.
880889
881890
Returns
882891
-------
@@ -932,17 +941,17 @@ def run(i_time):
932941
haz_list[i_time].plot_intensity(1, axis=axis, cmap='Greys', vmin=v_lim[0],
933942
vmax=v_lim[1], alpha=0.8)
934943
if plot_raster:
935-
exp.plot_hexbin(axis=axis, mask=exp_list[i_time], ignore_zero=True,
936-
pop_name=False, **args_exp)
944+
exp.plot_hexbin(axis=axis, mask=exp_list[i_time], ignore_zero=ignore_zero,
945+
pop_name=pop_name, **args_exp)
937946
if imp_list[i_time].coord_exp.size:
938-
imp_list[i_time].plot_hexbin_eai_exposure(axis=axis, pop_name=False,
947+
imp_list[i_time].plot_hexbin_eai_exposure(axis=axis, pop_name=pop_name,
939948
**args_imp)
940949
fig.delaxes(fig.axes[1])
941950
else:
942-
exp.plot_scatter(axis=axis, mask=exp_list[i_time], ignore_zero=True,
943-
pop_name=False, **args_exp)
951+
exp.plot_scatter(axis=axis, mask=exp_list[i_time], ignore_zero=ignore_zero,
952+
pop_name=pop_name, **args_exp)
944953
if imp_list[i_time].coord_exp.size:
945-
imp_list[i_time].plot_scatter_eai_exposure(axis=axis, pop_name=False,
954+
imp_list[i_time].plot_scatter_eai_exposure(axis=axis, pop_name=pop_name,
946955
**args_imp)
947956
fig.delaxes(fig.axes[1])
948957
fig.delaxes(fig.axes[1])
@@ -1155,7 +1164,7 @@ def select(self,
11551164
11561165
Returns
11571166
-------
1158-
imp : climada.engine.Impact
1167+
imp : climada.engine.impact.Impact
11591168
A new impact object with a selection of events and/or exposures
11601169
11611170
"""

0 commit comments

Comments
 (0)