# Path: sncosmo/utils.py
# def dict_to_array(d):
# def format_value(value, error=None, latex=False):
#     def __init__(self, *args, **kwargs):
#     def __getitem__(self, name):
#     def __getattr__(self, name):
#     def __repr__(self):
# def _integral_diff(x, pdf, a, q):
# def ppf(pdf, x, a, b):
#     def __init__(self, xmin, xmax, y):
#     def __call__(self, x):
# def _download_file(remote_url, target):
# def download_file(remote_url, local_name):
# def download_dir(remote_url, dirname):
#     def __init__(self, rootdir, remote_root):
#     def rootdir(self):
#     def _fetch_redirects(self):
#     def _get_url(self, remote_relpath):
#     def abspath(self, relpath, isdir=False):
# def alias_map(aliased, aliases, required=()):
# def integration_grid(low, high, target_spacing):
# def warn_once(name, depver, rmver, extra=None):
# class Result(dict):
# class Interp1D(object):
# class DataMirror(object):
#     FACTOR = 10.


import os
import numpy as np
import pytest
from tempfile import mkdtemp
from numpy.testing import assert_allclose
from scipy.stats import norm
from sncosmo import utils

    # Flat prior between 0 and 10
    def prior(x):
        return 1.

    x = np.array([0.1, 0.2, 0.9, 0.9999])
    y = utils.ppf(prior, x, 0., 10.)
    assert_allclose(y, [1., 2., 9., 9.999])

    # test a normal distribution
    priordist = norm(0., 1.)
    x = np.linspace(0.05, 0.95, 5)
    y = utils.ppf(priordist.pdf, x, -np.inf, np.inf)
    assert_allclose(y, priordist.ppf(x), atol=1.e-10)


def test_alias_map():
    mapping = utils.alias_map(['A', 'B_', 'foo'],
                              {'a': set(['a', 'a_']), 'b': set(['b', 'b_'])})
    assert mapping == {'a': 'A', 'b': 'B_'}


def test_data_mirror_rootdir():
    dirname = mkdtemp()

    # rootdir is a string
    mirror = utils.DataMirror(dirname, "url_goes_here")
    assert mirror.rootdir() == dirname

    # rootdir is a callable

# Path: sncosmo/utils.py
# def dict_to_array(d):
# def format_value(value, error=None, latex=False):
#     def __init__(self, *args, **kwargs):
#     def __getitem__(self, name):
#     def __getattr__(self, name):
#     def __repr__(self):
# def _integral_diff(x, pdf, a, q):
# def ppf(pdf, x, a, b):
#     def __init__(self, xmin, xmax, y):
#     def __call__(self, x):
# def _download_file(remote_url, target):
# def download_file(remote_url, local_name):
# def download_dir(remote_url, dirname):
#     def __init__(self, rootdir, remote_root):
#     def rootdir(self):
#     def _fetch_redirects(self):
#     def _get_url(self, remote_relpath):
#     def abspath(self, relpath, isdir=False):
# def alias_map(aliased, aliases, required=()):
# def integration_grid(low, high, target_spacing):
# def warn_once(name, depver, rmver, extra=None):
# class Result(dict):
# class Interp1D(object):
# class DataMirror(object):
#     FACTOR = 10.


# Path: sncosmo/tests/test_utils.py
import os
import numpy as np
import pytest
from tempfile import mkdtemp
from numpy.testing import assert_allclose
from scipy.stats import norm
from sncosmo import utils


    # Flat prior between 0 and 10
    def prior(x):
        return 1.

    x = np.array([0.1, 0.2, 0.9, 0.9999])
    y = utils.ppf(prior, x, 0., 10.)
    assert_allclose(y, [1., 2., 9., 9.999])

    # test a normal distribution
    priordist = norm(0., 1.)
    x = np.linspace(0.05, 0.95, 5)
    y = utils.ppf(priordist.pdf, x, -np.inf, np.inf)
    assert_allclose(y, priordist.ppf(x), atol=1.e-10)


def test_alias_map():
    mapping = utils.alias_map(['A', 'B_', 'foo'],
                              {'a': set(['a', 'a_']), 'b': set(['b', 'b_'])})
    assert mapping == {'a': 'A', 'b': 'B_'}


def test_data_mirror_rootdir():
    dirname = mkdtemp()

    # rootdir is a string
    mirror = utils.DataMirror(dirname, "url_goes_here")
    assert mirror.rootdir() == dirname

    # rootdir is a callable

    mirror = utils.DataMirror(lambda: dirname, "url_goes_here")