Ejemplo n.º 1
0
from barry.config import setup
from barry.models import PowerBeutler2017
from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC
from barry.samplers import DynestySampler
from barry.fitter import Fitter

if __name__ == "__main__":
    pfn, dir_name, file = setup(__file__)

    r = True
    models = [
        PowerBeutler2017(recon=r, smooth_type="hinton2017", name="Hinton2017"),
        PowerBeutler2017(recon=r, smooth_type="eh1998", name="EH1998")
    ]
    data = PowerSpectrum_SDSS_DR12_Z061_NGC(name="Recon mean",
                                            recon=r,
                                            min_k=0.02,
                                            max_k=0.30)
    sampler = DynestySampler(temp_dir=dir_name)

    fitter = Fitter(dir_name)
    fitter.add_model_and_dataset(models[0], data, name="Hinton2017")
    fitter.add_model_and_dataset(models[1], data, name="EH1998")
    fitter.set_sampler(sampler)
    fitter.set_num_walkers(10)
    fitter.fit(file)

    if fitter.should_plot():
        from chainconsumer import ChainConsumer

        c = ChainConsumer()
        pks = {}
Ejemplo n.º 2
0
from barry.fitter import Fitter

if __name__ == "__main__":
    pfn, dir_name, file = setup(__file__)

    c = getCambGenerator()
    r_s = c.get_data()[0]

    postprocess = BAOExtractor(r_s)

    sampler = DynestySampler(temp_dir=dir_name)
    fitter = Fitter(dir_name)

    for r in [True, False]:
        rt = "Recon" if r else "Prerecon"
        data = PowerSpectrum_SDSS_DR12_Z061_NGC(recon=r,
                                                postprocess=postprocess)
        n = PowerNoda2019(postprocess=postprocess,
                          recon=r,
                          nonlinear_type="spt")
        n2 = PowerNoda2019(postprocess=postprocess,
                           recon=r,
                           nonlinear_type="halofit")

        fitter.add_model_and_dataset(n,
                                     data,
                                     name=f"N19 {rt} SPT",
                                     color="r",
                                     shade_alpha=0.7,
                                     linestyle="-" if r else "--",
                                     zorder=10 if r else 2)
        fitter.add_model_and_dataset(n2,
Ejemplo n.º 3
0
    logging.basicConfig(
        level=logging.DEBUG,
        format="[%(levelname)7s |%(funcName)20s]   %(message)s")
    logging.getLogger("matplotlib").setLevel(logging.ERROR)
    recon = True
    model1 = PowerSeo2016(recon=recon, name=f"Seo2016, recon={recon}")
    model_smooth = PowerSeo2016(recon=recon,
                                name=f"Seo2016, recon={recon}",
                                smooth=True)

    from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC
    from barry.datasets import DummyPowerSpectrum_SDSS_DR12_Z061_NGC

    dataset1 = PowerSpectrum_SDSS_DR12_Z061_NGC(name="Recon mean",
                                                recon=recon,
                                                min_k=0.02,
                                                max_k=0.3,
                                                reduce_cov_factor=30,
                                                step_size=5)
    dataset2 = DummyPowerSpectrum_SDSS_DR12_Z061_NGC(
        name="Dummy data, real window fn",
        min_k=0.02,
        max_k=0.25,
        dummy_window=False)
    dataset3 = DummyPowerSpectrum_SDSS_DR12_Z061_NGC(name="DummyWindowFnToo",
                                                     min_k=0.02,
                                                     max_k=0.25,
                                                     dummy_window=True)

    data1 = dataset1.get_data()
    data2 = dataset2.get_data()
    data3 = dataset3.get_data()
    logging.basicConfig(
        level=logging.INFO,
        format="[%(levelname)7s |%(funcName)18s]   %(message)s")
    logging.getLogger("matplotlib").setLevel(logging.WARNING)

    camb = getCambGenerator()
    r_s = c.get_data()[0]
    extractor = BAOExtractor(r_s, reorder=False)
    extractor2 = PureBAOExtractor(r_s)

    step_size = 1
    mink = 0.02
    maxk = 0.3
    data_raw = PowerSpectrum_SDSS_DR12_Z061_NGC(step_size=step_size,
                                                fake_diag=False,
                                                min_k=0.0,
                                                max_k=0.32)
    data2 = PowerSpectrum_SDSS_DR12_Z061_NGC(postprocess=extractor,
                                             step_size=step_size,
                                             min_k=mink,
                                             max_k=maxk)

    ks = data_raw.ks
    pk = data_raw.data
    pk_cov = data_raw.cov
    denoms = extractor2.postprocess(ks, pk, None, return_denominator=True)
    is_extracted = extractor.get_is_extracted(ks)
    cov_brute = data2.cov
    k_range = extractor.get_krange()
    cov_noda = calc_cov_noda_mixed(pk_cov, denoms, ks, pk, k_range,
                                   is_extracted)
if __name__ == "__main__":
    pfn, dir_name, file = setup("../config/pk_individual.py")
    fitter = Fitter(dir_name, save_dims=2, remove_output=False)

    c = getCambGenerator()
    r_s = c.get_data()[0]
    p = BAOExtractor(r_s)

    sampler = DynestySampler(temp_dir=dir_name, nlive=200)

    for r in [True, False]:
        t = "Recon" if r else "Prerecon"
        ls = "-" if r else "--"

        d = PowerSpectrum_SDSS_DR12_Z061_NGC(recon=r, realisation=0)
        de = PowerSpectrum_SDSS_DR12_Z061_NGC(recon=r,
                                              postprocess=p,
                                              realisation=0)

        beutler_not_fixed = PowerBeutler2017(recon=r)
        beutler = PowerBeutler2017(recon=r)
        sigma_nl = 6.0 if r else 9.3
        beutler.set_default("sigma_nl", sigma_nl)
        beutler.set_fix_params(["om", "sigma_nl"])

        seo = PowerSeo2016(recon=r)
        ding = PowerDing2018(recon=r)
        noda = PowerNoda2019(recon=r, postprocess=p)

        for i in range(999):

if __name__ == "__main__":
    import seaborn as sb
    import matplotlib.pyplot as plt

    logging.basicConfig(level=logging.INFO, format="[%(levelname)7s |%(funcName)18s]   %(message)s")
    logging.getLogger("matplotlib").setLevel(logging.WARNING)

    camb = getCambGenerator()
    r_s = c.get_data()[0]
    extractor = PureBAOExtractor(r_s)
    mink = 0.02

    step_size = 1
    data_raw = PowerSpectrum_SDSS_DR12_Z061_NGC(step_size=step_size, min_k=0.0)
    data = PowerSpectrum_SDSS_DR12_Z061_NGC(step_size=step_size, min_k=mink)
    data2 = PowerSpectrum_SDSS_DR12_Z061_NGC(postprocess=extractor, step_size=step_size, min_k=mink)

    # Get all the data to compute the covariance
    ks = data_raw.ks
    pk = data_raw.data
    pk_cov = data_raw.cov
    denoms = extractor.postprocess(ks, pk, None, return_denominator=True)
    k_range = extractor.get_krange()

    cov_noda = calc_cov_noda(pk_cov, denoms, ks, pk, k_range, assume_diag=False)
    cov_noda2 = calc_cov_noda(pk_cov, denoms, ks, pk, k_range, assume_diag=True)
    cov_brute = data2.cov

    mask = np.where(ks < mink)
Ejemplo n.º 7
0
# We want to verify the behaviour of other models when the BAO extractor technique is applied to them
# We also want to see what the behaviour is if we keep the polynomial terms enabled or disable them.
if __name__ == "__main__":
    pfn, dir_name, file = setup(__file__)

    c = getCambGenerator()
    r_s = c.get_data()["r_s"]

    fitter = Fitter(dir_name)
    p = BAOExtractor(r_s)
    cs = ["#262232", "#116A71", "#48AB75", "#b7c742"]

    for r in [True]:
        t = "Recon" if r else "Prerecon"
        datae = PowerSpectrum_SDSS_DR12_Z061_NGC(recon=r, min_k=0.03, max_k=0.30, postprocess=p)
        for ls, n in zip(["-", ":"], ["", " (No Poly)"]):
            if n:
                fix = ["om", "f", "a1", "a2", "a3", "a4", "a5"]
            else:
                fix = ["om", "f"]
            fitter.add_model_and_dataset(PowerBeutler2017(postprocess=p, recon=r, fix_params=fix), datae, name=f"Beutler 2017{n}", linestyle=ls, color=cs[0])
            fitter.add_model_and_dataset(PowerSeo2016(postprocess=p, recon=r, fix_params=fix), datae, name=f"Seo 2016{n}", linestyle=ls, color=cs[1])
            fitter.add_model_and_dataset(PowerDing2018(postprocess=p, recon=r, fix_params=fix), datae, name=f"Ding 2018{n}", linestyle=ls, color=cs[2])
        fitter.add_model_and_dataset(PowerNoda2019(postprocess=p, recon=r), datae, name=f"Noda 2019", color=cs[3])

    sampler = DynestySampler(temp_dir=dir_name, nlive=300)
    fitter.set_sampler(sampler)
    fitter.set_num_walkers(10)
    fitter.fit(file)
Ejemplo n.º 8
0
        BAOExtractor(r_s, extra_ks=(0.095, 0.16)),
        BAOExtractor(r_s, extra_ks=(0.095, 0.17)),
        BAOExtractor(r_s, extra_ks=(0.095, 0.18)),
        BAOExtractor(r_s, extra_ks=(0.095, 0.19)),
        BAOExtractor(r_s, extra_ks=(0.095, 0.20)),
        BAOExtractor(r_s, extra_ks=(0.095, 0.21)),
        BAOExtractor(r_s, extra_ks=(0.095, 0.22)),
        BAOExtractor(r_s, extra_ks=(0.095, 0.23)),
        BAOExtractor(r_s, extra_ks=(0.095, 0.24)),
    ]

    recon = True
    for p in ps:
        n = f"$k = {p.extra_ks[1]:0.2f}\, h / {{\\rm Mpc}}$"
        model = PowerNoda2019(postprocess=p, recon=recon)
        data = PowerSpectrum_SDSS_DR12_Z061_NGC(min_k=0.02, max_k=0.30, postprocess=p, recon=recon)
        fitter.add_model_and_dataset(model, data, name=n)

    sampler = DynestySampler(temp_dir=dir_name)

    fitter.set_sampler(sampler)
    fitter.set_num_walkers(30)
    fitter.fit(file)

    if fitter.should_plot():
        from chainconsumer import ChainConsumer

        c = ChainConsumer()
        for posterior, weight, chain, model, data, extra in fitter.load():
            print(extra["name"])
            c.add_chain(chain, weights=weight, parameters=model.get_labels(), **extra)
Ejemplo n.º 9
0
import logging
from barry.models import PowerBeutler2017

if __name__ == "__main__":
    logging.basicConfig(
        level=logging.DEBUG,
        format="[%(levelname)7s |%(funcName)20s]   %(message)s")
    logging.getLogger("matplotlib").setLevel(logging.ERROR)
    from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC

    for recon in [True, False]:
        dataset1 = PowerSpectrum_SDSS_DR12_Z061_NGC(recon=recon)
        data1 = dataset1.get_data()

        # Run on mean
        model = PowerBeutler2017(recon=recon,
                                 name=f"Beutler2017, recon={recon}")
        model.set_data(data1)
        p, minv = model.optimize(maxiter=2000, niter=200)
        sigma_nl = p["sigma_nl"]

        print(
            f"recon={recon}, Sigma_nl found to be {sigma_nl:0.3f} with prob {minv:0.3f}"
        )
        model.set_default("sigma_nl", sigma_nl)
        model.set_fix_params(["om", "sigma_nl"])

        # Recon 6.0
        # Prerecon 9.3
Ejemplo n.º 10
0
if __name__ == "__main__":
    pfn, dir_name, file = setup(__file__)

    c = getCambGenerator()
    r_s = c.get_data()["r_s"]
    p = BAOExtractor(r_s)

    sampler = DynestySampler(temp_dir=dir_name)
    fitter = Fitter(dir_name)

    cs = ["#262232", "#116A71", "#48AB75", "#D1E05B"]

    for r in [True, False]:
        t = "Recon" if r else "Prerecon"
        ls = "-" if r else "--"
        d = PowerSpectrum_SDSS_DR12_Z061_NGC(recon=r, min_k=0.03, max_k=0.21)
        de = PowerSpectrum_SDSS_DR12_Z061_NGC(recon=r,
                                              postprocess=p,
                                              min_k=0.03,
                                              max_k=0.21)

        # Fix sigma_nl for one of the Beutler models
        model = PowerBeutler2017(recon=r)
        sigma_nl = 6.0 if r else 9.3
        model.set_default("sigma_nl", sigma_nl)
        model.set_fix_params(["om", "sigma_nl"])

        fitter.add_model_and_dataset(PowerBeutler2017(recon=r),
                                     d,
                                     name=f"Beutler 2017 {t}",
                                     linestyle=ls,
Ejemplo n.º 11
0
        format="[%(levelname)7s |%(funcName)20s]   %(message)s")
    logging.getLogger("matplotlib").setLevel(logging.ERROR)

    c = getCambGenerator()
    r_s = c.get_data()["r_s"]

    postprocess = BAOExtractor(r_s, mink=0.15)

    for recon in [True, False]:

        model1 = PowerNoda2019(recon=recon,
                               name=f"Noda2019, recon={recon}",
                               postprocess=postprocess,
                               fix_params=["om", "f", "gamma"])
        dataset1 = PowerSpectrum_SDSS_DR12_Z061_NGC(recon=recon,
                                                    postprocess=postprocess,
                                                    min_k=0.03,
                                                    max_k=0.15)
        data1 = dataset1.get_data()
        print(list(data1[0].keys()))
        print(data1[0]["ks_output"])
        exit()
        # First comparison - the actual recon data
        model1.set_data(data1)
        p, minv = model1.optimize()
        print(recon)
        print(p)
        print(minv)
        model1.plot(p)

        # FINDINGS
        # 1.992 for Recon, 1.996 for prerecon
Ejemplo n.º 12
0
if __name__ == "__main__":
    pfn, dir_name, file = setup(__file__)

    c = getCambGenerator()
    r_s = c.get_data()["r_s"]

    postprocess = BAOExtractor(r_s)
    r = True
    model = PowerNoda2019(postprocess=postprocess, recon=r, name="")
    mink = 0.03
    maxk = 0.30
    datas = [
        PowerSpectrum_SDSS_DR12_Z061_NGC(name="Mock covariance",
                                         recon=r,
                                         min_k=mink,
                                         max_k=maxk,
                                         postprocess=postprocess),
        PowerSpectrum_SDSS_DR12_Z061_NGC(name="Nishimichi, full",
                                         recon=r,
                                         min_k=mink,
                                         max_k=maxk,
                                         postprocess=postprocess),
        PowerSpectrum_SDSS_DR12_Z061_NGC(name="Nishimichi, diag",
                                         recon=r,
                                         min_k=mink,
                                         max_k=maxk,
                                         postprocess=postprocess),
    ]

    # Compute the pseudo-analytic cov from Noda and Nishimichi
Ejemplo n.º 13
0
from barry.datasets import CorrelationFunction_SDSS_DR12_Z061_NGC, PowerSpectrum_SDSS_DR12_Z061_NGC
from barry.samplers import DynestySampler
from barry.fitter import Fitter
import numpy as np
import pandas as pd

# Check correlation between pk and xi results using recon Ding
if __name__ == "__main__":
    pfn, dir_name, file = setup(__file__)
    fitter = Fitter(dir_name, save_dims=2, remove_output=False)
    sampler = DynestySampler(temp_dir=dir_name, nlive=400)

    for r in [True]:
        t = "Recon" if r else "Prerecon"

        d_pk = PowerSpectrum_SDSS_DR12_Z061_NGC(recon=r, realisation=0)
        d_xi = CorrelationFunction_SDSS_DR12_Z061_NGC(recon=r, realisation=0)

        ding_pk = PowerDing2018(recon=r)
        ding_pk_smooth = PowerDing2018(recon=r, smooth=True)

        ding_xi = CorrDing2018(recon=r)
        ding_xi_smooth = CorrDing2018(recon=r, smooth=True)

        for i in range(999):
            d_pk.set_realisation(i)
            d_xi.set_realisation(i)

            fitter.add_model_and_dataset(
                ding_pk,
                d_pk,
Ejemplo n.º 14
0
if __name__ == "__main__":
    logging.basicConfig(
        level=logging.DEBUG,
        format="[%(levelname)7s |%(funcName)20s]   %(message)s")
    logging.getLogger("matplotlib").setLevel(logging.ERROR)
    recon = True
    model1 = PowerDing2018(recon=recon, name=f"Ding2018, recon={recon}")
    model_smooth = PowerDing2018(recon=recon,
                                 name=f"Ding2018, recon={recon}",
                                 smooth=True)

    from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC
    from barry.datasets import DummyPowerSpectrum_SDSS_DR12_Z061_NGC

    dataset1 = PowerSpectrum_SDSS_DR12_Z061_NGC(name="Recon mean", recon=recon)
    dataset2 = DummyPowerSpectrum_SDSS_DR12_Z061_NGC(
        name="Dummy data, real window fn", dummy_window=False)
    dataset3 = DummyPowerSpectrum_SDSS_DR12_Z061_NGC(name="DummyWindowFnToo",
                                                     dummy_window=True)
    data1 = dataset1.get_data()
    data2 = dataset2.get_data()
    data3 = dataset3.get_data()

    # First comparison - the actual recon data
    model1.set_data(data1)
    p, minv = model1.optimize()
    model_smooth.set_data(data1)
    p2, minv2 = model_smooth.optimize()
    print(p)
    print(minv)
Ejemplo n.º 15
0
if __name__ == "__main__":
    pfn, dir_name, file = setup(__file__)

    c = getCambGenerator()
    r_s = c.get_data()["r_s"]
    p = BAOExtractor(r_s)

    sampler = DynestySampler(temp_dir=dir_name, nlive=1000)
    fitter = Fitter(dir_name)

    cs = ["#262232", "#116A71", "#48AB75", "#D1E05B"]

    for r in [True, False]:
        t = "Recon" if r else "Prerecon"
        ls = "-" if r else "--"
        d = PowerSpectrum_SDSS_DR12_Z061_NGC(recon=r)
        de = PowerSpectrum_SDSS_DR12_Z061_NGC(recon=r, postprocess=p)

        # Fix sigma_nl for one of the Beutler models
        model = PowerBeutler2017(recon=r)
        sigma_nl = 6.0 if r else 9.3
        model.set_default("sigma_nl", sigma_nl)
        model.set_fix_params(["om", "sigma_nl"])

        fitter.add_model_and_dataset(PowerBeutler2017(recon=r),
                                     d,
                                     name=f"Beutler 2017 {t}",
                                     linestyle=ls,
                                     color=cs[0])
        fitter.add_model_and_dataset(
            model,
from barry.models import PowerBeutler2017

if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG, format="[%(levelname)7s |%(funcName)20s]   %(message)s")
    logging.getLogger("matplotlib").setLevel(logging.ERROR)
    from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC

    for recon in [True, False]:
        model = PowerBeutler2017(recon=recon, name=f"Beutler2017, recon={recon}")
        model_smooth = PowerBeutler2017(recon=recon, name=f"Beutler2017, recon={recon}", smooth=True)

        model.set_default("om", 0.31)
        model_smooth.set_default("om", 0.31)
        # Assuming the change from 0.675 to 0.68 is something we can ignore, or we can add h0 to the default parameters.

        dataset1 = PowerSpectrum_SDSS_DR12_Z061_NGC(name=f"SDSS recon={recon}", recon=recon, reduce_cov_factor=31.62)
        data1 = dataset1.get_data()

        # First comparison - the actual recon data
        model.set_data(data1)
        p, minv = model.optimize()
        model_smooth.set_data(data1)
        p2, minv2 = model_smooth.optimize()
        print(p)
        print(minv)
        model.plot(p, smooth_params=p2)

        # FINDINGS
        # Yes, no issue recovering SDSS mean to alpha=1.0006