Commit 1feb9438 authored by Colm Talbot's avatar Colm Talbot

start setting up some post processing

parent 67c21364
Pipeline #17699 failed with stages
in 1 minute and 53 seconds
import logging
import os
import numpy as np
import deepdish
from chainconsumer import ChainConsumer
import pandas as pd
class Result(dict):
......@@ -113,4 +115,32 @@ class Result(dict):
fig = c.plotter.plot_distributions(**kwargs)
return fig
def samples_to_data_frame(self):
"""
Convert array of samples to data frame.
:return:
"""
data_frame = pd.DataFrame(self.samples, columns=self.search_parameter_keys)
self.posterior = data_frame
for key in self.fixed_parameter_keys:
self.posterior[key] = self.prior[key].sample(len(self.posterior))
def construct_cbc_derived_parameters(self):
"""
Construct widely used derived parameters of CBCs
:return:
"""
self.posterior['mass_chirp'] = (self.posterior.mass_1 * self.posterior.mass_2)**0.6 \
/ (self.posterior.mass_1 + self.posterior.mass_2)**0.2
self.posterior['q'] = self.posterior.mass_2 / self.posterior.mass_1
self.posterior['eta'] = (self.posterior.mass_1 * self.posterior.mass_2) \
/ (self.posterior.mass_1 + self.posterior.mass_2)**2
self.posterior['chi_eff'] = (self.posterior.a_1 * np.cos(self.posterior.tilt_1)
+ self.posterior.q * self.posterior.a_2 * np.cos(self.posterior.tilt_2))\
/ (1 + self.posterior.q)
self.posterior['chi_p'] = max(self.posterior.a_1 * np.sin(self.posterior.tilt_1),
(4 * self.posterior.q + 3) / (3 * self.posterior.q + 4) * self.posterior.q
* self.posterior.a_2 * np.sin(self.posterior.tilt_2))
\ No newline at end of file
......@@ -300,6 +300,8 @@ def run_sampler(likelihood, priors, label='label', outdir='outdir',
else:
result.log_bayes_factor = result.logz - result.noise_logz
result.injection_parameters = injection_parameters
result.prior = prior
result.samples_to_data_frame()
result.save_to_file(outdir=outdir, label=label)
return result
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment