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

Incorrect conversion between Hz and rad/s #636

Open
jonniediegelman opened this issue Mar 27, 2023 · 12 comments
Open

Incorrect conversion between Hz and rad/s #636

jonniediegelman opened this issue Mar 27, 2023 · 12 comments

Comments

@jonniediegelman
Copy link

julia> uconvert(u"rad/s", 1.0u"Hz")
1.0 rad s⁻¹

I would expect this to give 6.2831853 rad s⁻¹

@giordano
Copy link
Collaborator

julia> uconvert(u"rad", 1.0)
1.0 rad

@jonniediegelman
Copy link
Author

So the incorrect conversion is between unitless and radians?

@giordano
Copy link
Collaborator

"Incorrect" for some definition of "correctness", yes, but the point is that radians are dimensionless

@jonniediegelman
Copy link
Author

Yes, but this version of "correctness" is the one that most people use and will be expecting from a unitful package, even if it's not strictly the most correct.

image

@jariji
Copy link

jariji commented Mar 31, 2023

The author of the Frink programming language has a lot of opinionated commentary on units. Here he is on hertz and radians.

His summary conclusion:

// In summary:  Frink grudgingly follows the SI's ridiculous, broken definition
// of "Hz".  You should not use "Hz".  The SI's definition of Hz should be
// considered harmful and broken.  Instead, if you're talking about circular
// or sinusoidal motion, use terms like "cycles/sec" "revolutions/s",
// "rpm", "circle/min", etc. and Frink will do the right thing because it
// doesn't involve the stupid SI definition that doesn't match what any
// human knows about sinusoidal motion.  Use of "Hz" will cause communication
// problems, errors, and make one party or another look insane in the eyes
// of the other.

@jonniediegelman
Copy link
Author

jonniediegelman commented Mar 31, 2023

Thanks @jariji. That whole rant was actually really helpful for understanding the issue. I would be in favor of printing this snippet from it out as a warning whenever someone uses Hz in Unitful (because it's almost never going to be what they intended it to be):

If you follow the rules of the SI,
1 Hz = 1/s = 1 radian/s which is simply inconsistent and violates basic
ideas of sinusoidal motion, and is simply a stupid definition.
The entire rest of the world, up until that point, knew that 1 Hz needs to 
be equal to *2 pi* radians/s or be changed to mean *cycles/second* for 
these to be reconcilable.  If you use "Hz" to mean cycles/second, say,
in sinusoidal motion, as the world has done for a century, know that the SI
made all your calculations wrong.

@sostock
Copy link
Collaborator

sostock commented Apr 4, 2023

Instead of Hz, you can use the units rps or Hz2π:

julia> uconvert(u"rad/s", 1.0u"rps")
6.283185307179586 rad s^-1

julia> uconvert(u"rad/s", 1.0u"Hz2π")
6.283185307179586 rad s^-1

@sostock
Copy link
Collaborator

sostock commented Apr 4, 2023

I would be in favor of printing this snippet from it out as a warning whenever someone uses Hz in Unitful

Printing something every time a specific unit is used is simply impractical. I would guess that some people use the Hz unit successfully. If we implement this proposal, we make their code slower by several orders of magnitude for no good reason. Just imagine some calculation involving loops. One day you update Unitful, and now your code runs forever because every loop iteration which used to do some simple arithmetics now also prints a paragraph of text. Your terminal is filled with millions of lines of the same three sentences, calling the definition of Hz you used in your code “stupid”. Why punish everyone who uses Hz successfully?

(because it's almost never going to be what they intended it to be)

This might be true in the context of sinusoidal/circular motion, but in general I don’t agree with it. The unit Hz is used in many contexts, not just sinusoidal motion.

The problem only arises in sinusoidal/circular motion, because rad/s is used for angular frequency and, in the context of sinusoidal motion, Hz is (usually) only used for frequency, not angular frequency. In order to convert from frequency to angular frequency, I have to multiply by , not just change units. If I’m not dealing with sinusoidal motion, I never run into this problem.

Maybe we could add a FAQ section in the manual. We could also add warnings to the docstrings of Hz and rad (because the reason for the behavior of Hz is really that 1 rad == 1 instead of 2π rad == 1).

@jonniediegelman
Copy link
Author

jonniediegelman commented Apr 4, 2023

Printing something every time a specific unit is used is simply impractical

That was mostly hyperbole. I don't think we should actually print out a wall of text whenever someone uses the unit. But honestly even doing that would be better than the current situation of silently giving an unexpected result.

The problem only arises in sinusoidal/circular motion

Okay, but sinusoidal motion is where Hz is mostly being used in physics contexts. It's usually not describing literal physical angular motion (the only angular motion is happening in the complex plane), but it often is converted to rad/s for making other calculations more convenient. Frequency response functions are a good example where the system you're studying the frequency response of is generally not a rotational system, but will still often be analyzed in terms of angular frequency.

Maybe we could add a FAQ section in the manual. We could also add warnings to the docstrings of Hz and rad (because the reason for the behavior of Hz is really that 1 rad == 1 instead of 2π rad == 1).

I don't think a docstring would be sufficient here because people wouldn't usually check the docstring of a physical unit if they have no reason to believe they might be misunderstanding it.

I can't emphasize enough that the common understanding and practical usage of a hertz is that of a cycle per second, not of an unqualified "one per second". Even the NIST page on SI time units describes one hertz as "one cycle per second".

@ederag
Copy link

ederag commented Apr 17, 2023

#531 (comment) nailed it, IMO:

[...] ω and f are not the same quantity in different units...
What I want is really a change of variables, not a unit transformation. 🙃 [...]

@Eben60
Copy link
Contributor

Eben60 commented Dec 28, 2023

I can't emphasize enough that the common understanding and practical usage of a hertz is that of a cycle per second, not of an unqualified "one per second". Even the NIST page on SI time units describes one hertz as "one cycle per second".

NIST page writes:

The number of periods or cycles per second is called frequency. The SI unit for frequency is the hertz (Hz). One hertz is the same as one cycle per second.

Thus "period" and "cycle" are used synonymously there, I'd also add "event" as a further synonym. Though "cycle" might suggest sinusoidal/circular motion, "period" doesn't. Hz is a universal unit for all kind of periodic processes. I happily use Hz to measure the pulse frequency of a step motor controller.

@jagot
Copy link

jagot commented Apr 5, 2024

Related publication:

  • Bunker, P., Mills, I. M., & Jensen, P. (2019). The Planck constant
    and its units. Journal of Quantitative Spectroscopy and Radiative
    Transfer, 237,
    106594. DOI: 10.1016/j.jqsrt.2019.106594

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

No branches or pull requests

7 participants