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

Absolute momentum units bug fix #1956

Merged
merged 3 commits into from Jul 7, 2021
Merged

Conversation

23ccozad
Copy link
Contributor

@23ccozad 23ccozad commented Jul 5, 2021

  • Implements @jthielen's solution to issue Error in absolute_momentum (bug in normal_component?) #1948, which converts u and v to m/s before passing to normal_component().

  • Refactors one line of absolute_momentum(), but I'm not familiar with the absolute momentum calculation. I'm willing to include more refactoring in this PR, but I would need some more specific direction on what to adjust/remove.

Checklist

Ensures that units are provided to `u` and `v` when calculating normal_component.
@23ccozad 23ccozad added Area: Calc Pertains to calculations Area: Units Pertains to unit information Type: Bug Something is not working like it should labels Jul 5, 2021
@23ccozad 23ccozad marked this pull request as ready for review July 5, 2021 19:33
Comment on lines 295 to 296
u = u.metpy.convert_units('m/s')
v = v.metpy.convert_units('m/s')
Copy link
Member

Choose a reason for hiding this comment

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

Maybe change these to e.g. u.metpy.quantity()? Then the last line of the function could be:

return (norm_wind + f * distance).metpy.convert_units('m/s')

Comment on lines 304 to 305
x = x.metpy.convert_units('meters')
y = y.metpy.convert_units('meters')
Copy link
Member

Choose a reason for hiding this comment

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

Could maybe just entirely eliminate these lines? Not quite sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"It looks like removing them doesn't break any tests"... famous last words.

Copy link
Member

Choose a reason for hiding this comment

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

😆 It's an "opportunity" to test better if that's the case. 😉

@dopplershift dopplershift added this to the 1.1.0 milestone Jul 6, 2021
New test makes sure that absolute_momentum() works when using units from the xarray DataArray `units` attribute.
@dopplershift dopplershift merged commit 44b29d8 into Unidata:main Jul 7, 2021
@23ccozad 23ccozad deleted the abs_momentum branch July 16, 2021 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Calc Pertains to calculations Area: Units Pertains to unit information Type: Bug Something is not working like it should
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in absolute_momentum (bug in normal_component?)
2 participants