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

Feature/tc holland vtrans #833

Merged
merged 7 commits into from
Jan 11, 2024
Merged

Feature/tc holland vtrans #833

merged 7 commits into from
Jan 11, 2024

Conversation

ThomasRoosli
Copy link
Collaborator

… and Holland 2010 model

Changes proposed in this PR:

  • in the Holland model 2008 and 2010 implementation a doublecounting of translational velocity is removed
  • as the resulting v_ang_norm already contains vtrans_norm, we now subtract it first, before converting the angular velocity and the translational velocity to vectors and then adding (vectorial) vtrans to (vectorial (v_ang).

To highlight the advantage of removing the double counting. The calculated maximum windspeed is compared with the reported windspeeds for each timestep of 20 years of storm tracks data from ibtracks.
The comparison is done for the current develop branch and for the proposed changes. The proposed changes are able to (i) increase r-squared value and (ii) to decrease the intercept of a linear regression on this comparison. (results can be found here: https://github.com/ThomasRoosli/CLIMADA_test_TC_vtrans_addition/blob/main/CLIMADA_TC_holland_vtrans_comparison.ipynb).

This comes comparison was done additionally to a detailed investigation of several storms in the North Atlantic Ocean.

PR Author Checklist

PR Reviewer Checklist

Copy link
Collaborator

@tovogt tovogt left a comment

Choose a reason for hiding this comment

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

Thanks, great work! Ready to be merged from my side.

CHANGELOG.md Outdated Show resolved Hide resolved
climada/hazard/trop_cyclone.py Outdated Show resolved Hide resolved
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.

I can't clearly say if the new implementation is correct. For the newly added model cases, the v_trans_corr seems to be applied twice.

The function is generally hard to read because of all the manual broadcasting and indexing. I think it would help to transpose the arrays, so that the default broadcasting rules of numpy apply (last dimensions are broadcast). But I think this would be too much for this PR. I have a few suggestions, though.

# In these models, v_ang_norm already contains vtrans_norm, so subtract it first, before
# converting to vectors and then adding (vectorial) vtrans again. Make sure to apply the
# "absorbing factor" in both steps:
vtrans_norm_bc = np.broadcast_arrays(si_track["vtrans_norm"].values[:, None], d_centr)[0]
Copy link
Member

Choose a reason for hiding this comment

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

Make clear that we only want the broadcast of one array

Suggested change
vtrans_norm_bc = np.broadcast_arrays(si_track["vtrans_norm"].values[:, None], d_centr)[0]
vtrans_norm_bc = np.broadcast_to(si_track["vtrans_norm"].values[:, None], d_centr.shape)

Copy link
Collaborator

@tovogt tovogt Jan 9, 2024

Choose a reason for hiding this comment

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

It's true that it does the same. If you single out this line of code, it might be clearer the way you put it. But np.broadcast_arrays is used in a lot of places in this file, and I find it easier to read the whole code if similar code patterns are used everywhere. However, I don't really care that much, actually.

Edit: Seems like we are going to replace all instances of broadcast_arrays with broadcast_to now, which is totally fine with me.

climada/hazard/trop_cyclone.py Show resolved Hide resolved
climada/hazard/trop_cyclone.py Show resolved Hide resolved
@tovogt
Copy link
Collaborator

tovogt commented Jan 9, 2024

The function is generally hard to read because of all the manual broadcasting and indexing. I think it would help to transpose the arrays, so that the default broadcasting rules of numpy apply (last dimensions are broadcast). But I think this would be too much for this PR. I have a few suggestions, though.

I don't think that it is possible to reduce everything to numpy's default broadcasting rules because sometimes broadcasting is done in time, and sometimes in space (and sometimes both), and sometimes it's done in the two vectorial components of a vector field.

In general, I think that code with manual broadcasting is better readable and safer because broadcasting is explicit and you (mostly) know what the code is doing. Implicit broadcasting can be dangerous...

@ThomasRoosli
Copy link
Collaborator Author

The function is generally hard to read because of all the manual broadcasting and indexing. I think it would help to transpose the arrays, so that the default broadcasting rules of numpy apply (last dimensions are broadcast). But I think this would be too much for this PR. I have a few suggestions, though.

I don't think that it is possible to reduce everything to numpy's default broadcasting rules because sometimes broadcasting is done in time, and sometimes in space (and sometimes both), and sometimes it's done in the two vectorial components of a vector field.

In general, I think that code with manual broadcasting is better readable and safer because broadcasting is explicit and you always know what the code is doing. Implicit broadcasting can be dangerous...

I would suggest to change broadcast_arrays to broadcast_to in all lines of the module (as suggested by @peanutfun ) and keep the explicit broadcasting (keep [:,:,::-1] instead of [...,::-1] ) for readability and safety. Does everyone agree, @tovogt and @peanutfun ?

@tovogt
Copy link
Collaborator

tovogt commented Jan 10, 2024

Fyi, I just tested what replacing broadcast_arrays with broadcast_to would look like. I actually like it and decided to push it to your branch. Feel free to revert if you disagree.

ThomasRoosli and others added 2 commits January 10, 2024 13:38
Co-authored-by: Thomas Vogt <57705593+tovogt@users.noreply.github.com>
Co-authored-by: Thomas Vogt <57705593+tovogt@users.noreply.github.com>
CHANGELOG.md Outdated Show resolved Hide resolved
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.

Very good, thank you for your additional contribution @tovogt. As you and @ThomasRoosli agree on the matter of "explicit indexing", we will leave it in. Great work, everyone! I will merge.

@peanutfun peanutfun merged commit 104dfdb into develop Jan 11, 2024
0 of 6 checks passed
@emanuel-schmid emanuel-schmid deleted the feature/tc_holland_vtrans branch March 13, 2024 15:05
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