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

Using Unitful.jl & UnitfulAstro.jl for unit handling #48

Open
cadojo opened this issue Sep 7, 2020 · 4 comments
Open

Using Unitful.jl & UnitfulAstro.jl for unit handling #48

cadojo opened this issue Sep 7, 2020 · 4 comments

Comments

@cadojo
Copy link

cadojo commented Sep 7, 2020

AstroBase currently uses its own unit types, and is limited to the set of units it implements. Is integrating Unitful and UnitfulAstro a desired feature? If so, I'd be interested in implementing this. But I wanted to check to see if that was a desired feature for AstroBase first.

@helgee
Copy link
Member

helgee commented Sep 11, 2020

Yes and no 😄

While I believe that having units available would be great, I also hold the opinion that they should not be the default. In my experience they make the implemention quite a bit more complicated and often require some nasty workarounds (the caveat here is that the only truly "unitful" code base I worked with was AstroPy and it has been a while since I last unsuccessfully tried to introduce Unitful.jl in AstroBase).

My plan was to offer unit support as an extension on top of AstroBase.jl, e.g. UnitfulAstroBase.jl. This is the reason why constants in AstroBase are implemented as functions so that one can offer differently typed constants via multiple dispatch. For example:

using Unitful

# One could overload `speed_of_light` like this
speed_of_light(::Type{<:Quantity}, unit::Unitful.VelocityUnits) = unit(SPEED_OF_LIGHT * u"m/s")
speed_of_light(T::Type{<:Quantity}) = speed_of_light(T, u"m/s")

This is not set in stone, though 🤔

@cadojo
Copy link
Author

cadojo commented Oct 7, 2020

That makes sense, that's a great idea to keep constants as functions so they can be overloaded. The reason I asked is I'm developing an Astrodynamics library alongside a graduate Astrodynamics course this semester. The library is really just for me to learn about Astrodynamics, to help with my assignments, and to get some more practice with Julia.

My library requires Unitful values, so if I learn anything about integrating Unitful types, or if I find any novel ways of going about this, I'll let you know. If anything I implement could be used to help the real Astrodynamics.jl, or AstroBase.jl, then I'd be happy to help!

@helgee
Copy link
Member

helgee commented Oct 9, 2020

If anything I implement could be used to help the real Astrodynamics.jl, or AstroBase.jl, then I'd be happy to help!

That would be great and certainly much appreciated 👍

@helgee
Copy link
Member

helgee commented Oct 23, 2020

FYI @cadojo: This issue here nicely illustrates why units by default might not be the best solution JuliaSpace/SatelliteToolbox.jl#44

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

2 participants