JuliaAstro / AstroBase.jl

Interfaces, types, and functions for space science packages
Mozilla Public License 2.0
13 stars 6 forks source link

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

Open cadojo opened 4 years ago

cadojo commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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