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

add notebooks

parent 0d37d2db
No related branches found
No related tags found
No related merge requests found
Showing
with 4332 additions and 0 deletions
File added
File added
File added
%% Cell type:code id:8cf15b3c tags:
``` python
%matplotlib notebook
```
%% Cell type:code id:d5332cc4 tags:
``` python
import itertools
import numpy
import matplotlib
from matplotlib import patches
from matplotlib import pyplot
from pycbc import waveform
from pycbc.inference import io
from pycbc import conversions
from scripts import scatter_histograms
```
%% Cell type:code id:0dd8e4c7 tags:
``` python
pyplot.style.use('seaborn-colorblind')
```
%% Cell type:code id:29a5dff2 tags:
``` python
color_cycle = [c['color'] for c in matplotlib.rcParams['axes.prop_cycle']]
colors = itertools.cycle(color_cycle)
# cycle around
for _ in range(5):
next(colors)
```
%% Cell type:markdown id:f7551a5f tags:
# PyCBC Inference Read Samples
%% Cell type:code id:29d23980 tags:
``` python
filenames = {'GW190521': '/work/yifan.wang/gw190521_xrerun/t3-localrun/0_700/result.hdf',
'GW191109': '/work/yifan.wang/testingGR-o3b/t2-o3bevents/o3btgr_output/samples_files/H1L1V1-INFERENCE_GW191109_010717-1126259200-400.hdf',
'GW200220':'/work/yifan.wang/testingGR-o3b/t4-mpi-massive/t2-200220-mpv1000/result.hdf'}
samples = {}
for lbl, fn in filenames.items():
fp = io.loadfile(fn, 'r')
s = fp.read_samples(['srcmchirp', 'q', 'parity_mpvinverse'])
samples[lbl] = s
fp.close()
```
%% Cell type:code id:a94f9251 tags:
``` python
filelabels = {'GW190521': 'GW190521',
'GW191109': 'GW191109',
'GW200220': 'GW200220'
}
```
%% Cell type:code id:fc371486 tags:
``` python
samples
```
%% Output
{'GW190521': rec.array([(-27873.26400656, 83.26078987, 436.04949975, 1.43400538),
(-27875.2432163 , 71.57790771, 541.07468378, 1.64651789),
(-27875.26155477, 74.09536189, 440.63653902, 1.73495024), ...,
(-27880.60033757, 63.38915481, 277.02222192, 1.29027691),
(-27869.3461176 , 95.44301611, 381.03490203, 1.50594504),
(-27877.14788405, 79.98899193, 313.76083404, 1.28679349)],
dtype=[('loglikelihood', '<f8'), ('srcmchirp', '<f8'), ('parity_mpvinverse', '<f8'), ('q', '<f8')]),
'GW191109': rec.array([(-17938.0557928 , 48.73074706, 144.75730556, 1.16390601),
(-17942.74637522, 52.43607729, 329.71287488, 1.02073016),
(-17942.07580232, 41.9276795 , 180.19740616, 2.19670947), ...,
(-17940.19991335, 48.96967047, 405.20982651, 1.45601162),
(-17935.2245303 , 50.17113232, 235.30007999, 1.16774801),
(-17938.96972275, 53.97280568, 244.20575908, 1.28908152)],
dtype=[('loglikelihood', '<f8'), ('srcmchirp', '<f8'), ('parity_mpvinverse', '<f8'), ('q', '<f8')]),
'GW200220': rec.array([(-81869.72084721, 64.4399525 , 511.48166829, 2.134752 ),
(-81863.8137886 , 89.29121051, 418.60442017, 3.00415035),
(-81867.14210206, 67.036858 , 239.90584564, 1.45710404), ...,
(-81863.32826024, 59.46329134, 606.33211039, 2.63692637),
(-81864.82296474, 69.8439018 , 467.65624429, 1.19154618),
(-81866.23224365, 104.03905068, 100.25604593, 2.5061787 )],
dtype=[('loglikelihood', '<f8'), ('srcmchirp', '<f8'), ('parity_mpvinverse', '<f8'), ('q', '<f8')])}
%% Cell type:code id:ea533ca3 tags:
``` python
labels = {'srcmchirp': waveform.parameters.srcmchirp.label,
'q': waveform.parameters.q.label,
'parity_mpvinverse':'$M_\mathrm{PV}^{-1} (\mathrm{GeV}^{-1})$'
}
```
%% Cell type:code id:d1fc164a tags:
``` python
x = 'srcmchirp'
y = 'q'
z = 'parity_mpvinverse'
mins = {x: min(s[x].min() for s in samples.values()),
y: min(s[y].min() for s in samples.values()),
z: min(s[z].min() for s in samples.values())
}
maxs = {x: max(s[x].max() for s in samples.values()),
y: min(max(s[y].max() for s in samples.values()),6),
z: max(s[z].max() for s in samples.values())
}
```
%% Cell type:code id:e95d473c tags:
``` python
mins
```
%% Output
{'srcmchirp': 31.170769850622765,
'q': 1.0000229039873965,
'parity_mpvinverse': 0.006938599419005487}
%% Cell type:code id:6ed4aeed tags:
``` python
maxs
```
%% Output
{'srcmchirp': 149.1743322543928,
'q': 6,
'parity_mpvinverse': 999.9916720638518}
%% Cell type:code id:e84b1343 tags:
``` python
# create a pool for evaluating the kombine kde
from pycbc.pool import choose_pool
pool = choose_pool(10)
```
%% Cell type:code id:37a7a798 tags:
``` python
samples
```
%% Output
{'GW190521': rec.array([(-27873.26400656, 83.26078987, 436.04949975, 1.43400538),
(-27875.2432163 , 71.57790771, 541.07468378, 1.64651789),
(-27875.26155477, 74.09536189, 440.63653902, 1.73495024), ...,
(-27880.60033757, 63.38915481, 277.02222192, 1.29027691),
(-27869.3461176 , 95.44301611, 381.03490203, 1.50594504),
(-27877.14788405, 79.98899193, 313.76083404, 1.28679349)],
dtype=[('loglikelihood', '<f8'), ('srcmchirp', '<f8'), ('parity_mpvinverse', '<f8'), ('q', '<f8')]),
'GW191109': rec.array([(-17938.0557928 , 48.73074706, 144.75730556, 1.16390601),
(-17942.74637522, 52.43607729, 329.71287488, 1.02073016),
(-17942.07580232, 41.9276795 , 180.19740616, 2.19670947), ...,
(-17940.19991335, 48.96967047, 405.20982651, 1.45601162),
(-17935.2245303 , 50.17113232, 235.30007999, 1.16774801),
(-17938.96972275, 53.97280568, 244.20575908, 1.28908152)],
dtype=[('loglikelihood', '<f8'), ('srcmchirp', '<f8'), ('parity_mpvinverse', '<f8'), ('q', '<f8')]),
'GW200220': rec.array([(-81869.72084721, 64.4399525 , 511.48166829, 2.134752 ),
(-81863.8137886 , 89.29121051, 418.60442017, 3.00415035),
(-81867.14210206, 67.036858 , 239.90584564, 1.45710404), ...,
(-81863.32826024, 59.46329134, 606.33211039, 2.63692637),
(-81864.82296474, 69.8439018 , 467.65624429, 1.19154618),
(-81866.23224365, 104.03905068, 100.25604593, 2.5061787 )],
dtype=[('loglikelihood', '<f8'), ('srcmchirp', '<f8'), ('parity_mpvinverse', '<f8'), ('q', '<f8')])}
%% Cell type:code id:737146e4 tags:
``` python
filecolors = {}
fig, axd = (None, None)
for run in samples:
c = next(colors)
filecolors[run] = c
s = samples[run]
fig, axd = scatter_histograms.create_multidim_plot(
['parity_mpvinverse', 'srcmchirp'], s, labels=labels,
mins=mins, maxs=maxs,
plot_scatter=False, plot_contours=True,
marginal_percentiles=[], contour_percentiles=[50, 90],
fill_color=None, contour_color=c, hist_color=c, line_color=c,
contour_ls=['solid', 'dashed'], contour_labels=False, fold_masses=True,
use_kombine=True, kdeargs={'pool': pool, 'max_samples': 200},
fig=fig, axis_dict=axd,
)
# add legend
handles = []
lbls = []
for run, c in filecolors.items():
l = filelabels[run]
handles.append(patches.Patch(color=c, label=l))
lbls.append(l)
fig.legend(loc=(0.7, 0.75), handles=handles, labels=lbls)
fig.savefig('3events.png')
```
%% Cell type:code id:95c5bcdf tags:
``` python
color_cycle = ['#1f77b4', '#ff7f0e']
colors = itertools.cycle(color_cycle)
# cycle around
for _ in range(5):
next(colors)
```
%% Cell type:code id:e69aacc6 tags:
``` python
color_cycle = [c['color'] for c in matplotlib.rcParams['axes.prop_cycle']]
colors = itertools.cycle(color_cycle)
# cycle around
#for _ in range(5):
# next(colors)
```
%% Cell type:code id:5902c7f1 tags:
``` python
for i in range(5):
print(i)
```
%% Output
0
1
2
3
4
%% Cell type:code id:4ff63d8a tags:
``` python
color_cycle
```
%% Output
['#0072B2', '#009E73', '#D55E00', '#CC79A7', '#F0E442', '#56B4E9']
%% Cell type:code id:2b6d8f06 tags:
``` python
[c['color'] for c in matplotlib.rcParams['axes.prop_cycle']]
```
%% Output
['#0072B2', '#009E73', '#D55E00', '#CC79A7', '#F0E442', '#56B4E9']
%% Cell type:code id:87080ba5 tags:
``` python
filecolors = {}
fig, axd = (None, None)
for run in samples:
c = next(colors)
filecolors[run] = c
s = samples[run]
fig, axd = scatter_histograms.create_multidim_plot(
['parity_mpvinverse', 'srcmchirp','q'], s, labels=labels,
mins=mins, maxs=maxs,
plot_scatter=False, plot_contours=True,
marginal_percentiles=[], contour_percentiles=[50, 90],
fill_color=None, contour_color=c, hist_color=c, line_color=c,
contour_ls=['solid', 'dashed'], contour_labels=False, fold_masses=True,
use_kombine=True, kdeargs={'pool': pool, 'max_samples': 200},
fig=fig, axis_dict=axd,
)
# add legend
handles = []
lbls = []
for run, c in filecolors.items():
l = filelabels[run]
handles.append(patches.Patch(color=c, label=l))
lbls.append(l)
fig.legend(loc=(0.7, 0.75), handles=handles, labels=lbls)
fig.show()
fig.savefig('./3events-2.png')
```
%% Cell type:code id:132771ea tags:
``` python
```
%% Cell type:code id:8cf15b3c tags:
``` python
%matplotlib notebook
```
%% Cell type:code id:d5332cc4 tags:
``` python
import itertools
import numpy
import matplotlib
from matplotlib import patches
from matplotlib import pyplot
from pycbc import waveform
from pycbc.inference import io
from pycbc import conversions
from scripts import scatter_histograms
```
%% Cell type:code id:0dd8e4c7 tags:
``` python
pyplot.style.use('seaborn-colorblind')
```
%% Cell type:code id:29a5dff2 tags:
``` python
color_cycle = [c['color'] for c in matplotlib.rcParams['axes.prop_cycle']]
colors = itertools.cycle(color_cycle)
# cycle around
for _ in range(5):
next(colors)
```
%% Cell type:markdown id:f7551a5f tags:
# PyCBC Inference Read Samples
%% Cell type:code id:29d23980 tags:
``` python
filenames = {'GW190521': '/work/yifan.wang/gw190521_xrerun/t3-localrun/0_700/result.hdf',
'GW191109': '/work/yifan.wang/testingGR-o3b/t2-o3bevents/o3btgr_output/samples_files/H1L1V1-INFERENCE_GW191109_010717-1126259200-400.hdf'}
samples = {}
for lbl, fn in filenames.items():
fp = io.loadfile(fn, 'r')
s = fp.read_samples(['srcmchirp', 'q', 'parity_mpvinverse'])
samples[lbl] = s
fp.close()
```
%% Cell type:code id:a94f9251 tags:
``` python
filelabels = {'GW190521': 'GW190521',
'GW191109': 'GW191109',
'GW200220': 'GW200220'
}
```
%% Cell type:code id:fc371486 tags:
``` python
samples
```
%% Output
{'GW190521': rec.array([(-27873.26400656, 1.43400538, 83.26078987, 436.04949975),
(-27875.2432163 , 1.64651789, 71.57790771, 541.07468378),
(-27875.26155477, 1.73495024, 74.09536189, 440.63653902), ...,
(-27880.60033757, 1.29027691, 63.38915481, 277.02222192),
(-27869.3461176 , 1.50594504, 95.44301611, 381.03490203),
(-27877.14788405, 1.28679349, 79.98899193, 313.76083404)],
dtype=[('loglikelihood', '<f8'), ('q', '<f8'), ('srcmchirp', '<f8'), ('parity_mpvinverse', '<f8')]),
'GW191109': rec.array([(-17938.05582598, 1.26533831, 53.21310226, 197.79672422),
(-17942.74637522, 1.02073016, 52.43607729, 329.71287488),
(-17942.07580232, 2.19670947, 41.9276795 , 180.19740616), ...,
(-17940.19991335, 1.45601162, 48.96967047, 405.20982651),
(-17935.22456401, 1.43324543, 47.64874267, 235.73097815),
(-17938.96972275, 1.28908152, 53.97280568, 244.20575908)],
dtype=[('loglikelihood', '<f8'), ('q', '<f8'), ('srcmchirp', '<f8'), ('parity_mpvinverse', '<f8')])}
%% Cell type:code id:ea533ca3 tags:
``` python
labels = {'srcmchirp': waveform.parameters.srcmchirp.label,
'q': waveform.parameters.q.label,
'parity_mpvinverse':'$M_\mathrm{PV}^{-1} (\mathrm{GeV}^{-1})$'
}
```
%% Cell type:code id:d1fc164a tags:
``` python
x = 'srcmchirp'
y = 'q'
z = 'parity_mpvinverse'
mins = {x: min(s[x].min() for s in samples.values()),
y: min(s[y].min() for s in samples.values()),
z: min(s[z].min() for s in samples.values())
}
maxs = {x: max(s[x].max() for s in samples.values()),
y: min(max(s[y].max() for s in samples.values()),6),
z: max(s[z].max() for s in samples.values())
}
```
%% Cell type:code id:e95d473c tags:
``` python
mins
```
%% Output
{'srcmchirp': 37.002503305720985,
'q': 1.0000229039873965,
'parity_mpvinverse': 0.007961298971146953}
%% Cell type:code id:6ed4aeed tags:
``` python
maxs
```
%% Output
{'srcmchirp': 107.9856545544305,
'q': 6,
'parity_mpvinverse': 699.9957055218948}
%% Cell type:code id:e84b1343 tags:
``` python
# create a pool for evaluating the kombine kde
from pycbc.pool import choose_pool
pool = choose_pool(10)
```
%% Cell type:code id:37a7a798 tags:
``` python
samples
```
%% Output
{'GW190521': rec.array([(-27873.26400656, 1.43400538, 83.26078987, 436.04949975),
(-27875.2432163 , 1.64651789, 71.57790771, 541.07468378),
(-27875.26155477, 1.73495024, 74.09536189, 440.63653902), ...,
(-27880.60033757, 1.29027691, 63.38915481, 277.02222192),
(-27869.3461176 , 1.50594504, 95.44301611, 381.03490203),
(-27877.14788405, 1.28679349, 79.98899193, 313.76083404)],
dtype=[('loglikelihood', '<f8'), ('q', '<f8'), ('srcmchirp', '<f8'), ('parity_mpvinverse', '<f8')]),
'GW191109': rec.array([(-17938.05582598, 1.26533831, 53.21310226, 197.79672422),
(-17942.74637522, 1.02073016, 52.43607729, 329.71287488),
(-17942.07580232, 2.19670947, 41.9276795 , 180.19740616), ...,
(-17940.19991335, 1.45601162, 48.96967047, 405.20982651),
(-17935.22456401, 1.43324543, 47.64874267, 235.73097815),
(-17938.96972275, 1.28908152, 53.97280568, 244.20575908)],
dtype=[('loglikelihood', '<f8'), ('q', '<f8'), ('srcmchirp', '<f8'), ('parity_mpvinverse', '<f8')])}
%% Cell type:code id:737146e4 tags:
``` python
filecolors = {}
fig, axd = (None, None)
for run in ['GW190521','GW191109']:
c = next(colors)
filecolors[run] = c
s = samples[run]
fig, axd = scatter_histograms.create_multidim_plot(
['parity_mpvinverse', 'srcmchirp'], s, labels=labels,
mins=mins, maxs=maxs,
plot_scatter=False, plot_contours=True,
marginal_percentiles=[], contour_percentiles=[50, 90],
fill_color=None, contour_color=c, hist_color=c, line_color=c,
contour_ls=['solid', 'dashed'], contour_labels=False, fold_masses=True,
use_kombine=True, kdeargs={'pool': pool, 'max_samples': 200},
fig=fig, axis_dict=axd,
)
# add legend
handles = []
lbls = []
for run, c in filecolors.items():
l = filelabels[run]
handles.append(patches.Patch(color=c, label=l))
lbls.append(l)
fig.legend(loc=(0.7, 0.75), handles=handles, labels=lbls)
fig.show()
```
%% Cell type:code id:95c5bcdf tags:
``` python
color_cycle = ['#1f77b4', '#ff7f0e']
colors = itertools.cycle(color_cycle)
# cycle around
for _ in range(5):
next(colors)
```
%% Cell type:code id:e69aacc6 tags:
``` python
color_cycle = [c['color'] for c in matplotlib.rcParams['axes.prop_cycle']]
colors = itertools.cycle(color_cycle)
# cycle around
#for _ in range(5):
# next(colors)
```
%% Cell type:code id:5902c7f1 tags:
``` python
for i in range(5):
print(i)
```
%% Output
0
1
2
3
4
%% Cell type:code id:4ff63d8a tags:
``` python
color_cycle
```
%% Output
['#0072B2', '#009E73', '#D55E00', '#CC79A7', '#F0E442', '#56B4E9']
%% Cell type:code id:2b6d8f06 tags:
``` python
[c['color'] for c in matplotlib.rcParams['axes.prop_cycle']]
```
%% Output
['#0072B2', '#009E73', '#D55E00', '#CC79A7', '#F0E442', '#56B4E9']
%% Cell type:code id:87080ba5 tags:
``` python
filecolors = {}
fig, axd = (None, None)
for run in ['GW190521','GW191109']:
c = next(colors)
filecolors[run] = c
s = samples[run]
fig, axd = scatter_histograms.create_multidim_plot(
['parity_mpvinverse', 'srcmchirp','q'], s, labels=labels,
mins=mins, maxs=maxs,
plot_scatter=False, plot_contours=True,
marginal_percentiles=[], contour_percentiles=[50, 90],
fill_color=None, contour_color=c, hist_color=c, line_color=c,
contour_ls=['solid', 'dashed'], contour_labels=False, fold_masses=True,
use_kombine=True, kdeargs={'pool': pool, 'max_samples': 200},
fig=fig, axis_dict=axd,
)
# add legend
handles = []
lbls = []
for run, c in filecolors.items():
l = filelabels[run]
handles.append(patches.Patch(color=c, label=l))
lbls.append(l)
fig.legend(loc=(0.7, 0.75), handles=handles, labels=lbls)
fig.show()
fig.savefig('./massive-3.png')
```
%% Cell type:code id:132771ea tags:
``` python
```
This diff is collapsed.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
notebook/3events-2.png

110 KiB

notebook/3events.png

88 KiB

File added
File added
File added
notebook/allresults.png

609 KiB

notebook/figs/GW150914_095045.png

25 KiB

notebook/figs/GW151012_095443.png

27.4 KiB

notebook/figs/GW151226_033853.png

27.6 KiB

notebook/figs/GW170104_101158.png

26.2 KiB

notebook/figs/GW170121_212536.png

25.3 KiB

notebook/figs/GW170202_135657.png

23.2 KiB

notebook/figs/GW170304_163753.png

22.3 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment