In [1]:
%autosave 20
import matplotlib.pyplot as plt
import numpy as np

import astropy.utils.iers
astropy.utils.iers.conf.auto_download = False
Autosaving every 20 seconds
In [2]:
import astropy.units as u
import astropy.constants as c

c.M_sun
Out[2]:
$1.9884754 \times 10^{30} \; \mathrm{kg}$
In [3]:
c.au.cgs
Out[3]:
$1.4959787 \times 10^{13} \; \mathrm{cm}$
In [4]:
AU = c.au.cgs.value
AU
Out[4]:
14959787070000.0
In [5]:
print(type(1*u.km))
print(type(u.km))
<class 'astropy.units.quantity.Quantity'>
<class 'astropy.units.core.PrefixUnit'>
In [6]:
a_mars = 1.5 * u.au
a_mars_km = a_mars.to_value(u.km)
type(a_mars_km)
Out[6]:
float
In [7]:
v = 2*np.pi * 1*u.au / (1*u.year)
v.to(u.km / u.s)
Out[7]:
$29.785254 \; \mathrm{\frac{km}{s}}$
In [8]:
v = np.sqrt(c.G * c.M_earth / c.R_earth)
In [9]:
M = 10 * u.Msun
Ledd = 4*np.pi * c.G * c.m_p * c.c / c.sigma_T * M
display(Ledd)
# Ledd.to(u.erg/u.s**2)
display(Ledd.to(u.erg / u.s))
Ledd.decompose()
$63.217536 \; \mathrm{\frac{m^{2}\,M_{\odot}}{s^{3}}}$
$1.2570652 \times 10^{39} \; \mathrm{\frac{erg}{s}}$
Out[9]:
$1.2570652 \times 10^{32} \; \mathrm{\frac{m^{2}\,kg}{s^{3}}}$
In [10]:
a = (10*u.g)**(2/7 + 1/5)
display(a)
$3.0599497 \; \mathrm{g^{1/2}}$
In [11]:
from fractions import Fraction as Fr
a = (10*u.g)**(Fr(2,7) + Fr(1,5))
display(a)
$3.0599497 \; \mathrm{g^{17/35}}$
In [12]:
angle = 90*u.deg
display(np.sin(angle))
angle = 1*u.arcsec
1 / np.sin(angle)
$1 \; \mathrm{}$
Out[12]:
$206264.81 \; \mathrm{}$
In [13]:
assert u.Angstrom == u.AA == u.angstrom
assert 1*u.m == 1e2*u.cm == 1e3*u.mm == 1e6*u.micrometer == 1e-6*u.Mm
(1*u.mpc).to(u.pc)
Out[13]:
$0.001 \; \mathrm{pc}$
In [14]:
micron = list(u.Angstrom.find_equivalent_units())[1]
(1*micron).to(u.cm)
Out[14]:
$6.957 \times 10^{10} \; \mathrm{cm}$
In [15]:
x = 10*u.cm / (100 * u.m)
display(x.to(u.dimensionless_unscaled))
x.value, x.unit
$0.001 \; \mathrm{}$
Out[15]:
(0.1, Unit("cm / m"))
In [16]:
delta_m = 1*u.mag
mAB = 10*u.ABmag  # u.STmag
m = mAB - delta_m
display(m.physical.to(u.erg/u.s/u.cm**2/u.Hz))

m1 = u.Magnitude(10 * u.count / u.s)
m2 = u.Magnitude(1e5 * u.count / u.hour)
display((m2 - m1).decompose() - delta_m)
m1.physical
$9.1201084 \times 10^{-24} \; \mathrm{\frac{erg}{Hz\,s\,cm^{2}}}$
$-2.1092437 \; \mathrm{mag}$$\mathrm{\left( \mathrm{} \right)}$
Out[16]:
$10 \; \mathrm{\frac{ct}{s}}$
In [17]:
from astropy import coordinates as coord

display(coord.SkyCoord('05h35m17.3s -05d23m28s'))
display(coord.SkyCoord(ra=5*u.hourangle, dec=-5*u.deg-23*u.arcmin))
star = coord.SkyCoord('05h35m17.3s -05d23m28s')
display(star.galactic)
coord.SkyCoord(l=5*u.deg, b=-5*u.deg-23*u.arcmin, frame='galactic')
coord.SkyCoord(l=5*u.deg, b=-5*u.deg-23*u.arcmin, distance=1*u.kpc, frame='galactic')
<SkyCoord (ICRS): (ra, dec) in deg
    (83.82208333, -5.39111111)>
<SkyCoord (ICRS): (ra, dec) in deg
    (75., -5.38333333)>
<SkyCoord (Galactic): (l, b) in deg
    (209.01374582, -19.38160147)>
Out[17]:
<SkyCoord (Galactic): (l, b, distance) in (deg, deg, kpc)
    (5., -5.38333333, 1.)>
In [18]:
from astropy.time import Time

t = Time.now()
loc = coord.EarthLocation.of_site('subaru')
# sai = coord.EarthLocation.of_address('Университетский проспект 13, Москва')
loc.geodetic
alt_az_frame = coord.AltAz(obstime=t, location=loc)
star.transform_to(alt_az_frame)
WARNING: Tried to get polar motions for times after IERS data is valid. Defaulting to polar motion from the 50-yr mean for those. This may affect precision at the 10s of arcsec level [astropy.coordinates.builtin_frames.utils]
WARNING: (some) times are outside of range covered by IERS table. Assuming UT1-UTC=0 for coordinate transformations. [astropy.coordinates.builtin_frames.utils]
Out[18]:
<SkyCoord (AltAz: obstime=2018-11-07 07:10:03.059219, location=(-5464468.109716696, -2493053.6504484517, 2150943.6050810195) m, pressure=0.0 hPa, temperature=0.0 deg_C, relative_humidity=0, obswl=1.0 micron): (az, alt) in deg
    (96.56492181, 2.31669402)>
In [32]:
from astropy import visualization

dt = np.linspace(0, 1, 100) * u.day
t = Time.now() + dt
moon = coord.get_moon(t)
print(type(moon))
keck = coord.EarthLocation.of_site('Keck')
moon_altaz = moon.transform_to(
    coord.AltAz(location=keck)
)
with visualization.quantity_support():
    plt.plot(dt, moon_altaz.alt.to(u.deg))
<class 'astropy.coordinates.sky_coordinate.SkyCoord'>
WARNING: Tried to get polar motions for times after IERS data is valid. Defaulting to polar motion from the 50-yr mean for those. This may affect precision at the 10s of arcsec level [astropy.coordinates.builtin_frames.utils]
WARNING: (some) times are outside of range covered by IERS table. Assuming UT1-UTC=0 for coordinate transformations. [astropy.coordinates.builtin_frames.utils]
In [37]:
with visualization.quantity_support():
    x = np.linspace(0, 1, 100) * u.km
    y = np.linspace(1, 0, 100) * u.km
    plt.xlabel('x')
    plt.plot(x, y)
In [45]:
from astropy import io

with io.fits.open('sombrero.fits') as sombr:
    hdu = sombr[0]
    print(hdu.header)
    data = hdu.data
plt.imshow(data, origin='lower')
SIMPLE  =                    T / conforms to FITS standard                      BITPIX  =                    8 / array data type                                NAXIS   =                    2 / number of array dimensions                     NAXIS1  =                  800                                                  NAXIS2  =                  448                                                  EXTEND  =                    T                                                  END                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
Out[45]:
<matplotlib.image.AxesImage at 0x7fd68c5e64e0>
In [49]:
data = io.ascii.read('freddi.dat')
display(data)
io.ascii.write(data['t', 'Mdot'], 'table.tex', format='latex')
Table length=201
tMdotMdiskRhotCirroutH2RTeffoutTirroutQiir2QvisoutLxmUmBmVmRmImJ
float64float64float64float64int64float64float64int64int64float64float64float64float64float64float64float64
0.00.001227462.62282e+251.3639500.099070214251.3000.014.924815.89515.979315.998416.325616.2118
0.25283455000000000.02.62594e+251.3639500.093938213042.3006.8279e+3014.854215.837615.93215.958916.292316.1819
0.53042750000000000.02.62726e+251.3639500.091645112516.0004.23856e+3314.793515.789615.893315.927116.265816.1582
0.751.4496e+162.62809e+251.3639500.09008912163.8008.52088e+3414.740815.748515.860615.900616.243916.1388
1.04.62499e+162.62862e+251.3639500.088892311895.7005.40876e+3514.695215.713415.833115.878516.225816.1228
1.251.1458e+172.62887e+251.3639500.087913911678.3001.96501e+3614.656215.683715.8115.860216.21116.1097
1.52.3681e+172.62876e+251.3639500.087084511495.3005.13231e+3614.623115.658815.790915.845116.198816.0991
1.754.26009e+172.62819e+251.3639500.086363711337.1001.07543e+3714.595415.638115.775215.832916.189116.0906
2.06.86785e+172.627e+251.3639500.085726311198.0001.92413e+3714.572415.621115.762515.823116.181416.0839
2.251.01423e+182.62507e+251.3639500.085155111073.9003.05923e+3714.553415.607315.752215.815416.175416.0788
................................................
47.752.14171e+189.93322e+241.3639500.06479737023.36007.26798e+3715.288616.323316.428616.438516.73716.5972
48.02.1276e+189.88738e+241.3639500.06473317011.77007.21346e+3715.292916.327316.432316.441816.7416.5999
48.252.11362e+189.84184e+241.3639500.06466917000.22007.15945e+3715.297216.331416.436116.445216.742916.6026
48.52.09975e+189.7966e+241.3639500.06460536988.71007.10593e+3715.301416.335416.439816.448616.745916.6053
48.752.086e+189.75166e+241.3639500.06454166977.24007.0529e+3715.305716.339416.443516.451916.748916.608
49.02.07237e+189.70701e+241.3639500.06447826965.82007.00036e+3715.3116.343416.447216.455316.751816.6107
49.252.05886e+189.66265e+241.3639500.06441496954.43006.94829e+3715.314216.347516.450916.458616.754816.6134
49.52.04545e+189.61858e+241.3639500.06435196943.09006.8967e+3715.318516.351516.454716.46216.757716.6161
49.752.03217e+189.57479e+241.3639500.0642896931.78006.84558e+3715.322716.355516.458416.465316.760716.6188
50.02.01899e+189.5313e+241.3639500.06422636920.52006.79493e+3715.32716.359516.46216.468716.763616.6214
In [50]:
with open('table.tex') as fh:
    print(fh.read())
\begin{table}
\begin{tabular}{cc}
t & Mdot \\
0.0 & 0.00122746 \\
0.25 & 283455000000000.0 \\
0.5 & 3042750000000000.0 \\
0.75 & 1.4496e+16 \\
1.0 & 4.62499e+16 \\
1.25 & 1.1458e+17 \\
1.5 & 2.3681e+17 \\
1.75 & 4.26009e+17 \\
2.0 & 6.86785e+17 \\
2.25 & 1.01423e+18 \\
2.5 & 1.39589e+18 \\
2.75 & 1.81519e+18 \\
3.0 & 2.25477e+18 \\
3.25 & 2.69884e+18 \\
3.5 & 3.13446e+18 \\
3.75 & 3.55188e+18 \\
4.0 & 3.94435e+18 \\
4.25 & 4.30774e+18 \\
4.5 & 4.6399e+18 \\
4.75 & 4.94025e+18 \\
5.0 & 5.20926e+18 \\
5.25 & 5.44815e+18 \\
5.5 & 5.65858e+18 \\
5.75 & 5.8425e+18 \\
6.0 & 6.00196e+18 \\
6.25 & 6.13901e+18 \\
6.5 & 6.25569e+18 \\
6.75 & 6.3539e+18 \\
7.0 & 6.43547e+18 \\
7.25 & 6.50206e+18 \\
7.5 & 6.55523e+18 \\
7.75 & 6.59637e+18 \\
8.0 & 6.62678e+18 \\
8.25 & 6.64762e+18 \\
8.5 & 6.65994e+18 \\
8.75 & 6.66468e+18 \\
9.0 & 6.66269e+18 \\
9.25 & 6.65474e+18 \\
9.5 & 6.64151e+18 \\
9.75 & 6.62361e+18 \\
10.0 & 6.60159e+18 \\
10.25 & 6.57595e+18 \\
10.5 & 6.54711e+18 \\
10.75 & 6.51549e+18 \\
11.0 & 6.48142e+18 \\
11.25 & 6.44523e+18 \\
11.5 & 6.40718e+18 \\
11.75 & 6.36754e+18 \\
12.0 & 6.32653e+18 \\
12.25 & 6.28434e+18 \\
12.5 & 6.24116e+18 \\
12.75 & 6.19714e+18 \\
13.0 & 6.15243e+18 \\
13.25 & 6.10716e+18 \\
13.5 & 6.06143e+18 \\
13.75 & 6.01535e+18 \\
14.0 & 5.96901e+18 \\
14.25 & 5.92249e+18 \\
14.5 & 5.87586e+18 \\
14.75 & 5.82918e+18 \\
15.0 & 5.78251e+18 \\
15.25 & 5.7359e+18 \\
15.5 & 5.68939e+18 \\
15.75 & 5.64302e+18 \\
16.0 & 5.59684e+18 \\
16.25 & 5.55086e+18 \\
16.5 & 5.50511e+18 \\
16.75 & 5.45963e+18 \\
17.0 & 5.41442e+18 \\
17.25 & 5.36951e+18 \\
17.5 & 5.32491e+18 \\
17.75 & 5.28064e+18 \\
18.0 & 5.2367e+18 \\
18.25 & 5.19311e+18 \\
18.5 & 5.14988e+18 \\
18.75 & 5.10701e+18 \\
19.0 & 5.06451e+18 \\
19.25 & 5.02239e+18 \\
19.5 & 4.98063e+18 \\
19.75 & 4.93926e+18 \\
20.0 & 4.89827e+18 \\
20.25 & 4.85767e+18 \\
20.5 & 4.81745e+18 \\
20.75 & 4.77761e+18 \\
21.0 & 4.73815e+18 \\
21.25 & 4.69908e+18 \\
21.5 & 4.66039e+18 \\
21.75 & 4.62208e+18 \\
22.0 & 4.58415e+18 \\
22.25 & 4.5466e+18 \\
22.5 & 4.50942e+18 \\
22.75 & 4.47261e+18 \\
23.0 & 4.43617e+18 \\
23.25 & 4.4001e+18 \\
23.5 & 4.36439e+18 \\
23.75 & 4.32904e+18 \\
24.0 & 4.29405e+18 \\
24.25 & 4.25942e+18 \\
24.5 & 4.22513e+18 \\
24.75 & 4.19119e+18 \\
25.0 & 4.15759e+18 \\
25.25 & 4.12434e+18 \\
25.5 & 4.09142e+18 \\
25.75 & 4.05883e+18 \\
26.0 & 4.02658e+18 \\
26.25 & 3.99465e+18 \\
26.5 & 3.96304e+18 \\
26.75 & 3.93175e+18 \\
27.0 & 3.90078e+18 \\
27.25 & 3.87012e+18 \\
27.5 & 3.83977e+18 \\
27.75 & 3.80972e+18 \\
28.0 & 3.77997e+18 \\
28.25 & 3.75052e+18 \\
28.5 & 3.72137e+18 \\
28.75 & 3.69251e+18 \\
29.0 & 3.66394e+18 \\
29.25 & 3.63565e+18 \\
29.5 & 3.60764e+18 \\
29.75 & 3.57991e+18 \\
30.0 & 3.55245e+18 \\
30.25 & 3.52527e+18 \\
30.5 & 3.49835e+18 \\
30.75 & 3.4717e+18 \\
31.0 & 3.44531e+18 \\
31.25 & 3.41918e+18 \\
31.5 & 3.39331e+18 \\
31.75 & 3.36769e+18 \\
32.0 & 3.34232e+18 \\
32.25 & 3.31719e+18 \\
32.5 & 3.29231e+18 \\
32.75 & 3.26767e+18 \\
33.0 & 3.24327e+18 \\
33.25 & 3.21911e+18 \\
33.5 & 3.19517e+18 \\
33.75 & 3.17147e+18 \\
34.0 & 3.148e+18 \\
34.25 & 3.12475e+18 \\
34.5 & 3.10172e+18 \\
34.75 & 3.07891e+18 \\
35.0 & 3.05632e+18 \\
35.25 & 3.03395e+18 \\
35.5 & 3.01178e+18 \\
35.75 & 2.98983e+18 \\
36.0 & 2.96808e+18 \\
36.25 & 2.94654e+18 \\
36.5 & 2.9252e+18 \\
36.75 & 2.90406e+18 \\
37.0 & 2.88312e+18 \\
37.25 & 2.86237e+18 \\
37.5 & 2.84182e+18 \\
37.75 & 2.82146e+18 \\
38.0 & 2.80129e+18 \\
38.25 & 2.7813e+18 \\
38.5 & 2.7615e+18 \\
38.75 & 2.74188e+18 \\
39.0 & 2.72244e+18 \\
39.25 & 2.70318e+18 \\
39.5 & 2.6841e+18 \\
39.75 & 2.66519e+18 \\
40.0 & 2.64646e+18 \\
40.25 & 2.62789e+18 \\
40.5 & 2.6095e+18 \\
40.75 & 2.59127e+18 \\
41.0 & 2.5732e+18 \\
41.25 & 2.5553e+18 \\
41.5 & 2.53756e+18 \\
41.75 & 2.51998e+18 \\
42.0 & 2.50256e+18 \\
42.25 & 2.4853e+18 \\
42.5 & 2.46818e+18 \\
42.75 & 2.45122e+18 \\
43.0 & 2.43442e+18 \\
43.25 & 2.41776e+18 \\
43.5 & 2.40125e+18 \\
43.75 & 2.38488e+18 \\
44.0 & 2.36866e+18 \\
44.25 & 2.35259e+18 \\
44.5 & 2.33665e+18 \\
44.75 & 2.32085e+18 \\
45.0 & 2.3052e+18 \\
45.25 & 2.28968e+18 \\
45.5 & 2.27429e+18 \\
45.75 & 2.25904e+18 \\
46.0 & 2.24392e+18 \\
46.25 & 2.22894e+18 \\
46.5 & 2.21408e+18 \\
46.75 & 2.19936e+18 \\
47.0 & 2.18476e+18 \\
47.25 & 2.17028e+18 \\
47.5 & 2.15593e+18 \\
47.75 & 2.14171e+18 \\
48.0 & 2.1276e+18 \\
48.25 & 2.11362e+18 \\
48.5 & 2.09975e+18 \\
48.75 & 2.086e+18 \\
49.0 & 2.07237e+18 \\
49.25 & 2.05886e+18 \\
49.5 & 2.04545e+18 \\
49.75 & 2.03217e+18 \\
50.0 & 2.01899e+18 \\
\end{tabular}
\end{table}