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

Magnitude of a Vector #3698

Closed
sgdecker opened this issue Nov 22, 2024 · 2 comments · Fixed by #3699
Closed

Magnitude of a Vector #3698

sgdecker opened this issue Nov 22, 2024 · 2 comments · Fixed by #3699
Labels
Area: Docs Affects documentation Type: Enhancement Enhancement to existing functionality
Milestone

Comments

@sgdecker
Copy link
Contributor

What can be better?

This is related to #537.

My use case is computing the magnitude of the water vapor mass flux. Of course I can just write the square root of the sum of the squares myself, but I first thought, maybe I could use wind_speed for this. However, that failed since the units are wrong. Then I looked into what the documentation says is the MetPy equivalent of GEMPAK's MAG function, and it says to use numpy.linalg.norm for this. In my case, I have 3D arrays (x,y,theta) of the i- and j-components of the mass flux, and my attempts to somehow use norm for this have failed.

My request is either:

  1. Determine that np.linalg.norm actually isn't equivalent to GEMPAK's MAG function, or
  2. Provide an example of how to use norm to compute the magnitude of a vector when the scalar components are 3D arrays in that box on the Conversion Guide. I suspect that, if this is possible, it involves constructing an array with such care that just doing the square root of the sum of the squares is much easier, in which case,
  3. Implement an actual mpcalc magnitude function (of which the wind_speed function becomes a special case that adds the requisite unit check)
@sgdecker sgdecker added the Area: Docs Affects documentation label Nov 22, 2024
@dopplershift
Copy link
Member

I think norm is wrong (or at least more complicated than necessary), but numpy.hypot() should be exactly what you want. I'd be happy to merge a PR to that effect for the GEMPAK guide.

@dopplershift dopplershift added the Type: Enhancement Enhancement to existing functionality label Nov 22, 2024
@sgdecker
Copy link
Contributor Author

Indeed, numpy.hypot() is exactly what it should be. I'll prepare a PR to make that change.

@dopplershift dopplershift added this to the 1.7.0 milestone Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Docs Affects documentation Type: Enhancement Enhancement to existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants