-
Notifications
You must be signed in to change notification settings - Fork 125
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
Possible bug in impact calculation #933
Comments
Given the error, I would first try to have a correctly made Hazard and maybe this solves the problem. |
Thanks - I now specified event_name as a list and get the same, as expected. |
Ok, thanks for checking. Could you please try with an exposure with at least 2 locations? |
That's a bit the whole point - with two exposure points (essentially duplicating the single exposure point) it then works. See bug description and commented line in the example code. |
Can you please check that your exposures are correctly initialized? Geopandas does not like it that much if one uses a single data point and that has for me led to failures in the past (but this is maybe not the case anymore). |
What do you mean by correctly initialized? Anyway, it is correct as far as I can tell. Also, this is a code that replicates the error but I got it in different contexts where the exposure was much larger. I don't think it's a geopandas issue, I think it's really about the looping of mat objects that takes place within np.hstack at the above mentioned line that creates the issue. For some reason, dimensions don't fit. I think it has to do with having a unique exposure point being analysed in the impact calculation (the same error is thrown if one has a multi-points exposure, but where only one point has centr_TC != -1, thereby only one is considered in the mininal exp_gdf) but cannot really figure out why. |
@aleeciu @chahank I debugged the issue and found the culprit digging through the source code: To be clear, this issue only occurs if BOTH
For sparse array multiplication, this will not happen, as a new matrix constructor is called and explicit zeros are removed. One remedy is to explicitly call |
Thanks a lot @peanutfun for investing the bug. Your explanation makes a lot of sense. Regarding the solution, I don't have strong opinions tbh. This is definetely an edge case so probably it does not make sense if the fix deteriorates the overall performance, although the impact quantification in my experience has never been a bottleneck in performance. |
I think it should be fine to add a check whether the size of the exposure is 1, and only then call |
Cool - at what place in the code you think this check should be placed? |
@aleeciu Inside climada_python/climada/engine/impact_calc.py Line 373 in e4a3cfd
The check has to be if the shape of Edit: Check can also be |
Just to comment on the last point: for most non-trivial applications such as uncertainty quantification, calibration or cost-benefit analysis the impact quantification is the main bottleneck in performance, so it is very central to not loose time there. |
@chahank Correct, but |
I thought of an even better solution, I hope: We should call |
@aleeciu would you have the time to create a PR? |
Hi @peanutfun , yes we will address this within the next two weeks. If you know from the top of your head where this call should likely happen in the code, please share it - otherwise I will make a first guess and we iterate over the PR. |
@aleeciu Excellent, looking forward to it! Probably within here: climada_python/climada/hazard/base.py Line 1073 in e4a3cfd
climada_python/climada/hazard/base.py Line 1138 in e4a3cfd
Edit: It's not required in |
Describe the bug
I noticed a weird behavior in the impact calculation. Inputting a valid exposure, hazard and impact function set leads to:
the error occurs at this line, i.e. when looping the impact matrix generator. After spending few hours, I still couldn't figure out what conditions lead to the error.
The code below reproduces it using one exposure point, one centroid and two hazard events. Interestingly enough, using an exposure with twice the same point makes it run just fine.
To Reproduce
Run the code below.
Code example:
Expected behavior
The expected behaviour would be to get an impact object, the actual result is:
Climada Version: 4.1.2.dev0
System Information (please complete the following information):
Any idea/clue?
The text was updated successfully, but these errors were encountered: