Esempio n. 1
0
                                         de,
                                         name=f"D18 + Extractor",
                                         linestyle=ls,
                                         color="p",
                                         realisation=i)
            fitter.add_model_and_dataset(beutler_extracted,
                                         de,
                                         name=f"B17 + Extractor",
                                         linestyle=ls,
                                         color="p",
                                         realisation=i)

    fitter.set_sampler(sampler)
    fitter.set_num_walkers(1)
    fitter.set_num_concurrent(700)
    if not fitter.should_plot():
        fitter.fit(file)

    if fitter.should_plot():
        import matplotlib.pyplot as plt
        import logging

        logging.info("Creating plots")

        model_results, summary = get_model_comparison_dataframe(fitter)

        # Define colour scheme and plt defaults
        c4 = ["#262232", "#116A71", "#48AB75", "#D1E05B"]
        plt.rc("text", usetex=True)
        plt.rc("font", family="serif")
Esempio n. 2
0
        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 = {}
        for posterior, weight, chain, model, data, extra in fitter.load():
            c.add_chain(chain,
                        weights=weight,
                        parameters=model.get_labels(),
                        **extra)

            # params = dict([(p.name, v) for p, v in zip(model.get_active_params(), chain[posterior.argmax(), :])])
            # params["om"] = 0.3121
            # model.set_data(datas[0].get_data())
            # key = f"{model.name}, alpha={params['alpha']:0.4f}"
            # pks[key] = model.get_model(datas[0].get_data(), params)
Esempio n. 3
0
from barry.fitter import Fitter
from barry.models.test import TestModel
from barry.datasets.test import TestDataset
from barry.samplers import MetropolisHastings

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

    model = TestModel()
    data = TestDataset()
    sampler = MetropolisHastings(num_steps=1000,
                                 num_burn=300,
                                 temp_dir=dir_name)

    fitter = Fitter(dir_name)
    fitter.add_model_and_dataset(model, data)
    fitter.set_num_walkers(2)
    fitter.set_sampler(sampler)
    fitter.fit(file)

    if fitter.should_plot():  # As I'm not sure if the cluster has matplotlib
        from chainconsumer import ChainConsumer

        res, = fitter.load()

        posterior, weight, chain, model, data, extra = res
        labels = model.get_labels()
        c = ChainConsumer()
        c.add_chain(chain, weights=weight, parameters=labels)
        c.plotter.plot(filename=pfn + "_contour.png")