Units
Physical quantity types for type-safe unit handling.
Available Units
Angle
| Constant | Value |
|---|---|
rad |
1 radian |
deg |
π/180 radians |
AngularRate
| Constant | Value |
|---|---|
rad_per_s |
1 rad/s |
deg_per_s |
π/180 rad/s |
DataRate
| Constant | Value |
|---|---|
bps |
1 bit/s |
kbps |
1 kbit/s |
Mbps |
1 Mbit/s |
Distance
| Constant | Value |
|---|---|
m |
1 meter |
km |
1000 meters |
au |
1 astronomical unit |
Frequency
| Constant | Value |
|---|---|
Hz |
1 Hz |
kHz |
1 kHz |
MHz |
1 MHz |
GHz |
1 GHz |
THz |
1 THz |
Power
| Constant | Value |
|---|---|
W |
1 W |
kW |
1 kW |
Temperature
| Constant | Value |
|---|---|
K |
1 K |
Velocity
| Constant | Value |
|---|---|
m_per_s |
1 m/s |
km_per_s |
1 km/s |
Decibel
| Constant | Value |
|---|---|
dB |
1 dB |
Quick Example
import lox_space as lox
# Use unit constants for readable code
angle = 45 * lox.deg
distance = 100 * lox.km
frequency = 2.4 * lox.GHz
velocity = 7.8 * lox.km_per_s
power = 10 * lox.W
temperature = 290 * lox.K
data_rate = 10 * lox.Mbps
# Convert to specific units
angle_deg = angle.to_degrees() # 45.0
distance_km = distance.to_kilometers() # 100.0
freq_ghz = frequency.to_gigahertz() # 2.4
# Convert to float (returns internal SI value)
angle_rad = float(angle) # radians
distance_m = float(distance) # meters
# Arithmetic
total = 100 * lox.km + 500 * lox.m # Distance
delta = 45 * lox.deg - 10 * lox.deg # Angle
scaled = 2.0 * distance # Distance
Angle
Angle type for type-safe angular values.
Use with unit constants: 45 * lox.deg or 1.5 * lox.rad
Convert to float with float(angle) (returns radians).
Methods:
-
to_arcseconds–Returns the value in arcseconds.
-
to_degrees–Returns the value in degrees.
-
to_radians–Returns the value in radians.
AngularRate
Angular rate type for type-safe angular velocity values.
Use with unit constants: 1.0 * lox.rad_per_s or 15 * lox.deg_per_s
Convert to float with float(rate) (returns rad/s).
Methods:
-
to_degrees_per_second–Returns the value in degrees per second.
-
to_radians_per_second–Returns the value in radians per second.
DataRate
Data rate type for type-safe data rate values.
Use with unit constants: 1e6 * lox.bps or 10 * lox.Mbps
Convert to float with float(rate) (returns bits/s).
Methods:
-
to_bits_per_second–Returns the value in bits per second.
-
to_kilobits_per_second–Returns the value in kilobits per second.
-
to_megabits_per_second–Returns the value in megabits per second.
Distance
Distance type for type-safe length values.
Use with unit constants: 100 * lox.km or 1.5 * lox.au
Convert to float with float(distance) (returns meters).
Methods:
-
to_astronomical_units–Returns the value in astronomical units.
-
to_kilometers–Returns the value in kilometers.
-
to_meters–Returns the value in meters.
Frequency
Frequency type for type-safe frequency values.
Use with unit constants: 2.4 * lox.GHz or 100 * lox.MHz
Convert to float with float(frequency) (returns Hz).
Methods:
-
to_gigahertz–Returns the value in gigahertz.
-
to_hertz–Returns the value in hertz.
-
to_kilohertz–Returns the value in kilohertz.
-
to_megahertz–Returns the value in megahertz.
-
to_terahertz–Returns the value in terahertz.
GravitationalParameter
Gravitational parameter (GM) type.
Constructor takes the value in m³/s².
Convert to float with float(gm) (returns m³/s²).
Methods:
-
from_km3_per_s2–Creates from a value in km³/s².
-
to_km3_per_s2–Returns the value in km³/s².
-
to_m3_per_s2–Returns the value in m³/s².
from_km3_per_s2
staticmethod
from_km3_per_s2(value: float) -> GravitationalParameter
Creates from a value in km³/s².
Power
Power type for type-safe power values.
Use with unit constants: 10 * lox.W or 1.5 * lox.kW
Convert to float with float(power) (returns Watts).
Methods:
-
to_dbw–Returns the value in dBW.
-
to_kilowatts–Returns the value in kilowatts.
-
to_watts–Returns the value in Watts.
Temperature
Velocity
Velocity type for type-safe speed values.
Use with unit constants: 7.8 * lox.km_per_s or 100 * lox.m_per_s
Convert to float with float(velocity) (returns m/s).
Methods:
-
to_kilometers_per_second–Returns the value in kilometers per second.
-
to_meters_per_second–Returns the value in meters per second.