Module airball.units
airball.units extends astropy.units with a yr2pi quantity such that yr2pi\(= \mathrm{yr}/(2\pi)\). This is the default time unit of REBOUND when the central mass object is one solar mass [\(M_\odot\)], the unit distance is one astronomical unit [AU], and the value of Newton's gravitational constant is 1.
airball.units also adds a stars quantity for keeping track of units of stars when doing encounter rates, density, and other calculations related to StellarEnvironments.
Simply use airball.units the way you would use any astropy.units, but enjoy the additional unit of time.
Example
import rebound
import airball.units as u
sim = rebound.Simulation()
sim.add('solar system')
vel = (sim.particles[8].v * u.au/u.yr2pi).to(u.km/u.s) # Get Neptune's velocity in km/s
The following documentation was automatically generated from the docstrings.
airball.units.UnitSet
A class for managing the units of another class.
The default units are [u.au, u.yr2pi, u.solMass, u.rad, u.km/u.s, u.stars/u.pc**3, u.stars].
If a list of units is provided, the UnitSet will attempt to determine the units of length, time, mass, angle, velocity, density, and object. Thus, if a unit of length and a unit of time are given, but no unit of velocity, then UnitSet will calculate the unit of velocity from the given units of length and time. If no units are provided, the default units will be used.
Two UnitSets are considered equal if the string representations of the units in each UnitSets are identical.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
UNIT_SYSTEM
|
list
|
A list of Astropy Units describing the units of the system. |
[]
|
Attributes:
| Name | Type | Description |
|---|---|---|
UNIT_SYSTEM |
list
|
A list of Astropy Units describing the units of the system. |
units |
dict
|
A dictionary of Astropy Units describing the units of the system. Can also access the dictionary from the object itself. |
length |
Unit
|
The unit of length. |
time |
Unit
|
The unit of time. |
mass |
Unit
|
The unit of mass. |
angle |
Unit
|
The unit of angle. |
velocity |
Unit
|
The unit of velocity in length/time. |
density |
Unit
|
The unit of density in object/length**3. |
object |
Unit
|
The unit of an object (such as a star). |
Example
import airball
import airball.units as u
us1 = airball.tools.UnitSet([u.pc, u.Myr])
us2 = airball.tools.UnitSet()
print(us1 == us2) # False
print(us1.velocity) # pc/Myr
print(us2["velocity"]) # au/yr2pi
Source code in src/airball/units.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |