-
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/refactor impact calc #436
Merged
Merged
Changes from 1 commit
Commits
Show all changes
136 commits
Select commit
Hold shift + click to select a range
aa90de3
Add methods to set imp vars from imp mat
06f9403
Cosmetics
41ad79b
Change set to calc
2984b94
Merge remote-tracking branch 'origin/develop' into feature/set_imp_ma…
e9d0fd7
Ordering the code
a15b2df
Make init
7f18c4d
Add haz_type as property
c6070de
Add centroid columns name in exposures as property
d4820f3
Add overwrite variable to assign_centroids
f49d492
Add method affect_values_gdf
f8bf6b0
Remove warning impf at int=0
48ca4d7
First commit - overhaul impact
51fdbb6
Add insurance layers
ad093af
Add methods get mdr, paa, fraction
9985414
Change sum to np.sum
3f5f402
Add affect_total_value
a2aa1e7
Reduce gdf to minimum necessary
b172eed
Correct exposure gdf column selection
8567c5d
Update docstrings
53a2bc1
Fix bug at_event / eai_exp
69ac247
Refactoring of methods to simplify code
1a028ff
Use generator instead of list
0bac4fc
Merge branch 'develop' into feature/refactor_impact_calc
7fc364d
Impact: improve performance by avoiding pandas operations
d694e5e
Add notimplementederror for mdf(0)
05ccc9a
Toggle logger warning for speed test
5a777af
Fetch only assigned impf
337e24e
Return the reduced exp indices only
bb8b457
Remove 0 from insured impacts
54df06e
Stich imp mat from generator
738108b
Rename impat_mat_list to _gen
d22ce45
Avoid generator to list conversion in insured risk
a6703c9
Rename exp_iimp
4cb3460
Add impact_calc class
7457e3a
Correct function signature
075836a
Adjust class name
31845f9
Correct indent
e2384d4
Typo: stich -> stitch
af831fd
Merge branch 'develop' into feature/refactor_impact_calc
emanuel-schmid 2e36267
PEP8
emanuel-schmid 07d12bc
impact: pydoc cosmetics
emanuel-schmid ed9b013
Include all helper methods in ImpactCalc
0cc03bb
Merge remote-tracking branch 'origin/feature/refactor_impact_calc' in…
a9458e3
Remove unused module
6bec23a
Improve cosmetics
6abd902
Improve docstring
6c69ce6
Import new class in init
414b369
Compute insured impact from existing imp_mat if available
8790eb4
Make two test files
82460c4
Add _return_impact method
057e719
Return impact object
e271925
Make risk_metrics a class method
a84d2fe
Separate Impact and ImpactCalc
bcf1590
Add deprecation warnings
c462290
Return min exp gdf instead of df
425cebf
Improve cover and deductible
15b7d57
Rename imp_mat to mat
bd7306e
Add tests for most exposed methods
41eb14e
Remove calc tests
c408414
Add test overwrite centroids flag
4598f13
Remove warning for impf nonzero at zero
3b34df9
Add docstrings
a32de31
Update test precision to account for different floating number
7f81052
Fix bug in insure mat
7c0e86f
Merge branch 'develop' into feature/refactor_impact_calc
emanuel-schmid e0a6a0a
Make 'imp_mat' an empty matrix by default
peanutfun 18609c6
Merge branch 'feature/refactor_impact_calc' of https://github.com/CLI…
peanutfun 90536e4
Avoid mutables in Impact and ImpactCalc signatures
peanutfun a54eb33
Add test case for ImpactCalc.impact_matrix
peanutfun 84f8245
Add input attribute consistency checks to init
0d17a90
Add unfinished impact init test
bd8cb31
Merge remote-tracking branch 'origin/feature/refactor_impact_calc' in…
660dbc2
Set default imp_mat to None
5cec3fd
Merge remote-tracking branch 'origin/feature/refactor_impact_calc' in…
01e4e27
Update init consistency tests
963a65f
Add from_eih test
76cbf9a
Add test risk transfer and residual risk
eb5eba1
Add test impact_per_year
e984543
Cosmetics
1238cdb
Remove unsued method
8e25d09
Add test for affected value
f8b5376
Add property tests
597bdd7
Add test get_mdr
3d3774a
Add test get paa
7792e7c
Add test get fraction
87cda77
Add docstring
cc353e6
Add chunk method
b33ba54
Update name cent to centr
10f68e9
Update docstring
1183d6f
Use np.array_split for chunks
246267b
Update naming
a60c0b6
Simplify argument chunker
670fcb1
Add test case for ImpactCalc.imp_mat_gen
peanutfun 3b35a3e
Add test for ImpactCalc.stitch_impact_matrix
peanutfun ffd0804
Add test for ImpactCalc.apply_deductible_to_mat
peanutfun 6fe8611
Fix bug and formatting in ImpactCalc.imp_mat_gen
peanutfun 4a2dac9
Add test with fraction not equal 1
c263c50
Improve error message in impact matrix chunking
peanutfun f3fe9d8
Merge branch 'feature/refactor_impact_calc' of https://github.com/CLI…
peanutfun 78c9be4
test_impact_calc: persistently revert the CONFIG changes in tearDown
emanuel-schmid 2a1122f
Replace instances in CONFIG instead of mocking
peanutfun 8a699f8
Add test for ImpactCalc.stitch_risk_metrics and update docstring
peanutfun d43c36b
Add deepcopy import to test_impact_calc
peanutfun 6ed55b0
Add test for ImpactCalc.insured_mat_gen and update docstring
peanutfun 96924ea
Add test for ImpactCalc.impact_matrix
peanutfun b8a39fd
Add TestInsuredImpactMatrixGenerator to test loader
peanutfun 2e21f9c
Add test for ImpactCalc._return_matrix
peanutfun d5341f3
Update docstring
763af8b
Merge branch 'develop' into feature/refactor_impact_calc
emanuel-schmid d386198
Merge branch 'develop' into feature/refactor_impact_calc
emanuel-schmid 4eead86
pydoc cosmetics
emanuel-schmid a2c773d
pydoc cosmetics
emanuel-schmid 1c318a4
pydoc consolidation
emanuel-schmid bb728ff
Merge branch 'develop' into feature/refactor_impact_calc
emanuel-schmid 3ee149c
Merge branch 'develop' into feature/refactor_impact_calc
emanuel-schmid e4daf2b
Improve attribute error message from_eih
1f5322e
Update from_eih tests
8c393c9
impact_calc.ImpactCalc: remove imp_mat attribute
emanuel-schmid 58449fd
ImpactCalc.impact: re-establish save_mat argument
emanuel-schmid 55e5ae7
Set assigned_centroids overwrite=False
7d4e5f6
(Re)-Set ignore zero to False
1aa5581
Update deprecation warning message
aaf2f93
Correct bug wrong exp_idx
f59e04d
Make new index in case the index is not ordered
bf3a813
Slice numpy instead of gdf
7c910d0
Add _orig_exp_idx to tests
24a77ad
Add tests with Flood
3aea175
Return empty impact if no exposures matching hazard
0a6c9e1
Repalce squeeze by ravel for atevent single event
5bdfd02
Add _orig_exp_idx as argument from beginning on
60c25ca
Update comment cosmetics
2014af8
Reduce lines to max length
cdc536d
Replace generator by list due to deprecation in np.hstack
ed18913
Merge branch 'develop' into feature/refactor_impact_calc
emanuel-schmid d678fa2
Merge branch 'develop' into feature/refactor_impact_calc
emanuel-schmid 74e3a8e
test_impact_calc: organize test data
emanuel-schmid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why would you change that to True? This is a bad idea as this results in a lot of extra computation time, often for nothing. A typical workflow implies that the Exposures object given to ImpactCalc already has assigned centroids. This line here is just in case that none are defined (which is a sub-optimal workflow, but needs to stay due to backwards compatibility).
Thus, this should be reversed.
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 see. Then we have the following problem:
does i.g. not print the same as
Simply, because in the first example
agg2
is likely wrong and in the secondagg1
.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.
Good point Emanuel, I remember that I stumbled upon this before!
I would be in favor of moving the whole centroids assignment procedure to the ImpactCalc object because semantically it's not a property of the Exposures object, but of the combination of an exposure with a hazard. However, I see the problem that it might be desirable to be able to reuse the same assignment with several different Hazard objects that share the same Centroids... And of course, there is the problem of backwards compatibility when people are explicitly using the
Exposures.assign_centroids
API.Maybe the easiest solution is to leave the API as it is, but have a boolean keyword argument
reassign_centroids=True
forImpactCalc.impact()
so the user can opt out of the reassignment if that's desired?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.
Me too actually, I'd favor moving the centroids assignments out of Exposures. Also I'm not yet ready to go for the easiest solution, as this looks like it may be crucial.
Two questions:
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 a rather complex discussion that will be very hard to follow clearly on a chat forum like here. But, a few remarks:
assign_centroids
is entirely removed from theImpact.calc
as it is an under the hood assignment which we would like the user to have control over (for instance, does one always want to use nearest-neighbors?). This way, the user must think and prepare consistent data.I also agree that a quick solution is not optimal. The current solution is the one that keeps the same convention as in the
Impact.calc()
method.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.
My suggestion would be to decouple the two discussion. This PR is about making the impact class more readable, more modular, better tested and more efficient. It is not about changing the inner workings of the API fundamentally as is here suggested with the change with the
assign_centroids
.