-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/reassign centr bydflt #527
Conversation
…roids(... overwrite=True)
set it to False wherever the assignment is obviously obsolete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! I mostly suggest cosmetic changes. In my suggestions for the comments I try to make clear to users what they gain by setting reassign_centroids
to False
, and when they can use it. Finally, by passing the force_reassign
parameter to reassign_centroids
, the method Forecast.calc
can be simplified by quite a bit.
@@ -299,7 +299,7 @@ def test_calc_insured_impact_fail(self): | |||
def test_minimal_exp_gdf(self): | |||
"""Test obtain minimal exposures gdf""" | |||
icalc = ImpactCalc(ENT.exposures, ENT.impact_funcs, HAZ) | |||
exp_min_gdf = icalc.minimal_exp_gdf('impf_TC') | |||
exp_min_gdf = icalc.minimal_exp_gdf('impf_TC', False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make it explicit here as well?
exp_min_gdf = icalc.minimal_exp_gdf('impf_TC', False) | |
exp_min_gdf = icalc.minimal_exp_gdf('impf_TC', reassign_centroids=False) |
Oh by the way, why is it called |
I agree that the name should rather be |
The methods in the module |
If centroids are not assigned for that kind of hazard, they are going to be assigned regardless of the flag, hence, to me, |
You are right, I've noticed that too. And I'm not sure yet either about the right way. But in any case, I think the proposed changes here are independent and therefore follow-up PRs are the better way to deal with |
True, but I think this is unexpected with regard to the new method signature. If I set
|
I disagree that this can be done separately. With the current change, we essentially make unsequa not usable, and cost benefit partially not usable. |
…he Impact.calc method
Co-authored-by: Lukas Riedel <[email protected]>
consequently, don't assign if not set to true
do it manually before the method is called
climada/engine/impact_calc.py
Outdated
assign_centroids : bool, optional | ||
indicates whether centroids are re-assigned to the self.exposures object | ||
or kept from previous impact calculation with a hazard of the same hazard type. | ||
Centroids assignment is an expensive operation; set this to ``False`` to save |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I introduced trailing whitespace, which triggers new linter warnings. Sorry about that!
Centroids assignment is an expensive operation; set this to ``False`` to save | |
Centroids assignment is an expensive operation; set this to ``False`` to save |
climada/engine/impact_calc.py
Outdated
assign_centroids : bool, optional | ||
indicates whether centroids are re-assigned to the self.exposures object | ||
or kept from previous impact calculation with a hazard of the same hazard type. | ||
Centroids assignment is an expensive operation; set this to ``False`` to save |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Centroids assignment is an expensive operation; set this to ``False`` to save | |
Centroids assignment is an expensive operation; set this to ``False`` to save |
climada/engine/impact_calc.py
Outdated
assign_centroids : bool | ||
Indicates whether centroids are re-assigned to the self.exposures object | ||
or kept from previous impact calculation with a hazard of the same hazard type. | ||
Centroids assignment is an expensive operation; set this to ``False`` to save |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Centroids assignment is an expensive operation; set this to ``False`` to save | |
Centroids assignment is an expensive operation; set this to ``False`` to save |
…pact.calc anymore
exp.assign_centroids(haz, overwrite=False) | ||
imp.calc(exposures=exp, impact_funcs=impf, hazard=haz, assign_centroids=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now a bit awkward, but it probably works fine. We should check whether the computation time remains stable. Have you already checked that on the test code? Shall I do some more testing?
I think the same change is needed for unsequa.calc_cost_benefit
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, same, same for calc_cost_benefit
. I just checked it in.
And yes, I have checked the computational impact, not by computation time itself which is marginal for the test cases I can get my hands on, but by number of calls to assign_centroids
with overwrite=True
.
And no, thanks, that should be fine. You don't have to do more testing. Unless you object I'm going to merge.
analagous to the assignment policy in unsequa.calc_impact
Changes proposed in this PR:
ImpactCalc.impact
parameter that may be used to suppress re-assignment of centroidsreassign_centroids
in both methodsimpact
andinsured_impact
.True
wherever it seemed suitable throughout the code baseThis PR fixes issue #515
Pull Request Checklist
develop
)