@@ -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