In [22]:
%autosave 20
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from astropy.coordinates import SkyCoord
import astropy.units as u
from scipy import optimize
import pandas as pd
In [20]:
coord = SkyCoord(ra=5*u.hourangle, dec=-5*u.deg-23*u.arcmin,
radial_velocity=5*u.km/u.s,
distance=100*u.pc,
pm_ra_cosdec=1*u.mas/u.yr, pm_dec=-1*u.mas/u.yr)
display(coord.transform_to('galactic'))
In [37]:
data = np.genfromtxt('diagram.csv', delimiter=',', names=('d', 'v'))
plt.plot(data['d'], data['v'], 'x')
def v_d(d, a, b):
return a + b * d
def v_d_jac(d, a, b):
jac = np.empty(d.shape + (2,))
jac[:,0] = 1
jac[:,1] = d
return jac
(v0, H0), _ = optimize.curve_fit(v_d, data['d'], data['v'],
(0, 500), jac=v_d_jac)
d_ = np.r_[data['d'].min():data['d'].max():100j]
plt.plot(d_, v_d(d_, v0, H0))
Out[37]:
In [52]:
from astroquery import vizier
from astroquery import simbad
# conda install -c astropy astroquery
# pip3 install astroquery
m87 = simbad.Simbad.query_object('M87')
display(m87)
m87_coord = SkyCoord(ra=m87['RA'], dec=m87['DEC'],
unit=(u.hourangle, u.deg))
display(m87_coord)
viz = vizier.Vizier(
column_filters={'Jmag': '<10'},
row_limit=100,
)
tables = viz.query_region(m87_coord[0], radius=1*u.deg,
catalog='2MASS')
tables[0]
Out[52]:
In [81]:
from scipy import integrate
# JLA
viz = vizier.Vizier(row_limit=1000)
tables = viz.get_catalogs('J/A+A/568/A22/tablef3')
t = tables[0]
def distance(z, Omega):
"""Luminosity distance, pc"""
z = np.asarray(z, dtype=float)
H0 = 70 / 1e6
c = 3e5
d = np.empty_like(z)
for i, z_i in np.ndenumerate(z):
d[i] = c / H0 * (1+z_i) * integrate.quad(
lambda z: 1 / np.sqrt(Omega + (1-Omega) * (1+z)**3),
0, z_i
)[0]
return d
def res(params, m, z, x1, c):
Omega, M0, alpha, beta = params
d = distance(z, Omega)
m_th = M0 - 5 + 5*np.log10(d) - alpha * x1 + beta * c
return m_th - m
result = optimize.least_squares(
res,
x0=(0.7, -19, 0.15, 2),
args=(t['mb'], t['zcmb'], t['x1'], t['c']),
bounds=([0, -22, 0, 0], [1, -18, 1, 3]),
)
print(result)
result.x
# import lmfit
Out[81]:
In [ ]:
?optimize.least_squares
In [ ]: