Skip to content

Commit 5084cd3

Browse files
assign centroids in impact calc of measure if not yet assigned
1 parent c500fd8 commit 5084cd3

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

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/entity/measures/base.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def check(self):
179179
u_check.size(2, self.mdd_impact, "Measure.mdd_impact")
180180
u_check.size(2, self.paa_impact, "Measure.paa_impact")
181181

182-
def calc_impact(self, exposures, imp_fun_set, hazard, assign_centroids=True):
182+
def calc_impact(self, exposures, imp_fun_set, hazard):
183183
"""
184184
Apply measure and compute impact and risk transfer of measure
185185
implemented over inputs.
@@ -192,12 +192,6 @@ def calc_impact(self, exposures, imp_fun_set, hazard, assign_centroids=True):
192192
impact function set instance
193193
hazard : climada.hazard.Hazard
194194
hazard instance
195-
assign_centroids : bool, optional
196-
indicates whether centroids are assigned to the self.exposures object.
197-
Centroids assignment is an expensive operation; set this to ``False`` to save
198-
computation time if the hazards' centroids are already assigned to the exposures
199-
object.
200-
Default: True
201195
202196
Returns
203197
-------
@@ -206,7 +200,15 @@ def calc_impact(self, exposures, imp_fun_set, hazard, assign_centroids=True):
206200
"""
207201

208202
new_exp, new_impfs, new_haz = self.apply(exposures, imp_fun_set, hazard)
209-
return self._calc_impact(new_exp, new_impfs, new_haz, assign_centroids)
203+
# assign centroids if missing
204+
if new_haz.centr_exp_col not in new_exp.gdf.columns:
205+
LOGGER.warning(
206+
"No assigned hazard centroids in exposure object after the "
207+
"application of the measure. The centroids were assigned in impact calcualtion."
208+
)
209+
new_exp.assign_centroids(new_haz)
210+
211+
return self._calc_impact(new_exp, new_impfs, new_haz)
210212

211213
def apply(self, exposures, imp_fun_set, hazard):
212214
"""
@@ -246,7 +248,7 @@ def apply(self, exposures, imp_fun_set, hazard):
246248

247249
return new_exp, new_impfs, new_haz
248250

249-
def _calc_impact(self, new_exp, new_impfs, new_haz, assign_centroids):
251+
def _calc_impact(self, new_exp, new_impfs, new_haz):
250252
"""Compute impact and risk transfer of measure implemented over inputs.
251253
252254
Parameters
@@ -267,7 +269,7 @@ def _calc_impact(self, new_exp, new_impfs, new_haz, assign_centroids):
267269
)
268270

269271
imp = ImpactCalc(new_exp, new_impfs, new_haz).impact(
270-
save_mat=False, assign_centroids=assign_centroids
272+
save_mat=False, assign_centroids=False
271273
)
272274
return imp.calc_risk_transfer(self.risk_transf_attach, self.risk_transf_cover)
273275

0 commit comments

Comments
 (0)