Skip to content

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.

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 and others added 3 commits May 6, 2024 10:18
Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
@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
@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 <chahan.kropf@posteo.com>
Co-authored-by: emanuel-schmid <schmide@ethz.ch>
Co-authored-by: Lukas Riedel <34276446+peanutfun@users.noreply.github.com>
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.

4 participants