diff --git a/CHANGELOG.md b/CHANGELOG.md index 9da7f48fa0fa9bc3014d68c59d0712c67151a1f6..9172cf23699628cae4cf0c5315524545079cf923 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Changes currently on master, but not under a tag. - Hyperparameter estimation now enables the user to provide the single event evidences - Add nested samples to nestle output - Prior and child classes now implement the \_\_eq\_\_ magic method for comparisons +- Add AlignedSpin gw prior ### Changes - Fix construct_cbc_derived_parameters diff --git a/test/prior_test.py b/test/prior_test.py index 3b22b6c60f2a9673b404e538c2d07665a59055e8..89047308738512b59799c994f90fb48ea3137309 100644 --- a/test/prior_test.py +++ b/test/prior_test.py @@ -7,7 +7,6 @@ import os import shutil from collections import OrderedDict - class TestPriorInstantiationWithoutOptionalPriors(unittest.TestCase): def setUp(self): @@ -152,7 +151,8 @@ class TestPriorClasses(unittest.TestCase): tupak.core.prior.Cauchy(name='test', unit='unit', alpha=0, beta=1), tupak.core.prior.Lorentzian(name='test', unit='unit', alpha=0, beta=1), tupak.core.prior.Gamma(name='test', unit='unit', k=1, theta=1), - tupak.core.prior.ChiSquared(name='test', unit='unit', nu=2) + tupak.core.prior.ChiSquared(name='test', unit='unit', nu=2), + tupak.gw.prior.AlignedSpin(name='test', unit='unit') ] def test_minimum_rescaling(self): diff --git a/tupak/gw/prior.py b/tupak/gw/prior.py index e876b25440788d4b645ca78541ab74eb03ffbaa3..d45f2a7eedc314242aa0618ecdabc60a416a0309 100644 --- a/tupak/gw/prior.py +++ b/tupak/gw/prior.py @@ -1,5 +1,6 @@ import os -from ..core.prior import PriorSet, FromFile, Prior, DeltaFunction, Gaussian +from ..core.prior import (PriorSet, Uniform, FromFile, Prior, DeltaFunction, + Gaussian, Interped) from ..core.utils import logger import numpy as np from scipy.interpolate import UnivariateSpline @@ -26,6 +27,43 @@ class UniformComovingVolume(FromFile): latex_label=latex_label, unit='Mpc') +class AlignedSpin(Interped): + + def __init__(self, a_prior=Uniform(0, 1), z_prior=Uniform(-1, 1), + name=None, latex_label=None, unit=None): + """ + Prior distribution for the aligned (z) component of the spin. + + This takes prior distributions for the magnitude and cosine of the tilt + and forms a compound prior. + + This is useful when using aligned-spin only waveform approximants. + + This is an extension of e.g., (A7) of https://arxiv.org/abs/1805.10457. + + Parameters + ---------- + a_prior: Prior + Prior distribution for spin magnitude + z_prior: Prior + Prior distribution for cosine spin tilt + name: see superclass + latex_label: see superclass + unit: see superclass + """ + self.a_prior = a_prior + self.z_prior = z_prior + chi_min = min(a_prior.maximum * z_prior.minimum, + a_prior.minimum * z_prior.maximum) + chi_max = a_prior.maximum * z_prior.maximum + xx = np.linspace(chi_min, chi_max, 800) + aas = np.linspace(a_prior.minimum, a_prior.maximum, 1000) + yy = [np.trapz(np.nan_to_num(a_prior.prob(aas) / aas * + z_prior.prob(x / aas)), aas) for x in xx] + Interped.__init__(self, xx=xx, yy=yy, name=name, + latex_label=latex_label, unit=unit) + + class BBHPriorSet(PriorSet): def __init__(self, dictionary=None, filename=None): """ Initialises a Prior set for Binary Black holes