Skip to content
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

Add polynomial s shape impact function #878

Merged
merged 13 commits into from
May 6, 2024
Merged

Conversation

chahank
Copy link
Member

@chahank chahank commented Apr 30, 2024

Changes proposed in this PR:

  • Adds a generic method to make polynomial s-shape impact functions ImpactFunc.from_poly_s_shape() as proposed by Emanuel et al. (2011). This methods generalizes the ImpfTropCyclone.from_emanuel() method.

This PR fixes #

PR Author Checklist

PR Reviewer Checklist

@chahank chahank requested a review from peanutfun April 30, 2024 14:01
Copy link
Member

@peanutfun peanutfun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the addition! I think the function will be very useful.

Please improve the documentation and the tests. One linter issue can also easily be fixed.

climada/entity/impact_funcs/base.py Outdated Show resolved Hide resolved
climada/entity/impact_funcs/base.py Outdated Show resolved Hide resolved
climada/entity/impact_funcs/base.py Outdated Show resolved Hide resolved
climada/entity/impact_funcs/base.py Outdated Show resolved Hide resolved
climada/entity/impact_funcs/base.py Outdated Show resolved Hide resolved
climada/entity/impact_funcs/base.py Outdated Show resolved Hide resolved
climada/entity/impact_funcs/test/test_base.py Outdated Show resolved Hide resolved
climada/entity/impact_funcs/test/test_base.py Outdated Show resolved Hide resolved
np.testing.assert_array_almost_equal(impf.mdd, np.zeros(5))
test_aux_vars(impf)

with self.assertRaises(ValueError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check actual error

Suggested change
with self.assertRaises(ValueError):
with self.assertRaisesRegex(ValueError, "Exponent value"):

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the correction! Why should we priorize using assertRaisesRegex ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it tests the actual error message. assertRaises would succeed with any ValueError thrown, but you want to test for a specific one here.

Note that this is basically a shortcut for the idiom we were using so far:

with self.assertRaises(Exception) as cm:
    do_stuff()
self.assertIn("Text", str(cm.exception))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes total sense, thanks!

@chahank
Copy link
Member Author

chahank commented May 6, 2024

Ok, I fixed all that you proposed, thanks! I also fixed one test and made sure that for threshold = half_point the method returns mdd=0 (else there was a divide by 0).

@peanutfun
Copy link
Member

Great work! Will merge.

@peanutfun peanutfun merged commit ac03762 into develop May 6, 2024
3 of 6 checks passed
@emanuel-schmid emanuel-schmid deleted the feature/new_s_shape_func branch May 8, 2024 07:30
gdeskos pushed a commit to gdeskos/climada_python that referenced this pull request Sep 16, 2024
---------

Co-authored-by: Chahan Kropf <[email protected]>
Co-authored-by: emanuel-schmid <[email protected]>
Co-authored-by: Lukas Riedel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants