gala Interoperability Guide

gala Interoperability Guide#

This guide shows how to convert between gala’s gala.units.UnitSystem and unxt’s unxt.unitsystems.AbstractUnitSystem.

Setup#

Importing unxts.interop.gala registers the conversions with plum as a side effect. unxt imports the package automatically when both it and gala are importable (gala can be absent on some platforms, e.g. Windows, in which case the conversions are not registered), so in practice you usually only need to import unxt and gala:

>>> import unxt
>>> import gala.units as gu

galaunxt#

The most direct route is unxt.unitsystem(), which accepts a gala.units.UnitSystem:

>>> gu.galactic
<UnitSystem (kpc, Myr, solMass, rad)>

>>> unxt.unitsystem(gu.galactic)
unitsystem(kpc, Myr, solMass, rad)

Because the conversions are registered with plum, you can equivalently use plum.convert with the target type:

>>> from plum import convert

>>> usys = convert(gu.galactic, unxt.AbstractUnitSystem)
>>> usys
unitsystem(kpc, Myr, solMass, rad)

unxtgala#

The reverse conversion goes through plum.convert with gala.units.UnitSystem as the target:

>>> convert(usys, gu.UnitSystem)
<UnitSystem (kpc, Myr, solMass, rad)>

Round trip#

Converting a unit system to the other library and back yields an equivalent unit system:

>>> back = convert(convert(gu.galactic, unxt.AbstractUnitSystem), gu.UnitSystem)
>>> back
<UnitSystem (kpc, Myr, solMass, rad)>

See Also#