from isochrones.query import Query, TwoMASS, WISE, Tycho2
ra=45.03433035439128; dec=0.23539164875137225;
pmra=43.75231341609215; pmdec=-7.6419899883511482;
epoch=2015.
q = Query(ra, dec, pmra=pmra, pmdec=pmdec, epoch=epoch)
tm = TwoMASS(q)
w = WISE(q)
tyc = Tycho2(q)
tm.get_id()
b'03000819+0014074'
from astroquery.vizier import Vizier
from astropy.coordinates import SkyCoord
import astropy.units as u
c = SkyCoord(ra, dec, unit='deg')
table = Vizier(columns=['*', '_r', '_RAJ2000', '_DEJ2000']).query_region(c,
catalog='2mass', radius=1*u.arcsec)[0]
table
_r | _RAJ2000 | _DEJ2000 | RAJ2000 | DEJ2000 | _2MASS | Jmag | e_Jmag | Hmag | e_Hmag | Kmag | e_Kmag | Qflg | Rflg | Bflg | Cflg | Xflg | Aflg |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
arcs | deg | deg | deg | deg | mag | mag | mag | mag | mag | mag | |||||||
float64 | float64 | float64 | float64 | float64 | bytes17 | float32 | float32 | float32 | float32 | float32 | float32 | bytes3 | bytes3 | bytes3 | bytes3 | uint8 | uint8 |
0.636 | 45.034161 | 0.235408 | 45.034161 | 0.235408 | 03000819+0014074 | 6.606 | 0.023 | 6.133 | 0.024 | 6.019 | 0.020 | AAA | 111 | 111 | 000 | 0 | 0 |
from isochrones.tests.test_query import test_queries
test_queries()
from isochrones import StarModel
from isochrones.dartmouth import Dartmouth_Isochrone
dar = Dartmouth_Isochrone()
WARNING:root:You have a wrong/corrupted/outdated Dartmouth triangulation! Delete /Users/tdm/.isochrones/dartmouth.tri and try re-importing to download afresh.
dirname = '../isochrones/tests/star4'
mod = StarModel.from_ini(dar, folder=dirname)
mod.print_ascii()
root ╠═ twomass H=(10.91, 0.02) @(0.00, 0 [4.00]) ║ ╚═ twomass J=(11.25, 0.02) @(0.00, 0 [4.00]) ║ ╚═ twomass K=(10.87, 0.01) @(0.00, 0 [4.00]) ║ ╠═ Lick delta-H=(0.00, 0.01) @(0.00, 0 [0.50]) ║ ║ ╚═ Lick delta-K=(0.00, 0.01) @(0.00, 0 [0.50]) ║ ║ ╚═ 0_0, Teff=[5465.0, 109.0], feh=[0.02, 0.15], logg=[4.449, 0.085] ║ ╚═ Lick delta-H=(4.34, 0.01) @(3.84, 53 [0.50]) ║ ╚═ Lick delta-K=(4.11, 0.06) @(3.84, 53 [0.50]) ║ ╚═ 0_1 ╚═ Lick delta-H=(7.49, 0.01) @(12.07, 256 [0.50]) ╚═ 0_2
mod.obs.Nstars
{0: 3}
mod.obs.systems
[0]
mod.lnlike([1.0, 0.8, 0.5, 9.4, 0.0, 100, 0.2] )
-232348.56573438906
from isochrones.tests.test_ini import test_ini
WARNING:root:You have a wrong/corrupted/outdated Dartmouth triangulation! Delete /Users/tdm/.isochrones/dartmouth.tri and try re-importing to download afresh.
test_ini()
from isochrones import StarModel
mod = StarModel.from_ini('dartmouth', folder='../isochrones/tests/star2')
mod.n_params
6
import scipy
scipy.__version__
'0.19.1'
import isochrones
from isochrones.dartmouth import Dartmouth_Isochrone
WARNING:root:You have a wrong/corrupted/outdated Dartmouth triangulation! Delete /Users/tdm/.isochrones/dartmouth.tri and try re-importing to download afresh.
dar = Dartmouth_Isochrone()
from isochrones.tests.tests import _basic_ic_checks
_basic_ic_checks(dar)
dar.radius(1., 9.5, 0.0)
0.95409593462955189
dar.radius(1.01, 9.72, 0.02)
1.0435559519926865
dar.radius(1.21,9.38,0.11)
1.2762022494652547
dar.radius(0.61, 9.89, -0.22)
0.5964945760402941
from isochrones.mist import MIST_Isochrone
mist = MIST_Isochrone()
mist.radius(1.0, 9.5, 0.0)
0.9764494078461442
mist.radius(1.01, 9.72, 0.02)
1.0671791635014685
mist.radius(1.21,9.38,0.11)
1.2836469028034225
mist.radius(0.61, 9.89, -0.22)
0.59475269177846402
dar.radius(1., 9.5, 0.0)
import isochrones.dartmouth
WARNING:root:You have a wrong/corrupted/outdated Dartmouth triangulation! Delete /Users/tdm/.isochrones/dartmouth.tri and try re-importing to download afresh.
from isochrones.dartmouth import DartmouthModelGrid
%timeit DartmouthModelGrid.verify_grids()
782 ms ± 13.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
from isochrones.mist import MISTModelGrid
%timeit MISTModelGrid.verify_grids()
3.01 s ± 54.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
import isochrones
import isochrones
from isochrones.dartmouth import Dartmouth_Isochrone
dar = Dartmouth_Isochrone()
--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-2-643606627c59> in <module>() ----> 1 dar = Dartmouth_Isochrone() ~/repositories/isochrones/isochrones/dartmouth/isochrone.py in __init__(self, bands, afe, y, **kwargs) 72 73 if TRI is None: ---> 74 DartmouthModelGrid.verify_grids() 75 try: 76 f = open(TRI_FILE,'rb') ~/repositories/isochrones/isochrones/grid.py in verify_grids(cls) 144 for f, md5 in zip(files, cls.zenodo_md5): 145 if not os.path.exists(f): --> 146 raise RuntimeError('{0} does not exist. Run "import isochrones.{1}; isochrones.{1}.download_grids()" to download.'.format(f, cls.name)) 147 elif hashlib.md5(open(f,'rb').read()).hexdigest() != md5: 148 raise RuntimeError('{0} is wrong/corrupted. Delete {0} and try again.'.format(f)) RuntimeError: /Users/tdm/.isochrones/dartmouth.tri does not exist. Run "import isochrones.dartmouth; isochrones.dartmouth.download_grids()" to download.
import isochrones.dartmouth; isochrones.dartmouth.download_grids()
Downloading files for dartmouth model grid: ('dartmouth.tgz', 'dartmouth.tri')... /Users/tdm/.isochrones/dartmouth.tgz exists; not downloading.
dar = Dartmouth_Isochrone()
dar = Dartmouth_Isochrone()
isochrones.dartmouth.download_grids()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-3-4cf3ff8ea033> in <module>() ----> 1 isochrones.dartmouth.download_grids() NameError: name 'isochrones' is not defined
from isochrones.mist import MIST_Isochrone
mist = MIST_Isochrone()
mist.radius(1.0, 9.6, 0.0)
Downloading files for mist model grid (('mist.tgz',))... /Users/tdm/.isochrones/mist.tgz verified. /Users/tdm/.isochrones/mist.tgz verified. /Users/tdm/.isochrones/mist/MIST_v1.0_UBVRIplus.h5 written. /Users/tdm/.isochrones/mist/MIST_v1.0_WISE.h5 written. /Users/tdm/.isochrones/mist/MIST_v1.0_SDSS.h5 written.
1.0021006303717472
import numpy as np
d = np.array([np.random.randn(100000) for i in range(4)]).T
d.shape
(100000, 4)
np.percentile(d, [5,16,50,84,95], axis=0)
array([[ -1.63828045e+00, -1.63072826e+00, -1.65102411e+00, -1.64924447e+00], [ -9.90019779e-01, -9.95726924e-01, -9.96526431e-01, -9.93260577e-01], [ -8.87989356e-04, -3.18889167e-03, 3.42285565e-03, 3.96761411e-03], [ 9.90394774e-01, 9.96530306e-01, 9.96822674e-01, 9.96571747e-01], [ 1.64419496e+00, 1.65023073e+00, 1.64854022e+00, 1.64616768e+00]])
from isochrones import StarModel
from isochrones.dartmouth import Dartmouth_Isochrone
dar = Dartmouth_Isochrone()
props = dict(Teff=(5800, 100), logg=(4.5, 0.1),
B=(5.7,0.05), V=(5.0, 0.05))
mod = StarModel(dar, **props)
mod.name
'single'
samples = mod.emcee_p0(200)
samples.shape
(200, 5)
type(samples)
numpy.ndarray
samples.max(axis=0)
array([ 3.21385964e+00, 1.01745308e+01, 4.96039106e-01, 2.97472721e+03, 9.98552464e-01])
%matplotlib inline
import os
import emcee3
from emcee3.backends import Backend, HDFBackend
import matplotlib.pyplot as plt
def trace_plot(star, directory='mcmc_chains', thin=10):
filename = os.path.join(directory, '{}.h5'.format(star))
b = HDFBackend(filename)
coords = b.get_coords()
ndim = coords.shape[-1]
fig, axes = plt.subplots(ndim, 1, sharex=True, figsize=(8,8))
for i,ax in enumerate(axes):
ax.plot(coords[::thin, :, i], lw=1, alpha=0.2);
axes[0].set_title(star)
return fig
trace_plot('test_sun');
from isochrones import StarModel
from isochrones.dartmouth import Dartmouth_Isochrone
dar = Dartmouth_Isochrone(minage=9.1)
props = dict(Teff=(5800, 100), logg=(4.5, 0.1),
B=(5.7,0.05), V=(5.0, 0.05))
WARNING:root:minage and maxage keywords are deprecated.Use instead the .set_bounds(age=(lo, hi)) attribute of StarModel.
mod = StarModel(dar, **props)
mod.bounds('age')
(8.3979400086720375, 10.176091259055681)
mod.prior('age', 9.0, bounds=mod.bounds('age'))
0.15610746393179967
from isochrones.priors import age_prior
from scipy.stats import uniform
type(uniform)
scipy.stats._continuous_distns.uniform_gen
d = uniform(3, 6)
d.pdf(2)
0.0
uniform?
from isochrones.priors import AV_prior
AV_prior._distribution.rvs(10)
array([ 0.51299349, 0.04524675, 0.3940439 , 0.35215637, 0.43375303, 0.9366318 , 0.92845353, 0.07610549, 0.3986907 , 0.11514545])
from scipy.stats import powerlaw
from isochrones.priors import distance_prior
distance_prior.sample(10)
array([ 2493.79176056, 2244.43780145, 2038.62230875, 2734.7536418 , 2922.87866723, 2891.70752346, 2393.58184595, 2782.12917959, 2964.78382157, 2464.10865769])
distance_prior.bounds
(0, 3000)
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
h, b, _ = plt.hist(distance_prior.sample(100000), normed=True);
plt.plot(b, [distance_prior(x, bounds=(0,3000)) for x in b], 'k')
[<matplotlib.lines.Line2D at 0x11e9f2fd0>]
h
array([ 5.42656575e-06, 2.97607882e-05, 7.19446578e-05, 1.33513995e-04, 2.14298153e-04, 3.17505290e-04, 4.33681578e-04, 5.72724527e-04, 7.22996030e-04, 9.11082846e-04])
b
array([ 69.95556691, 362.95855898, 655.96155105, 948.96454312, 1241.96753519, 1534.97052726, 1827.97351933, 2120.9765114 , 2413.97950347, 2706.98249554, 2999.98548761])
c = (b[1:] + b[:-1])/2
[distance_prior(x, bounds=(0,3000)) for x in c]
[5.2059622333904537e-06, 2.8838838628779319e-05, 7.1549660215594382e-05, 0.00013333842699383557, 0.000214205138963503, 0.00031414979612459654, 0.00043317239847711633, 0.00057127294602106232, 0.00072845143875643426, 0.00090470787668323288]
h1, b = np.histogram(distance_prior.sample(100000))
h,b = np.histogram(distance_prior.sample(100000), density=True)
c = (b[1:] + b[:-1])/2
pdf = [distance_prior(x, bounds=(0,3000)) for x in c]
1./np.sqrt(h1)
array([ 0.08137885, 0.035007 , 0.02200062, 0.01594752, 0.01269489, 0.0104967 , 0.0088454 , 0.00771884, 0.00682201, 0.00611967])
resid = np.abs(pdf - h)/pdf
resid
array([ 0.1135809 , 0.02592938, 0.04177793, 0.00522302, 0.00851507, 0.0010505 , 0.00066287, 0.00515454, 0.00666403, 0.00457766])
sigma = 1./np.sqrt(h1)
resid/sigma
array([ 1.39570551, 0.74069128, 1.89894356, 0.32751274, 0.67074751, 0.10007862, 0.07493934, 0.66778639, 0.97684366, 0.74802365])
len(c), len(h)
(10, 10)
array([ 1627.96972356, 8928.23647133, 21583.39734124, 40054.19848148, 64289.44587556, 95251.58703302, 130104.47344175, 171817.35805666, 216898.8089549 , 273324.85390158])
from isochrones.priors import salpeter_prior, q_prior, age_prior, distance_prior
import numpy as np
np.histogram(age_prior.sample(100), range=(9,10.15))
(array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), array([ 9. , 9.115, 9.23 , 9.345, 9.46 , 9.575, 9.69 , 9.805, 9.92 , 10.035, 10.15 ]))
age_prior.sample(100)
array([ 5.76603014e+09, 1.41086431e+10, 7.94351457e+09, 1.27408878e+10, 1.10371106e+10, 2.69580849e+09, 6.11247811e+09, 1.29721656e+10, 8.66101798e+09, 1.59534690e+09, 3.98162526e+09, 1.22230816e+09, 1.96614395e+09, 1.14279660e+10, 2.62940801e+09, 9.05939742e+09, 7.62076207e+09, 1.23113269e+10, 1.23985446e+10, 1.11973033e+09, 6.36853785e+09, 7.82397418e+09, 1.38097978e+09, 8.44312443e+09, 1.18797256e+10, 9.68425303e+09, 1.43228885e+09, 2.36023915e+09, 1.44174421e+09, 1.11486899e+10, 3.80644386e+09, 6.36478747e+09, 3.56029212e+09, 1.16111006e+10, 1.29505138e+10, 4.82583592e+09, 2.35306225e+09, 1.13157425e+10, 2.22386664e+09, 1.18510330e+10, 1.55973161e+09, 5.58396415e+09, 9.31387684e+09, 5.19813154e+09, 5.60572952e+09, 9.95476958e+09, 5.00001775e+09, 5.94196448e+09, 6.22058016e+09, 7.55321586e+09, 1.65365693e+09, 3.49641675e+09, 1.45906742e+09, 4.86963855e+09, 1.29588556e+10, 4.53125682e+09, 4.49155950e+09, 2.38766572e+09, 1.35785337e+10, 1.27249425e+10, 7.06561430e+09, 3.74531415e+09, 1.05095927e+10, 4.36351224e+09, 1.38268634e+10, 1.16211514e+10, 1.13885361e+10, 7.94259765e+09, 5.93174035e+09, 2.06782020e+09, 1.18538097e+10, 9.83586798e+09, 7.48428044e+09, 4.26794663e+09, 1.14817213e+09, 5.47210836e+09, 8.83642120e+09, 5.52590564e+09, 2.16418477e+09, 1.38756138e+10, 1.19829203e+09, 6.43001264e+09, 6.84273063e+09, 1.08864478e+10, 6.88792803e+09, 1.26848076e+10, 8.89480360e+09, 8.25259737e+09, 1.04606526e+10, 1.02485196e+10, 4.99506674e+09, 6.95611080e+09, 1.86487230e+09, 7.37366979e+09, 6.54729828e+09, 7.12738694e+09, 1.29338549e+10, 6.57203578e+09, 5.65110103e+09, 1.10403563e+09])
%matplotlib inline
age_prior.test_sampling(plot=True)
/Users/tdm/miniconda3/envs/isochrones/lib/python3.6/site-packages/numpy/lib/function_base.py:817: RuntimeWarning: invalid value encountered in true_divide return n/db/n.sum(), bins /Users/tdm/repositories/isochrones/isochrones/priors.py:36: RuntimeWarning: divide by zero encountered in true_divide sigma = 1./np.sqrt(hn)
[0 0 0 0 0 0 0 0 0 0] [ 9. 9.115 9.23 9.345 9.46 9.575 9.69 9.805 9.92 10.035 10.15 ]
distance_prior.sample(10000)
array([ 2120.47998504, 2180.35681688, 2073.15160746, ..., 1738.41056862, 2654.34308229, 1826.4959339 ])
import numpy as np
np.histogram?
from scipy.integrate import quad
plt.hist(salpeter_prior.sample(100000));
plt.plot()