question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Converting between angular frequency and frequency (e.g., rad/s to Hz)

See original GitHub issue

I just tried a couple of ways of converting from 'rad / s' to 'Hz' that gave me different behavior than I was expecting. Doing this conversion requires dividing by 2π, but the dimensionless_angles equivalency uses a factor of 1 instead of 2π. Here are some examples that confused me when I first tried them. The second example gets pretty close to the behavior I was expecting, except that it seems non-intuitive that 'cycle / s' cannot be converted to 'Hz'.

>>> from astropy import units as u
>>> angular_frequency = 1.0 * u.rad/u.s
>>> angular_frequency.to(u.Hz)
UnitConversionError: 'rad / s' (angular speed) and '1 / s' (frequency) are not convertible

>>> frequency = angular_frequency.to(u.cycle/u.s)   # a cycle is 2π radians
<Quantity 0.15915494309189535 cycle / s>
>>> frequency.to(u.Hz)
UnitConversionError: 'cycle / s' (angular speed) and 'Hz' (frequency) are not convertible

>>> u.set_enabled_equivalencies(u.dimensionless_angles())
>>> angular_frequency = 1.0 * u.rad/u.s
>>> angular_frequency.to(u.Hz)
<Quantity 1.0 Hz>

Should units allow conversion between angular frequency and frequency by default? Would it be better to add this as another equivalency along with dimensionless_angles? Or is the status quo preferred? Allowing this conversion by default would result in more readable code for me and I think this would be more intuitive, but I don’t know if there are any adverse consequences.

Also, here’s my code for a custom equivalency that gave me the expected behavior:

>>> angfreq_to_freq = [(u.rad/u.s, u.Hz, lambda x: x/(2*pi), lambda x: 2*pi*x)]
>>> angular_frequency = 1.0 * u.rad / u.s
>>> angular_frequency.to(u.Hz, equivalencies=angfreq_to_freq)
<Quantity 0.15915494309189535 Hz>

I tried this with astropy 1.3.2 and 2.0.dev18104. Related pull requests: https://github.com/astropy/astropy/pull/1160, https://github.com/astropy/astropy/pull/1161, https://github.com/astropy/astropy/pull/2544, https://github.com/astropy/astropy/pull/2559

Many thanks!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
namurphycommented, May 11, 2017

@mhvk - Sure! I’ll aim to get to that in the next couple of days, while simultaneously trying to get myself unconfused about this. You solution is very clear and explicity, so I like it and will use that approach going forward. I’ll also include it in the pull request.

I’m presently a net negative contributor (minus three characters!) so I’m happy to make a positive contribution!

0reactions
virtualmarioecommented, Aug 12, 2019

Hey @namurphy, this conversion is exactly what I was looking for in the context of neural population simulations. Thanks for raising the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rad/sec to hertz (Hz) conversion calculator - RapidTables.com
Angular velocity in radian per second (rad/s) to frequency in hertz (Hz) calculator and how to convert.
Read more >
Radians Per Second to Hertz Conversion (rad/s to Hz)
The frequency in hertz is equal to the radians per second multiplied by 0.159155. For example, here's how to convert 5 radians per...
Read more >
Rad/s to Hz Conversion - Calculatorology
Rad /s to Hz conversion calculator that converts the angular frequency in Radians per second (Rad/s) to the frequency in Hertz (Hz).
Read more >
Radians Per Second to Hertz - Kyle's Converter
1 Radian per Second: 1 Radian per second is comparative to 1/2π Hertz. Radians per second is a measure of angular frequency, it...
Read more >
Angular frequency (ω) - Questions and Answers ​in MRI
Hence, 1 Hz ≈ 6.28 rad/sec. Since 2π radians = 360°, 1 radian ≈ 57.3°. The YouTube video (left) may clarify some of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found