Description
openedon Jul 19, 2024
Currently the unxt
package vendors a custom Quantity
(and related) object as well as a UnitSystem
(and related).
The actual units and their conversions are managed by Astropy.
To make unxt
a tool for the general ML community it would be ideal to allow the user to choose what units backend to use.
This will require a fair bit of refactoring to decouple unxt
from astropy.units
. Instead of directly calling astropy functions we will need to develop more generic functions which can then refer to the chosen backend. I think we should lean into multiple dispatch and therefore draw inspiration from Unitful.jl
.
I'm envisioning
Dimensions-related API:
AbstractDimensions
: a non-init'able base class for all backends to subclass.AstropyDimensions
: wrapper aroundastropy.units.PhysicalType
- ...
-
dimensions
: function to create anAbstractDimensions
object. likenp.array
for makingnp.ndarray
. This is multi-dispatched for all the different ways to make a Dimensions object. (feat: dimensions function #181) -
dimensions_of
: function to get the dimensions of an object, returning dimensionless if it's not a dimensionful object. (feat: dimensions_of #177)
Dimensions-system-related API:
DimensionSystem
dimensionsystem
: function to create anAbstractDimensionsSystem
object, making a new subclass if necessary.dimensionsystem_of
: function to get / infer the dimension system of an object.
Units-related API:
AbstractUnits
: a non-init'able base class for all backends to subclass. This is a composite units object. Users will never see a lonely singular unit. This ensure that the API is the same, regardless of the backend.- attribute:
dimensions
- attribute:
AstropyUnits
: wrapper aroundastropy.units.CompositeUnit
- ...
-
units
: function to create anAbstractUnits
object. This is multi-dispatched for all the different ways to make a Units object. (feat: units #175) -
units_of
: function to get the units of an object, returning dimensionless if it's not a dimensionful object. (feat: units #175)
UnitSystem-related API:
-
AbstractUnitSystem
- specific subclasses, e.g.
LTMUnitSystem
for a length-time-mass only system -
unitsystem
: function to create anAbstractDimensionsSystem
object, making a new subclass if necessary. -
unitystem_of
: function to get / infer the dimension system of an object. (feat: unitsystem_of #170)
Quantity-related API:
-
AbstractQuantity
: base class- field
.value: Any
- field
.units: AbstractUnits
- field
-
AbstractParametricQuantity
,Quantity
,UncheckedQuantity
,AbstractDistance
,Distance
,Parallax
,DistanceModulus
-
uconvert
: the same API asUnitful.jl
for doing a quantity's unit conversions. (feat:uconvert
andustrip
#186) -
ustrip
: the same API asUnitful.jl
. (feat:uconvert
andustrip
#186) -
upreferred
: the same API asUnitful.jl
.
Support other plum API.
convert
promote
Planned backend support:
- Astropy
- Unyt
- Pint
- Julia's Unitful through e.g. JuliaCall
- Custom