From eb22779fe544c93d547824986c6a35690fbf9d0e Mon Sep 17 00:00:00 2001 From: Lukas Riedel <34276446+peanutfun@users.noreply.github.com> Date: Fri, 18 Nov 2022 17:55:50 +0100 Subject: [PATCH] Update ImpactFuncSet.__init__ (#568) * Add all ImpactFunc attributes to ImpactFunc.__init__ * Add type hints to ImpactFunc.__init__ * Update ImpactFunc classmethods to new init * Update tests to new ImpactFunc.__init__ * Update docs on InputVar regarding ImpactFunc * Update tutorials with new ImpactFunc.__init__ * Update ImpactFunc.__init__ docstring * Update argument order of ImpactFunc.__init__ * Fix linter issue * Update tests to new ImpactFunc.__init__ * Update tutorials with new ImpactFunc.__init__ * Enable passing impact funcs to ImpactFuncSet constructor * Update code base to new ImpactFuncSet constructor * Fix unit test of ImpactFuncSet Remove initialization with set because it does not guarantee insertion order. * undo re-plotting * Incorporate new ImpactFuncSet.__init__ method Co-authored-by: emanuel-schmid --- climada/engine/calibration_opt.py | 3 +- climada/engine/test/test_forecast.py | 6 +- climada/engine/unsequa/input_var.py | 3 +- climada/engine/unsequa/test/test_unsequa.py | 3 +- .../entity/impact_funcs/impact_func_set.py | 66 +++++++++------ .../impact_funcs/test/test_imp_fun_set.py | 84 ++++++++----------- climada/entity/measures/test/test_base.py | 3 +- climada/util/test/test_lines_polys_handler.py | 3 +- doc/tutorial/1_main_climada.ipynb | 3 +- doc/tutorial/climada_engine_CostBenefit.ipynb | 3 +- doc/tutorial/climada_engine_Forecast.ipynb | 6 +- doc/tutorial/climada_engine_Impact.ipynb | 12 +-- doc/tutorial/climada_engine_unsequa.ipynb | 3 +- .../climada_engine_unsequa_helper.ipynb | 3 +- ...mada_entity_Exposures_polygons_lines.ipynb | 8 +- .../climada_entity_ImpactFuncSet.ipynb | 4 +- doc/tutorial/climada_entity_MeasureSet.ipynb | 12 +-- doc/tutorial/climada_util_api_client.ipynb | 3 +- 18 files changed, 103 insertions(+), 125 deletions(-) diff --git a/climada/engine/calibration_opt.py b/climada/engine/calibration_opt.py index 176f60043..25ad6fa00 100644 --- a/climada/engine/calibration_opt.py +++ b/climada/engine/calibration_opt.py @@ -66,8 +66,7 @@ def calib_instance(hazard, exposure, impact_func, df_out=pd.DataFrame(), DataFrame with modelled impact written to rows for each year or event. """ - ifs = ImpactFuncSet() - ifs.append(impact_func) + ifs = ImpactFuncSet([impact_func]) impacts = ImpactCalc(exposures=exposure, impfset=ifs, hazard=hazard)\ .impact(assign_centroids=False) if yearly_impact: # impact per year diff --git a/climada/engine/test/test_forecast.py b/climada/engine/test/test_forecast.py index 48d8ea75d..3ca7f06e5 100644 --- a/climada/engine/test/test_forecast.py +++ b/climada/engine/test/test_forecast.py @@ -60,8 +60,7 @@ def test_Forecast_calc_properties(self): #vulnerability #generate vulnerability impact_function = ImpfStormEurope.from_welker() - impact_function_set = ImpactFuncSet() - impact_function_set.append(impact_function) + impact_function_set = ImpactFuncSet([impact_function]) #create and calculate Forecast forecast = Forecast({dt.datetime(2018,1,1): haz}, expo, impact_function_set) forecast.calc() @@ -130,8 +129,7 @@ def test_Forecast_plot(self): #vulnerability #generate vulnerability impact_function = ImpfStormEurope.from_welker() - impact_function_set = ImpactFuncSet() - impact_function_set.append(impact_function) + impact_function_set = ImpactFuncSet([impact_function]) #create and calculate Forecast forecast = Forecast({dt.datetime(2018,1,2): haz1, dt.datetime(2017,12,31): haz2}, diff --git a/climada/engine/unsequa/input_var.py b/climada/engine/unsequa/input_var.py index 11813adc9..0aa097ef8 100644 --- a/climada/engine/unsequa/input_var.py +++ b/climada/engine/unsequa/input_var.py @@ -92,8 +92,7 @@ def imp_fun_tc(G, v_half, vmin, k, _id=1): mdd=mdd, paa=paa) imp_fun.check() - impf_set = ImpactFuncSet() - impf_set.append(imp_fun) + impf_set = ImpactFuncSet([imp_fun]) return impf_set distr_dict = {"G": sp.stats.uniform(0.8, 1), "v_half": sp.stats.uniform(50, 100), diff --git a/climada/engine/unsequa/test/test_unsequa.py b/climada/engine/unsequa/test/test_unsequa.py index 008c4f1b3..2cabbc7db 100755 --- a/climada/engine/unsequa/test/test_unsequa.py +++ b/climada/engine/unsequa/test/test_unsequa.py @@ -59,8 +59,7 @@ def impf_dem(x_paa=1, x_mdd=1): paa = np.arange(0, len(intensity)) / len(intensity) * x_paa impf = ImpactFunc(haz_type, id, intensity, mdd, paa, intensity_unit) impf.check() - impf_set = ImpactFuncSet() - impf_set.append(impf) + impf_set = ImpactFuncSet([impf]) return impf_set diff --git a/climada/entity/impact_funcs/impact_func_set.py b/climada/entity/impact_funcs/impact_func_set.py index af42cb3ad..362a377f0 100755 --- a/climada/entity/impact_funcs/impact_func_set.py +++ b/climada/entity/impact_funcs/impact_func_set.py @@ -23,6 +23,7 @@ import copy import logging +from typing import Optional, Iterable from itertools import repeat import numpy as np import pandas as pd @@ -61,7 +62,7 @@ } """MATLAB variable names""" -class ImpactFuncSet(): +class ImpactFuncSet: """Contains impact functions of type ImpactFunc. Loads from files with format defined in FILE_EXT. @@ -74,29 +75,47 @@ class ImpactFuncSet(): directly accessed. Use the class methods instead. """ - def __init__(self): - """Empty initialization. + def __init__( + self, + impact_funcs: Optional[Iterable[ImpactFunc]] = None, + tag: Optional[Tag] = None + ): + """Initialization. + + Build an impact function set from an iterable of ImpactFunc. + + Parameters + ---------- + impact_funcs : iterable of ImpactFunc, optional + An iterable (list, set, array, ...) of ImpactFunc. + tag : climada.entity.tag.Tag, optional + The entity tag of this object. Examples -------- Fill impact functions with values and check consistency data: - >>> fun_1.haz_type = 'TC' - >>> fun_1.id = 3 - >>> fun_1.intensity = np.array([0, 20]) - >>> fun_1.paa = np.array([0, 1]) - >>> fun_1.mdd = np.array([0, 0.5]) - >>> fun_1 = ImpactFunc(haz_type, id, intensity, mdd, paa) - >>> imp_fun = ImpactFuncSet() - >>> imp_fun.append(fun_1) + >>> intensity = np.array([0, 20]) + >>> paa = np.array([0, 1]) + >>> mdd = np.array([0, 0.5]) + >>> fun_1 = ImpactFunc("TC", 3, intensity, mdd, paa) + >>> imp_fun = ImpactFuncSet([fun_1]) >>> imp_fun.check() - Read impact functions from file and checks consistency data. + Read impact functions from file and check data consistency. + + >>> imp_fun = ImpactFuncSet.from_excel(ENT_TEMPLATE_XLS) - >>> imp_fun = ImpactFuncSet() - >>> imp_fun.read(ENT_TEMPLATE_XLS) + Todo + ---- + * Automatically check this object if impact_funcs is not None. """ self.clear() + if tag is not None: + self.tag = tag + if impact_funcs is not None: + for impf in impact_funcs: + self.append(impf) def clear(self): """Reinitialize attributes.""" @@ -359,16 +378,13 @@ def from_excel(cls, file_name, description='', var_names=None): Returns ------- - ImpFuncSet + ImpactFuncSet """ if var_names is None: var_names = DEF_VAR_EXCEL - imp_func_set = cls() dfr = pd.read_excel(file_name, var_names['sheet_name']) - imp_func_set.clear() - imp_func_set.tag.file_name = str(file_name) - imp_func_set.tag.description = description + imp_func_set = cls(tag=Tag(str(file_name), description)) imp_func_set._fill_dfr(dfr, var_names) return imp_func_set @@ -423,9 +439,6 @@ def _get_hdf5_str(imp, idxs, file_name, var_name): return prev_str imp = u_hdf5.read(file_name) - impf_set = cls() - impf_set.tag.file_name = str(file_name) - impf_set.tag.description = description try: imp = imp[var_names['sup_field_name']] @@ -434,6 +447,7 @@ def _get_hdf5_str(imp, idxs, file_name, var_name): try: imp = imp[var_names['field_name']] funcs_idx = _get_hdf5_funcs(imp, file_name, var_names) + impact_funcs = [] for imp_key, imp_rows in funcs_idx.items(): # Store arguments in a dict (missing ones will be default) impf_kwargs = dict() @@ -455,11 +469,11 @@ def _get_hdf5_str(imp, idxs, file_name, var_name): imp[var_names['var_name']['inten']], imp_rows) impf_kwargs["mdd"] = np.take(imp[var_names['var_name']['mdd']], imp_rows) impf_kwargs["paa"] = np.take(imp[var_names['var_name']['paa']], imp_rows) - impf_set.append(ImpactFunc(**impf_kwargs)) + impact_funcs.append(ImpactFunc(**impf_kwargs)) except KeyError as err: raise KeyError("Not existing variable: %s" % str(err)) from err - return impf_set + return cls(impact_funcs, Tag(str(file_name), description)) def read_mat(self, *args, **kwargs): """This function is deprecated, use ImpactFuncSet.from_mat instead.""" @@ -540,8 +554,8 @@ def _get_xls_funcs(dfr, var_names): # check that the unit of the intensity is the same, if provided try: if len(df_func[var_names['col_name']['unit']].unique()) != 1: - raise ValueError('Impact function with two different \ - intensity units.') + raise ValueError('Impact function with two different' + ' intensity units.') impf_kwargs["intensity_unit"] = df_func[var_names['col_name'] ['unit']].values[0] except KeyError: diff --git a/climada/entity/impact_funcs/test/test_imp_fun_set.py b/climada/entity/impact_funcs/test/test_imp_fun_set.py index 805a78b84..73b072c61 100644 --- a/climada/entity/impact_funcs/test/test_imp_fun_set.py +++ b/climada/entity/impact_funcs/test/test_imp_fun_set.py @@ -22,7 +22,7 @@ import numpy as np from climada import CONFIG -from climada.entity.impact_funcs.impact_func_set import ImpactFuncSet, ImpactFunc +from climada.entity.impact_funcs.impact_func_set import ImpactFuncSet, ImpactFunc, Tag from climada.util.constants import ENT_TEMPLATE_XLS, ENT_DEMO_TODAY ENT_TEST_MAT = CONFIG.exposures.test_data.dir().joinpath('demo_today.mat') @@ -65,17 +65,13 @@ def test_add_wrong_error(self): def test_remove_func_pass(self): """Test remove_func removes ImpactFunc of ImpactFuncSet correcty.""" - imp_fun = ImpactFuncSet() - vulner_1 = ImpactFunc("TC", 1) - imp_fun.append(vulner_1) + imp_fun = ImpactFuncSet([ImpactFunc("TC", 1)]) imp_fun.remove_func() self.assertEqual(0, len(imp_fun._data)) def test_remove_wrong_error(self): """Test error is raised when invalid inputs.""" - imp_fun = ImpactFuncSet() - vulner_1 = ImpactFunc("TC", 1) - imp_fun.append(vulner_1) + imp_fun = ImpactFuncSet([ImpactFunc("TC", 1)]) with self.assertLogs('climada.entity.impact_funcs.impact_func_set', level='WARNING') as cm: imp_fun.remove_func('FL') self.assertIn('No ImpactFunc with hazard FL.', cm.output[0]) @@ -85,9 +81,7 @@ def test_remove_wrong_error(self): def test_get_hazards_pass(self): """Test get_hazard_types function.""" - imp_fun = ImpactFuncSet() - vulner_1 = ImpactFunc("TC", 1) - imp_fun.append(vulner_1) + imp_fun = ImpactFuncSet([ImpactFunc("TC", 1)]) self.assertEqual(1, len(imp_fun.get_hazard_types())) self.assertEqual(['TC'], imp_fun.get_hazard_types()) @@ -133,9 +127,7 @@ def test_get_ids_pass(self): def test_get_ids_wrong_zero(self): """Test get_ids method with wrong inputs.""" - imp_fun = ImpactFuncSet() - vulner_1 = ImpactFunc("WS", 56) - imp_fun.append(vulner_1) + imp_fun = ImpactFuncSet([ImpactFunc("WS", 56)]) self.assertEqual([], imp_fun.get_ids('TC')) def test_get_func_pass(self): @@ -167,9 +159,7 @@ def test_get_func_pass(self): def test_get_func_wrong_error(self): """Test get_func method with wrong inputs.""" - imp_fun = ImpactFuncSet() - vulner_1 = ImpactFunc("WS", 56) - imp_fun.append(vulner_1) + imp_fun = ImpactFuncSet([ImpactFunc("WS", 56)]) self.assertEqual([], imp_fun.get_func('TC')) def test_size_pass(self): @@ -242,6 +232,28 @@ def test_append_pass(self): self.assertIn(3, imp_fun._data['TC'].keys()) self.assertIn(3, imp_fun._data['FL'].keys()) + def test_init_with_iterable(self): + """Check that initializing with iterables works""" + def _check_contents(imp_fun): + self.assertEqual(imp_fun.size("TC"), 2) + self.assertEqual(imp_fun.size("FL"), 1) + self.assertEqual(imp_fun.size(fun_id=1), 1) + self.assertEqual(imp_fun.size(fun_id=3), 2) + np.testing.assert_array_equal(imp_fun.get_ids("TC"), [1, 3]) + np.testing.assert_array_equal(imp_fun.get_ids("FL"), [3]) + + # Initialize with empty list + impf_set = ImpactFuncSet([]) + self.assertEqual(impf_set.size("TC"), 0) + self.assertFalse(impf_set.get_ids("TC")) + + # Initialize with list + _check_contents(ImpactFuncSet( + [ImpactFunc("TC", 1), ImpactFunc("TC", 3), ImpactFunc("FL", 3)])) + # Initialize with tuple + _check_contents(ImpactFuncSet( + (ImpactFunc("TC", 1), ImpactFunc("TC", 3), ImpactFunc("FL", 3)))) + def test_remove_add_pass(self): """Test ImpactFunc can be added after removing.""" imp_fun = ImpactFuncSet() @@ -261,12 +273,11 @@ class TestChecker(unittest.TestCase): """Test loading funcions from the ImpactFuncSet class""" def test_check_wrongPAA_fail(self): """Wrong PAA definition""" - imp_fun = ImpactFuncSet() intensity = np.array([1, 2, 3]) mdd = np.array([1, 2, 3]) paa = np.array([1, 2]) vulner = ImpactFunc("TC", 1, intensity, mdd, paa) - imp_fun.append(vulner) + imp_fun = ImpactFuncSet([vulner]) with self.assertRaises(ValueError) as cm: imp_fun.check() @@ -274,12 +285,11 @@ def test_check_wrongPAA_fail(self): def test_check_wrongMDD_fail(self): """Wrong MDD definition""" - imp_fun = ImpactFuncSet() intensity = np.array([1, 2, 3]) mdd = np.array([1, 2]) paa = np.array([1, 2, 3]) vulner = ImpactFunc("TC", 1, intensity, mdd, paa) - imp_fun.append(vulner) + imp_fun = ImpactFuncSet([vulner]) with self.assertRaises(ValueError) as cm: imp_fun.check() @@ -290,18 +300,9 @@ class TestExtend(unittest.TestCase): def test_extend_to_empty_same(self): """Extend ImpactFuncSet to empty one.""" imp_fun = ImpactFuncSet() - imp_fun_add = ImpactFuncSet() - vulner_1 = ImpactFunc("TC", 1) - imp_fun_add.append(vulner_1) - - vulner_2 = ImpactFunc("TC", 3) - imp_fun_add.append(vulner_2) - - vulner_3 = ImpactFunc("FL", 3) - imp_fun_add.append(vulner_3) - - imp_fun_add.tag.file_name = 'file1.txt' - + imp_fun_add = ImpactFuncSet( + (ImpactFunc("TC", 1), ImpactFunc("TC", 3), ImpactFunc("FL", 3)), + Tag('file1.txt')) imp_fun.extend(imp_fun_add) imp_fun.check() @@ -313,12 +314,9 @@ def test_extend_to_empty_same(self): def test_extend_equal_same(self): """Extend the same ImpactFuncSet. The inital ImpactFuncSet is obtained.""" - imp_fun = ImpactFuncSet() vulner_1 = ImpactFunc("TC", 1) - imp_fun.append(vulner_1) - - imp_fun_add = ImpactFuncSet() - imp_fun_add.append(vulner_1) + imp_fun = ImpactFuncSet([vulner_1]) + imp_fun_add = ImpactFuncSet([vulner_1]) imp_fun.extend(imp_fun_add) imp_fun.check() @@ -339,16 +337,8 @@ def test_extend_different_extend(self): vulner_3 = ImpactFunc("FL", 3) imp_fun.append(vulner_3) - imp_fun_add = ImpactFuncSet() - vulner_1 = ImpactFunc("TC", 1) - imp_fun_add.append(vulner_1) - - vulner_2 = ImpactFunc("WS", 1) - imp_fun_add.append(vulner_2) - - vulner_3 = ImpactFunc("FL", 3) - imp_fun_add.append(vulner_3) - + imp_fun_add = ImpactFuncSet( + (ImpactFunc("TC", 1), ImpactFunc("WS", 1), ImpactFunc("FL", 3))) imp_fun.extend(imp_fun_add) imp_fun.check() diff --git a/climada/entity/measures/test/test_base.py b/climada/entity/measures/test/test_base.py index 83ca6d5ff..7dabbef14 100644 --- a/climada/entity/measures/test/test_base.py +++ b/climada/entity/measures/test/test_base.py @@ -49,7 +49,6 @@ def test_change_imp_func_pass(self): meas = MeasureSet.from_mat(ENT_TEST_MAT) act_1 = meas.get_measure(name='Mangroves')[0] - imp_set = ImpactFuncSet() haz_type = 'XX' idx = 1 intensity = np.arange(10, 100, 10) @@ -62,7 +61,7 @@ def test_change_imp_func_pass(self): 0.398500000000000, 0.657000000000000, 1.000000000000000, 1.000000000000000, 1.000000000000000]) imp_tc = ImpactFunc(haz_type, idx, intensity, mdd, paa) - imp_set.append(imp_tc) + imp_set = ImpactFuncSet([imp_tc]) new_imp = act_1._change_imp_func(imp_set).get_func('XX')[0] self.assertTrue(np.array_equal(new_imp.intensity, np.array([4., 24., 34., 44., diff --git a/climada/util/test/test_lines_polys_handler.py b/climada/util/test/test_lines_polys_handler.py index 2020abaef..91c65af8f 100644 --- a/climada/util/test/test_lines_polys_handler.py +++ b/climada/util/test/test_lines_polys_handler.py @@ -49,8 +49,7 @@ GDF_POINT = EXP_POINT.gdf IMPF = ImpfStormEurope.from_welker() -IMPF_SET = ImpactFuncSet() -IMPF_SET.append(IMPF) +IMPF_SET = ImpactFuncSet([IMPF]) COL_CHANGING = ['value', 'latitude', 'longitude', 'geometry', 'geometry_orig'] diff --git a/doc/tutorial/1_main_climada.ipynb b/doc/tutorial/1_main_climada.ipynb index dc9522484..fa13b3e21 100644 --- a/doc/tutorial/1_main_climada.ipynb +++ b/doc/tutorial/1_main_climada.ipynb @@ -640,8 +640,7 @@ "metadata": {}, "outputs": [], "source": [ - "imp_fun_set = ImpactFuncSet()\n", - "imp_fun_set.append(imp_fun)" + "imp_fun_set = ImpactFuncSet([imp_fun])" ] }, { diff --git a/doc/tutorial/climada_engine_CostBenefit.ipynb b/doc/tutorial/climada_engine_CostBenefit.ipynb index d03db5d67..47b2a3ea6 100644 --- a/doc/tutorial/climada_engine_CostBenefit.ipynb +++ b/doc/tutorial/climada_engine_CostBenefit.ipynb @@ -589,8 +589,7 @@ "impf_tc = ImpfTropCyclone.from_emanuel_usa()\n", "\n", "# add the impact function to an Impact function set\n", - "impf_set = ImpactFuncSet()\n", - "impf_set.append(impf_tc)\n", + "impf_set = ImpactFuncSet([impf_tc])\n", "impf_set.check()\n", "impf_tc.plot()" ] diff --git a/doc/tutorial/climada_engine_Forecast.ipynb b/doc/tutorial/climada_engine_Forecast.ipynb index c6827a4b9..2718ca852 100644 --- a/doc/tutorial/climada_engine_Forecast.ipynb +++ b/doc/tutorial/climada_engine_Forecast.ipynb @@ -58,8 +58,7 @@ "source": [ "#generate vulnerability\n", "impact_function = ImpfStormEurope.from_welker()\n", - "impact_function_set = ImpactFuncSet()\n", - "impact_function_set.append(impact_function)" + "impact_function_set = ImpactFuncSet([impact_function])" ] }, { @@ -297,8 +296,7 @@ "imp_fun_low = ImpactFunc(haz_type, idx, intensity, mdd, paa, intensity_unit, name)\n", "imp_fun_low.check()\n", "# fill ImpactFuncSet\n", - "impf_set = ImpactFuncSet()\n", - "impf_set.append(imp_fun_low)" + "impf_set = ImpactFuncSet([imp_fun_low])" ] }, { diff --git a/doc/tutorial/climada_engine_Impact.ipynb b/doc/tutorial/climada_engine_Impact.ipynb index eed8bc830..a9cc71007 100644 --- a/doc/tutorial/climada_engine_Impact.ipynb +++ b/doc/tutorial/climada_engine_Impact.ipynb @@ -588,8 +588,7 @@ "impf_tc = ImpfTropCyclone.from_emanuel_usa()\n", "\n", "# add the impact function to an Impact function set\n", - "impf_set = ImpactFuncSet()\n", - "impf_set.append(impf_tc)\n", + "impf_set = ImpactFuncSet([impf_tc])\n", "impf_set.check()" ] }, @@ -1184,9 +1183,8 @@ "ax_pnt.get_figure().colorbar(ax_pnt.collections[0], fraction=0.0175, pad=0.02).set_label('Intensity (m/s)') # add colorbar\n", "\n", "# Set impact function\n", - "impf_pnt = ImpactFuncSet()\n", "impf_tc = ImpfTropCyclone.from_emanuel_usa()\n", - "impf_pnt.append(impf_tc)\n", + "impf_pnt = ImpactFuncSet([impf_tc])\n", "impf_pnt.check()\n", "\n", "# Get the hazard type and hazard id\n", @@ -1337,8 +1335,7 @@ "paa = np.ones(intensity.size)\n", "impf_dum = ImpactFunc(hazard_type, haz_id, intensity, mdd, paa, \"m\", \"dummy\")\n", "# Add the impact function to the impact function set\n", - "impf_ras = ImpactFuncSet()\n", - "impf_ras.append(impf_dum)\n", + "impf_ras = ImpactFuncSet([impf_dum])\n", "impf_ras.check()\n", "\n", "# Exposures: rename column and assign id\n", @@ -1600,8 +1597,7 @@ "\n", "# impact function\n", "impf_def = ImpfTropCyclone.from_emanuel_usa()\n", - "impfs_video = ImpactFuncSet()\n", - "impfs_video.append(impf_def)\n", + "impfs_video = ImpactFuncSet([impf_def])\n", "impfs_video.check()\n", "\n", "# compute sequence of hazards using TropCyclone video_intensity method\n", diff --git a/doc/tutorial/climada_engine_unsequa.ipynb b/doc/tutorial/climada_engine_unsequa.ipynb index 7b1221c10..0c13e0441 100644 --- a/doc/tutorial/climada_engine_unsequa.ipynb +++ b/doc/tutorial/climada_engine_unsequa.ipynb @@ -1031,8 +1031,7 @@ " paa = np.array([sigmoid_func(v, G, v_half, vmin, k) for v in intensity])\n", " imp_fun = ImpactFunc(\"TC\", _id, intensity, mdd, paa, intensity_unit)\n", " imp_fun.check()\n", - " impf_set = ImpactFuncSet()\n", - " impf_set.append(imp_fun)\n", + " impf_set = ImpactFuncSet([imp_fun])\n", " return impf_set\n", "\n", "\n", diff --git a/doc/tutorial/climada_engine_unsequa_helper.ipynb b/doc/tutorial/climada_engine_unsequa_helper.ipynb index d4f57c721..2f89eee8d 100644 --- a/doc/tutorial/climada_engine_unsequa_helper.ipynb +++ b/doc/tutorial/climada_engine_unsequa_helper.ipynb @@ -1158,8 +1158,7 @@ "source": [ "from climada.entity import ImpactFuncSet, ImpfTropCyclone\n", "impf = ImpfTropCyclone.from_emanuel_usa()\n", - "impf_set_base = ImpactFuncSet()\n", - "impf_set_base.append(impf)" + "impf_set_base = ImpactFuncSet([impf])" ] }, { diff --git a/doc/tutorial/climada_entity_Exposures_polygons_lines.ipynb b/doc/tutorial/climada_entity_Exposures_polygons_lines.ipynb index 332b59fe9..d9fe066f2 100644 --- a/doc/tutorial/climada_entity_Exposures_polygons_lines.ipynb +++ b/doc/tutorial/climada_entity_Exposures_polygons_lines.ipynb @@ -74,8 +74,7 @@ "EXP_MIX = Exposures.concat([EXP_POLY, EXP_LINE, EXP_POINT])\n", "\n", "IMPF = ImpfStormEurope.from_welker()\n", - "IMPF_SET = ImpactFuncSet()\n", - "IMPF_SET.append(IMPF)" + "IMPF_SET = ImpactFuncSet([IMPF])" ] }, { @@ -125,7 +124,7 @@ " exp=EXP_MIX, impf_set=IMPF_SET, haz=HAZ,\n", " res=0.2, to_meters=False, disagg_met=u_lp.DisaggMethod.DIV, disagg_val=None,\n", " agg_met=u_lp.AggMethod.SUM\n", - " );" + " )" ] }, { @@ -506,8 +505,7 @@ "storms = StormEurope.from_footprints(WS_DEMO_NC, description='test_description')\n", "# define impact function\n", "impf = ImpfStormEurope.from_welker()\n", - "impf_set = ImpactFuncSet()\n", - "impf_set.append(impf)" + "impf_set = ImpactFuncSet([impf])" ] }, { diff --git a/doc/tutorial/climada_entity_ImpactFuncSet.ipynb b/doc/tutorial/climada_entity_ImpactFuncSet.ipynb index 35cf7980e..096286232 100644 --- a/doc/tutorial/climada_entity_ImpactFuncSet.ipynb +++ b/doc/tutorial/climada_entity_ImpactFuncSet.ipynb @@ -272,9 +272,7 @@ "imp_fun_3.check()\n", "\n", "# add the 2 impact functions into ImpactFuncSet\n", - "imp_fun_set = ImpactFuncSet()\n", - "imp_fun_set.append(imp_fun_1)\n", - "imp_fun_set.append(imp_fun_3)" + "imp_fun_set = ImpactFuncSet([imp_fun_1, imp_fun_3])" ] }, { diff --git a/doc/tutorial/climada_entity_MeasureSet.ipynb b/doc/tutorial/climada_entity_MeasureSet.ipynb index c5975d183..10e2ffeeb 100644 --- a/doc/tutorial/climada_entity_MeasureSet.ipynb +++ b/doc/tutorial/climada_entity_MeasureSet.ipynb @@ -138,8 +138,7 @@ "\n", "# impact functions\n", "impf_tc = ImpfTropCyclone.from_emanuel_usa()\n", - "impf_all = ImpactFuncSet()\n", - "impf_all.append(impf_tc)\n", + "impf_all = ImpactFuncSet([impf_tc])\n", "impf_all.plot();\n", "\n", "# dummy Hazard and Exposures\n", @@ -238,8 +237,7 @@ "\n", "# impact functions\n", "impf_tc = ImpfTropCyclone.from_emanuel_usa()\n", - "impf_all = ImpactFuncSet()\n", - "impf_all.append(impf_tc)\n", + "impf_all = ImpactFuncSet([impf_tc])\n", "\n", "# Hazard\n", "haz = Hazard.from_hdf5(HAZ_DEMO_H5)\n", @@ -373,8 +371,7 @@ "\n", "# impact functions\n", "impf_tc = ImpfTropCyclone.from_emanuel_usa()\n", - "impf_all = ImpactFuncSet()\n", - "impf_all.append(impf_tc)\n", + "impf_all = ImpactFuncSet([impf_tc])\n", "\n", "# Hazard\n", "haz = Hazard.from_hdf5(HAZ_DEMO_H5)\n", @@ -462,8 +459,7 @@ "\n", "# impact functions\n", "impf_tc = ImpfTropCyclone.from_emanuel_usa()\n", - "impf_all = ImpactFuncSet()\n", - "impf_all.append(impf_tc)\n", + "impf_all = ImpactFuncSet([impf_tc])\n", "\n", "# Hazard\n", "haz = Hazard.from_hdf5(HAZ_DEMO_H5)\n", diff --git a/doc/tutorial/climada_util_api_client.ipynb b/doc/tutorial/climada_util_api_client.ipynb index b2dfa8c79..55118a273 100644 --- a/doc/tutorial/climada_util_api_client.ipynb +++ b/doc/tutorial/climada_util_api_client.ipynb @@ -441,8 +441,7 @@ "imp_fun.check()\n", "imp_fun.plot()\n", "\n", - "imp_fun_set = ImpactFuncSet()\n", - "imp_fun_set.append(imp_fun)\n", + "imp_fun_set = ImpactFuncSet([imp_fun])\n", "\n", "litpop.impact_funcs = imp_fun_set" ]