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

Angle units hstr() and dstr() format unnecessary not fitting #513

Closed
mworion opened this issue Dec 22, 2020 · 6 comments
Closed

Angle units hstr() and dstr() format unnecessary not fitting #513

mworion opened this issue Dec 22, 2020 · 6 comments

Comments

@mworion
Copy link

mworion commented Dec 22, 2020

@brandon-rhodes
It is not an big issue but from user side it hurts me. If you have an angle defined and use

angle.hstr(), you get a format like 12h 07m 30.00s

if you use

angle.dstr(), you get a format like 181deg 52' 30.0"

So in one you have hyphens in the other m and s. So my proposal would be to change dstr() to:

12d 07m 30.00s

Does this makes sense for you ?

Michel

@brandon-rhodes
Copy link
Member

12d 07m 30.00s

That looks to my eyes like “12 days, 7 minutes, 30 seconds” when I read it, and double-checking against https://en.wikipedia.org/wiki/International_System_of_Units confirms that d means “days”. So we cannot, alas, replace “day” with “d” and agree with the official standards; nor can we use “s” for anything but the standard SI second.

I wish the string could have included the official symbol “°” for degree, but that would have caused problems under Python 2, and also for anyone without a Unicode display.

Also, we can't change that default without changing the behavior of all the programs that already use that method.

What if dstr() were to gain a fmt parameter that allowed the user to choose their own text to put around the values?

@mworion
Copy link
Author

mworion commented Dec 22, 2020

That would be even a better idea. I also would think about using this fmt parameter for hstr() as well. So the user could decide about the interpretation.

@mworion
Copy link
Author

mworion commented Dec 22, 2020

Another chance might be:
12deg 07m 30.00s
to ge rid of the hyphens...

@brandon-rhodes
Copy link
Member

By the hyphens, I assume you mean the quote and double-quote.

The quote and double-quote stand in for the prime and double-prime that are really the official way those units are written. I will be avoiding "m" and "s" because (a) that looks too much like minutes and seconds of time, since "s" is the official SI unit of time abbreviation, and (b) because existing programs already count on exactly that string being returned — if existing users, for example, use .replace() to substitute in their own symbols, then changing the output breaks those programs.

But adding a fmt to dstr() and hstr() should be possible! I'll mark this as a feature request and will plan to try making the change within the next release or two.

@mworion
Copy link
Author

mworion commented Dec 22, 2020

Let's go your proposed path. It makes a lot of sense. Many thanks and Merry Christmas !

@brandon-rhodes
Copy link
Member

I just made a new release, and format strings are now offered by both methods:

https://rhodesmill.org/skyfield/api-units.html#formatting-angles

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants