-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathastrophys.py
More file actions
226 lines (198 loc) · 5.18 KB
/
astrophys.py
File metadata and controls
226 lines (198 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
224
225
226
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
This package defines the astrophysics-specific units. They are also
available in (and should be used through) the `astropy.units` namespace.
"""
# avoid ruff complaints about undefined names defined by def_unit
# ruff: noqa: F821
import numpy as np
from astropy.constants import si as _si
from . import si
from .core import def_unit, set_enabled_units
from .docgen import generate_dunder_all, generate_unit_summary
# To ensure si units of the constants can be interpreted.
set_enabled_units([si])
__all__: list[str] = [] # Units are added at the end
_ns = globals()
###########################################################################
# LENGTH
def_unit(
(["AU", "au"], ["astronomical_unit"]),
_si.au,
namespace=_ns,
prefixes=True,
doc="astronomical unit: approximately the mean Earth--Sun distance.",
)
def_unit(
["pc", "parsec"],
_si.pc,
namespace=_ns,
prefixes=True,
doc="parsec: approximately 3.26 light-years.",
)
def_unit(
["solRad", "R_sun", "Rsun"],
_si.R_sun,
namespace=_ns,
doc="Solar radius",
prefixes=False,
format={"latex": r"R_{\odot}", "unicode": "R\N{SUN}"},
)
def_unit(
["jupiterRad", "R_jup", "Rjup", "R_jupiter", "Rjupiter"],
_si.R_jup,
namespace=_ns,
prefixes=False,
doc="Jupiter radius",
# LaTeX jupiter symbol requires wasysym
format={"latex": r"R_{\rm J}", "unicode": "R\N{JUPITER}"},
)
def_unit(
["earthRad", "R_earth", "Rearth"],
_si.R_earth,
namespace=_ns,
prefixes=False,
doc="Earth radius",
# LaTeX earth symbol requires wasysym
format={"latex": r"R_{\oplus}", "unicode": "R⊕"},
)
def_unit(
["lyr", "lightyear"],
(_si.c * si.yr).to(si.m),
namespace=_ns,
prefixes=True,
doc="Light year",
)
def_unit(
["lsec", "lightsecond"],
(_si.c * si.s).to(si.m),
namespace=_ns,
prefixes=False,
doc="Light second",
)
###########################################################################
# MASS
def_unit(
["solMass", "M_sun", "Msun"],
_si.M_sun,
namespace=_ns,
prefixes=False,
doc="Solar mass",
format={"latex": r"M_{\odot}", "unicode": "M\N{SUN}"},
)
def_unit(
["jupiterMass", "M_jup", "Mjup", "M_jupiter", "Mjupiter"],
_si.M_jup,
namespace=_ns,
prefixes=False,
doc="Jupiter mass",
# LaTeX jupiter symbol requires wasysym
format={"latex": r"M_{\rm J}", "unicode": "M\N{JUPITER}"},
)
def_unit(
["earthMass", "M_earth", "Mearth"],
_si.M_earth,
namespace=_ns,
prefixes=False,
doc="Earth mass",
# LaTeX earth symbol requires wasysym
format={"latex": r"M_{\oplus}", "unicode": "M⊕"},
)
##########################################################################
# ENERGY
def_unit(
["foe", "Bethe", "bethe"],
1e51 * si.g * si.cm**2 / si.s**2,
namespace=_ns,
prefixes=False,
doc="foe or Bethe: 1e51 erg, used to measure energy emitted by a supernova",
)
###########################################################################
# ILLUMINATION
def_unit(
["solLum", "L_sun", "Lsun"],
_si.L_sun,
namespace=_ns,
prefixes=False,
doc="Solar luminance",
format={"latex": r"L_{\odot}", "unicode": "L\N{SUN}"},
)
###########################################################################
# SPECTRAL DENSITY
def_unit(
(["ph", "photon"], ["photon"]),
format={"ogip": "photon", "vounit": "photon"},
namespace=_ns,
prefixes=True,
)
def_unit(
["Jy", "Jansky", "jansky"],
1e-26 * si.W / si.m**2 / si.Hz,
namespace=_ns,
prefixes=True,
doc="Jansky: spectral flux density",
)
def_unit(
["R", "Rayleigh", "rayleigh"],
(1e10 / (4 * np.pi)) * ph * si.m**-2 * si.s**-1 * si.sr**-1,
namespace=_ns,
prefixes=True,
doc="Rayleigh: photon flux",
)
###########################################################################
# EVENTS
def_unit(
(["ct", "count"], ["count"]),
format={"fits": "count", "ogip": "count", "vounit": "count"},
namespace=_ns,
prefixes=True,
exclude_prefixes=["p"],
)
def_unit(
["adu"],
namespace=_ns,
prefixes=True,
)
def_unit(
["DN", "dn"],
namespace=_ns,
prefixes=False,
)
###########################################################################
# MISCELLANEOUS
# Some of these are very FITS-specific and perhaps considered a mistake.
# Maybe they should be moved into the FITS format class?
# TODO: This is defined by the FITS standard as "relative to the sun".
# Is that mass, volume, what?
def_unit(
["Sun"],
namespace=_ns,
)
def_unit(
["chan"],
namespace=_ns,
prefixes=True,
)
def_unit(
["bin"],
namespace=_ns,
prefixes=True,
)
def_unit(
["beam"],
namespace=_ns,
prefixes=True,
)
def_unit(
["electron"],
doc="Number of electrons",
namespace=_ns,
format={"latex": r"e^{-}", "unicode": "e⁻"},
)
###########################################################################
# ALL & DOCSTRING
__all__ += generate_dunder_all(globals()) # noqa: PLE0605
if __doc__ is not None:
# This generates a docstring for this module that describes all of the
# standard units defined here.
__doc__ += generate_unit_summary(globals())