diff --git a/tupak/core/prior.py b/tupak/core/prior.py index 8ea049c6befa343e9c0845d124f12f699e9c2f1f..d426052b13543e720b94cd8db859dbfa87a07b21 100644 --- a/tupak/core/prior.py +++ b/tupak/core/prior.py @@ -7,12 +7,13 @@ from scipy.integrate import cumtrapz from scipy.special import erf, erfinv import scipy.stats import os +from collections import OrderedDict from tupak.core.utils import logger from tupak.core import utils -class PriorSet(dict): +class PriorSet(OrderedDict): def __init__(self, dictionary=None, filename=None): """ A set of priors @@ -23,8 +24,8 @@ class PriorSet(dict): filename: str, None If given, a file containing the prior to generate the prior set. """ - dict.__init__(self) - if type(dictionary) is dict: + OrderedDict.__init__(self) + if type(dictionary) in [dict, OrderedDict]: self.update(dictionary) elif type(dictionary) is str: logger.debug('Argument "dictionary" is a string.' @@ -32,6 +33,8 @@ class PriorSet(dict): self.read_in_file(dictionary) elif type(filename) is str: self.read_in_file(filename) + elif dictionary is not None: + raise ValueError("PriorSet input dictionay not understood") def write_to_file(self, outdir, label): """ Write the prior distribution to file. diff --git a/tupak/core/sampler.py b/tupak/core/sampler.py index ae5007ac5939593e2146ba5f62c5313f8a045d4d..aadbe4a0ebaf70f8ffc49ed033ed6238a2b7cfd0 100644 --- a/tupak/core/sampler.py +++ b/tupak/core/sampler.py @@ -7,6 +7,7 @@ import numpy as np import datetime import deepdish import pandas as pd +from collections import OrderedDict from tupak.core.utils import logger from tupak.core.result import Result, read_in_result @@ -1001,12 +1002,12 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir', if priors is None: priors = dict() - if type(priors) == dict: + if type(priors) in [dict, OrderedDict]: priors = tupak.core.prior.PriorSet(priors) elif isinstance(priors, tupak.core.prior.PriorSet): pass else: - raise ValueError + raise ValueError("Input priors not understood") priors.fill_priors(likelihood, default_priors_file=default_priors_file)