@@ -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,17 @@ 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 will be assigned during impact "
208+ "calculation. This is potentiall costly. To silence this warning, make sure "
209+ "that centroids are assigned to all exposures."
210+ )
211+ new_exp .assign_centroids (new_haz )
212+
213+ return self ._calc_impact (new_exp , new_impfs , new_haz )
210214
211215 def apply (self , exposures , imp_fun_set , hazard ):
212216 """
@@ -246,7 +250,7 @@ def apply(self, exposures, imp_fun_set, hazard):
246250
247251 return new_exp , new_impfs , new_haz
248252
249- def _calc_impact (self , new_exp , new_impfs , new_haz , assign_centroids ):
253+ def _calc_impact (self , new_exp , new_impfs , new_haz ):
250254 """Compute impact and risk transfer of measure implemented over inputs.
251255
252256 Parameters
@@ -267,7 +271,7 @@ def _calc_impact(self, new_exp, new_impfs, new_haz, assign_centroids):
267271 )
268272
269273 imp = ImpactCalc (new_exp , new_impfs , new_haz ).impact (
270- save_mat = False , assign_centroids = assign_centroids
274+ save_mat = False , assign_centroids = False
271275 )
272276 return imp .calc_risk_transfer (self .risk_transf_attach , self .risk_transf_cover )
273277
0 commit comments