Open nstarman opened 4 months ago
The new API is complete 🎉. What remains is good for a v2, where we offer choices of backends beyond Astropy. Users should see minimal changes, only a new Dimension
and Unit
object, which wrap the backend and provide improved features like array * unit = unxt.Quantity
, not astropy.Quantity
.
Currently the
unxt
package vendors a customQuantity
(and related) object as well as aUnitSystem
(and related). The actual units and their conversions are managed by Astropy. To makeunxt
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
fromastropy.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 fromUnitful.jl
. I'm envisioningDimensions-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. (#181)dimensions_of
: function to get the dimensions of an object, returning dimensionless if it's not a dimensionful object. (#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.dimensions
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. (#175)units_of
: function to get the units of an object, returning dimensionless if it's not a dimensionful object. (#175)UnitSystem-related API:
AbstractUnitSystem
LTMUnitSystem
for a length-time-mass only systemunitsystem
: function to create anAbstractDimensionsSystem
object, making a new subclass if necessary.unitystem_of
: function to get / infer the dimension system of an object. (#170)Quantity-related API:
AbstractQuantity
: base class.value: Any
.unit: AbstractUnits
AbstractParametricQuantity
,Quantity
,UncheckedQuantity
,AbstractDistance
,Distance
,Parallax
,DistanceModulus
uconvert
: the same API asUnitful.jl
for doing a quantity's unit conversions. (#186)ustrip
: the same API asUnitful.jl
. (#186)upreferred
: the same API asUnitful.jl
.Support other plum API.
convert
: this enables conversion to/from Astropy quantity. We can easily set up interoperability with Pint, unyt.promote
: this is used to enable Q subclasses to interact, e.g. acoordinax.Distance
* aunxt.Quantity
promotes to aQuantity
.Planned backend support: