def test_starfit(): rootdir = os.path.abspath(os.path.join(os.path.dirname(__file__))) testdir = os.path.join(rootdir, "star1") if mnest: basename = "{}/{}-".format(chainsdir, np.random.randint(1000000)) kwargs = dict(n_live_points=20, max_iter=100, basename=basename, verbose=False) getLogger().info("Testing starfit function with multinest...") else: kwargs = dict(nburn=20, niter=20, ninitial=10) getLogger().info("Testing starfit function with emcee...") mod, _ = starfit(testdir, overwrite=True, use_emcee=not mnest, no_plots=True, **kwargs) mod.samples if mnest: files = glob.glob("{}*".format(basename)) for f in files: os.remove(f)
def test_interp(): xx, yy, zz = [np.arange(10 + np.log10(n)) * n for n in [1, 10, 100]] def func(x, y, z): return x**2 * np.cos(y / 10) + z df = pd.DataFrame( [(x, y, z, func(x, y, z)) for x, y, z in itertools.product(xx, yy, zz)], columns=["x", "y", "z", "val"], ).set_index(["x", "y", "z"]) grid = np.reshape(df.val.values, (10, 11, 12)) interp = RegularGridInterpolator([xx, yy, zz], grid) df_interp = DFInterpolator(df) grid_pars = [6.0, 50.0, 200.0] pars = [3.1, 44.0, 503.0] # Make sure grid point returns correct exact value assert df_interp(grid_pars, ["val"]) == func(*grid_pars) # Check linear interpolation vis-a-vis scipy try: assert np.isclose(df_interp(pars, ["val"]), interp(pars)[0], atol=1e-11) except AssertionError: getLogger().debug("mine: {}, scipy: {}".format( df_interp(pars, ["val"]), interp(pars)[0])) raise pts = np.random.random(size=(10, 3)) * 9 pts[:, 1] *= 10 pts[:, 2] *= 100 assert np.allclose(df_interp([pts[:, 0], pts[:, 1], pts[:, 2]], ["val"]).ravel(), interp(pts), atol=1e-11)
import numpy as np import tempfile import tables as tb from pandas.util.testing import assert_frame_equal from isochrones.mist import MIST_Isochrone from isochrones import StarModel from isochrones.starfit import starfit from isochrones.logger import getLogger mnest = True try: import pymultinest except: getLogger().warning("No PyMultiNest; fits will use emcee") mnest = False chainsdir = tempfile.gettempdir() props = dict(Teff=(5800, 100), logg=(4.5, 0.1), J=(3.58, 0.05), K=(3.22, 0.05)) def test_fitting(): mod_mist = _check_fitting(StarModel(MIST_Isochrone, **props)) _check_saving(mod_mist) def test_starfit(): rootdir = os.path.abspath(os.path.join(os.path.dirname(__file__)))
import numpy as np import tempfile import tables as tb from pandas.util.testing import assert_frame_equal from isochrones.mist import MIST_Isochrone from isochrones import StarModel from isochrones.starfit import starfit from isochrones.logger import getLogger mnest = True try: import pymultinest except: getLogger().warning('No PyMultiNest; fits will use emcee') mnest = False chainsdir = tempfile.gettempdir() props = dict(Teff=(5800, 100), logg=(4.5, 0.1), J=(3.58, 0.05), K=(3.22, 0.05)) def test_fitting(): mod_mist = _check_fitting(StarModel(MIST_Isochrone, **props)) _check_saving(mod_mist) def test_starfit(): rootdir = os.path.abspath(os.path.join(os.path.dirname(__file__)))