Skip to content
Snippets Groups Projects
Commit d6442691 authored by Yifan Wang's avatar Yifan Wang
Browse files

notebooks

parent bda75d0e
Branches master
No related tags found
No related merge requests found
%% Cell type:markdown id:5e728de6 tags:
# Plotting Options
%% Cell type:code id:furnished-potato tags:
``` python
import numpy as np
import h5py,glob,os
from pycbc import conversions
from scipy import stats
from tqdm import tqdm
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
# PLOTTING OPTIONS
fig_width_pt = 3*246.0 # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27 # Convert pt to inch
golden_mean = (np.sqrt(5)-1.0)/2.0 # Aesthetic ratio
fig_width = fig_width_pt*inches_per_pt # width in inches
fig_height = fig_width*golden_mean+0.5 # height in inches
fig_size = [fig_width,fig_height]
# PLOTTING OPTIONS
fig_width_pt = 3*246.0 # Get this from LaTeX using \showthe\columnwidth
inches_per_pt = 1.0/72.27 # Convert pt to inch
golden_mean = (np.sqrt(5)-1.0)/2.0 # Aesthetic ratio
fig_width = fig_width_pt*inches_per_pt # width in inches
fig_height = fig_width*golden_mean # height in inches
fig_size = [fig_width,fig_height]
params = { 'axes.labelsize': 24,
'font.family': 'serif',
'font.serif': 'Computer Modern Raman',
'font.size': 24,
'legend.fontsize': 20,
'xtick.labelsize': 24,
'ytick.labelsize': 24,
'axes.grid' : True,
'text.usetex': True,
'savefig.dpi' : 100,
'lines.markersize' : 14,
'figure.figsize': fig_size}
mpl.rcParams.update(params)
from pesummary.core.plots.bounded_1d_kde import bounded_1d_kde
```
%% Cell type:code id:e3b939a3 tags:
``` python
binmin = 0
binmax = 1000
binnum = int(int(binmax-binmin) + 1)
print(binnum)
bins = np.linspace(binmin,binmax,binnum)
```
%% Output
1001
%% Cell type:markdown id:01419cad tags:
# GW190521 real data run
%% Cell type:code id:5cbd2e49 tags:
``` python
f = h5py.File('/work/yifan.wang/testingGR-o3b/t4-mpi-massive/GW190521-mpv1000/extract.hdf','r')
```
%% Cell type:code id:a3f7f975 tags:
``` python
d = bounded_1d_kde(f['samples']['parity_mpvinverse'][()])
```
%% Cell type:code id:da49b929 tags:
``` python
r = d(bins[:-1])
r = r/np.sum(r)/(bins[2]-bins[1])
```
%% Cell type:code id:8f9bcae6 tags:
``` python
combine = np.zeros(len(bins[:-1]))
event = []
for i in range(100):
txt = np.loadtxt('./INJDATA/GW190521/'+str(i)+'.txt')
event.append(txt[:,1])
combine += txt[:,1]
```
%% Cell type:code id:cdc06bac tags:
``` python
plt.plot(bins[:-1],combine/100,label='injection average')
plt.plot(bins[:-1],r,label='GW190521')
plt.plot(100,100,color='gray',zorder=-1,alpha=1,label='injections')
for i in range(100):
plt.plot(bins[:-1],event[i],color='gray',zorder=-1,alpha=0.1)
plt.legend()
plt.ylim(0,0.004)
plt.xlim(0,1000)
plt.title('GW190521')
plt.ylabel('Probability Density')
plt.xlabel('$M_\mathrm{PV}^{-1}$ [GeV$^{-1}$]')
plt.savefig('GW190521-inj.png',bbox_inches='tight')
```
%% Output
%% Cell type:markdown id:97916621 tags:
# Bayes factor
%% Cell type:code id:753ebecb tags:
``` python
0.001/r[0]
```
%% Output
10.997900661198125
%% Cell type:code id:584ed5f1 tags:
``` python
np.log(0.001/r[0])
```
%% Output
2.3977044056023975
%% Cell type:code id:13cc1368 tags:
``` python
np.median(f['samples']['parity_mpvinverse'][:])/np.std(f['samples']['parity_mpvinverse'][:])
```
%% Output
2.11694748406522
%% Cell type:code id:a7a900e7 tags:
``` python
r0 = [event[i][0] for i in range(100)]
```
%% Cell type:code id:80fec17a tags:
``` python
np.sort(0.001/np.array(r0))
```
%% Output
array([ 0.10760022, 0.12231412, 0.1491996 , 0.17254167, 0.19083087,
0.19924071, 0.20795018, 0.20839901, 0.20857025, 0.21132103,
0.21489632, 0.21980263, 0.22463276, 0.23087591, 0.2325678 ,
0.23780638, 0.24164496, 0.24436879, 0.25928547, 0.27801257,
0.28535016, 0.29337103, 0.30878492, 0.31968284, 0.31973142,
0.32378121, 0.32481493, 0.34276225, 0.35061967, 0.35403893,
0.36487152, 0.36761182, 0.37567379, 0.41706441, 0.43634365,
0.44148127, 0.44879488, 0.48232095, 0.48260404, 0.48874957,
0.49077087, 0.49716043, 0.4997546 , 0.50248692, 0.50269499,
0.5054598 , 0.50973671, 0.51876029, 0.52082413, 0.5305977 ,
0.53718161, 0.53774539, 0.54849621, 0.54964462, 0.57738073,
0.58006832, 0.59143698, 0.59951194, 0.60704105, 0.61505825,
0.61837905, 0.66972387, 0.69290913, 0.70589659, 0.71326893,
0.73171696, 0.75443428, 0.76732157, 0.77484612, 0.77513832,
0.78708929, 0.79322574, 0.79375416, 0.82795317, 0.83535967,
0.8373832 , 0.86032494, 0.87910256, 0.89052968, 0.93234874,
0.93450264, 0.97997868, 0.98925307, 0.99747858, 1.03073057,
1.06253297, 1.17100283, 1.18475713, 1.19467888, 1.22474887,
1.27758112, 1.36423179, 1.37571616, 1.39121304, 1.42592869,
1.51822558, 1.79046334, 1.82822198, 2.34268803, 25.30624655])
%% Cell type:code id:18494e04 tags:
``` python
np.argsort(0.001/np.array(r0))
```
%% Output
array([46, 84, 56, 75, 13, 64, 90, 31, 48, 78, 58, 86, 73, 76, 82, 72, 74,
61, 33, 43, 59, 99, 37, 69, 18, 5, 38, 23, 10, 65, 70, 44, 77, 51,
36, 28, 15, 60, 57, 85, 2, 39, 16, 62, 97, 79, 94, 49, 91, 12, 81,
8, 21, 54, 11, 71, 29, 24, 45, 52, 30, 93, 42, 67, 34, 68, 53, 1,
22, 98, 96, 20, 32, 47, 3, 55, 89, 92, 17, 83, 4, 35, 25, 95, 27,
7, 26, 40, 80, 6, 87, 0, 19, 88, 9, 66, 14, 41, 63, 50])
%% Cell type:code id:f9d5ef68 tags:
``` python
```
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment