In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
import pandas as pd
from os import path
import seaborn as sns
sns.set_context("talk")

BBH class

  • $ecc==0$: never merge, period is lifetime in Gyr, seperation won't change
  • $ecc==1$: merge quickly, period is time of merge, seperation won't change
  • rest:
    • merge: seperation==ecc==0, period is time of merge
    • present: period is in unit of second, seperation!=0, ecc!=0

In [3]:
# ## load example data for testing
# BBHex=pd.read_csv('../data/RES/1024/BBHex.dat',delim_whitespace=True,header=None,
#                 names=['Galaxy','RA','Dec','Dist','VMag','Model','Age','T_eject','M1','M2','Seperation','Ecc','Period'])
# BBHex.sample(2)

# ## label example data for analysis
# merge_list=((BBHex.Seperation==0)&(BBHex.Ecc==0))|(BBHex.Ecc==1)
# present_list=-merge_list

# merger=BBHex[merge_list]
# merger=merger.rename(columns={'Period':'T_merge'})
# present=BBHex[present_list]

In [4]:
dir_data='../data/Res/0220'

In [5]:
# Load complete data set
BBH=pd.read_csv(path.join(dir_data,'BBHnow.dat.gz'),delim_whitespace=True,header=None, 
                 names=['PGC','RA','Dec','Dist','VMag','Model',
                        'Age','T_eject','M1','M2','Seperation','Ecc','Period'])

merger=BBH[((BBH.Seperation==0)&(BBH.Ecc==0))|(BBH.Ecc==1)]
merger=merger.rename(columns={'Period':'T_merge'})
present=BBH[-(((BBH.Seperation==0)&(BBH.Ecc==0))|(BBH.Ecc==1))]

In [6]:
BBH['MC']=(BBH.M1*BBH.M2)**0.6*(BBH.M1+BBH.M2)**(-0.2)

5 realization results

(93328, 13)
(17287278, 13)
(17380606, 14)

In [7]:
display(merger.shape,present.shape,BBH.shape)


(86939, 13)
(17417734, 13)
(17504673, 14)

In [8]:
MC=(30*35)**0.6*(30+35)**(-0.2)

In [9]:
MC


Out[9]:
28.19232596224401

In [12]:
sns.distplot(BBH.MC[BBH.MC<50])
title('BBH merged: 93,328; present BBH: 17,287,278; total: 17,380,606')
xlabel('Chirp Mass')

annotate('GW150914',xy=(MC,0.018),xytext=(MC,0.04),arrowprops=dict(facecolor='red', shrink=0.05))
# savefig('../Fig/MC.jpeg',dpi=200,bbox_inches='tight')


Out[12]:
<matplotlib.text.Annotation at 0x116bdcd30>

In [13]:
## Generate sample data for develop analysis scripts
# BBH.sample(10000).to_csv('../data/RES/1024/BBHex.dat')

Mergers

Event Rate:

  1. [LSC]BBH;aLIGO.pdf: $9 \sim 240Gpc^{-3}yr^{-1}$
  2. [Carl;Morscher;Fred]BBH;GC;aLIGO.pdf: $10\sim100$ per year

My path:

  1. merge event distribution over time
  2. find the possibility of merge at recent, total merger: 93328 $(30Mpc)^{-3}(13.5Gyr)^{-1}$
  3. scale it to $Gpc^{-3}yr^{-1}$

In [14]:
merger.sample(5)


Out[14]:
PGC RA Dec Dist VMag Model Age T_eject M1 M2 Seperation Ecc T_merge
5621946 25021 11.52554 -30.307720 16.903999 -20.828215 173-3 10.895874 0.1837 41.263000 31.516001 0.0 0.0 3.708287
4782161 48419 22.50835 -45.995960 22.000000 -19.008215 271-6 10.770565 0.3604 19.611000 18.462999 0.0 0.0 3.652473
5065318 13391 6.83578 60.845928 28.840000 -21.688213 38-2 11.552853 0.3490 22.360001 48.660999 0.0 0.0 2.313600
9964946 25317 11.60927 36.410309 25.351000 -20.108213 203-8 12.369750 4.0252 30.129000 24.877001 0.0 0.0 7.778749
8425940 28969 12.51011 41.643669 13.614000 -21.648214 248-6 12.588146 0.6662 19.785000 27.833000 0.0 0.0 1.584652

In [15]:
sum(merger.Ecc==1)


Out[15]:
7526

In [ ]:


In [16]:
sns.distplot(BBH.T_eject,kde=True,norm_hist=True)
text(7,0.3,BBH.T_eject.describe())

ylim([0,0.6])
xlim([-0.5,14])
# savefig(path.join(dir_data,'Fig/Teject_hist.jpeg'),dpi=200,bbox_inches='tight')


Out[16]:
(-0.5, 14)

In [17]:
merge_kde=sns.distplot(merger.T_merge,kde=True,norm_hist=True)
text(7,0.116,merger.T_merge.describe())
xlim([-0.5,14])

# savefig(path.join(dir_data,'Fig/Tmerge_hist.jpeg'),dpi=200,bbox_inches='tight')


Out[17]:
(-0.5, 14)

In [18]:
# sns.set_context("poster")

In [19]:
merge_curve=merge_kde.get_lines()[0].get_data()

$\frac{1}{4\pi/3*(30Mpc)^3*13.5Gyr}=\frac{1}{4\pi/3*27000*13.5 {Gpc}^3 yr}$


In [20]:
scale=len(merger)/(4.*pi/3.*30**3)/13.5

In [22]:
from scipy.interpolate import interp1d
f2=interp1d(merge_curve[0],merge_curve[1]*scale,kind='cubic')

f2(13.5)


Out[22]:
array(0.00066872965753163)

In [23]:
plot(merge_curve[0],merge_curve[1]*scale)
title("merger event rate, per Gpc^3 per year, in local frame")


Out[23]:
<matplotlib.text.Text at 0x1165c8c50>

In [24]:
from scipy.integrate import quad

integrate from $z=0.6$, which means t=7.7587 to 13.78, d_c=0 to 2.206 Gpc

cosmic calculation


In [25]:
quad(f2, 7.7587,13.5)


Out[25]:
(0.01107842655991399, 7.902013965883777e-09)

Consider cosmology, bhb merger in farther space can will be detectable


In [26]:
import numpy as np
import matplotlib.pyplot as pl
import scipy.stats as st

x = merger.Dist
y = merger.T_merge

xmin=5
xmax=35

ymin=0
ymax=15

# Peform the kernel density estimate
xx, yy = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]
positions = np.vstack([xx.ravel(), yy.ravel()])
values = np.vstack([x, y])
kernel = st.gaussian_kde(values)
f = np.reshape(kernel(positions).T, xx.shape)

fig = pl.figure()
ax = fig.gca()
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
# Contourf plot
cfset = ax.contourf(xx, yy, f, cmap='Blues')
## Or kernel density estimate plot instead of the contourf plot
#ax.imshow(np.rot90(f), cmap='Blues', extent=[xmin, xmax, ymin, ymax])
# Contour plot
cset = ax.contour(xx, yy, f, colors='k')
# Label plot
ax.clabel(cset, inline=1, fontsize=10)
ax.set_xlabel('Distance [Mpc]')
ax.set_ylabel('Merge Time [Gyr]')

def tdelay(time,distance):
    return time-distance*3.2625/1000

distance=np.arange(0,35,0.1)

y1=tdelay(13.5,distance)
y2=tdelay(13.4,distance)

# plt.fill_between(distance, y1, y2, color='grey', alpha='0.5')

# pl.savefig('../Fig/Event_rate.jpeg',dpi=200,bbox_inches='tight')


---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/colors.py in to_rgba(c, alpha)
    140     try:
--> 141         rgba = _colors_full_map.cache[c, alpha]
    142     except (KeyError, TypeError):  # Not in cache, or unhashable.

KeyError: (0.2980392156862745, '0.5')

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/colors.py in _to_rgba_no_colorcycle(c, alpha)
    191     try:
--> 192         c = tuple(map(float, c))
    193     except TypeError:

TypeError: 'float' object is not iterable

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-26-9f5cfc1cbee0> in <module>()
     42 y2=tdelay(13.4,distance)
     43 
---> 44 plt.fill_between(distance, y1, y2, color='grey', alpha='0.5')
     45 
     46 # pl.savefig('../Fig/Event_rate.jpeg',dpi=200,bbox_inches='tight')

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/pyplot.py in fill_between(x, y1, y2, where, interpolate, step, hold, data, **kwargs)
   2999         ret = ax.fill_between(x, y1, y2=y2, where=where,
   3000                               interpolate=interpolate, step=step, data=data,
-> 3001                               **kwargs)
   3002     finally:
   3003         ax._hold = washold

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1890                     warnings.warn(msg % (label_namer, func.__name__),
   1891                                   RuntimeWarning, stacklevel=2)
-> 1892             return func(ax, *args, **kwargs)
   1893         pre_doc = inner.__doc__
   1894         if pre_doc is None:

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/axes/_axes.py in fill_between(self, x, y1, y2, where, interpolate, step, **kwargs)
   4844             polys.append(X)
   4845 
-> 4846         collection = mcoll.PolyCollection(polys, **kwargs)
   4847 
   4848         # now update the datalim and autoscale

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/collections.py in __init__(self, verts, sizes, closed, **kwargs)
    922         %(Collection)s
    923         """
--> 924         Collection.__init__(self, **kwargs)
    925         self.set_sizes(sizes)
    926         self.set_verts(verts, closed)

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/collections.py in __init__(self, edgecolors, facecolors, linewidths, linestyles, antialiaseds, offsets, transOffset, norm, cmap, pickradius, hatch, urls, offset_position, zorder, **kwargs)
    160 
    161         self._path_effects = None
--> 162         self.update(kwargs)
    163         self._paths = None
    164 

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/artist.py in update(self, props)
    883         try:
    884             ret = [_update_property(self, k, v)
--> 885                    for k, v in props.items()]
    886         finally:
    887             self.eventson = store

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/artist.py in <listcomp>(.0)
    883         try:
    884             ret = [_update_property(self, k, v)
--> 885                    for k, v in props.items()]
    886         finally:
    887             self.eventson = store

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/artist.py in _update_property(self, k, v)
    877                 if func is None or not six.callable(func):
    878                     raise AttributeError('Unknown property %s' % k)
--> 879                 return func(v)
    880 
    881         store = self.eventson

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/collections.py in set_alpha(self, alpha)
    746                 raise TypeError('alpha must be a float or None')
    747         artist.Artist.set_alpha(self, alpha)
--> 748         self._set_facecolor(self._original_facecolor)
    749         self._set_edgecolor(self._original_edgecolor)
    750 

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/collections.py in _set_facecolor(self, c)
    657         except AttributeError:
    658             pass
--> 659         self._facecolors = mcolors.to_rgba_array(c, self._alpha)
    660         self.stale = True
    661 

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/colors.py in to_rgba_array(c, alpha)
    235     result = np.empty((len(c), 4), float)
    236     for i, cc in enumerate(c):
--> 237         result[i] = to_rgba(cc, alpha)
    238     return result
    239 

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/colors.py in to_rgba(c, alpha)
    141         rgba = _colors_full_map.cache[c, alpha]
    142     except (KeyError, TypeError):  # Not in cache, or unhashable.
--> 143         rgba = _to_rgba_no_colorcycle(c, alpha)
    144         try:
    145             _colors_full_map.cache[c, alpha] = rgba

/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/colors.py in _to_rgba_no_colorcycle(c, alpha)
    192         c = tuple(map(float, c))
    193     except TypeError:
--> 194         raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
    195     if len(c) not in [3, 4]:
    196         raise ValueError("RGBA sequence should have length 3 or 4")

ValueError: Invalid RGBA argument: 0.2980392156862745

In [27]:
sns.jointplot(merger.Dist,merger.T_merge,kind='kde')


Out[27]:
<seaborn.axisgrid.JointGrid at 0x1198f4b00>

In [28]:
merger['MC']=(merger.M1*merger.M2)**0.6*(merger.M1+merger.M2)**(-0.2)

In [29]:
sns.distplot(merger.MC[merger.MC<50],kde=True)


Out[29]:
<matplotlib.axes._subplots.AxesSubplot at 0x1176a8cf8>

In [31]:
fig = figure()#figsize=(12,8))
ax = fig.add_subplot(111, projection="mollweide")
    # RA: [0h-24h] -> [-pi,pi]; Dec: [-90°,90°] -> [-pi/2,pi/2]\n"
ax.scatter((merger.RA-12)/12*pi,merger.Dec/180*pi,s=2)#,c=expGCpG.iMType,
#           s=5*(2+log10(30./expGCpG.Dist.convert_objects(convert_numeric=True))),cmap=cm.Accent)
ax.set_xticklabels(['2h','4h','6h','8h','10h','12h','14h','16h','18h','20h','22h'])
ax.grid(True)


/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/projections/geo.py:493: RuntimeWarning: invalid value encountered in arcsin
  theta = np.arcsin(y / np.sqrt(2))

In [22]:
import matplotlib.pyplot as plt
import numpy as np
from moviepy.video.io.bindings import mplfig_to_npimage
import moviepy.editor as mpy


WARNING:py.warnings:/Users/domi/anaconda/lib/python2.7/site-packages/skimage/filter/__init__.py:6: skimage_deprecation: The `skimage.filter` module has been renamed to `skimage.filters`.  This placeholder module will be removed in v0.13.
  warn(skimage_deprecation('The `skimage.filter` module has been renamed '


In [23]:
# duration = 1

# dt=0.2
# snap=lambda t:merger[(merger.T_merge>t)&(merger.T_merge<t+dt)]

# fig = figure()#figsize=(12,8))
# ax = fig.add_subplot(111, projection="mollweide")
#     # RA: [0h-24h] -> [-pi,pi]; Dec: [-90°,90°] -> [-pi/2,pi/2]\n"
# ax.scatter((snap(0).RA-12)/12*pi,snap(0).Dec/180*pi)#,c=expGCpG.iMType,
# #           s=5*(2+log10(30./expGCpG.Dist.convert_objects(convert_numeric=True))),cmap=cm.Accent)
# ax.set_xticklabels(['2h','4h','6h','8h','10h','12h','14h','16h','18h','20h','22h'])
# ax.grid(True)

# def make_frame_mpl(t):
#     ax.scatter((snap(t/duration).RA-12)/12*pi,snap(t/duration).Dec/180*pi)
#     return mplfig_to_npimage(fig) # RGB image of the figure

# animation =mpy.VideoClip(make_frame_mpl, duration=duration)

In [24]:
import time

In [25]:
# fig = figure()#figsize=(12,8))
# ax = fig.add_subplot(111, projection="mollweide")
# ax.set_xticklabels(['2h','4h','6h','8h','10h','12h','14h','16h','18h','20h','22h'])
# ax.grid(True)

# for t in linspace(0,13,260):
#     # RA: [0h-24h] -> [-pi,pi]; Dec: [-90°,90°] -> [-pi/2,pi/2]\n"
# #    ax.scatter((snap(0).RA-12)/12*pi,snap(0).Dec/180*pi)#,c=expGCpG.iMType,
# #           s=5*(2+log10(30./expGCpG.Dist.convert_objects(convert_numeric=True))),cmap=cm.Accent)
#     ax.scatter((snap(t).RA-12)/12*pi,snap(t).Dec/180*pi)
#     time.sleep(0.01)

Present BBHs


In [32]:
present.sample(5)


Out[32]:
PGC RA Dec Dist VMag Model Age T_eject M1 M2 Seperation Ecc Period
11826574 27611 12.23008 14.899960 13.614 -21.508215 244-8 11.836887 1.4310 12.620000 70.748001 2.144852 0.782952 1.085759e+07
10677245 38816 15.43486 9.204220 25.351 -18.958214 190-10 12.403166 1.7870 11.637000 36.813000 34.392902 0.954900 9.145203e+08
9900321 37759 15.00669 -13.552640 29.923 -20.108213 23-9 11.557030 0.2496 25.424999 26.197001 206.890000 0.751000 1.307160e+10
15839149 131185 12.07111 -63.219299 25.319 -20.888214 241-2 12.202074 2.3073 23.412001 25.518000 276.260010 0.965200 2.071698e+10
2972418 26204 11.85049 -28.805969 22.909 -21.858213 310-8 12.743888 1.7558 20.729000 32.298000 97.926018 0.392500 4.199868e+09

In [33]:
# fig = figure()#figsize=(12,8))
# ax = fig.add_subplot(111, projection="mollweide")
#     # RA: [0h-24h] -> [-pi,pi]; Dec: [-90°,90°] -> [-pi/2,pi/2]\n"
# ax.scatter((present.RA-12)/12*pi,present.Dec/180*pi,#c=expGCpG.iMType,
#            s=log(2000000000/present.Period))#,cmap=cm.Accent)
# ax.set_xticklabels(['2h','4h','6h','8h','10h','12h','14h','16h','18h','20h','22h'])
# ax.grid(True)

In [34]:
sns.distplot(log10(2./(present.Period[log10(present.Period)<5.45])),rug=True,kde=True,bins=49)
xlim([-4.9,-3.5])
text(-4.2,1,(log10(2./(present.Period[log10(present.Period)<5.1])).describe()))
xlabel("Binary Frequency")
# savefig('../Fig/period.jpeg',dpi=200,bbox_inches='tight')


Out[34]:
<matplotlib.text.Text at 0x117b454e0>

In [121]:
sum(log10(present.Period)<8.5)


Out[121]:
989788

In [36]:
present[log10(present.Period)<4]


Out[36]:
PGC RA Dec Dist VMag Model Age T_eject M1 M2 Seperation Ecc Period
12004041 28543 12.42335 18.19076 17.865 -22.128214 268-3 11.314168 6.2945 13.569 13.439 0.013206 0.188957 9216.6338

In [40]:
present[log10(present.Period)<4.4]


Out[40]:
PGC RA Dec Dist VMag Model Age T_eject M1 M2 Seperation Ecc Period
921436 25448 11.647600 -10.583470 23.333000 -19.038214 73-6 12.502220 0.4914 12.728000 19.122000 0.021475 0.283038 17598.6190
923855 52314 7.723061 -29.216417 24.306000 -22.058214 73-6 12.504010 0.4914 12.728000 19.122000 0.019504 0.251179 15232.7980
6623979 14748 7.671610 -1.573780 18.450001 -18.418215 180-5 8.937468 1.8080 9.956500 26.408001 0.024079 0.287059 19554.8240
6630891 50448 23.554640 -54.094528 26.302999 -20.958214 180-5 8.939259 1.8080 9.956500 26.408001 0.022365 0.262244 17504.5350
7878555 163153 11.880020 44.127190 13.694000 -17.668215 234-1 11.059373 0.5331 53.057999 22.082001 0.034749 0.195282 23584.3110
9168093 17851 9.214370 31.680941 27.986000 -15.708214 203-1 11.876270 1.5094 25.000999 13.354000 0.024699 0.300754 19780.4730
9170494 24089 11.240930 17.259991 20.797001 -19.098213 203-1 11.873286 1.5094 25.000999 13.354000 0.027920 0.344954 23774.4670
11060326 23437 11.053090 27.972460 23.121000 -20.968214 266-10 10.840380 0.4948 27.497000 10.700000 0.025487 0.235592 20777.7480
11098445 38143 15.154470 -11.321590 28.054001 -21.628214 287-2 11.729479 1.7466 15.263000 63.075001 0.036299 0.334490 24659.6880
12000585 17749 9.159350 33.123489 26.062000 -21.568214 268-3 11.308201 6.2945 13.569000 13.439000 0.020655 0.331987 18027.7770
12004041 28543 12.423350 18.190760 17.865000 -22.128214 268-3 11.314168 6.2945 13.569000 13.439000 0.013206 0.188957 9216.6338
12010890 131184 12.045830 -61.674599 19.694000 -20.888214 268-3 11.307604 6.2945 13.569000 13.439000 0.021157 0.340767 18688.5640
12143663 3095 1.335190 3.415340 29.923000 -21.328215 320-6 12.944383 0.5889 23.341000 22.677000 0.024188 0.226955 17500.9080
13159181 14313 7.407750 61.693920 28.840000 -20.288214 97-8 12.502817 9.0041 21.468000 9.372900 0.017283 0.343813 12912.5930
16562575 31791 13.143720 -49.506302 17.298000 -21.788214 82-5 11.389354 0.3539 25.812000 51.585999 0.031337 0.154411 19900.4470

In [41]:
present['MC']=(present.M1*present.M2)**0.6*(present.M1+present.M2)**(-0.2)


/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  if __name__ == '__main__':

In [42]:
present.MC.describe()


Out[42]:
count    1.741773e+07
mean     2.022156e+01
std      1.043717e+01
min      2.785840e+00
25%      1.437788e+01
50%      1.959352e+01
75%      2.273398e+01
max      4.808978e+02
Name: MC, dtype: float64

In [241]:
# present[present.MC==min(present.MC)]

In [355]:
sns.distplot(present.MC)#[present.MC<50])


Out[355]:
<matplotlib.axes._subplots.AxesSubplot at 0x591caed50>

In [43]:
inspiral=present[log10(2./present.Period)>-4.0]

In [44]:
inspiral


Out[44]:
PGC RA Dec Dist VMag Model Age T_eject M1 M2 Seperation Ecc Period MC
921436 25448 11.647600 -10.583470 23.333000 -19.038214 73-6 12.502220 0.4914 12.728000 19.122000 0.021475 0.283038 17598.6190 13.525527
923855 52314 7.723061 -29.216417 24.306000 -22.058214 73-6 12.504010 0.4914 12.728000 19.122000 0.019504 0.251179 15232.7980 13.525527
6623979 14748 7.671610 -1.573780 18.450001 -18.418215 180-5 8.937468 1.8080 9.956500 26.408001 0.024079 0.287059 19554.8240 13.796528
6630891 50448 23.554640 -54.094528 26.302999 -20.958214 180-5 8.939259 1.8080 9.956500 26.408001 0.022365 0.262244 17504.5350 13.796528
9168093 17851 9.214370 31.680941 27.986000 -15.708214 203-1 11.876270 1.5094 25.000999 13.354000 0.024699 0.300754 19780.4730 15.753492
12000585 17749 9.159350 33.123489 26.062000 -21.568214 268-3 11.308201 6.2945 13.569000 13.439000 0.020655 0.331987 18027.7770 11.755751
12004041 28543 12.423350 18.190760 17.865000 -22.128214 268-3 11.314168 6.2945 13.569000 13.439000 0.013206 0.188957 9216.6338 11.755751
12010890 131184 12.045830 -61.674599 19.694000 -20.888214 268-3 11.307604 6.2945 13.569000 13.439000 0.021157 0.340767 18688.5640 11.755751
12143663 3095 1.335190 3.415340 29.923000 -21.328215 320-6 12.944383 0.5889 23.341000 22.677000 0.024188 0.226955 17500.9080 20.027996
13159181 14313 7.407750 61.693920 28.840000 -20.288214 97-8 12.502817 9.0041 21.468000 9.372900 0.017283 0.343813 12912.5930 12.144340
16562575 31791 13.143720 -49.506302 17.298000 -21.788214 82-5 11.389354 0.3539 25.812000 51.585999 0.031337 0.154411 19900.4470 31.395410

In [45]:
sum(merger.Ecc==1)


Out[45]:
7526

In [46]:
merger.Seperation.describe()


Out[46]:
count    8.693900e+04
mean     1.488378e+04
std      2.881894e+05
min      0.000000e+00
25%      0.000000e+00
50%      0.000000e+00
75%      0.000000e+00
max      5.894200e+06
Name: Seperation, dtype: float64

In [48]:
inspiral.ix[inspiral.index,['RA','Dec','Dist','Model','Age','T_eject','M1','M2','MC','Seperation','Ecc','Period']].to_csv('../data/RES/0220/present.dat',sep=' ',index=None,float_format='%.3f')

In [356]:
inspiral.ix[inspiral.index,['RA','Dec','Dist','Model','Age','T_eject','M1','M2','MC','Seperation','Ecc','Period']]


Out[356]:
RA Dec Dist Model Age T_eject M1 M2 MC Seperation Ecc Period
6187829 23.016649 30.144890 13.243000 82-5 11.390547 0.3539 25.812000 51.585999 31.395410 0.028834 0.136647 17564.4490
10734627 3.641410 -35.450630 19.952999 268-3 11.308201 6.2945 13.569000 13.439000 11.755751 0.020655 0.331987 18027.7770
11968679 12.513720 12.391220 17.219000 287-2 11.731866 1.7466 15.263000 63.075001 25.781240 0.029473 0.261929 18041.9040
12987257 22.131229 31.359209 14.997000 242-5 12.530862 10.3789 19.155001 26.336000 19.503569 0.016038 0.318455 9504.0088
13975714 7.451130 80.178062 28.973000 181-2 10.563506 2.9944 47.715000 12.773000 20.636444 0.018797 0.146195 10457.9320
17277365 12.031560 -18.886419 20.797001 203-1 11.877463 1.5094 25.000999 13.354000 15.753492 0.023459 0.282925 18310.3030
17280284 12.365260 4.474180 18.030001 203-1 11.878657 1.5094 25.000999 13.354000 15.753492 0.021443 0.253121 16001.3400

$\dot{f}=k_0 f^{11/3}$

$k_0=\frac{96}{5}(2\pi)^{8/3}\frac{G^{5/3}}{c^5}\frac{m_1*m_2}{(m_1+m_2)^{1/3}}=\frac{96}{5}(2\pi)^{8/3}\frac{G^{5/3}}{c^5}M_{chirp}^{5/3}=const* M_{chirp}^{5/3}$

$const=3.68e-6 s^{5/3}$

$n=\frac{3\eta}{8k_0}f_{min}^{-8/3}$ where $f_{min}=\frac{2}{T_{max}\simeq 10^{4.4}[s]}\simeq 2*10^{-4.4} Hz$

N in [$\frac{4\pi}{3}30^3$ Mpc^3] = $\frac{3}{8k_0} f_{min}^{-8/3} \eta$ in [s x per Gpc^3 per year]

=> $N=\frac{3}{8k_0} f_{min}^{-8/3} \eta *[yr/s]*[Gpc^3/(V(30Mpc))]$

==> $\Delta t=\frac{3}{8k_0}f^{-8/3}_{now}$ per 30 Mpc^3 volume

when merge within 1 yr ($\Delta t \le 1yr$), $f \ge f_{min} = (\frac{8}{3} k_0 \Delta t)^{-3/8} $

$f_{min} = (\frac{8}{3}\frac{96}{5}(2\pi)^{8/3} \frac{G^{5/3}}{c^5}* 1yr)^{-3/8} M_{chirp}^{-5/8} \simeq 0.1164 M_{chirp}^{-5/8} Hz$  per 30 Mpc^3 volume, which is $4\pi/3*30^3 *10^{-9}$ Gpc^3 colume

In [49]:
def f_N(MC,eta,f_min):
    return 3./8./(3.68e-6*MC**(5./3.))*(f_min)**(-8./3.)/3.154e7*(4.*3.14/3.*30.**3.*10**(-9))*eta

In [50]:
f_N(19.6,10,10**-4.0)


Out[50]:
1189.762993988716

$f_N(19.6,10\sim100,10^{4.0})=[1190, 11897]$

in my case: $N=7$

  • $N=7$ only from dynamically formed bbh
  • field has $10^4$ more stars, might be [$10^{-2}$ to 0.5] less efficiency for bbh
  • bh formation merger events not counted
  • GC underestimated (GC SN \& dwarf Galaxy)
  • more bbh channel (galactic nucleus...)

In [51]:
def f_eta(MC,N,f_min):
    return N*8./3.*(3.68e-6*MC**(5./3.))/(f_min)**(-8./3.)*3.154e7/(4.*3.14/3.*30.**3.*10**(-9))

In [52]:
f_eta(19.6,10,10**-4.098)


Out[52]:
0.046047516271764025

In [117]:



/Users/domi/Dropbox/Research/Local_universe/ml_fit

Generate file for LISA analysis

Parameters for binary source

  • $f_0$: binary frequency
  • $\theta_s,\phi_s,\theta_L,\phi_L$: s for source; L for angular momentum vector
  • $\mathrm{A}=\frac{M_1M_2}{rD}$: amplitude
  • $\varphi_0$: phase at $t=0$
    M1 = parameters(1)
    M2 = parameters(2)
    Porb = parameters(3)     : orbital period, represent for orbital separation r, s
    d = parameters(4)        : distance between source and observer, pc
    thetas = parameters(5)   : based on galactic radec
    phis = parameters(6)     : based on galactic radec
    thetal = parameters(7)   : [0,  pi] angular momentum 
    phil = parameters(8)     : [0, 2pi] angular momentum
    phio = parameters(9)     : [0, 2pi] phase
    gam = parameters(10)     : [0, 2pi] amplitude modulation, Lambda
    e = parameters(11)       : eccentricity

In [53]:
present.shape


Out[53]:
(17417734, 14)

In [54]:
present.keys()


Out[54]:
Index(['PGC', 'RA', 'Dec', 'Dist', 'VMag', 'Model', 'Age', 'T_eject', 'M1',
       'M2', 'Seperation', 'Ecc', 'Period', 'MC'],
      dtype='object')

In [115]:
lisadata=present[['M1','M2','Period']] # M_sun, M_sun, second
lisadata['Dist']=present.Dist*1.0e6 # Mpc -> pc
lisadata['thetas']=present.Dec.apply(lambda x: (x+90.)/180.0*pi) # [-90,90]->[0,pi]
lisadata['phis']=present.RA.apply(lambda x: x*15.0/180.0*pi)  # [0,24]->[0,2pi]
np.random.seed(seed=427)
lisadata['thetal']=np.random.rand(len(present))*pi # [0,pi]
lisadata['phil']=np.random.rand(len(present))*2*pi # [0,2pi]
lisadata['phio']=np.random.rand(len(present))*2*pi # [0,2pi]
lisadata['gam']=np.random.rand(len(present))*2*pi # [0,2pi]
lisadata['e']=present.Ecc


/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:2: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  from ipykernel import kernelapp as app
/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:3: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  app.launch_new_instance()
/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:4: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:7: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:8: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:9: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
/Users/domi/anaconda3/envs/py35/lib/python3.5/site-packages/ipykernel/__main__.py:10: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

In [116]:
lisadata.sample(1000).describe().ix[['min','max']]


Out[116]:
M1 M2 Period Dist thetas phis thetal phil phio gam e
min 4.2961 3.77930 1.400164e+07 787000.0 0.044721 0.017370 0.003819 0.008622 0.007196 0.004564 0.000000
max 213.8400 315.26999 7.175870e+19 29958000.0 2.970167 6.269001 3.140603 6.274837 6.279184 6.280259 0.999761

In [118]:
lisadata.to_csv('../data/RES/0220/lisa.dat.gz',
                sep='\t',index=None,compression='gzip')

In [124]:
lisadata[lisadata.Period<10**8.5].to_csv('../data/RES/0220/lisa_8.5.dat.gz',
                sep='\t',index=None,compression='gzip')

In [ ]:

$T_{eject}$ variation for each model


In [6]:
## Load BHLIB
bhlib=pd.DataFrame()
###################################
for i in range(1,325): # model
    for j in range(1,11):  # model id
###################################
        bhe=pd.read_csv('../data/BHsystem/%d-%d-bhe.dat' %(i,j),
                    usecols=[0, 2, 3, 4, 6, 8, 10, 20], names=['T_eject','Type1','Type2','M1','M2','Seperation','Ecc','Model'], 
                    header=None, delim_whitespace=True)
        bhe.Model='%d-%d' %(i,j)
        bhlib=pd.concat([bhlib,bhe],ignore_index=False)

In [7]:
# BHB binary
bhblib=bhlib[bhlib.Type1==14*(bhlib.Type2==14)].copy(deep=True)
bhsys=bhlib[-(bhlib.Type1==14*(bhlib.Type2==14))].copy(deep=True)
bhblib=bhblib.drop(bhblib.columns[[1, 2]], axis=1)

In [16]:


In [63]:
for i in range(1,325):
    for j in range(1,6):
        fig=figure(i)
        try:
            sns.distplot(bhblib.T_eject[bhblib.Model=="%d-%d" % (i,j)],rug=True,label='Model %d-%d' % (i,j))
        except:
            print "no ejected bbh in %d-%d" % (i,j)
    legend()
    savefig('../Fig/BHE_var/model-%d.jpeg' % i, dpi=200,bbox_inches='tight')
    close(fig)


no ejected bbh in 3-1
no ejected bbh in 3-2
no ejected bbh in 3-3
no ejected bbh in 3-4
no ejected bbh in 3-5
no ejected bbh in 21-1
no ejected bbh in 21-2
no ejected bbh in 21-3
no ejected bbh in 21-4
no ejected bbh in 29-4
no ejected bbh in 39-5
no ejected bbh in 75-2
no ejected bbh in 75-3
no ejected bbh in 75-5
no ejected bbh in 80-1
no ejected bbh in 80-4
no ejected bbh in 80-5
no ejected bbh in 86-5
no ejected bbh in 111-1
no ejected bbh in 111-2
no ejected bbh in 111-3
no ejected bbh in 111-4
no ejected bbh in 111-5
no ejected bbh in 120-1
no ejected bbh in 120-2
no ejected bbh in 120-3
no ejected bbh in 120-4
no ejected bbh in 120-5
no ejected bbh in 129-1
no ejected bbh in 129-2
no ejected bbh in 129-3
no ejected bbh in 129-4
no ejected bbh in 129-5
no ejected bbh in 132-2
no ejected bbh in 132-3
no ejected bbh in 132-4
no ejected bbh in 138-1
no ejected bbh in 138-2
no ejected bbh in 138-3
no ejected bbh in 138-4
no ejected bbh in 138-5
no ejected bbh in 156-3
no ejected bbh in 156-4
no ejected bbh in 159-3
no ejected bbh in 165-1
no ejected bbh in 165-2
no ejected bbh in 165-3
no ejected bbh in 165-4
no ejected bbh in 165-5
no ejected bbh in 177-1
no ejected bbh in 228-1
no ejected bbh in 228-2
no ejected bbh in 228-3
no ejected bbh in 228-4
no ejected bbh in 273-1
no ejected bbh in 273-2
no ejected bbh in 273-3
no ejected bbh in 273-4
no ejected bbh in 273-5
no ejected bbh in 282-2
no ejected bbh in 282-5
no ejected bbh in 291-2
no ejected bbh in 300-5
no ejected bbh in 325-1
no ejected bbh in 325-2
no ejected bbh in 325-3
no ejected bbh in 325-4
no ejected bbh in 325-5

Weird models

  • 48
  • 210

In [92]:
i=48
for j in range(1,6):
    fig=figure(i)
    try:
        sns.distplot(bhblib.T_eject[bhblib.Model=="%d-%d" % (i,j)],kde=True,rug=True,label='Model %d-%d' % (i,j))
    except:
        print "no ejected bbh in %d-%d" % (i,j)
legend()


Out[92]:
<matplotlib.legend.Legend at 0x1e2cf8450>

In [104]:
bhblib[bhblib.Model.str.match(r"48-\d")]


Out[104]:
T_eject M1 M2 Seperation Ecc Model
0 0.0148 23.401 8.6009 372.280 0.3650 48-1
1 0.0295 22.421 7.0458 18.236 0.4326 48-1
2 0.0295 24.633 10.4470 64.778 0.0000 48-1
3 0.0295 22.927 7.8046 55.931 0.5738 48-1
4 0.0377 13.996 13.9930 187.990 0.3373 48-1
5 0.0459 13.116 13.0960 123.850 0.6183 48-1
0 0.0295 13.996 13.9930 112.680 0.3373 48-2
1 0.0295 22.421 7.0458 27.667 0.4326 48-2
2 0.0295 24.633 10.4470 62.088 0.0000 48-2
3 0.0295 22.927 7.8046 49.010 0.5738 48-2
4 0.0839 23.878 95.8090 38.594 0.4789 48-2
0 0.0295 13.116 13.0960 119.630 0.6183 48-3
1 0.0295 24.633 10.4470 65.881 0.0000 48-3
2 0.0295 22.927 7.8046 54.191 0.5738 48-3
3 0.0587 25.035 10.6970 776.250 0.6012 48-3
5 0.0768 89.237 132.8200 51.130 0.3970 48-3
6 0.0945 118.220 32.4980 85.542 0.5589 48-3
0 0.0148 23.401 8.6009 175.630 0.1852 48-4
1 0.0295 22.421 7.0458 62.021 0.4327 48-4
2 0.0295 24.889 10.5950 889.570 0.0000 48-4
3 0.0295 26.790 11.8450 448.630 0.3408 48-4
4 0.0295 24.633 10.4470 63.366 0.0000 48-4
5 0.0295 22.927 7.8046 71.977 0.5738 48-4
6 0.0461 85.026 32.9540 100.630 0.2839 48-4
7 0.0503 13.471 13.0960 106.730 0.4993 48-4
8 0.1279 92.233 18.5880 31.729 0.4597 48-4
0 0.0148 24.240 8.6009 131.610 0.2549 48-5
1 0.0295 22.421 7.0458 20.464 0.4326 48-5
2 0.0295 24.889 10.5950 616.450 0.0126 48-5
3 0.0295 24.633 10.4470 69.725 0.0000 48-5
4 0.0295 22.927 7.8046 64.231 0.5738 48-5
5 0.0730 241.810 107.7600 51.748 0.2071 48-5
6 0.0853 190.410 149.3100 55.128 0.6238 48-5
10 0.1700 13.116 13.0960 118.560 0.6183 48-5

In [ ]:


In [ ]:


In [128]:
for i in range(1,6):
    sns.distplot(bhblib.T_eject[bhblib.Model.str.contains('-%d' % i)],norm_hist=True,label='run %d' % i)
legend()
# savefig('../Fig/BHE_var/runs.jpeg',dpi=200,bbox_inches='tight')


Out[128]:
<matplotlib.legend.Legend at 0x12b6a4150>

In [ ]:


In [23]:
from gcpg import build

In [26]:
reload(build)


Out[26]:
<module 'gcpg.build' from 'gcpg/build.py'>

In [27]:
build.analysis('/Users/domi/Desktop/RES/1101')


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-27-54aeb417027a> in <module>()
----> 1 build.analysis('/Users/domi/Desktop/RES/1101')

/Users/domi/Dropbox/Research/Local_universe/ml_fit/gcpg/build.py in analysis(dir_data)
     71     savefig(path.join(dir_data,'Fig/Tmerge_hist.jpeg'),dpi=200,bbox_inches='tight')
     72 
---> 73     sns.distplot(log10(2./(present.Period[log10(present.Period)<5.45])),rug=True,kde=True,bins=49)
     74     xlim([-4.9,-3.5])
     75     text(-4.2,1,(log10(2./(present.Period[log10(present.Period)<5.1])).describe()))

NameError: global name 'log10' is not defined

In [ ]: