Skip to content

New API and choice of units backends #139

Open

Description

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 around astropy.units.PhysicalType
    • ...
  • dimensions: function to create an AbstractDimensions object. like np.array for making np.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 an AbstractDimensionsSystem 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
  • AstropyUnits: wrapper around astropy.units.CompositeUnit
  • ...
  • units: function to create an AbstractUnits 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 an AbstractDimensionsSystem 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
  • AbstractParametricQuantity, Quantity, UncheckedQuantity, AbstractDistance, Distance, Parallax, DistanceModulus
  • uconvert: the same API as Unitful.jl for doing a quantity's unit conversions. (feat: uconvert and ustrip #186)
  • ustrip: the same API as Unitful.jl. (feat: uconvert and ustrip #186)
  • upreferred: the same API as Unitful.jl.

Support other plum API.

  • convert
  • promote

Planned backend support:

  • Astropy
  • Unyt
  • Pint
  • Julia's Unitful through e.g. JuliaCall
  • Custom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions