-
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
Plotting with plot_eai_exp_geom fails due to exposures vs impact shape mismatch #992
Comments
Good catch, and this makes sense that it fails at the moment. I guess this poses the fundamental question of whether we want to accept exposures with repeating index. I am not sure what is the advantage of allowing it. Any opinion @emanuel-schmid @peanutfun ? For this case we could also just make it happen inside of the lines polygons module. But maybe before that, do you understand whether it is just a problem with the plotting, or is the disaggregation / aggregation result fundamentally wrong with repeating indices? If it is just for plotting, we can adjust just the plotting method. If it is the result, then we need to reset the index for all dissagregation operations. |
I did a quick test and the computed |
Thanks for checking! This is what I was expecting. So, we should raise an error in the aggregation stage if there are repeated indices. We could also force a reindexing in the dissagregation stage, but not sure. And this is on the level of the geodataframe, not the exposure in itself. |
What would be the issue with a forced reindexing? Shouldn't a dataframe have a unique index in the first place anyways? |
I agree that unique indices are good. But, in general, the code should not modify the input date if not absoutely needed. Here is an example of when resetting the index would be a problem. Suppose you have a large exposure for all of Europe. Now, you make computations for sub-regions separately (maybe for computation reasons), but then want to put results together later on. If you have a unique index for the full Europe, this is an easy task. If one resets the index for each sub-region calculation, this may become more complicated. Hence, I would first raise an error if there are repeated indices (with instructions on how to resolve it). Where exactly in the code to raise the errors needs a bit of reflection maybe. |
That makes sense, thanks for the example!
I agree. I can have a look into that and make a suggestion on where the raising of the error is the most appropriate. |
A very quick solution would probably be to call The underlying problem here is that the code assumes that the index labels in the exposure GDF are unique (which they might not be) and even more so that it is integer (which is not required by any means). If the index is indeed an 0..N-1 integer, then it is trivial. You can also uniquely identify all objects in a dataframe by their position using the length N of the frame and the Regarding the question of unique indices when concatenating exposures: The default behavior of |
Describe the bug
I am using the
lines_polys_handler
handler to compute impacts using lines as exposures and plotting the resulting EAI usingplot_eai_exp_geom
. However, theplot_eai_exp_geom
fails with aValueError: Length of values (861875) does not match length of index (861881)
. Apparently, this comes from a mismatch between the shape of the original exposures and the reaggregated impacts causing the error when attempting to do the following value assignement:I have had a look, and apparently the error happens when the index of the exposures' geodataframe has non-unique values, i.e. see lines 5 to 8:
The error comes from an ill-defined
Exposures
but I assume we would want to catch that in a way? Any suggestion on a fix?To Reproduce
Code example:
Climada Version: [5.0.1.dev0]
System Information (please complete the following information):
The text was updated successfully, but these errors were encountered: