In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
import pandas as pd
import numpy as np
import astropy.units as u

from starutils.populations import StarPopulation,StarPopulation_FromH5,BinaryPopulation,BGStarPopulation,BGStarPopulation_FromH5
from isochrones.dartmouth import Dartmouth_Isochrone
dar = Dartmouth_Isochrone()

In [3]:
n = 1e4
pri = dar(1*np.ones(n),9.7,0.0, return_df=True)
sec = dar(np.linspace(0.15,1,n),9.7,0, return_df=True)

In [4]:
import scipy.stats as stats
def random_period(N,mu=5.03,sigma=2.28):
    dist = stats.norm(5.03,2.28)
    return 10**dist.rvs(N)

def random_eccentricity(N,a=.697,b=3.3):
    dist = stats.beta(a,b)
    return dist.rvs(N)

In [5]:
from astropy.units import Quantity
import astropy.units as u
binpop = BinaryPopulation(pri,sec, Quantity(1000,'parsec'), period=random_period(n), ecc=random_eccentricity(n))

In [6]:
binpop.orbpop.scatterplot(rmax=1e4)



In [7]:
binpop.apply_trend_constraint(1*u.km/u.s,10*u.yr,overwrite=True)
binpop.set_maxrad(4*u.arcsec)

In [8]:
binpop.constraint_piechart()



In [9]:
binpop.constraints


Out[9]:
{'Max Rsky': <<class 'starutils.constraints.UpperLimit'>: Max Rsky < 4.0 arcsec>,
 'RV monitoring': <<class 'starutils.constraints.JointConstraintOr'>: RV monitoring>}

In [10]:
binpop.save_hdf('testpop.h5')

In [11]:
from starutils.populations import BinaryPopulation_FromH5

In [12]:
binpop2 = BinaryPopulation_FromH5('testpop.h5')

In [13]:
binpop2.orbpop.scatterplot(rmax=1e4)



In [14]:
ls


demo.ipynb  test.h5  testpop.h5

In [3]:
df = pd.read_hdf('test.h5','df')

In [4]:
bgpop = BGStarPopulation(df)

In [5]:
bgpop.Rsky


Out[5]:
<Quantity [ 1204.77499473, 1388.26572231, 1639.26465736,...,
            1676.86166035, 1620.471855  , 1086.81130276] arcsec>

In [9]:
bgpop.maxrad = 4
bgpop.Rsky


Out[9]:
<Quantity [ 2.67727777, 3.08503494, 3.64281035,...,  3.72635925,
            3.60104857, 2.41513623] arcsec>

In [8]:
print bgpop.density


0.0115246141975 1 / arcsec2

In [10]:
bgpop.maxrad


Out[10]:
$4 \; \mathrm{{}^{\prime\prime}}$

In [11]:
bgpop.save_hdf('testbgpop.h5')

In [3]:
bgpop2 = BGStarPopulation_FromH5('testbgpop.h5')

In [4]:
bgpop2.maxrad


Out[4]:
$4 \; \mathrm{{}^{\prime\prime}}$

In [6]:
print bgpop2.density


0.0115246141975 1 / arcsec2

In [8]:
bgpop2.maxrad = 2*u.arcsec

In [15]:


In [9]:
bgpop2.Rsky


Out[9]:
<Quantity [ 1.33863888, 1.54251747, 1.82140517,...,  1.86317962,
            1.80052428, 1.20756811] arcsec>

In [14]:
bgpop2._maxrad


Out[14]:
$2 \; \mathrm{{}^{\prime}}$

In [22]:
(2*u.arcmin / bgpop2._maxrad).decompose()


Out[22]:
$15 \; \mathrm{}$

In [ ]: