Beispiel #1
0
def main():
    # cluster parameters
    redshift = 0.7019
    NH_1022pcm2 = 0.0137
    Z_solar = 0.3

    # for calculating distances, etc.
    cosmology = mb.Cosmology(redshift)

    # annuli object contains edges of annuli
    annuli = mb.Annuli(getEdges(), cosmology)

    # load each band, chopping outer radius
    bands = []
    for bandE in bandEs:
        bands.append(loadBand(bandE))

    # Data object represents annuli and bands
    data = mb.Data(bands, annuli)

    # flat metallicity profile
    Z_cmpt = mb.CmptFlat('Z', annuli, defval=Z_solar)
    # this is the modified beta model density described in Sanders+17 (used in McDonald+12)
    # (single mode means only one beta model, as described in Vikhlinin+06)
    ne_cmpt = mb.CmptVikhDensity('ne', annuli, mode='single')

    # nfw mass model
    nfw = mb.CmptMassNFW(annuli)

    # hydrostatic model combining mass, density and metallicity
    model = mb.ModelHydro(
        annuli, nfw, ne_cmpt, Z_cmpt, NH_1022pcm2=NH_1022pcm2)

    # get default parameters
    pars = model.defPars()

    # add parameter which allows variation of background with a
    # Gaussian prior with sigma=0.1
    pars['backscale'] = mb.ParamGaussian(1., prior_mu=1, prior_sigma=0.1)

    # freeze metallicity at fixed value
    pars['Z'].frozen = True

    # change range of NFW concentration and r200
    # (val is initial value, minval and maxval give allowed range)
    pars['nfw_logconc'].val = N.log10(4)
    pars['nfw_logconc'].minval = N.log10(1)
    pars['nfw_logconc'].maxval = N.log10(10)
    pars['nfw_r200_logMpc'].minval = -2
    pars['nfw_r200_logMpc'].maxval = 1

    # override default outer pressure
    pars['Pout_logergpcm3'].minval = -16
    pars['Pout_logergpcm3'].maxval = -8
    
    # stop radii going beyond edge of data
    pars['ne_logrc_1'].maxval = annuli.edges_logkpc[-2]
    pars['ne_logr_s'].maxval = annuli.edges_logkpc[-2]

    # some ranges of parameters to allow for the density model
    pars['ne_gamma'].val = 3.
    pars['ne_gamma'].frozen = True
    pars['ne_logrc_1'].val = 2.
    pars['ne_alpha'].val = 0.1
    pars['ne_alpha'].maxval = 4
    pars['ne_alpha'].minval = 0.
    pars['ne_epsilon'].maxval = 10

    # do fitting of data with model
    fit = mb.Fit(pars, model, data)
    # refreshThawed is required if frozen is changed after Fit is
    # constructed before doFitting (it's not required here)
    fit.refreshThawed()
    fit.doFitting()

    # construct MCMC object and do burn in
    mcmc = mb.MCMC(fit, walkers=nwalkers, processes=nthreads)
    mcmc.burnIn(nburn)

    # save best fit
    with open('%s_fit.pickle' % name, 'wb') as f:
        pickle.dump(fit, f, -1)

    # run mcmc proper
    chainfilename = '%s_chain.hdf5' % name
    mcmc.run(nlength)
    mcmc.save(chainfilename)

    # construct a set of physical median profiles from the chain and
    # save
    profs = mb.replayChainPhys(
        chainfilename, model, pars, thin=10, confint=68.269)
    mb.savePhysProfilesHDF5('%s_medians.hdf5' % name, profs)
    mb.savePhysProfilesText('%s_medians.txt' % name, profs)
Beispiel #2
0
from joxsz_plots import traceplot, triangle, best_fit_prof, fitwithmod, comp_rad_profs, plot_rad_profs, comp_mass_prof, mass_plot, frac_gas_prof, frac_gas_plot
from types import MethodType
import emcee as mc
from multiprocessing import Pool

#################
## Global and local variables

mystep = 2.  # constant sampling step in arcsec for SZ analysis (values higher than (1/3)*FWHM of the SZ beam are not recommended)
m_e = 0.5109989 * 1e3  # electron rest mass (keV/c^2)
sigma_T = 6.6524587158 * 1e-25  # Thomson cross section (cm^2)
R_b = 5000.  # Radial cluster extent (kpc), serves as upper bound for Compton y parameter integration

# Cluster cosmology
redshift = 0.888
cosmology = mb.Cosmology(redshift)
cosmology.H0 = 67.32  # Hubble's constant (km/s/Mpc)
cosmology.WM = 0.3158  # matter density
cosmology.WV = 0.6842  # vacuum density

# name for outputs
name = 'joxsz'
plotdir = './'  # directory for the plots
savedir = './'  # directory for saved files

# Uncertainty level
ci = 95

# MCMC parameters
nburn = 2000  # number of burn-in iterations
nlength = 5000  # number of chain iterations (after burn-in)
def main():
    indir = '.'

    cosmology = mbproj2.Cosmology(0.1028)

    # define annuli using 1st two columns in this file
    annuli = mbproj2.loadAnnuli(
        os.path.join(indir, 'sb_profile_1200_2500.dat.rebin'), cosmology)

    # load count profiles for each band
    bands = []
    for emin, emax in ((0.5, 1.2), (1.2, 2.5), (2.5, 6.0)):
        band =  mbproj2.loadBand(
            os.path.join(indir, 'sb_profile_%i_%i.dat.rebin' % (
                emin*1000, emax*1000)),
            emin, emax,
            os.path.join(indir, 'ann_0_total_rmf.fits'),
            os.path.join(indir, 'ann_0_total_arf.fits'))
        band.backrates = N.loadtxt(
            os.path.join(indir, 'sb_bgcomb_%i_%i.dat.rebin.norm' % (
                emin*1000, emax*1000)))[:,2]
        bands.append(band)

    data = mbproj2.Data(bands, annuli)

    # this is the mass component to use
    nfw = mbproj2.CmptMassNFW(annuli)
    # density component
    ne_cmpt = mbproj2.CmptBinned(
        'ne', annuli, log=True, defval=-2, minval=-6., maxval=1.)
    # metallicity component
    Z_cmpt = mbproj2.CmptFlat(
        'Z', annuli, defval=N.log10(0.3), log=True, minval=-2., maxval=1.)

    # combine components to create model
    model = mbproj2.ModelHydro(
        annuli, nfw, ne_cmpt, Z_cmpt, NH_1022pcm2=0.378)

    # get default parameters
    pars = model.defPars()

    # example change in parameter
    pars['Z'].val = N.log10(0.4)
    pars['Z'].frozen = True

    # estimate densities from surface brightness to avoid fits
    mbproj2.estimateDensityProfile(model, data, pars)

    # fit parameters to data
    fit = mbproj2.Fit(pars, model, data)
    fit.doFitting()

    # now start MCMC using 4 processes
    mcmc = mbproj2.MCMC(fit, walkers=200, processes=4)
    mcmc.burnIn(1000)
    mcmc.run(1000)
    mcmc.save('chain.hdf5')

    # compute physical profiles and save as medians
    profs = mbproj2.replayChainPhys('chain.hdf5', model, pars)
    mbproj2.savePhysProfilesHDF5('medians.hdf5', profs)