Skip to content
Snippets Groups Projects
Commit dc91820d authored by Moritz Huebner's avatar Moritz Huebner
Browse files

Merge branch 'allow-for-ordered-dicts' into 'master'

Allows users to give priors as an OrderedDict

See merge request Monash/tupak!142
parents c74659f4 864b400f
No related branches found
No related tags found
1 merge request!142Allows users to give priors as an OrderedDict
Pipeline #28046 passed
......@@ -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.
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment