CLIMADA-project / climada_python

Python (3.8+) version of CLIMADA
GNU General Public License v3.0
291 stars 115 forks source link

Update unsequa to fully support the latest version of SALib #886

Closed luseverin closed 3 weeks ago

luseverin commented 1 month ago

Changes proposed in this PR:

This PR fixes #828

PR Author Checklist

PR Reviewer Checklist

luseverin commented 1 month ago

A few more comments on this PR:

luseverin commented 1 month ago

Great, thanks!

I think there are a few small things to update, and maybe one general idea for the tests. Since the tests for the different method repeat themselves, it would be better to define a function and then call it in a loop for all methods instead of copying large parts of the code.

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.

chahank commented 4 weeks ago

Great job, we are almost there! What is missing:

luseverin commented 3 weeks ago

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:

for name, attr in unc_data.__dict__.items():
            if 'sens_df' in name:
                np.testing.assert_array_equal(
                    attr.param.unique(),
                    np.array(['x_exp', 'x_paa', 'x_mdd'])
                    )
                np.testing.assert_array_equal(
                    attr.si.unique(),
                    np.array(['mu', 'mu_star', 'sigma', 'mu_star_conf'])
                    )
                if 'eai' in name:
                    self.assertEqual(
                        attr.size,
                        len(unc_data.param_labels)*4*(len(exp_unc.evaluate().gdf) + 3)
                        )
                elif 'at_event' in name:
                    self.assertEqual(
                        attr.size,
                        len(unc_data.param_labels) * 4 * (haz.size + 3)
                        )
                else:
                    self.assertEqual(len(attr),
                                     len(unc_data.param_labels) * 4
                                     )

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.

luseverin commented 3 weeks ago

Ok so I incorporated your last suggestions. If there is no further comments from your side I suggest we merge this PR?

chahank commented 3 weeks ago

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.

luseverin commented 3 weeks ago

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, plot_rp_uncertainty is too complex, or they are too many local variables in Calc_delta_climate.uncertainty. It is not straightforward to me how these should be treated so I would rather leave them as is for the moment if that's fine..

chahank commented 3 weeks ago

Thanks for checking. For the moment these are fine I think.

Feel free to merge, and thanks for the work!