import numpy as np sys.path.append("..") from barry.datasets.dataset_power_spectrum import PowerSpectrum_DESIMockChallenge_Handshake from barry.cosmology.camb_generator import getCambGenerator from barry.config import setup from barry.models import PowerSpectrumFit, PowerSeo2016, PowerBeutler2017, PowerDing2018, PowerNoda2019 from barry.samplers import DynestySampler from barry.fitter import Fitter if __name__ == "__main__": pfn, dir_name, file = setup(__file__) sampler = DynestySampler(temp_dir=dir_name, nlive=1000) fitter = Fitter(dir_name) cs = ["#262232", "#116A71", "#48AB75", "#D1E05B"] d = PowerSpectrum_DESIMockChallenge_Handshake(min_k=0.005, max_k=0.3, isotropic=False, realisation="data", fit_poles=[0, 2]) fitter.add_model_and_dataset(PowerBeutler2017(isotropic=False), d, name=f"Beutler 2017 Prerecon", color=cs[0]) fitter.add_model_and_dataset(PowerSeo2016(isotropic=False), d, name=f"Seo 2016 Prerecon", color=cs[1]) fitter.add_model_and_dataset(PowerDing2018(isotropic=False), d, name=f"Ding 2018 Prerecon", color=cs[2]) fitter.add_model_and_dataset(PowerNoda2019(isotropic=False), d, name=f"Noda 2019 Prerecon", color=cs[3]) fitter.set_sampler(sampler) fitter.set_num_walkers(10) fitter.fit(file) if fitter.should_plot():
from barry.config import setup from barry.fitter import Fitter from barry.models.test import TestModel from barry.datasets.test import TestDataset from barry.samplers import DynestySampler if __name__ == "__main__": pfn, dir_name, file = setup(__file__) model = TestModel() data = TestDataset() sampler = DynestySampler(temp_dir=dir_name, max_iter=None) fitter = Fitter(dir_name) fitter.add_model_and_dataset(model, data) fitter.set_sampler(sampler) fitter.set_num_walkers(1) fitter.fit(file) if fitter.should_plot(): res, = fitter.load() posterior, weight, chain, evidence, model, data, extra = res import matplotlib.pyplot as plt fig, ax = plt.subplots(nrows=2) ax[0].plot(weight) ax[1].plot(evidence)
from barry.models.model import Correction # Compare model fits with different analytic marginalisation options and where we fix the marginalised # parameters. The three types of marginalisation should give the same posteriors ("partial" is not strictly # the same, but looks identical for most purposes). The fit with fixed values will give a bad posterior. 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=500) # sampler = EnsembleSampler(temp_dir=dir_name, num_steps=5000) fitter = Fitter(dir_name) cs = ["#262232", "#294D5F", "#197D7A", "#48AC7C"] for r in [False]: t = "Recon" if r else "Prerecon" ls = "-" # if r else "--" d = PowerSpectrum_Beutler2019(recon=r, isotropic=True, reduce_cov_factor=np.sqrt(2000.0)) # Fix sigma_nl for one of the Beutler models model = PowerBeutler2017(recon=r, isotropic=d.isotropic, fix_params=["om"], correction=Correction.HARTLAP)
from barry.postprocessing import BAOExtractor from barry.config import setup from barry.models import PowerSeo2016, PowerBeutler2017, PowerDing2018 from barry.samplers import DynestySampler from barry.fitter import Fitter from barry.models.model import Correction 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 [False]: t = "Recon" if r else "Prerecon" # Changing fitting range and sigma values to match Hee-Jong d = PowerSpectrum_DESIMockChallenge0_Z01(recon=r, isotropic=False, realisation="data", min_k=0.001, max_k=0.30) model = PowerBeutler2017(recon=r, isotropic=False, correction=Correction.NONE)
from barry.postprocessing import BAOExtractor from barry.config import setup from barry.models import PowerBeutler2017 from barry.samplers import DynestySampler from barry.fitter import Fitter from barry.models.model import Correction 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 [False]: t = "Recon" if r else "Prerecon" # Fix sigma_nl for one of the Beutler models model = PowerBeutler2017(recon=r, isotropic=False, correction=Correction.NONE) model.set_default("sigma_nl_par", 10.9) model.set_default("sigma_nl_perp", 5.98) model.set_fix_params(["om", "sigma_nl_par", "sigma_nl_perp"]) for mink, maxk in [(0.02, 0.3), (0.02, 0.4), (0.02, 0.5), (0.03, 0.3), (0.03, 0.5), (0.03, 0.4), (0.04, 0.3), (0.04, 0.4), (0.04, 0.5)]: d = PowerSpectrum_DESIMockChallenge0_Z01(recon=r, isotropic=False, realisation="data", min_k=mink, max_k=maxk) fitter.add_model_and_dataset(model, d, name=f"B17 Fixed {t}, k = ({mink:0.2f}, {maxk:0.2f})")
sys.path.append("..") from barry.datasets.dataset_power_spectrum import PowerSpectrum_DESIMockChallenge_Handshake from barry.cosmology.camb_generator import getCambGenerator from barry.config import setup from barry.models import PowerSeo2016, PowerBeutler2017, PowerDing2018, PowerNoda2019 from barry.samplers import DynestySampler from barry.fitter import Fitter if __name__ == "__main__": pfn, dir_name, file = setup(__file__) c = getCambGenerator() r_s = c.get_data()["r_s"] sampler = DynestySampler(temp_dir=dir_name, nlive=1000) fitter = Fitter(dir_name) cs = ["#262232", "#116A71", "#48AB75", "#D1E05B"] d = PowerSpectrum_DESIMockChallenge_Handshake(min_k=0.005, max_k=0.3, isotropic=False, realisation="data", fit_poles=[0, 2]) d2 = PowerSpectrum_DESIMockChallenge_Handshake(min_k=0.005, max_k=0.3, isotropic=False, realisation="data", fit_poles=[0, 2, 4]) fitter.add_model_and_dataset(PowerBeutler2017(isotropic=False),
from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC from barry.postprocessing import BAOExtractor from barry.cosmology.camb_generator import getCambGenerator from barry.samplers import DynestySampler 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",
from barry.postprocessing import BAOExtractor from barry.config import setup from barry.models import PowerBeutler2017, CorrBeutler2017 from barry.datasets.dataset_power_spectrum import PowerSpectrum_DESIMockChallenge from barry.datasets.dataset_correlation_function import CorrelationFunction_DESIMockChallenge from barry.fitter import Fitter import numpy as np import pandas as pd from barry.models.model import Correction from barry.utils import weighted_avg_and_cov, break_vector_and_get_blocks from barry.cosmology.power_spectrum_smoothing import smooth from barry.generate import get_cosmologies if __name__ == "__main__": pfn, dir_name, file = setup(__file__) fitter = Fitter(dir_name, remove_output=True) sampler = DynestySampler(temp_dir=dir_name, nlive=500) cs = ["#CAF270", "#84D57B", "#4AB482", "#219180", "#1A6E73", "#234B5B", "#232C3B"] data = PowerSpectrum_DESIMockChallenge(recon=True, isotropic=False, fit_poles=[0, 2], min_k=0.02, max_k=0.45) # c = data.get_data()[0]["cosmology"] # generator = CambGenerator(om_resolution=1, h0_resolution=1, h0=c["h0"], ob=c["ob"], ns=c["ns"], redshift=c["z"], # mnu=c["mnu"]) # generator.load_data(can_generate=True) model = PowerBeutler2017(recon=True, isotropic=False, fix_params=["om"], poly_poles=[0, 2], correction=Correction.NONE, marg="full") pklin = np.array(pd.read_csv("../barry/data/desi_mock_challenge_post_recon/Pk_Planck15_Table4.txt", delim_whitespace=True, header=None)) model.set_fix_params(["om"])
# redorder cov matrix, pk goes first, then the extracted part mask_extracted = postprocess.get_is_extracted(datas[0].ks) index_sort = np.arange(mask_extracted.size).astype( np.int) + (1000 * mask_extracted) a = np.argsort(index_sort) cov_noda = cov_noda[:, a] cov_noda = cov_noda[a, :] cov_noda_diag = cov_noda_diag[:, a] cov_noda_diag = cov_noda_diag[a, :] datas[1].set_cov(cov_noda) datas[2].set_cov(cov_noda_diag) sampler = DynestySampler(temp_dir=dir_name) fitter = Fitter(dir_name) fitter.add_model_and_dataset(model, datas[0], name="Mock-computed") fitter.add_model_and_dataset(model, datas[1], name="Nishimichi 2018, full") fitter.add_model_and_dataset(model, datas[2], name="Nishimichi 2018, diagonal") fitter.set_sampler(sampler) fitter.set_num_walkers(10) fitter.fit(file) if fitter.should_plot(): from chainconsumer import ChainConsumer c = ChainConsumer() for posterior, weight, chain, evidence, model, data, extra in fitter.load( ):
from barry.models.model import Correction # Check to see if including the hexadecapole or higher order multipoles gives tighter constraints on BAO parameters # when fitting the mock average if __name__ == "__main__": pfn, dir_name, file = setup(__file__) # dir_name = dir_name + "nlive_1500/" c = getCambGenerator() r_s = c.get_data()["r_s"] p = BAOExtractor(r_s) sampler = DynestySampler(temp_dir=dir_name, nlive=500) # sampler = EnsembleSampler(temp_dir=dir_name, num_steps=5000) fitter = Fitter(dir_name) cs = ["#262232", "#116A71", "#48AB75", "#D1E05B"] for r in [True]: t = "Recon" if r else "Prerecon" ls = "-" # if r else "--" d_quad = PowerSpectrum_Beutler2019(recon=r, isotropic=False, fit_poles=[0, 2], reduce_cov_factor=np.sqrt(2000.0)) d_odd = PowerSpectrum_Beutler2019(recon=r, isotropic=False, fit_poles=[0, 1, 2], reduce_cov_factor=np.sqrt(2000.0)) d_hexa = PowerSpectrum_Beutler2019(recon=r,
from barry.postprocessing import BAOExtractor from barry.config import setup from barry.models import PowerSeo2016, PowerBeutler2017, PowerDing2018 from barry.samplers import DynestySampler from barry.fitter import Fitter from barry.models.model import Correction 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 [False]: t = "Recon" if r else "Prerecon" d = PowerSpectrum_DESIMockChallenge0_Z01(recon=r, isotropic=False, realisation="data") # Fix sigma_nl for one of the Beutler models model = PowerBeutler2017(recon=r, isotropic=False, correction=Correction.NONE) model.set_default("sigma_nl_par", 10.9) model.set_default("sigma_nl_perp", 5.98) model.set_fix_params(["om", "sigma_nl_par", "sigma_nl_perp"]) fitter.add_model_and_dataset(PowerBeutler2017(recon=r, isotropic=False, correction=Correction.NONE, fix_params=["om"]), d, name=f"Beutler 2017 {t}") fitter.add_model_and_dataset(model, d, name=f"Beutler 2017 Fixed $\\Sigma_{{nl}}$ {t}")
from barry.postprocessing import BAOExtractor from barry.cosmology.camb_generator import getCambGenerator from barry.samplers import DynestySampler from barry.fitter import Fitter # Check the impact of fixing parameters in the Noda model if __name__ == "__main__": pfn, dir_name, file = setup(__file__) c = getCambGenerator() r_s = c.get_data()["r_s"] 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, fix_params=["om", "f", "gamma", "b"]) n.param_dict["b"].default = 1.992 if r else 1.996 fitter.add_model_and_dataset( n, data, name=f"N19 {rt} fixed $f$, $\\gamma_{{rec}}$, $b$", linestyle="-" if r else "--", color="o",
import sys sys.path.append("..") from barry.cosmology.camb_generator import getCambGenerator from barry.config import setup from barry.models import PowerDing2018, CorrDing2018 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):
import numpy as np sys.path.append("..") from barry.datasets.dataset_power_spectrum import PowerSpectrum_DESIMockChallenge_Handshake from barry.cosmology.camb_generator import getCambGenerator from barry.config import setup from barry.models import PowerSpectrumFit, PowerSeo2016, PowerBeutler2017, PowerDing2018, PowerNoda2019 from barry.samplers import DynestySampler from barry.fitter import Fitter from barry.cosmology.power_spectrum_smoothing import smooth if __name__ == "__main__": pfn, dir_name, file = setup(__file__) sampler = DynestySampler(temp_dir=dir_name, nlive=1000) fitter = Fitter(dir_name) cs = ["#262232", "#116A71", "#48AB75", "#D1E05B"] d = PowerSpectrum_DESIMockChallenge_Handshake(min_k=0.005, max_k=0.3, isotropic=False, realisation="data", fit_poles=[0, 2]) fitter.add_model_and_dataset(PowerBeutler2017(isotropic=False), d, name=f"Cullan's Pk", color=cs[0]) # Re-do the desi fits, but now using the linear pk provided for the UNIT sim
from barry.postprocessing import BAOExtractor from barry.config import setup from barry.utils import weighted_avg_and_cov from barry.models import PowerBeutler2017 from barry.datasets.dataset_power_spectrum import PowerSpectrum_SDSS_DR12, PowerSpectrum_eBOSS_LRGpCMASS from barry.fitter import Fitter import numpy as np import pandas as pd from barry.models.model import Correction # Run an optimisation on each of the post-recon SDSS DR12 mocks. Then compare to the pre-recon mocks # to compute the cross-correlation between BAO parameters and pre-recon measurements if __name__ == "__main__": pfn, dir_name, file = setup(__file__) fitter = Fitter(dir_name, remove_output=False) c = getCambGenerator() # sampler = DynestySampler(temp_dir=dir_name, nlive=500) sampler = Optimiser(temp_dir=dir_name, tol=1.0e-4) cs = ["#262232", "#116A71", "#48AB75", "#D1E05B"] datasets = [ PowerSpectrum_SDSS_DR12(redshift_bin=1, galactic_cap="ngc", recon="iso", isotropic=False, fit_poles=[0, 2], min_k=0.02,
from barry.models import PowerSeo2016, PowerBeutler2017, PowerDing2018, PowerNoda2019 from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC from barry.samplers import DynestySampler from barry.fitter import Fitter # Checks to see if the better fits from the power spectrum are due to differences in the effective fitting range. # Spoiler: No. 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
from barry.models import PowerNoda2019, PowerSeo2016, PowerBeutler2017, PowerDing2018 from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC from barry.postprocessing import BAOExtractor from barry.cosmology.camb_generator import getCambGenerator from barry.samplers import DynestySampler from barry.fitter import Fitter # 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])
from barry.utils import weighted_avg_and_cov from barry.models import PowerBeutler2017 from barry.datasets.dataset_power_spectrum import PowerSpectrum_SDSS_DR12, PowerSpectrum_eBOSS_LRGpCMASS from barry.fitter import Fitter import numpy as np import pandas as pd from barry.models.model import Correction import matplotlib as plt from matplotlib import cm # Run an optimisation on each of the post-recon SDSS DR12 mocks. Then compare to the pre-recon mocks # to compute the cross-correlation between BAO parameters and pre-recon measurements if __name__ == "__main__": pfn, dir_name, file = setup(__file__) fitter = Fitter(dir_name) c = getCambGenerator() sampler = DynestySampler(temp_dir=dir_name, nlive=500) cmap = plt.cm.get_cmap("viridis") datasets = [ PowerSpectrum_SDSS_DR12( redshift_bin=1, realisation="data", galactic_cap="ngc", recon="iso", isotropic=False, fit_poles=[0, 2],
import sys sys.path.append("..") from barry.samplers import DynestySampler from barry.cosmology.camb_generator import getCambGenerator from barry.postprocessing import BAOExtractor from barry.config import setup from barry.models import PowerSeo2016, PowerBeutler2017, PowerDing2018, PowerNoda2019 from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC from barry.fitter import Fitter import numpy as np import pandas as pd 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)
sys.path.append("..") from barry.config import setup from barry.models import PowerNoda2019 from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC from barry.postprocessing import BAOExtractor from barry.cosmology.camb_generator import CambGenerator from barry.samplers import DynestySampler from barry.fitter import Fitter if __name__ == "__main__": pfn, dir_name, file = setup(__file__) c = CambGenerator() r_s = c.get_data()[0] fitter = Fitter(dir_name) ps = [ BAOExtractor(r_s, extra_ks=(0.095, 0.13)), BAOExtractor(r_s, extra_ks=(0.095, 0.14)), BAOExtractor(r_s, extra_ks=(0.095, 0.15)), 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)), ]
ax[0].set_xlabel(l) axes[0, 0].set_ylabel(r"$N_{\mathrm{mocks}}$") fig.savefig(figname, bbox_inches="tight", transparent=True, dpi=300) return nstats, means, covs, corr if __name__ == "__main__": # Get the relative file paths and names pfn, dir_name, file = setup(__file__) # Set up the Fitting class and Dynesty sampler with 250 live points. fitter = Fitter(dir_name, remove_output=False) sampler = DynestySampler(temp_dir=dir_name, nlive=250) mocktypes = ["abacus_cutsky"] nzbins = [3] # Loop over the mocktypes allnames = [] for i, (mocktype, redshift_bins) in enumerate(zip(mocktypes, nzbins)): # Loop over the available redshift bins for each mock type for z in range(redshift_bins): # Create the data. We'll fit mono-, quad- and hexadecapole between k=0.02 and 0.3. # First load up mock mean and add it to the fitting list. dataset = PowerSpectrum_DESI_KP4(
from barry.config import setup 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")
from barry.utils import plot_bestfit from barry.samplers import DynestySampler # Run a quick test using dynesty to fit a mock mean. if __name__ == "__main__": pfn, dir_name, file = setup(__file__) data = PowerSpectrum_SDSS_DR12(isotropic=True, recon="iso") model = PowerBeutler2017(isotropic=data.isotropic, recon=data.recon, marg="full") sampler = DynestySampler(temp_dir=dir_name) fitter = Fitter(dir_name) fitter.add_model_and_dataset(model, data) fitter.set_sampler(sampler) fitter.set_num_walkers(1) fitter.fit(file) if fitter.should_plot(): from chainconsumer import ChainConsumer posterior, weight, chain, evidence, model, data, extra = fitter.load( )[0] print(extra["name"]) chi2, dof, bband, mods, smooths = plot_bestfit(posterior, chain, model, title=extra["name"],
sys.path.append("..") from barry.samplers import DynestySampler from barry.cosmology.camb_generator import getCambGenerator from barry.postprocessing import BAOExtractor from barry.config import setup from barry.models import PowerSeo2016, PowerBeutler2017, PowerDing2018, PowerNoda2019 from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC from barry.fitter import Fitter import numpy as np import pandas as pd if __name__ == "__main__": pfn, dir_name, file = setup(__file__) 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)
import os import numpy as np import pandas as pd from scipy.interpolate import interp1d sys.path.append("..") from barry.config import setup from barry.models import CorrBeutler2017, CorrDing2018, CorrSeo2016 from barry.datasets import CorrelationFunction_SDSS_DR12_Z061_NGC from barry.samplers import DynestySampler from barry.fitter import Fitter if __name__ == "__main__": pfn, dir_name, file = setup(__file__) sampler = DynestySampler(temp_dir=dir_name, nlive=1000) fitter = Fitter(dir_name, remove_output=False) cs = ["#262232", "#116A71", "#48AB75", "#D1E05B"] for r in [True, False]: t = "Recon" if r else "Prerecon" ls = "-" if r else "--" d = CorrelationFunction_SDSS_DR12_Z061_NGC(recon=r) # Fix sigma_nl for one of the Beutler models model = CorrBeutler2017() 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(CorrBeutler2017(), d, name=f"Beutler 2017 {t}", linestyle=ls, color=cs[0]) fitter.add_model_and_dataset(model, d, name=f"Beutler 2017 Fixed $\\Sigma_{{nl}}$ {t}", linestyle=ls, color=cs[0])
from barry.cosmology.camb_generator import getCambGenerator from barry.postprocessing import BAOExtractor from barry.config import setup from barry.utils import weighted_avg_and_std, get_model_comparison_dataframe from barry.models import PowerDing2018, PowerBeutler2017 from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC from barry.samplers import DynestySampler from barry.fitter import Fitter import numpy as np import pandas as pd # Check if B17 and D18 results change if we apply the BAO extractor technique. # Spoiler: They do not. if __name__ == "__main__": pfn, dir_name, file = setup(__file__) fitter = Fitter(dir_name, remove_output=False) c = getCambGenerator() r_s = c.get_data()["r_s"] 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)
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 = {} for posterior, weight, chain, model, data, extra in fitter.load(): c.add_chain(chain, weights=weight, parameters=model.get_labels(),
import sys sys.path.append("..") from barry.cosmology.camb_generator import getCambGenerator from barry.postprocessing import BAOExtractor from barry.config import setup, weighted_avg_and_std from barry.models import PowerDing2018, PowerBeutler2017 from barry.datasets import PowerSpectrum_SDSS_DR12_Z061_NGC from barry.samplers import DynestySampler from barry.fitter import Fitter import numpy as np import pandas as pd if __name__ == "__main__": pfn, dir_name, file = setup(__file__) fitter = Fitter(dir_name, 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)