Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • john-veitch/bilby
  • duncanmmacleod/bilby
  • colm.talbot/bilby
  • lscsoft/bilby
  • matthew-pitkin/bilby
  • salvatore-vitale/tupak
  • charlie.hoy/bilby
  • bfarr/bilby
  • virginia.demilio/bilby
  • vivien/bilby
  • eric-howell/bilby
  • sebastian-khan/bilby
  • rhys.green/bilby
  • moritz.huebner/bilby
  • joseph.mills/bilby
  • scott.coughlin/bilby
  • matthew.carney/bilby
  • hyungwon.lee/bilby
  • monica.rizzo/bilby
  • christopher-berry/bilby
  • lindsay.demarchi/bilby
  • kaushik.rao/bilby
  • charles.kimball/bilby
  • andrew.matas/bilby
  • juan.calderonbustillo/bilby
  • patrick-meyers/bilby
  • hannah.middleton/bilby
  • eve.chase/bilby
  • grant.meadors/bilby
  • khun.phukon/bilby
  • sumeet.kulkarni/bilby
  • daniel.reardon/bilby
  • cjhaster/bilby
  • sylvia.biscoveanu/bilby
  • james-clark/bilby
  • meg.millhouse/bilby
  • joshua.willis/bilby
  • nikhil.sarin/bilby
  • paul.easter/bilby
  • youngmin/bilby
  • daniel-williams/bilby
  • shanika.galaudage/bilby
  • bruce.edelman/bilby
  • avi.vajpeyi/bilby
  • isobel.romero-shaw/bilby
  • andrew.kim/bilby
  • dominika.zieba/bilby
  • jonathan.davies/bilby
  • marc.arene/bilby
  • srishti.tiwari/bilby-tidal-heating-eccentric
  • aditya.vijaykumar/bilby
  • michael.williams/bilby
  • cecilio.garcia-quiros/bilby
  • rory-smith/bilby
  • maite.mateu-lucena/bilby
  • wushichao/bilby
  • kaylee.desoto/bilby
  • brandon.piotrzkowski/bilby
  • rossella.gamba/bilby
  • hunter.gabbard/bilby
  • deep.chatterjee/bilby
  • tathagata.ghosh/bilby
  • arunava.mukherjee/bilby
  • philip.relton/bilby
  • reed.essick/bilby
  • pawan.gupta/bilby
  • francisco.hernandez/bilby
  • rhiannon.udall/bilby
  • leo.tsukada/bilby
  • will-farr/bilby
  • vijay.varma/bilby
  • jeremy.baier/bilby
  • joshua.brandt/bilby
  • ethan.payne/bilby
  • ka-lok.lo/bilby
  • antoni.ramos-buades/bilby
  • oliviastephany.wilk/bilby
  • jack.heinzel/bilby
  • samson.leong/bilby-psi4
  • viviana.caceres/bilby
  • nadia.qutob/bilby
  • michael-coughlin/bilby
  • hemantakumar.phurailatpam/bilby
  • boris.goncharov/bilby
  • sama.al-shammari/bilby
  • siqi.zhong/bilby
  • jocelyn-read/bilby
  • marc.penuliar/bilby
  • stephanie.letourneau/bilby
  • alexandresebastien.goettel/bilby
  • alec.gunny/bilby
  • serguei.ossokine/bilby
  • pratyusava.baral/bilby
  • sophie.hourihane/bilby
  • eunsub/bilby
  • james.hart/bilby
  • pratyusava.baral/bilby-tg
  • zhaozc/bilby
  • pratyusava.baral/bilby_SoG
  • tomasz.baka/bilby
  • nicogerardo.bers/bilby
  • soumen.roy/bilby
  • isaac.mcmahon/healpix-redundancy
  • asamakai.baker/bilby-frequency-dependent-antenna-pattern-functions
  • anna.puecher/bilby
  • pratyusava.baral/bilby-x-g
  • thibeau.wouters/bilby
  • christian.adamcewicz/bilby
  • raffi.enficiaud/bilby
109 results
Show changes
......@@ -129,13 +129,6 @@ def setup_command_line_args():
return args
def read_in_results(filename_list):
results_list = []
for filename in filename_list:
results_list.append(bilby.core.result.read_in_result(filename=filename))
return bilby.core.result.ResultList(results_list)
def print_bayes_factors(results_list):
for res in results_list:
print(f"For result {res.label}:")
......@@ -204,7 +197,7 @@ def save(result, args):
def main():
args = setup_command_line_args()
results_list = read_in_results(args.results)
results_list = bilby.core.result.read_in_result_list(args.results)
if args.save:
for result in results_list:
......
#!/usr/bin/env python
"""
An example of how to use bilby to perform parameter estimation for
non-gravitational wave data. In this case, fitting a linear function to
data with background Gaussian noise. We then compare the result to posteriors
estimated using the Fisher Information Matrix approximation.
"""
import copy
import bilby
import numpy as np
# A few simple setup steps
outdir = "outdir"
np.random.seed(123)
# First, we define our "signal model", in this case a simple linear function
def model(time, m, c):
return time * m + c
# Now we define the injection parameters which we make simulated data with
injection_parameters = dict(m=0.5, c=0.2)
# For this example, we'll use standard Gaussian noise
# These lines of code generate the fake data. Note the ** just unpacks the
# contents of the injection_parameters when calling the model function.
sampling_frequency = 10
time_duration = 10
time = np.arange(0, time_duration, 1 / sampling_frequency)
N = len(time)
sigma = np.random.normal(1, 0.01, N)
data = model(time, **injection_parameters) + np.random.normal(0, sigma, N)
# Now lets instantiate a version of our GaussianLikelihood, giving it
# the time, data and signal model
likelihood = bilby.likelihood.GaussianLikelihood(time, data, model, sigma)
# From hereon, the syntax is exactly equivalent to other bilby examples
# We make a prior
priors = dict()
priors["m"] = bilby.core.prior.Uniform(0, 5, "m")
priors["c"] = bilby.core.prior.Uniform(-2, 2, "c")
priors = bilby.core.prior.PriorDict(priors)
# And run sampler
result = bilby.run_sampler(
likelihood=likelihood,
priors=priors,
sampler="dynesty",
nlive=1000,
injection_parameters=injection_parameters,
outdir=outdir,
label="Nested Sampling",
)
# Finally plot a corner plot: all outputs are stored in outdir
result.plot_corner()
fim = bilby.core.fisher.FisherMatrixPosteriorEstimator(likelihood, priors)
result_fim = copy.deepcopy(result)
result_fim.posterior = fim.sample_dataframe("maxL", 10000)
result_fim.label = "Fisher"
bilby.core.result.plot_multiple(
[result, result_fim], parameters=injection_parameters, truth_color="k"
)
#!/usr/bin/env python
"""
Tutorial to demonstrate running parameter estimation on a binary neutron star
with equation of state inference using a 3 piece dynamic polytrope model.
This example estimates the masses and polytrope model parameters.
This polytrope model is generically introduced in https://arxiv.org/pdf/1804.04072.pdf.
LALSimulation has an implementation of this generic model with 3 polytrope pieces attached
to a crust EOS, and that can be found in LALSimNeutronStarEOSDynamicPolytrope.c.
Details on a 4 piece static polytrope model can be found here https://arxiv.org/pdf/0812.2163.pdf.
The reparameterization here uses a 3-piece dynamic polytrope model implemented in lalsimulation
LALSimNeutronStarEOSDynamicPolytrope.c.
"""
import bilby
import numpy as np
# Specify the output directory and the name of the simulation.
outdir = "outdir"
label = "bns_polytrope_eos_simulation"
bilby.core.utils.setup_logger(outdir=outdir, label=label)
# Set up a random seed for result reproducibility. This is optional!
np.random.seed(88170235)
# We are going to inject a binary neutron star waveform with component mass and lambda
# values consistent with the MPA1 equation of state.
# The lambda values are generated from LALSimNeutronStarEOS_MPA1.dat
# lalsim-ns-params -n MPA1 -m 1.523194
# lalsim-ns-params -n MPA1 -m 1.5221469
# Note that we injection with tidal params (lambdas) but recover in eos model params.
injection_parameters = dict(
mass_1=1.523194,
mass_2=1.5221469,
lambda_1=311.418,
lambda_2=312.717,
chi_1=0.0001,
chi_2=0.0001,
luminosity_distance=57.628867,
theta_jn=0.66246341,
psi=0.18407784,
phase=5.4800181,
geocent_time=10.0,
ra=3.6309322,
dec=-0.30355747,
)
# Set the duration and sampling frequency of the data segment that we're going
# to inject the signal into. For the
# TaylorF2 waveform, we cut the signal close to the isco frequency
duration = 64
sampling_frequency = 2 * 2048
start_time = injection_parameters["geocent_time"] + 2 - duration
# Fixed arguments passed into the source model. The analysis starts at 40 Hz.
waveform_arguments = dict(
waveform_approximant="TaylorF2",
reference_frequency=30.0,
minimum_frequency=30.0,
)
# Create the waveform_generator using a LAL Binary Neutron Star source function
waveform_generator = bilby.gw.WaveformGenerator(
duration=duration,
sampling_frequency=sampling_frequency,
frequency_domain_source_model=bilby.gw.source.lal_binary_neutron_star,
parameter_conversion=bilby.gw.conversion.convert_to_lal_binary_neutron_star_parameters,
waveform_arguments=waveform_arguments,
)
# Set up interferometers. In this case we'll use three interferometers
# (LIGO-Hanford (H1), LIGO-Livingston (L1), and Virgo (V1)).
# These default to their design sensitivity and start at 40 Hz.
interferometers = bilby.gw.detector.InterferometerList(["H1", "L1", "V1"])
for interferometer in interferometers:
interferometer.minimum_frequency = 30.0
interferometers.set_strain_data_from_zero_noise(
sampling_frequency=sampling_frequency, duration=duration, start_time=start_time
)
interferometers.inject_signal(
parameters=injection_parameters, waveform_generator=waveform_generator
)
# Load the default prior for binary neutron stars.
# We're going to sample in chirp_mass, mass_ratio, and model parameters
# rather than mass_1, mass_2, or lamba_tilde, delta_lambda_tilde.
# BNS have aligned spins by default, if you want to allow precessing spins
# pass aligned_spin=False to the BNSPriorDict
priors = bilby.gw.prior.BNSPriorDict()
priors["chirp_mass"] = bilby.gw.prior.Uniform(0.4, 4.4)
priors["mass_ratio"] = bilby.gw.prior.Uniform(0.125, 1)
# The following are dynamic polytrope model priors
# They are required for EOS inference
priors["eos_polytrope_gamma_0"] = bilby.core.prior.Uniform(
1.0, 5.0, name="Gamma0", latex_label="$\\Gamma_0$"
)
priors["eos_polytrope_gamma_1"] = bilby.core.prior.Uniform(
1.0, 5.0, name="Gamma1", latex_label="$\\Gamma_1$"
)
priors["eos_polytrope_gamma_2"] = bilby.core.prior.Uniform(
1.0, 5.0, name="Gamma2", latex_label="$\\Gamma_2$"
)
"""
One can run this model without the reparameterization using the following
priors in place of the scaled pressure priors. The reparameterization approximates
the flat priors in pressure however the reparameterization initializes twice as fast.
priors["eos_polytrope_log10_pressure_1"] = bilby.core.prior.Uniform(
34.0, 37.0, name="plogp1", latex_label="$log(p_1)$"
)
priors["eos_polytrope_log10_pressure_2"] = bilby.core.prior.Uniform(
34.0, 37.0, name="plogp2", latex_label="$log(p_2)$"
)
"""
priors["eos_polytrope_scaled_pressure_ratio"] = bilby.core.prior.Uniform(
minimum=0.0, maximum=1, name="Pressure_Ratio", latex_label="$\\rho$"
)
priors["eos_polytrope_scaled_pressure_2"] = bilby.core.prior.Triangular(
minimum=0.0, maximum=4.0, mode=4, name="Pressure_offset", latex_label="$p_0$"
)
priors["eos_check"] = bilby.gw.prior.EOSCheck()
# The eos_check sets up a rejection prior for sampling.
# It should be enabled for all eos runs.
# Pinning other parameters to their injected values.
for key in [
"luminosity_distance",
"geocent_time",
"chi_1",
"chi_2",
"psi",
"phase",
"ra",
"dec",
"theta_jn",
]:
priors[key] = injection_parameters[key]
# Remove tidal parameters from our priors.
priors.pop("lambda_1")
priors.pop("lambda_2")
# Initialise the likelihood by passing in the interferometer data (IFOs)
# and the waveform generator
likelihood = bilby.gw.GravitationalWaveTransient(
interferometers=interferometers,
waveform_generator=waveform_generator,
time_marginalization=False,
phase_marginalization=False,
distance_marginalization=False,
priors=priors,
)
# Run sampler. This model has mostly been testing with the `dynesty` sampler.
result = bilby.run_sampler(
conversion_function=bilby.gw.conversion.generate_all_bns_parameters,
likelihood=likelihood,
priors=priors,
sampler="dynesty",
nlive=1000,
dlogz=0.1,
injection_parameters=injection_parameters,
outdir=outdir,
label=label,
)
result.plot_corner()
#!/usr/bin/env python
"""
Tutorial to demonstrate running parameter estimation on a binary neutron star
with equation of state inference using a spectral decomposition model.
This example estimates the masses and spectral model parameters.
Details on the spectral model can be found in https://arxiv.org/pdf/1805.11217.pdf.
The principal component analysis (PCA) used for the spectral model here can be found
in the appendix of https://arxiv.org/pdf/2001.01747.pdf.
"""
import bilby
import numpy as np
# Specify the output directory and the name of the simulation.
outdir = "outdir"
label = "bns_spectral_eos_simulation"
bilby.core.utils.setup_logger(outdir=outdir, label=label)
# Set up a random seed for result reproducibility. This is optional!
np.random.seed(88170235)
# We are going to inject a binary neutron star waveform with component mass and lambda
# values consistent with the MPA1 equation of state.
# The lambda values are generated from LALSimNeutronStarEOS_MPA1.dat
# lalsim-ns-params -n MPA1 -m 1.523194
# lalsim-ns-params -n MPA1 -m 1.5221469
# Note that we injection with tidal params (lambdas) but recover in eos model params.
injection_parameters = dict(
mass_1=1.523194,
mass_2=1.5221469,
lambda_1=311.418,
lambda_2=312.717,
chi_1=0.0001,
chi_2=0.0001,
luminosity_distance=57.628867,
theta_jn=0.66246341,
psi=0.18407784,
phase=5.4800181,
geocent_time=10.0,
ra=3.6309322,
dec=-0.30355747,
)
# Set the duration and sampling frequency of the data segment that we're going
# to inject the signal into. For the
# TaylorF2 waveform, we cut the signal close to the isco frequency
duration = 64
sampling_frequency = 2 * 2048
start_time = injection_parameters["geocent_time"] + 2 - duration
# Fixed arguments passed into the source model. The analysis starts at 40 Hz.
waveform_arguments = dict(
waveform_approximant="TaylorF2",
reference_frequency=30.0,
minimum_frequency=30.0,
)
# Create the waveform_generator using a LAL Binary Neutron Star source function
waveform_generator = bilby.gw.WaveformGenerator(
duration=duration,
sampling_frequency=sampling_frequency,
frequency_domain_source_model=bilby.gw.source.lal_binary_neutron_star,
parameter_conversion=bilby.gw.conversion.convert_to_lal_binary_neutron_star_parameters,
waveform_arguments=waveform_arguments,
)
# Set up interferometers. In this case we'll use three interferometers
# (LIGO-Hanford (H1), LIGO-Livingston (L1), and Virgo (V1)).
# These default to their design sensitivity and start at 30 Hz.
interferometers = bilby.gw.detector.InterferometerList(["H1", "L1", "V1"])
for interferometer in interferometers:
interferometer.minimum_frequency = 30.0
interferometers.set_strain_data_from_zero_noise(
sampling_frequency=sampling_frequency, duration=duration, start_time=start_time
)
interferometers.inject_signal(
parameters=injection_parameters, waveform_generator=waveform_generator
)
# Load the default prior for binary neutron stars.
# We're going to sample in chirp_mass, mass_ratio, and model parameters
# rather than mass_1, mass_2, or lamba_tilde, delta_lambda_tilde.
# BNS have aligned spins by default, if you want to allow precessing spins
# pass aligned_spin=False to the BNSPriorDict
priors = bilby.gw.prior.BNSPriorDict()
# The following are spectral decomposition model priors
# Note that we sample in 'eos_spectral_pca_gamma_*', which is a
# prior space that enables more efficient. These parameters are
# subsequently converted to the spectral decomposition model space.
# These priors are required for EOS inference
priors["eos_spectral_pca_gamma_0"] = bilby.core.prior.Uniform(
-4.37722, 4.91227, name="pca_gamma0", latex_label="$\\gamma^{pca}_0$"
)
priors["eos_spectral_pca_gamma_1"] = bilby.core.prior.Uniform(
-1.82240, 2.06387, name="pca_gamma1", latex_label="$\\gamma^{pca}_1$"
)
priors["eos_spectral_pca_gamma_2"] = bilby.core.prior.Uniform(
-0.32445, 0.36469, name="pca_gamma2", latex_label="$\\gamma^{pca}_2$"
)
priors["eos_spectral_pca_gamma_3"] = bilby.core.prior.Uniform(
-0.09529, 0.11046, name="pca_gamma3", latex_label="$\\gamma^{pca}_3$"
)
priors["eos_check"] = bilby.gw.prior.EOSCheck()
# The eos_check sets up a rejection prior for sampling.
# It should be enabled for all eos runs.
# Pinning other parameters to their injected values.
for key in [
"luminosity_distance",
"geocent_time",
"chi_1",
"chi_2",
"psi",
"phase",
"ra",
"dec",
"theta_jn",
]:
priors[key] = injection_parameters[key]
# Remove tidal parameters from our priors.
priors.pop("lambda_1")
priors.pop("lambda_2")
# Initialise the likelihood by passing in the interferometer data (IFOs)
# and the waveform generator
likelihood = bilby.gw.GravitationalWaveTransient(
interferometers=interferometers,
waveform_generator=waveform_generator,
time_marginalization=False,
phase_marginalization=False,
distance_marginalization=False,
priors=priors,
)
# Run sampler. This model has mostly been testing with the `dynesty` sampler.
result = bilby.run_sampler(
conversion_function=bilby.gw.conversion.generate_all_bns_parameters,
likelihood=likelihood,
priors=priors,
sampler="dynesty",
nlive=1000,
dlogz=0.1,
injection_parameters=injection_parameters,
outdir=outdir,
label=label,
)
result.plot_corner()
......@@ -129,6 +129,8 @@ class TestProposals(TestBaseProposals):
def proposal_check(self, prop, ndim=2, N=100):
chain = self.create_chain(ndim=ndim)
if getattr(prop, 'needs_likelihood_and_priors', False):
return
print(f"Testing {prop.__class__.__name__}")
# Timing and return type
......
......@@ -135,6 +135,27 @@ class TestPriorClasses(unittest.TestCase):
minimum=5e0,
maximum=1e2,
),
bilby.core.prior.Triangular(
name="test",
unit="unit",
minimum=-1.1,
maximum=3.14,
mode=0.,
),
bilby.core.prior.Triangular(
name="test",
unit="unit",
minimum=0.,
maximum=4.,
mode=4.,
),
bilby.core.prior.Triangular(
name="test",
unit="unit",
minimum=2.,
maximum=5.,
mode=2.,
),
bilby.gw.prior.ConditionalUniformComovingVolume(
condition_func=condition_func, name="redshift", minimum=0.1, maximum=1.0
),
......@@ -702,6 +723,7 @@ class TestPriorClasses(unittest.TestCase):
bilby.core.prior.Gamma,
bilby.core.prior.MultivariateGaussian,
bilby.core.prior.FermiDirac,
bilby.core.prior.Triangular,
bilby.gw.prior.HealPixPrior,
),
):
......@@ -725,6 +747,7 @@ class TestPriorClasses(unittest.TestCase):
bilby.core.prior.Gamma,
bilby.core.prior.MultivariateGaussian,
bilby.core.prior.FermiDirac,
bilby.core.prior.Triangular,
bilby.gw.prior.HealPixPrior,
),
):
......
......@@ -59,9 +59,10 @@ class TestResult(unittest.TestCase):
d=2,
)
)
self.outdir = "test_outdir"
result = bilby.core.result.Result(
label="label",
outdir="outdir",
outdir=self.outdir,
sampler="nestle",
search_parameter_keys=["x", "y"],
fixed_parameter_keys=["c", "d"],
......@@ -87,7 +88,7 @@ class TestResult(unittest.TestCase):
def tearDown(self):
bilby.utils.command_line_args.bilby_test_mode = True
try:
shutil.rmtree(self.result.outdir)
shutil.rmtree(self.outdir)
except OSError:
pass
del self.result
......@@ -491,6 +492,40 @@ class TestResult(unittest.TestCase):
self.assertTrue(np.array_equal(az.log_likelihood["log_likelihood"].values.squeeze(),
log_likelihood))
def test_result_caching(self):
class SimpleLikelihood(bilby.Likelihood):
def __init__(self):
super().__init__(parameters={"x": None})
def log_likelihood(self):
return -self.parameters["x"]**2
likelihood = SimpleLikelihood()
priors = dict(x=bilby.core.prior.Uniform(-5, 5, "x"))
# Trivial subclass of Result
class NotAResult(bilby.core.result.Result):
pass
result = bilby.run_sampler(
likelihood, priors, sampler='bilby_mcmc', nsamples=10, L1steps=1,
proposal_cycle="default_noGMnoKD", printdt=1,
check_point_plot=False,
result_class=NotAResult)
# result should be specified result_class
assert isinstance(result, NotAResult)
cached_result = bilby.run_sampler(
likelihood, priors, sampler='bilby_mcmc', nsamples=10, L1steps=1,
proposal_cycle="default_noGMnoKD", printdt=1,
check_point_plot=False,
result_class=NotAResult)
# so should a result loaded from cache
assert isinstance(cached_result, NotAResult)
class TestResultListError(unittest.TestCase):
def setUp(self):
......
......@@ -3,7 +3,6 @@ import unittest
import numpy as np
import pandas as pd
import bilby
from bilby.gw import conversion
......@@ -658,5 +657,217 @@ class TestGenerateMassParameters(unittest.TestCase):
self.expected_values, source=True)
class TestEquationOfStateConversions(unittest.TestCase):
'''
Class to test equation of state conversions.
The test points were generated from a simulation independent of bilby using the original lalsimulation calls.
Specific cases tested are described within each function.
'''
def setUp(self):
self.mass_1_source_spectral = [
4.922542724434885,
4.350626907771598,
4.206155335439082,
1.7822696459661311,
1.3091740103047926
]
self.mass_2_source_spectral = [
3.459974694590303,
1.2276461777181447,
3.7287707089639976,
0.3724016563531846,
1.055042934805801
]
self.spectral_pca_gamma_0 = [
0.7074873121348357,
0.05855931126849878,
0.7795329261793462,
1.467907561566463,
2.9066488405635624
]
self.spectral_pca_gamma_1 = [
-0.29807111670823816,
2.027708558522935,
-1.4415775226512115,
-0.7104870098896858,
-0.4913817181089619
]
self.spectral_pca_gamma_2 = [
0.25625095371021156,
-0.19574096643220049,
-0.2710238103460012,
0.22815820981582358,
-0.1543413205016374
]
self.spectral_pca_gamma_3 = [
-0.04030365100175101,
0.05698030777919032,
-0.045595911403040264,
-0.023480394227900117,
-0.07114492992285618
]
self.spectral_gamma_0 = [
1.1259406796075457,
0.3191335618787259,
1.3651245109783452,
1.3540140238735314,
1.4551949842961993
]
self.spectral_gamma_1 = [
0.26791504475282835,
0.3930374252139248,
0.11438399886108475,
0.14181113477953,
-0.11989033256620368
]
self.spectral_gamma_2 = [
-0.06810849354463173,
-0.038250139296677754,
-0.0801540229444505,
-0.05230330841791625,
-0.005197303281460286
]
self.spectral_gamma_3 = [
0.002848121360389597,
0.000872447754855139,
0.005528747386660879,
0.0024325946344566484,
0.00043890906202786106
]
self.mass_1_source_polytrope = [
2.2466565877822573,
2.869741556013239,
4.123897187899834,
2.014160764697004,
1.414796714032148,
2.0919349759766614
]
self.mass_2_source_polytrope = [
0.36696047254774256,
0.8580637120326807,
1.650477659961306,
1.310399737462001,
0.5470843356210495,
1.2311162283818198
]
self.polytrope_log10_pressure_1 = [
34.05849276958394,
33.06962096113144,
33.07579629429792,
33.93412833210738,
34.24096323517809,
35.293288373856534
]
self.polytrope_log10_pressure_2 = [
33.82891829901602,
35.14230456819543,
34.940095188881976,
34.72710820593933,
35.42780071717415,
35.648689969687915
]
self.polytrope_gamma_0 = [
2.359580734009537,
2.3111471709796945,
4.784129809424835,
1.4900432021657437,
1.0037220431922798,
4.183994058757201
]
self.polytrope_gamma_1 = [
1.9497583698697314,
1.0141111305083874,
2.8228335336587826,
4.032519623275465,
1.10894361284508,
3.168076721819637
]
self.polytrope_gamma_2 = [
4.6001755196585385,
4.424090418206996,
4.429607300132092,
1.8176338276795763,
2.9938859949129797,
1.300271383168368
]
self.lambda_1_spectral = [0., 0., 0., 0., 1275.7253186286332]
self.lambda_2_spectral = [0., 0., 0., 0., 4504.897675043909]
self.lambda_1_polytrope = [0., 0., 0., 0., 0., 234.66424898184766]
self.lambda_2_polytrope = [0., 0., 0., 0., 0., 3710.931378294547]
self.eos_check_spectral = [0, 0, 0, 0, 1]
self.eos_check_polytrope = [0, 0, 0, 0, 0, 1]
def test_spectral_pca_to_spectral(self):
for i in range(len(self.mass_1_source_spectral)):
spectral_gamma_0, spectral_gamma_1, spectral_gamma_2, spectral_gamma_3 = \
conversion.spectral_pca_to_spectral(
self.spectral_pca_gamma_0[i],
self.spectral_pca_gamma_1[i],
self.spectral_pca_gamma_2[i],
self.spectral_pca_gamma_3[i]
)
self.assertAlmostEqual(spectral_gamma_0, self.spectral_gamma_0[i], places=5)
self.assertAlmostEqual(spectral_gamma_1, self.spectral_gamma_1[i], places=5)
self.assertAlmostEqual(spectral_gamma_2, self.spectral_gamma_2[i], places=5)
self.assertAlmostEqual(spectral_gamma_3, self.spectral_gamma_3[i], places=5)
def test_spectral_params_to_lambda_1_lambda_2(self):
'''
The points cover 5 test cases:
- Fail SimNeutronStarEOS4ParamSDGammaCheck()
- Fail max_speed_of_sound_ <=1.1
- Fail mass_1_source <= max_mass
- Fail mass_2_source >= min_mass
- Passes all and produces accurate lambda_1, lambda_2, eos_check values
'''
for i in range(len(self.mass_1_source_spectral)):
spectral_gamma_0, spectral_gamma_1, spectral_gamma_2, spectral_gamma_3 = \
conversion.spectral_pca_to_spectral(
self.spectral_pca_gamma_0[i],
self.spectral_pca_gamma_1[i],
self.spectral_pca_gamma_2[i],
self.spectral_pca_gamma_3[i]
)
lambda_1, lambda_2, eos_check = \
conversion.spectral_params_to_lambda_1_lambda_2(
spectral_gamma_0,
spectral_gamma_1,
spectral_gamma_2,
spectral_gamma_3,
self.mass_1_source_spectral[i],
self.mass_2_source_spectral[i]
)
self.assertAlmostEqual(self.lambda_1_spectral[i], lambda_1, places=0)
self.assertAlmostEqual(self.lambda_2_spectral[i], lambda_2, places=0)
self.assertAlmostEqual(self.eos_check_spectral[i], eos_check)
def test_polytrope_or_causal_params_to_lambda_1_lambda_2_causal(self):
'''
The points cover 6 test cases:
- Fail log10_pressure1 >= log10_pressure2
- Fail SimNeutronStarEOS3PDViableFamilyCheck()
- Fail max_speed_of_sound_ <= 1.1
- Fail mass_1_source <= max_mass
- Fail mass_2_source >= min_mass
- Passes all and produces accurate lambda_1, lambda_2, eos_check values
'''
for i in range(len(self.mass_1_source_polytrope)):
lambda_1, lambda_2, eos_check = \
conversion.polytrope_or_causal_params_to_lambda_1_lambda_2(
self.polytrope_gamma_0[i],
self.polytrope_log10_pressure_1[i],
self.polytrope_gamma_1[i],
self.polytrope_log10_pressure_2[i],
self.polytrope_gamma_2[i],
self.mass_1_source_polytrope[i],
self.mass_2_source_polytrope[i],
0
)
self.assertAlmostEqual(self.lambda_1_polytrope[i], lambda_1, places=3)
self.assertAlmostEqual(self.lambda_2_polytrope[i], lambda_2, places=3)
self.assertAlmostEqual(self.eos_check_polytrope[i], eos_check)
if __name__ == "__main__":
unittest.main()
......@@ -950,14 +950,14 @@ class TestCreateROQLikelihood(unittest.TestCase):
class TestInOutROQWeights(unittest.TestCase):
@parameterized.expand(['npz', 'json', 'hdf5'])
@parameterized.expand(['npz', 'hdf5'])
def test_out_single_basis(self, format):
likelihood = self.create_likelihood_single_basis()
filename = f'weights.{format}'
likelihood.save_weights(filename, format=format)
self.assertTrue(os.path.exists(filename))
@parameterized.expand(['npz', 'json', 'hdf5'])
@parameterized.expand(['npz', 'hdf5'])
def test_in_single_basis(self, format):
likelihood = self.create_likelihood_single_basis()
filename = f'weights.{format}'
......