Commit d4c24a07 authored by Moritz Huebner's avatar Moritz Huebner
Browse files

Revert "Renamed"

This reverts commit e577ba98
parent 534223a8
Pipeline #34423 passed with stage
in 9 minutes and 26 seconds
......@@ -15,7 +15,7 @@ import bilby # noqa
import inspect
class PriorDict(OrderedDict):
class PriorSet(OrderedDict):
def __init__(self, dictionary=None, filename=None):
""" A set of priors
......@@ -238,14 +238,6 @@ class PriorDict(OrderedDict):
return False
class PriorSet(PriorDict):
def __init__(self, dictionary=None, filename=None):
""" DEPRECATED: USE PriorDict INSTEAD"""
logger.warning("The name 'PriorSet' is deprecated use 'PriorDict' instead")
super(PriorSet, self).__init__(dictionary, filename)
def create_default_prior(name, default_priors_file=None):
"""Make a default prior for a parameter with a known name.
......@@ -269,7 +261,7 @@ def create_default_prior(name, default_priors_file=None):
"No prior file given.")
prior = None
else:
default_priors = PriorDict(filename=default_priors_file)
default_priors = PriorSet(filename=default_priors_file)
if name in default_priors.keys():
prior = default_priors[name]
else:
......
......@@ -10,7 +10,7 @@ from collections import OrderedDict
from . import utils
from .utils import logger, infer_parameters_from_function
from .prior import PriorDict, DeltaFunction
from .prior import PriorSet, DeltaFunction
def result_file_name(outdir, label):
......@@ -81,7 +81,7 @@ class Result(dict):
setattr(self, key, val)
if getattr(self, 'priors', None) is not None:
self.priors = PriorDict(self.priors)
self.priors = PriorSet(self.priors)
def __add__(self, other):
matches = ['sampler', 'search_parameter_keys']
......
......@@ -4,7 +4,7 @@ import datetime
from collections import OrderedDict
from ..utils import command_line_args, logger
from ..prior import PriorDict
from ..prior import PriorSet
from .base_sampler import Sampler
from .cpnest import Cpnest
......@@ -101,8 +101,8 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir',
priors = dict()
if type(priors) in [dict, OrderedDict]:
priors = PriorDict(priors)
elif isinstance(priors, PriorDict):
priors = PriorSet(priors)
elif isinstance(priors, PriorSet):
pass
else:
raise ValueError("Input priors not understood")
......
......@@ -3,7 +3,7 @@ import datetime
import numpy as np
from pandas import DataFrame
from ..utils import logger, command_line_args
from ..prior import Prior, PriorDict
from ..prior import Prior, PriorSet
from ..result import Result, read_in_result
......@@ -35,7 +35,7 @@ class Sampler(object):
-------
likelihood: likelihood.Likelihood
A object with a log_l method
priors: bilby.core.prior.PriorDict
priors: bilby.core.prior.PriorSet
Priors to be used in the search.
This has attributes for each parameter to be sampled.
external_sampler: Module
......@@ -74,10 +74,10 @@ class Sampler(object):
self, likelihood, priors, outdir='outdir', label='label',
use_ratio=False, plot=False, skip_import_verification=False, **kwargs):
self.likelihood = likelihood
if isinstance(priors, PriorDict):
if isinstance(priors, PriorSet):
self.priors = priors
else:
self.priors = PriorDict(priors)
self.priors = PriorSet(priors)
self.label = label
self.outdir = outdir
self.use_ratio = use_ratio
......
......@@ -12,7 +12,7 @@ from ..core import likelihood
from ..core.utils import logger
from ..core.prior import Prior, Uniform
from .detector import InterferometerList
from .prior import BBHPriorDict
from .prior import BBHPriorSet
from .source import lal_binary_black_hole
from .utils import noise_weighted_inner_product
from .waveform_generator import WaveformGenerator
......@@ -122,7 +122,7 @@ class GravitationalWaveTransient(likelihood.Likelihood):
self.interferometers.start_time,
self.interferometers.start_time + self.interferometers.duration)
else:
self.prior[key] = BBHPriorDict()[key]
self.prior[key] = BBHPriorSet()[key]
@property
def prior(self):
......
import os
import numpy as np
from scipy.interpolate import UnivariateSpline
from ..core.prior import (PriorDict, Uniform, FromFile, Prior, DeltaFunction,
from ..core.prior import (PriorSet, Uniform, FromFile, Prior, DeltaFunction,
Gaussian, Interped)
from ..core.utils import logger
......@@ -65,7 +65,7 @@ class AlignedSpin(Interped):
latex_label=latex_label, unit=unit)
class BBHPriorDict(PriorDict):
class BBHPriorSet(PriorSet):
def __init__(self, dictionary=None, filename=None):
""" Initialises a Prior set for Binary Black holes
......@@ -82,7 +82,7 @@ class BBHPriorDict(PriorDict):
elif filename is not None:
if not os.path.isfile(filename):
filename = os.path.join(os.path.dirname(__file__), 'prior_files', filename)
PriorDict.__init__(self, dictionary=dictionary, filename=filename)
PriorSet.__init__(self, dictionary=dictionary, filename=filename)
def test_redundancy(self, key):
"""
......@@ -135,15 +135,7 @@ class BBHPriorDict(PriorDict):
return redundant
class BBHPriorSet(BBHPriorDict):
def __init__(self, dictionary=None, filename=None):
""" DEPRECATED: USE BBHPriorDict INSTEAD"""
logger.warning("The name 'BBHPriorSet' is deprecated use 'BBHPriorDict' instead")
super(BBHPriorSet, self).__init__(dictionary, filename)
class BNSPriorDict(PriorDict):
class BNSPriorSet(PriorSet):
def __init__(self, dictionary=None, filename=None):
""" Initialises a Prior set for Binary Neutron Stars
......@@ -161,10 +153,10 @@ class BNSPriorDict(PriorDict):
elif filename is not None:
if not os.path.isfile(filename):
filename = os.path.join(os.path.dirname(__file__), 'prior_files', filename)
PriorDict.__init__(self, dictionary=dictionary, filename=filename)
PriorSet.__init__(self, dictionary=dictionary, filename=filename)
def test_redundancy(self, key):
bbh_redundancy = BBHPriorDict().test_redundancy(key)
bbh_redundancy = BBHPriorSet().test_redundancy(key)
if bbh_redundancy:
return True
redundant = False
......@@ -182,14 +174,6 @@ class BNSPriorDict(PriorDict):
return redundant
class BNSPriorSet(BNSPriorDict):
def __init__(self, dictionary=None, filename=None):
""" DEPRECATED: USE BNSPriorDict INSTEAD"""
super(BNSPriorSet, self).__init__(dictionary, filename)
logger.warning("The name 'BNSPriorSet' is deprecated use 'BNSPriorDict' instead")
Prior._default_latex_labels = {
'mass_1': '$m_1$',
'mass_2': '$m_2$',
......@@ -219,7 +203,7 @@ Prior._default_latex_labels = {
'delta_lambda': '$\\delta\\Lambda$'}
class CalibrationPriorDict(PriorDict):
class CalibrationPriorSet(PriorSet):
def __init__(self, dictionary=None, filename=None):
""" Initialises a Prior set for Binary Black holes
......@@ -234,7 +218,7 @@ class CalibrationPriorDict(PriorDict):
if dictionary is None and filename is not None:
filename = os.path.join(os.path.dirname(__file__),
'prior_files', filename)
PriorDict.__init__(self, dictionary=dictionary, filename=filename)
PriorSet.__init__(self, dictionary=dictionary, filename=filename)
self.source = None
def write_to_file(self, outdir, label):
......@@ -249,7 +233,7 @@ class CalibrationPriorDict(PriorDict):
label: str
Label for prior.
"""
PriorDict.write_to_file(self, outdir=outdir, label=label)
PriorSet.write_to_file(self, outdir=outdir, label=label)
if self.source is not None:
prior_file = os.path.join(outdir, "{}.prior".format(label))
with open(prior_file, "a") as outfile:
......@@ -280,7 +264,7 @@ class CalibrationPriorDict(PriorDict):
Returns
-------
prior: PriorDict
prior: PriorSet
Priors for the relevant parameters.
This includes the frequencies of the nodes which are _not_ sampled.
"""
......@@ -303,7 +287,7 @@ class CalibrationPriorDict(PriorDict):
phase_sigma_nodes =\
UnivariateSpline(frequency_array, phase_sigma)(nodes)
prior = CalibrationPriorDict()
prior = CalibrationPriorSet()
for ii in range(n_nodes):
name = "recalib_{}_amplitude_{}".format(label, ii)
latex_label = "$A^{}_{}$".format(label, ii)
......@@ -350,7 +334,7 @@ class CalibrationPriorDict(PriorDict):
Returns
-------
prior: PriorDict
prior: PriorSet
Priors for the relevant parameters.
This includes the frequencies of the nodes which are _not_ sampled.
"""
......@@ -362,7 +346,7 @@ class CalibrationPriorDict(PriorDict):
phase_mean_nodes = [0] * n_nodes
phase_sigma_nodes = [phase_sigma] * n_nodes
prior = CalibrationPriorDict()
prior = CalibrationPriorSet()
for ii in range(n_nodes):
name = "recalib_{}_amplitude_{}".format(label, ii)
latex_label = "$A^{}_{}$".format(label, ii)
......@@ -382,11 +366,3 @@ class CalibrationPriorDict(PriorDict):
latex_label=latex_label)
return prior
class CalibrationPriorSet(CalibrationPriorDict):
def __init__(self, dictionary=None, filename=None):
""" DEPRECATED: USE BNSPriorDict INSTEAD"""
super(CalibrationPriorSet, self).__init__(dictionary, filename)
logger.warning("The name 'CalibrationPriorSet' is deprecated use 'CalibrationPriorDict' instead")
......@@ -89,7 +89,7 @@ for interferometer in interferometers:
interferometer.plot_data(signal=signal, outdir=outdir, label=label)
# set up priors
priors = bilby.gw.prior.BBHPriorDict()
priors = bilby.gw.prior.BBHPriorSet()
for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'psi',
'geocent_time', 'phase']:
priors[key] = injection_parameters[key]
......
......@@ -64,7 +64,7 @@ ifos.inject_signal(waveform_generator=waveform_generator,
# The above list does *not* include mass_1, mass_2, iota and luminosity
# distance, which means those are the parameters that will be included in the
# sampler. If we do nothing, then the default priors get used.
priors = bilby.gw.prior.BBHPriorDict()
priors = bilby.gw.prior.BBHPriorSet()
priors['geocent_time'] = bilby.core.prior.Uniform(
minimum=injection_parameters['geocent_time'] - 1,
maximum=injection_parameters['geocent_time'] + 1,
......
......@@ -64,7 +64,7 @@ interferometers.inject_signal(parameters=injection_parameters,
# Load the default prior for binary neutron stars.
# We're going to sample in chirp_mass, symmetric_mass_ratio, lambda_tilde, and
# delta_lambda rather than mass_1, mass_2, lambda_1, and lambda_2.
priors = bilby.gw.prior.BNSPriorDict()
priors = bilby.gw.prior.BNSPriorSet()
for key in ['psi', 'geocent_time', 'ra', 'dec', 'chi_1', 'chi_2',
'iota', 'luminosity_distance', 'phase']:
priors[key] = injection_parameters[key]
......
......@@ -48,7 +48,7 @@ ifos.inject_signal(waveform_generator=waveform_generator,
# Set up prior
# Note it is possible to sample in different parameters to those that were
# injected.
priors = bilby.gw.prior.BBHPriorDict()
priors = bilby.gw.prior.BBHPriorSet()
priors.pop('mass_1')
priors.pop('mass_2')
priors.pop('luminosity_distance')
......
......@@ -58,7 +58,7 @@ ifos.inject_signal(waveform_generator=waveform_generator,
parameters=injection_parameters)
# Now we set up the priors on each of the binary parameters.
priors = bilby.core.prior.PriorDict()
priors = bilby.core.prior.PriorSet()
priors["mass_1"] = bilby.core.prior.Uniform(
name='mass_1', minimum=5, maximum=60, unit='$M_{\\odot}$')
priors["mass_2"] = bilby.core.prior.Uniform(
......
......@@ -39,7 +39,7 @@ ifos.inject_signal(waveform_generator=waveform_generator,
# Set up prior
# This loads in a predefined set of priors for BBHs.
priors = bilby.gw.prior.BBHPriorDict()
priors = bilby.gw.prior.BBHPriorSet()
# These parameters will not be sampled
for key in ['tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'phase', 'iota', 'ra',
'dec', 'geocent_time', 'psi']:
......
......@@ -38,7 +38,7 @@ ifos.inject_signal(waveform_generator=waveform_generator,
parameters=injection_parameters)
# Set up prior
priors = bilby.gw.prior.BBHPriorDict()
priors = bilby.gw.prior.BBHPriorSet()
# These parameters will not be sampled
for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'iota', 'ra',
'dec']:
......
......@@ -30,7 +30,7 @@ ifos.set_strain_data_from_power_spectral_densities(
ifos.inject_signal(waveform_generator=waveform_generator,
parameters=injection_parameters)
priors = bilby.gw.prior.BBHPriorDict()
priors = bilby.gw.prior.BBHPriorSet()
for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'psi',
'mass_1', 'mass_2', 'phase', 'geocent_time', 'luminosity_distance',
'iota']:
......
......@@ -30,7 +30,7 @@ interferometers = bilby.gw.detector.get_event_data(label)
# The prior is printed to the terminal at run-time.
# You can overwrite this using the syntax below in the file,
# or choose a fixed value by just providing a float value as the prior.
prior = bilby.gw.prior.BBHPriorDict(filename='GW150914.prior')
prior = bilby.gw.prior.BBHPriorSet(filename='GW150914.prior')
# In this step we define a `waveform_generator`. This is out object which
# creates the frequency-domain strain. In this instance, we are using the
......
......@@ -6,7 +6,7 @@ stimation on GW150914 using open data.
"""
import bilby
prior = bilby.gw.prior.BBHPriorDict(filename='GW150914.prior')
prior = bilby.gw.prior.BBHPriorSet(filename='GW150914.prior')
interferometers = bilby.gw.detector.get_event_data("GW150914")
likelihood = bilby.gw.likelihood.get_binary_black_hole_likelihood(interferometers)
result = bilby.run_sampler(likelihood, prior, label='GW150914')
......
......@@ -85,7 +85,7 @@ class TestGWTransient(unittest.TestCase):
frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole,
)
self.prior = bilby.gw.prior.BBHPriorDict()
self.prior = bilby.gw.prior.BBHPriorSet()
self.prior['geocent_time'] = bilby.prior.Uniform(
minimum=self.parameters['geocent_time'] - self.duration / 2,
maximum=self.parameters['geocent_time'] + self.duration / 2)
......@@ -158,7 +158,7 @@ class TestTimeMarginalization(unittest.TestCase):
frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole,
)
self.prior = bilby.gw.prior.BBHPriorDict()
self.prior = bilby.gw.prior.BBHPriorSet()
self.prior['geocent_time'] = bilby.prior.Uniform(
minimum=self.parameters['geocent_time'] - self.duration / 2,
maximum=self.parameters['geocent_time'] + self.duration / 2)
......@@ -224,7 +224,7 @@ class TestMarginalizedLikelihood(unittest.TestCase):
frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole,
)
self.prior = bilby.gw.prior.BBHPriorDict()
self.prior = bilby.gw.prior.BBHPriorSet()
self.prior['geocent_time'] = bilby.prior.Uniform(
minimum=self.parameters['geocent_time'] - self.duration / 2,
maximum=self.parameters['geocent_time'] + self.duration / 2)
......@@ -287,7 +287,7 @@ class TestPhaseMarginalization(unittest.TestCase):
frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole,
)
self.prior = bilby.gw.prior.BBHPriorDict()
self.prior = bilby.gw.prior.BBHPriorSet()
self.prior['geocent_time'] = bilby.prior.Uniform(
minimum=self.parameters['geocent_time'] - self.duration / 2,
maximum=self.parameters['geocent_time'] + self.duration / 2)
......@@ -350,7 +350,7 @@ class TestTimePhaseMarginalization(unittest.TestCase):
frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole,
)
self.prior = bilby.gw.prior.BBHPriorDict()
self.prior = bilby.gw.prior.BBHPriorSet()
self.prior['geocent_time'] = bilby.prior.Uniform(
minimum=self.parameters['geocent_time'] - self.duration / 2,
maximum=self.parameters['geocent_time'] + self.duration / 2)
......
......@@ -13,7 +13,7 @@ class TestBBHPriorSet(unittest.TestCase):
'/'.join(os.path.dirname(
os.path.abspath(sys.argv[0])).split('/')[:-1])
self.filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'prior_files/binary_black_holes.prior')
self.default_prior = bilby.gw.prior.BBHPriorDict(
self.default_prior = bilby.gw.prior.BBHPriorSet(
filename=self.filename)
def tearDown(self):
......@@ -21,7 +21,7 @@ class TestBBHPriorSet(unittest.TestCase):
del self.filename
def test_create_default_prior(self):
default = bilby.gw.prior.BBHPriorDict()
default = bilby.gw.prior.BBHPriorSet()
minima = all([self.default_prior[key].minimum == default[key].minimum
for key in default.keys()])
maxima = all([self.default_prior[key].maximum == default[key].maximum
......@@ -32,10 +32,10 @@ class TestBBHPriorSet(unittest.TestCase):
self.assertTrue(all([minima, maxima, names]))
def test_create_from_dict(self):
bilby.gw.prior.BBHPriorDict(dictionary=self.prior_dict)
bilby.gw.prior.BBHPriorSet(dictionary=self.prior_dict)
def test_create_from_filename(self):
bilby.gw.prior.BBHPriorDict(filename=self.filename)
bilby.gw.prior.BBHPriorSet(filename=self.filename)
def test_key_in_prior_not_redundant(self):
test = self.default_prior.test_redundancy('mass_1')
......@@ -62,7 +62,7 @@ class TestCalibrationPrior(unittest.TestCase):
phase_sigma = 0.1
n_nodes = 9
label = 'test'
test = bilby.gw.prior.CalibrationPriorDict.constant_uncertainty_spline(
test = bilby.gw.prior.CalibrationPriorSet.constant_uncertainty_spline(
amplitude_sigma, phase_sigma, self.minimum_frequency,
self.maximum_frequency, n_nodes, label)
......
......@@ -304,10 +304,10 @@ class TestPriorSet(unittest.TestCase):
self.prior_dict = dict(mass=self.first_prior,
speed=self.second_prior,
length=self.third_prior)
self.prior_set_from_dict = bilby.core.prior.PriorDict(dictionary=self.prior_dict)
self.prior_set_from_dict = bilby.core.prior.PriorSet(dictionary=self.prior_dict)
self.default_prior_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'prior_files/binary_black_holes.prior')
self.prior_set_from_file = bilby.core.prior.PriorDict(filename=self.default_prior_file)
self.prior_set_from_file = bilby.core.prior.PriorSet(filename=self.default_prior_file)
def tearDown(self):
del self.first_prior
......@@ -387,7 +387,7 @@ class TestPriorSet(unittest.TestCase):
self.assertDictEqual(expected, self.prior_set_from_dict)
def test_prior_set_from_dict_but_using_a_string(self):
prior_set = bilby.core.prior.PriorDict(dictionary=self.default_prior_file)
prior_set = bilby.core.prior.PriorSet(dictionary=self.default_prior_file)
expected = dict(
mass_1=bilby.core.prior.Uniform(
name='mass_1', minimum=5, maximum=100, unit='$M_{\\odot}$'),
......@@ -416,7 +416,7 @@ class TestPriorSet(unittest.TestCase):
def test_dict_argument_is_not_string_or_dict(self):
with self.assertRaises(ValueError):
bilby.core.prior.PriorDict(dictionary=list())
bilby.core.prior.PriorSet(dictionary=list())
def test_sample_subset_correct_size(self):
size = 7
......@@ -476,7 +476,7 @@ class TestFillPrior(unittest.TestCase):
self.likelihood.parameters = dict(a=0, b=0, c=0, d=0, asdf=0, ra=1)
self.likelihood.non_standard_sampling_parameter_keys = dict(t=8)
self.priors = dict(a=1, b=1.1, c='string', d=bilby.core.prior.Uniform(0, 1))
self.priors = bilby.core.prior.PriorDict(dictionary=self.priors)
self.priors = bilby.core.prior.PriorSet(dictionary=self.priors)
self.default_prior_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),
'prior_files/binary_black_holes.prior')
self.priors.fill_priors(self.likelihood, self.default_prior_file)
......@@ -515,7 +515,7 @@ class TestCreateDefaultPrior(unittest.TestCase):
def test_bbh_params(self):
prior_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'prior_files/binary_black_holes.prior')
prior_set = bilby.core.prior.PriorDict(filename=prior_file)
prior_set = bilby.core.prior.PriorSet(filename=prior_file)
for prior in prior_set:
self.assertEqual(prior_set[prior], bilby.core.prior.create_default_prior(name=prior,
default_priors_file=prior_file))
......
......@@ -59,7 +59,7 @@ class TestResult(unittest.TestCase):
self.result.plot_corner(parameters=dict(x=1, y=1))
def test_plot_corner_with_priors(self):
priors = bilby.core.prior.PriorDict()
priors = bilby.core.prior.PriorSet()
priors['x'] = bilby.core.prior.Uniform(-1, 1, 'x')
priors['y'] = bilby.core.prior.Uniform(-1, 1, 'y')
self.result.plot_corner(priors=priors)
......
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