-
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
Update unsequa to fully support the latest version of SALib #886
Conversation
A few more comments on this PR:
|
@@ -152,6 +154,7 @@ Changed: | |||
|
|||
- `geopandas` >=0.13 → >=0.14 | |||
- `pandas` >=1.5,<2.0 → >=2.1 | |||
- `salib` >=1.3.0 → >=1.4.7 |
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.
@emanuel-schmid : why would we indicate two different larger than versions (as for geopandas)?
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 about dependency version constraint changes. They start from the given minimal version of the last release (left hand side) and end at the given minimal version of this release (right hand side).
However: the whole version change section is eventually done at release time by a script I wrote. Don't bother, it will be overwritten!
climada/engine/unsequa/calc_base.py
Outdated
if param not in self.distr_dict: #dummy_0 param added to uniform_base_sample | ||
#when using ff method, need to ignore it? | ||
continue |
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 think we should rather explicitly catch the case for dummy_
variables and only ignore these instead of all possible params.
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.
Do we still need this line of code? As we now raise a ValueError
when the number of parameters is not a power of 2 and require the user to input their own dummy parameter beforehand. Then if the user inputs their own dummy parameter, the dummy parameters should be covered by the df_samples[param] = df_samples[param].apply(self.distr_dict[param].ppf)
, correct?
climada/engine/unsequa/calc_base.py
Outdated
@@ -500,10 +536,44 @@ def _calc_sens_df(method, problem_sa, sensitivity_kwargs, param_labels, X, unc_d | |||
else: | |||
sens_indices = method.analyze(problem_sa, Y, | |||
**sensitivity_kwargs) | |||
#refactor incoherent SALib output | |||
nparams = len(param_labels) | |||
if method.__name__ == 'SALib.analyze.ff': |
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 not use the attribute sensitivity_method
? This would be more stable I think.
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.
Because it is not available from within _calc_sens_df, I think? But we can pass it as an argument of _calc_sens_df if you think it is worth it.
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.
hmmm not sure. But maybe then just check for the last 2 strings ff
. Because I vaguely remember that Salib had played around with changing the module structure, such that it would not be Salib.analyse.ff
but something Salib.xxx.ff
.
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.
Ok then I changed it to only check if the corresponding last characters of the method name string correspond to the target method name instead of the entire Salib.analyse.ff
.
…add more robust check of name of sensensitivity method
Ok so I included your suggested changes + I added a prototype of a generic testing function for testing the different sensitivity methods. I store all the parameters and expected tests results in a dict which I pass to the function that gets looped over. Maybe not the most efficient way to do it so please let me know if you have any suggestions for improvements. |
Great job, we are almost there! What is missing:
|
Ok so I tried to simplify the tests of the sensitivity methods as much as possible in the generic test functions, and removed the previous method-specific test functions. I wasn't sure about a few lines that only appeared in the test for the morris method though:
I did not include these lines in the generic test function as it did not seem absolutely necessary to me, but if you think those should be included just let me know. Additionally, I need to fix the few new linter issues that popped up but I think it shouldn't be an issue. Otherwise I think I adressed the rest of your comments. |
climada/engine/unsequa/calc_base.py
Outdated
# Assume sens_first_order_dict is a dictionary where values are lists/arrays of varying lengths | ||
# !for some reason this make the plotting methods fail | ||
#sens_first_order_df = pd.DataFrame({k: pd.Series(v, dtype=object) | ||
# for k, v in sens_first_order_dict.items()}) | ||
|
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.
Is this something that still needs to be addressed or is it a left-over?
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.
It's a left-over, I cleaned it up.
@@ -36,6 +36,8 @@ | |||
from climada.hazard import Hazard | |||
from climada.engine import ImpactCalc | |||
from climada.engine.unsequa import InputVar, CalcImpact, UncOutput, CalcCostBenefit, CalcDeltaImpact | |||
from climada.engine.unsequa.calc_base import LOGGER as ILOG |
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.
Any particular reason for renaming the logger? Why not just use LOGGER
?
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.
No, no reason, it was just blind copying of the code I saw on stackoverflow, I'll change that!
Ok so I incorporated your last suggestions. If there is no further comments from your side I suggest we merge this PR? |
I think it looks good! Just FYI: you managed to remove 39 pylint warnings, and add 16. Maybe you can take a last look whether the 16 new ones are easy to avoid or not. Else, this is ready to merge from my point of view. |
So I have checked and the warnings are mainly "too-many-locals", "too-complex", "invalid-name", etc. Most of those are coming from lines that I not directly touched or that got included to the commits because of trailing whitespaces that got removed by VScode. For instance, |
Thanks for checking. For the moment these are fine I think. Feel free to merge, and thanks for the work! |
Changes proposed in this PR:
CalcDeltaClimate
This PR fixes #828
PR Author Checklist
develop
)PR Reviewer Checklist