Skip to content

Add polynomial s shape impact function#878

Merged
peanutfun merged 13 commits intodevelopfrom
feature/new_s_shape_func
May 6, 2024
Merged

Add polynomial s shape impact function#878
peanutfun merged 13 commits intodevelopfrom
feature/new_s_shape_func

Conversation

@chahank
Copy link
Copy Markdown
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
Copy Markdown
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.

np.testing.assert_array_almost_equal(impf.mdd, np.zeros(5))
test_aux_vars(impf)

with self.assertRaises(ValueError):
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Great work! Will merge.

@peanutfun peanutfun merged commit ac03762 into develop May 6, 2024
@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