Skip to content

Commit

Permalink
MeasureSet.from_excel: leave default fallback to init
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Vogt committed Oct 28, 2022
1 parent 3d7cc15 commit c6141ed
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions climada/entity/measures/measure_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,58 +444,56 @@ 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],
dfr[var_names['col_name']['haz_int_b']][idx])
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('')
Expand Down

0 comments on commit c6141ed

Please sign in to comment.