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

Add unit "angstrom" #271

Merged
merged 2 commits into from
Oct 6, 2019
Merged

Add unit "angstrom" #271

merged 2 commits into from
Oct 6, 2019

Conversation

singularitti
Copy link
Contributor

@singularitti singularitti commented Sep 24, 2019

I was going to contribute to UnitfulAtomic.jl, but the author asks me to try here first.

I did not find any abbreviation of "angstrom" as "mi" does. But requiring input Å as a unit is harder than just typing angstrom. If you have better ideas, I would like to adopt.

@singularitti
Copy link
Contributor Author

Wiki for angstrom: https://en.wikipedia.org/wiki/Angstrom

@ajkeller34
Copy link
Collaborator

I would suggest adding a line const Å = angstrom so that people who want to type it are able to do so but otherwise I agree this is a well-known and common unit that should probably go here.

Was it necessary to write Unitful.nm in the macro?

@giordano
Copy link
Collaborator

@singularitti
Copy link
Contributor Author

singularitti commented Sep 25, 2019

Note that Angstrom is already in UnitfulAstro.jl: https://github.com/JuliaAstro/UnitfulAstro.jl/blob/5598f8357944eeb6e5c1885adba444f3cc1f86a9/src/UnitfulAstro.jl#L55

That's a good point. I do not know why they need this unit since "angstrom" is so small to be astronomical. I do not know whether it would impact people who write

using UnitfulAstro: angstrom

if we merge this PR into Unitful.jl and ask UnitfulAstro.jl maintainers to remove it.

But it sounds weird to me that I need to install UnitfulAstro.jl in my field: dealing with atoms and molecules.

@giordano
Copy link
Collaborator

I do not know why they need this unit since "angstrom" is so small to be astronomical

Wavelengths 🙂

if we merge this PR into Unitful.jl and ask UnitfulAstro.jl maintainers to remove it.

I'm sure we'll find a way to not break users' code if angstrom is added here 😉

@singularitti
Copy link
Contributor Author

singularitti commented Sep 25, 2019

I would suggest adding a line const Å = angstrom so that people who want to type it are able to do so but otherwise I agree this is a well-known and common unit that should probably go here.

Was it necessary to write Unitful.nm in the macro?

The reason I used Unitful.nm is that it will keep the fractional-structure when converting

julia> @unit angstrom "Å" Angstrom (1 // 10) * Unitful.nm false

julia> Unitful.register(Main)

julia> ustrip(u"cm", 1u"angstrom")
1//100000000

However, if I use UnitfulAstro.jl, it will be converted to floats:

julia> using UnitfulAstro

julia> ustrip(u"cm", 1u"angstrom")
1.0e-8

However, u"m" and u"cm" are related by fractionals:

julia> ustrip(u"m", 1u"cm")
1//100

So the relation breaks.
I do not know whether this is a good choice. But I saw you prefer fractional-structures:

@unit inch      "inch"     Inch                 (254//10000)*m          false
@unit mil       "mil"      Mil                  (1//1000)*inch          false

@singularitti
Copy link
Contributor Author

I would suggest adding a line const Å = angstrom so that people who want to type it are able to do so but otherwise I agree this is a well-known and common unit that should probably go here.

Hi, would you mind pointing out where should I add const Å = angstrom?

@@ -182,6 +182,7 @@ const R∞ = 10_973_731.568_160/m # (21) Rydberg constant
@unit ft "ft" Foot 12inch false
@unit yd "yd" Yard 3ft false
@unit mi "mi" Mile 1760yd false
@unit angstrom "Å" Angstrom (1//10)*Unitful.nm false

Copy link
Collaborator

Choose a reason for hiding this comment

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

const Å = angstrom should go immediately following the @unit definition.

@ajkeller34
Copy link
Collaborator

The reason I used Unitful.nm is that it will keep the fractional-structure...

My question was really about whether the Unitful. part of Unitful.nm was necessary. Why not just write nm, consistent with the style of the rest of the file?

Note that Angstrom is already in UnitfulAstro.jl

At least the u_str macro shouldn't fail silently if you have two different modules defining the same unit—I think the unit from the most recently registered units module is used, and importantly a warning should be emitted.

@codecov-io
Copy link

Codecov Report

Merging #271 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #271   +/-   ##
=======================================
  Coverage   78.34%   78.34%           
=======================================
  Files          15       15           
  Lines        1076     1076           
=======================================
  Hits          843      843           
  Misses        233      233
Impacted Files Coverage Δ
src/pkgdefaults.jl 20.4% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5bdf76e...12fe3af. Read the comment docs.

@singularitti
Copy link
Contributor Author

The reason I used Unitful.nm is that it will keep the fractional-structure...

My question was really about whether the Unitful. part of Unitful.nm was necessary. Why not just write nm, consistent with the style of the rest of the file?

Note that Angstrom is already in UnitfulAstro.jl

At least the u_str macro shouldn't fail silently if you have two different modules defining the same unit—I think the unit from the most recently registered units module is used, and importantly a warning should be emitted.

Oh, I was just not aware of that. I have updated as you suggested.

@singularitti
Copy link
Contributor Author

Any updated information?

@ajkeller34 ajkeller34 merged commit 9e21cd0 into PainterQubits:master Oct 6, 2019
singularitti added a commit to MineralsCloud/EquationsOfState.jl that referenced this pull request Oct 10, 2019
singularitti added a commit to MineralsCloud/EquationsOfState.jl that referenced this pull request Nov 27, 2019
…19-11-27-08-09-32-349-3759351010

CompatHelper: add new compat entry for "Unitful" at version "0.18"

Because I want the unit "angstrom" merged in PainterQubits/Unitful.jl#271
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

Successfully merging this pull request may close these issues.

4 participants