Using Unitful.jl & UnitfulAstro.jl for unit handling
cadojo opened this issue · 4 comments
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.
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 🤔
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!
If anything I implement could be used to help the real
Astrodynamics.jl
, orAstroBase.jl
, then I'd be happy to help!
That would be great and certainly much appreciated 👍
FYI @cadojo: This issue here nicely illustrates why units by default might not be the best solution JuliaSpace/SatelliteToolbox.jl#44