"tilt_1=0.5, # polar angle between primary spin and the orbital angular momentum (radians)\n",
...
...
@@ -236,7 +236,6 @@
{
"cell_type": "markdown",
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
...
...
@@ -266,9 +265,7 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"metadata": {},
"source": [
"Again, notice that the plot is saved as a \"waveform.png\" in the output dir.\n",
"\n",
...
...
@@ -277,7 +274,25 @@
]
}
],
"metadata": {},
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% Cell type:code id: tags:
```
```python
!rmvisualising_the_results/*
```
%% Cell type:markdown id: tags:
# Visualising the results
In this tutorial, we demonstrate the plotting tools built-in to `bilby` and how to extend them. First, we run a simple injection study and return the `result` object.
%% Cell type:code id: tags:
```
```python
importbilby
importmatplotlib.pyplotasplt
%matplotlibinline
time_duration=4.# time duration (seconds)
sampling_frequency=2048.# sampling frequency (Hz)
outdir='visualising_the_results'# directory in which to store output
label='example'# identifier to apply to output files
# specify injection parameters
injection_parameters=dict(
mass_1=36., # source frame (non-redshifted) primary mass (solar masses)
mass_2=29., # source frame (non-redshifted) secondary mass (solar masses)
mass_1=36.,# detector frame (redshifted) primary mass (solar masses)
mass_2=29.,# detector frame (redshifted) secondary mass (solar masses)
a_1=0.4,# primary dimensionless spin magnitude
a_2=0.3,# secondary dimensionless spin magnitude
tilt_1=0.5,# polar angle between primary spin and the orbital angular momentum (radians)
tilt_2=1.0,# polar angle between secondary spin and the orbital angular momentum
phi_12=1.7,# azimuthal angle between primary and secondary spin (radians)
phi_jl=0.3,# azimuthal angle between total angular momentum and orbital angular momentum (radians)
luminosity_distance=200.,# luminosity distance to source (Mpc)
theta_jn=0.4,# inclination angle between line of sight and orbital angular momentum (radians)
phase=1.3,# phase (radians)
ra=1.375,# source right ascension (radians)
dec=-1.2108,# source declination (radians)
geocent_time=1126259642.413,# reference time at geocentre (time of coalescence or peak amplitude) (GPS seconds)
psi=2.659# gravitational wave polarisation angle
)
# specify waveform arguments
waveform_arguments=dict(
waveform_approximant='IMRPhenomPv2',# waveform approximant name
reference_frequency=50.,# gravitational waveform reference frequency (Hz)
In running this code, we already made the first plot! In the function `bilby.detector.get_interferometer_with_fake_noise_and_injection`, the ASD, detector data, and signal are plotted together. This figure is saved under `visualsing_the_results/H1_frequency_domain_data.png`. Note that `visualising_the_result` is our `outdir` where all the output of the run is stored. Let's take a quick look at that directory now:
%% Cell type:code id: tags:
```
```python
!lsvisualising_the_results/
```
%% Cell type:markdown id: tags:
## Corner plots
Now lets make some corner plots. You can easily generate a corner plot using `result.plot_corner()` like this:
%% Cell type:code id: tags:
```
```python
result.plot_corner()
plt.show()
```
%% Cell type:markdown id: tags:
In a notebook, this figure will display. But by default the file is also saved to `visualising_the_result/example_corner.png`. If you change the label to something more descriptive then the `example` here will of course be replaced.
%% Cell type:markdown id: tags:
You may also want to plot a subset of the parameters, or perhaps add the `injection_paramters` as lines to check if you recovered them correctly. All this can be done through `plot_corner`. Under the hood, `plot_corner` uses
[chain consumer](https://samreay.github.io/ChainConsumer/index.html), and all the keyword arguments passed to `plot_corner` are passed through to [the `plot` function of chain consumer](https://samreay.github.io/ChainConsumer/chain_api.html#chainconsumer.plotter.Plotter.plot).
### Adding injection parameters to the plot
In the previous plot, you'll notice `bilby` added the injection parameters to the plot by default. You can switch this off by setting `truth=None` when you call `plot_corner`. Or to add different injection parameters to the plot, just pass this as a keyword argument for `truth`. In this example, we just add a line for the luminosity distance by passing a dictionary of the value we want to display.
Notice here, we also passed in a keyword argument `filename=`, this overwrites the default filename and instead saves the file as `visualising_the_results/subset.png`. Useful if you want to create lots of different plots. Let's check what the outdir looks like now
%% Cell type:code id: tags:
```
```python
!lsvisualising_the_results/
```
%% Cell type:markdown id: tags:
## Alternative
If you would prefer to do the plotting yourself, you can get hold of the samples and the ordering as follows and then plot with a different module. Here is an example using the [`corner`](http://corner.readthedocs.io/en/latest/) package
%% Cell type:code id: tags:
```
```python
importcorner
samples=result.samples
labels=result.parameter_labels
fig=corner.corner(samples,labels=labels)
plt.show()
```
%% Cell type:markdown id: tags:
## Other plots
We also include some other types of plots which may be useful. Again, these are built on chain consumer so you may find it useful to check the [documentation](https://samreay.github.io/ChainConsumer/chain_api.html#plotter-class) to see how these plots can be extended. Below, we show just one example of these.
#### Distribution plots
These plots just show the 1D histograms for each parameter
%% Cell type:code id: tags:
```
```python
result.plot_marginals()
plt.show()
```
%% Cell type:markdown id: tags:
#### Best-Fit Time Domain Waveform plot
Some plots specific to compact binary coalescence parameter estimation results can
be created by re-loading the result as a `CBCResult`: