From c6141ed78d7c8db607128eed92383c5b228ec2c2 Mon Sep 17 00:00:00 2001 From: Thomas Vogt Date: Fri, 28 Oct 2022 14:21:48 +0200 Subject: [PATCH] MeasureSet.from_excel: leave default fallback to init --- climada/entity/measures/measure_set.py | 62 +++++++++++++------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/climada/entity/measures/measure_set.py b/climada/entity/measures/measure_set.py index 6a8571fcb..be0548dda 100755 --- a/climada/entity/measures/measure_set.py +++ b/climada/entity/measures/measure_set.py @@ -444,11 +444,6 @@ def read_att_excel(measures, dfr, var_names): """Read Excel measures attributes""" num_mes = len(dfr.index) for idx in range(0, num_mes): - try: - haz_type = dfr[var_names['col_name']['haz']][idx] - except KeyError: - haz_type = "" - # Search for (a, b) values, put a=1 otherwise try: hazard_inten_imp = (dfr[var_names['col_name']['haz_int_a']][idx], @@ -456,46 +451,49 @@ def read_att_excel(measures, dfr, var_names): except KeyError: hazard_inten_imp = (1, dfr['hazard intensity impact'][idx]) + meas_kwargs = dict( + name=dfr[var_names['col_name']['name']][idx], + cost=dfr[var_names['col_name']['cost']][idx], + hazard_freq_cutoff=dfr[var_names['col_name']['haz_frq']][idx], + hazard_set=dfr[var_names['col_name']['haz_set']][idx], + hazard_inten_imp=hazard_inten_imp, + mdd_impact=(dfr[var_names['col_name']['mdd_a']][idx], + dfr[var_names['col_name']['mdd_b']][idx]), + paa_impact=(dfr[var_names['col_name']['paa_a']][idx], + dfr[var_names['col_name']['paa_b']][idx]), + imp_fun_map=dfr[var_names['col_name']['fun_map']][idx], + risk_transf_attach=dfr[var_names['col_name']['risk_att']][idx], + risk_transf_cover=dfr[var_names['col_name']['risk_cov']][idx], + color_rgb=np.fromstring( + dfr[var_names['col_name']['color']][idx], dtype=float, sep=' '), + ) + + try: + meas_kwargs["haz_type"] = dfr[var_names['col_name']['haz']][idx] + except KeyError: + pass + try: - exposures_set = dfr[var_names['col_name']['exp_set']][idx] + meas_kwargs["exposures_set"] = dfr[var_names['col_name']['exp_set']][idx] except KeyError: - exposures_set = "" + pass try: - exp_region_id = ast.literal_eval( + meas_kwargs["exp_region_id"] = ast.literal_eval( dfr[var_names['col_name']['exp_reg']][idx]) except KeyError: - exp_region_id = None + pass except ValueError: - exp_region_id = dfr[var_names['col_name']['exp_reg']][idx] + meas_kwargs["exp_region_id"] = dfr[var_names['col_name']['exp_reg']][idx] try: - risk_transf_cost_factor = ( + meas_kwargs["risk_transf_cost_factor"] = ( dfr[var_names['col_name']['risk_fact']][idx] ) except KeyError: - risk_transf_cost_factor = 1 + pass - measures.append(Measure( - name=dfr[var_names['col_name']['name']][idx], - haz_type=haz_type, - color_rgb=np.fromstring( - dfr[var_names['col_name']['color']][idx], dtype=float, sep=' '), - cost=dfr[var_names['col_name']['cost']][idx], - hazard_freq_cutoff=dfr[var_names['col_name']['haz_frq']][idx], - hazard_set=dfr[var_names['col_name']['haz_set']][idx], - hazard_inten_imp=hazard_inten_imp, - exposures_set=exposures_set, - exp_region_id=exp_region_id, - mdd_impact=(dfr[var_names['col_name']['mdd_a']][idx], - dfr[var_names['col_name']['mdd_b']][idx]), - paa_impact=(dfr[var_names['col_name']['paa_a']][idx], - dfr[var_names['col_name']['paa_b']][idx]), - imp_fun_map=dfr[var_names['col_name']['fun_map']][idx], - risk_transf_attach=dfr[var_names['col_name']['risk_att']][idx], - risk_transf_cover=dfr[var_names['col_name']['risk_cov']][idx], - risk_transf_cost_factor=risk_transf_cost_factor, - )) + measures.append(Measure(**meas_kwargs)) dfr = pd.read_excel(file_name, var_names['sheet_name']) dfr = dfr.fillna('')