Skip to content

Commit 54e26e9

Browse files
committed
split off astronomical constants from units
1 parent b008016 commit 54e26e9

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Series of astronomical constants, which are in turn used by the units of the
3+
same names.
4+
"""
5+
6+
import numpy as np
7+
from amuse.units.si import m, kg
8+
from amuse.units.derivedsi import W, km
9+
10+
au = 149597870691.0 | m
11+
parsec = au / np.tan(np.pi / (180 * 60 * 60))
12+
lightyear = 9460730472580.8 | km
13+
Lsun = 3.839e26 | W
14+
Msun = 1.98892e30 | kg
15+
Rsun = 6.955e8 | m
16+
Mjupiter = 1.8987e27 | kg
17+
Rjupiter = 71492.0 | km
18+
Mearth = 5.9722e24 | kg
19+
Rearth = 6371.0088 | km # IUGG mean radius

src/amuse/units/units.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import numpy
66
from . import constants
7+
from . import astronomical_constants
78
from . import quantities
89

910
# The two imports below are to explicitly expose everything directly used in
@@ -43,20 +44,20 @@
4344

4445
# astronomical units
4546
angstrom = named("angstrom", "angstrom", 1e-10 * m)
46-
au = named("astronomical unit", "au", 149597870691.0 * m)
47-
aud = named("au per day", "aud", 149597870691.0 * m / day)
48-
parsec = named("parsec", "parsec", au / numpy.tan(numpy.pi / (180 * 60 * 60)))
47+
au = named("astronomical unit", "au", astronomical_constants.au.as_unit())
48+
aud = named("au per day", "aud", astronomical_constants.au.as_unit() / day)
49+
parsec = named("parsec", "parsec", astronomical_constants.parsec.as_unit())
4950
kpc = named("kilo parsec", "kpc", 10**3 * parsec)
5051
Mpc = named("mega parsec", "Mpc", 10**6 * parsec)
5152
Gpc = named("giga parsec", "Gpc", 10**9 * parsec)
52-
lightyear = named("light year", "ly", 9460730472580.8 * km)
53-
LSun = named("solar luminosity", "LSun", 3.839e26 * W)
54-
MSun = named("solar mass", "MSun", 1.98892e30 * kg)
55-
RSun = named("solar radius", "RSun", 6.955e8 * m)
56-
MJupiter = named("jupiter mass", "MJupiter", 1.8987e27 * kg)
57-
RJupiter = named("jupiter radius", "RJupiter", 71492.0 * km)
58-
MEarth = named("earth mass", "MEarth", 5.9722e24 * kg)
59-
REarth = named("earth radius", "REarth", 6371.0088 * km) # IUGG mean radius
53+
lightyear = named("light year", "ly", astronomical_constants.lightyear.as_unit())
54+
LSun = named("solar luminosity", "LSun", astronomical_constants.Lsun.as_unit())
55+
MSun = named("solar mass", "MSun", astronomical_constants.Msun.as_unit())
56+
RSun = named("solar radius", "RSun", astronomical_constants.Rsun.as_unit())
57+
MJupiter = named("jupiter mass", "MJupiter", astronomical_constants.Mjupiter.as_unit())
58+
RJupiter = named("jupiter radius", "RJupiter", astronomical_constants.Rjupiter.as_unit())
59+
MEarth = named("earth mass", "MEarth", astronomical_constants.Mearth.as_unit())
60+
REarth = named("earth radius", "REarth", astronomical_constants.Rearth.as_unit())
6061
kyr = named("kilo year", "kyr", 1000 * yr)
6162
myr = named("million year", "Myr", 1000000 * yr)
6263
gyr = named("giga (billion) year", "Gyr", 1000000000 * yr)

0 commit comments

Comments
 (0)