In [1]:
from isochrones import get_ichrone


Emcee3 not imported; be advised.

In [2]:
mist = get_ichrone('mist', tracks=True)

In [4]:
grid = mist.model_grid
grid.get_directory_path(feh=-4.0)


Out[4]:
'/Users/tmorton/.isochrones/mist/tracks/MIST_v1.2_feh_m4.00_afe_p0.0_vvcrit0.4_EEPS'

In [5]:
grid.get_tarball_file(feh=-4.0)


Out[5]:
'/Users/tmorton/.isochrones/mist/tracks/MIST_v1.2_feh_m4.00_afe_p0.0_vvcrit0.4_EEPS.txz'

In [1]:
from isochrones.mist import MIST_EvolutionTrack
mist_track = MIST_EvolutionTrack()
mist_track.get_eep(0.08, 9.51, 0.)


Emcee3 not imported; be advised.
Out[1]:
nan

In [2]:
mist_track.model_grid.df.head()


Out[2]:
mass logg delta_nu initial_mass phase eep radius Mbol logTeff feh density nu_max logL Teff interpolated star_age age dt_deep
initial_feh initial_mass EEP
-4.0 0.1 1 0.1 3.033277 21.776686 0.1 -1.0 1.0 1.593804 5.132871 3.620834 -3.978406 0.034821 143.524548 -0.157148 4176.707371 False 13343.289397 4.125263 0.026168
2 0.1 3.038935 21.993078 0.1 -1.0 2.0 1.583455 5.147664 3.620769 -3.978406 0.035509 145.419039 -0.163066 4176.085183 False 14171.978264 4.151430 0.026121
3 0.1 3.044805 22.219791 0.1 -1.0 3.0 1.572790 5.163015 3.620702 -3.978406 0.036236 147.409881 -0.169206 4175.435381 False 15048.910447 4.177505 0.026016
4 0.1 3.050886 22.457004 0.1 -1.0 4.0 1.561817 5.178922 3.620631 -3.978406 0.037005 149.499346 -0.175569 4174.757681 False 15975.827275 4.203463 0.025996
5 0.1 3.057203 22.706349 0.1 -1.0 5.0 1.550499 5.195452 3.620558 -3.978406 0.037821 151.703570 -0.182181 4174.049081 False 16962.744747 4.229496 0.025996

In [7]:
track = mist_track.model_grid.df.xs((0, 1), level=('initial_feh', 'initial_mass'))

In [10]:
import holoviews as hv
hv.extension('bokeh')
import hvplot.pandas



In [15]:
track.hvplot.scatter('EEP', 'age').options(height=600, width=1000, marker='+')


Out[15]:

In [ ]:


In [ ]:


In [4]:
mist_track.generate(0.08, 9.51, 0.)


Out[4]:
mass logg delta_nu initial_mass phase eep radius Mbol logTeff feh ... H_mag K_mag G_mag BP_mag RP_mag W1_mag W2_mag W3_mag TESS_mag Kepler_mag
0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

1 rows × 29 columns


In [ ]:


In [ ]:


In [ ]:


In [1]:
from isochrones.query import Query, TwoMASS, WISE, Tycho2

In [2]:
ra=45.03433035439128; dec=0.23539164875137225;
pmra=43.75231341609215; pmdec=-7.6419899883511482;
epoch=2015.

In [3]:
q = Query(ra, dec, pmra=pmra, pmdec=pmdec, epoch=epoch)

In [4]:
tm = TwoMASS(q)
w = WISE(q)
tyc = Tycho2(q)

In [5]:
tm.get_id()


Out[5]:
b'03000819+0014074'

In [6]:
from astroquery.vizier import Vizier

In [20]:
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]

In [18]:
table


Out[18]:
<Table masked=True length=1>
_r_RAJ2000_DEJ2000RAJ2000DEJ2000_2MASSJmage_JmagHmage_HmagKmage_KmagQflgRflgBflgCflgXflgAflg
arcsdegdegdegdegmagmagmagmagmagmag
float64float64float64float64float64bytes17float32float32float32float32float32float32bytes3bytes3bytes3bytes3uint8uint8
0.63645.0341610.23540845.0341610.23540803000819+00140746.6060.0236.1330.0246.0190.020AAA11111100000

In [1]:
from isochrones.tests.test_query import test_queries

In [2]:
test_queries()

In [1]:
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.

In [2]:
dirname = '../isochrones/tests/star4'

mod = StarModel.from_ini(dar, folder=dirname)

In [3]:
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

In [4]:
mod.obs.Nstars


Out[4]:
{0: 3}

In [5]:
mod.obs.systems


Out[5]:
[0]

In [6]:
mod.lnlike([1.0, 0.8, 0.5, 9.4, 0.0, 100, 0.2] )


Out[6]:
-232348.56573438906

In [1]:
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.

In [2]:
test_ini()

In [4]:
from isochrones import StarModel
mod = StarModel.from_ini('dartmouth', folder='../isochrones/tests/star2')

In [5]:
mod.n_params


Out[5]:
6

In [2]:
import scipy
scipy.__version__


Out[2]:
'0.19.1'

In [8]:
import isochrones

In [1]:
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.

In [6]:
dar = Dartmouth_Isochrone()

In [7]:
from isochrones.tests.tests import _basic_ic_checks

In [8]:
_basic_ic_checks(dar)

In [9]:
dar.radius(1., 9.5, 0.0)


Out[9]:
0.95409593462955189

In [5]:
dar.radius(1.01, 9.72, 0.02)


Out[5]:
1.0435559519926865

In [6]:
dar.radius(1.21,9.38,0.11)


Out[6]:
1.2762022494652547

In [7]:
dar.radius(0.61, 9.89, -0.22)


Out[7]:
0.5964945760402941

In [8]:
from isochrones.mist import MIST_Isochrone

In [9]:
mist = MIST_Isochrone()

In [10]:
mist.radius(1.0, 9.5, 0.0)


Out[10]:
0.9764494078461442

In [16]:
mist.radius(1.01, 9.72, 0.02)


Out[16]:
1.0671791635014685

In [18]:
mist.radius(1.21,9.38,0.11)


Out[18]:
1.2836469028034225

In [19]:
mist.radius(0.61, 9.89, -0.22)


Out[19]:
0.59475269177846402

In [ ]:
dar.radius(1., 9.5, 0.0)

In [1]:
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.

In [2]:
from isochrones.dartmouth import DartmouthModelGrid

In [3]:
%timeit DartmouthModelGrid.verify_grids()


782 ms ± 13.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [5]:
from isochrones.mist import MISTModelGrid

In [6]:
%timeit MISTModelGrid.verify_grids()


3.01 s ± 54.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [1]:
import isochrones

In [1]:
import isochrones

In [1]:
from isochrones.dartmouth import Dartmouth_Isochrone

In [2]:
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.

In [3]:
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.

In [4]:
dar = Dartmouth_Isochrone()

In [6]:
dar = Dartmouth_Isochrone()

In [3]:
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

In [3]:
from isochrones.mist import MIST_Isochrone

In [4]:
mist = MIST_Isochrone()

In [5]:
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.
Out[5]:
1.0021006303717472

In [7]:
import numpy as np

In [14]:
d = np.array([np.random.randn(100000) for i in range(4)]).T

In [15]:
d.shape


Out[15]:
(100000, 4)

In [16]:
np.percentile(d, [5,16,50,84,95], axis=0)


Out[16]:
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]])

In [1]:
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)

In [2]:
mod.name


Out[2]:
'single'

In [3]:
samples = mod.emcee_p0(200)

In [4]:
samples.shape


Out[4]:
(200, 5)

In [7]:
type(samples)


Out[7]:
numpy.ndarray

In [10]:
samples.max(axis=0)


Out[10]:
array([  3.21385964e+00,   1.01745308e+01,   4.96039106e-01,
         2.97472721e+03,   9.98552464e-01])

In [1]:
%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

In [10]:
trace_plot('test_sun');



In [1]:
from isochrones import StarModel
from isochrones.dartmouth import Dartmouth_Isochrone

In [2]:
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.

In [3]:
mod = StarModel(dar, **props)

In [4]:
mod.bounds('age')


Out[4]:
(8.3979400086720375, 10.176091259055681)

In [5]:
mod.prior('age', 9.0, bounds=mod.bounds('age'))


Out[5]:
0.15610746393179967

In [6]:
from isochrones.priors import age_prior

In [7]:
from scipy.stats import uniform

In [8]:
type(uniform)


Out[8]:
scipy.stats._continuous_distns.uniform_gen

In [9]:
d = uniform(3, 6)

In [12]:
d.pdf(2)


Out[12]:
0.0

In [13]:
uniform?

In [2]:
from isochrones.priors import AV_prior

In [6]:
AV_prior._distribution.rvs(10)


Out[6]:
array([ 0.51299349,  0.04524675,  0.3940439 ,  0.35215637,  0.43375303,
        0.9366318 ,  0.92845353,  0.07610549,  0.3986907 ,  0.11514545])

In [2]:
from scipy.stats import powerlaw

In [1]:
from isochrones.priors import distance_prior

In [2]:
distance_prior.sample(10)


Out[2]:
array([ 2493.79176056,  2244.43780145,  2038.62230875,  2734.7536418 ,
        2922.87866723,  2891.70752346,  2393.58184595,  2782.12917959,
        2964.78382157,  2464.10865769])

In [10]:
distance_prior.bounds


Out[10]:
(0, 3000)

In [21]:
%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')


Out[21]:
[<matplotlib.lines.Line2D at 0x11e9f2fd0>]

In [22]:
h


Out[22]:
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])

In [24]:
b


Out[24]:
array([   69.95556691,   362.95855898,   655.96155105,   948.96454312,
        1241.96753519,  1534.97052726,  1827.97351933,  2120.9765114 ,
        2413.97950347,  2706.98249554,  2999.98548761])

In [27]:
c = (b[1:] + b[:-1])/2

In [28]:
[distance_prior(x, bounds=(0,3000)) for x in c]


Out[28]:
[5.2059622333904537e-06,
 2.8838838628779319e-05,
 7.1549660215594382e-05,
 0.00013333842699383557,
 0.000214205138963503,
 0.00031414979612459654,
 0.00043317239847711633,
 0.00057127294602106232,
 0.00072845143875643426,
 0.00090470787668323288]

In [49]:
h1, b = np.histogram(distance_prior.sample(100000))
h,b = np.histogram(distance_prior.sample(100000), density=True)
c = (b[1:] + b[:-1])/2

In [50]:
pdf = [distance_prior(x, bounds=(0,3000)) for x in c]

In [51]:
1./np.sqrt(h1)


Out[51]:
array([ 0.08137885,  0.035007  ,  0.02200062,  0.01594752,  0.01269489,
        0.0104967 ,  0.0088454 ,  0.00771884,  0.00682201,  0.00611967])

In [53]:
resid = np.abs(pdf - h)/pdf

In [54]:
resid


Out[54]:
array([ 0.1135809 ,  0.02592938,  0.04177793,  0.00522302,  0.00851507,
        0.0010505 ,  0.00066287,  0.00515454,  0.00666403,  0.00457766])

In [55]:
sigma = 1./np.sqrt(h1)

In [56]:
resid/sigma


Out[56]:
array([ 1.39570551,  0.74069128,  1.89894356,  0.32751274,  0.67074751,
        0.10007862,  0.07493934,  0.66778639,  0.97684366,  0.74802365])

In [29]:
len(c), len(h)


Out[29]:
(10, 10)

In [31]:



Out[31]:
array([   1627.96972356,    8928.23647133,   21583.39734124,
         40054.19848148,   64289.44587556,   95251.58703302,
        130104.47344175,  171817.35805666,  216898.8089549 ,
        273324.85390158])

In [1]:
from isochrones.priors import salpeter_prior, q_prior, age_prior, distance_prior

In [4]:
import numpy as np
np.histogram(age_prior.sample(100), range=(9,10.15))


Out[4]:
(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 ]))

In [5]:
age_prior.sample(100)


Out[5]:
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])

In [2]:
%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 ]

In [7]:
distance_prior.sample(10000)


Out[7]:
array([ 2120.47998504,  2180.35681688,  2073.15160746, ...,  1738.41056862,
        2654.34308229,  1826.4959339 ])

In [3]:
import numpy as np
np.histogram?

In [ ]:
from scipy.integrate import quad

In [59]:
plt.hist(salpeter_prior.sample(100000));
plt.plot()



In [ ]: