DimensionlessUnitSystem#
- class gala.units.DimensionlessUnitSystem[source]#
Bases:
UnitSystemInitialize a dimensionless unit system. All quantities are treated as dimensionless.
Methods Summary
decompose(q)A thin wrapper around
astropy.units.Quantity.decompose()that knows how to handle Quantities with physical types with non-default representations.from_string(name)Create a UnitSystem instance from a name.
get_constant(name)Retrieve a constant with specified name in this unit system.
to_dict()Return a dictionary representation of the unit system with keys set by the physical types and values set by the unit objects.
Methods Documentation
- decompose(q)#
A thin wrapper around
astropy.units.Quantity.decompose()that knows how to handle Quantities with physical types with non-default representations.
- classmethod from_string(name: str) UnitSystem#
Create a UnitSystem instance from a name.
- Parameters:
- name
str The name of the unit system. Examples of valid names are ‘galactic’, ‘solarsystem’, and ‘dimensionless’.
- name
- Returns:
- usys
UnitSystem The corresponding unit system instance.
- usys
Examples
Create the galactic unit system from its name:
>>> usys = UnitSystem.from_string('galactic') >>> usys['length'] Unit("kpc")
- get_constant(name)[source]#
Retrieve a constant with specified name in this unit system.
- Parameters:
- name
str The name of the constant, e.g., G.
- name
- Returns:
- const
float The value of the constant represented in this unit system.
- const
Examples
We will get the value of the speed of light in a custom unit system:
>>> usys = UnitSystem(u.kpc, u.Myr, u.Msun, u.radian) >>> usys.get_constant('c') 306.6013937855506