class TestCosmoHammerSampler(object):
    ctx = None
    params = np.array([[1,2,3],[4,5,6]])
    
    def setup(self):
        self.ctx=ChainContext(self, self.params)
        
    def test_no_data(self):
        assert self.ctx.getParent() == self
        assert self.ctx.getParams() is self.params
        assert self.ctx.contains("key") == False
        assert self.ctx.getData() is not None
        assert len(list(self.ctx.getData().items())) == 0
    
    def test_add_data(self):
        assert self.ctx.contains("key") == False
        assert self.ctx.getData() is not None
        
        self.ctx.add("key", "value")
        
        assert self.ctx.contains("key") == True
        assert self.ctx.getData() is not None
        
        assert self.ctx.get("key") == "value"

    def test_remove_data(self):
        assert self.ctx.contains("key2") == False
        assert self.ctx.getData() is not None
        
        self.ctx.add("key2", "value")
        
        assert self.ctx.contains("key2") == True
        assert self.ctx.getData() is not None
        
        assert self.ctx.get("key2") == "value"
        
        self.ctx.remove("key2")
        assert self.ctx.contains("key2") == False

    def test_get_default(self):
        assert self.ctx.contains("aaa") == False
        assert self.ctx.get("aaa", "default") == "default"
        
        
    def test_additional_data(self):
        assert self.ctx.getData() is not None
        assert len(list(self.ctx.getData().items())) == 0
        
        self.ctx.getData()["moreData"] = "data"
        assert len(list(self.ctx.getData().items())) == 1
class TestCosmoHammerSampler(object):
    ctx = None
    params = np.array([[1, 2, 3], [4, 5, 6]])

    def setup(self):
        self.ctx = ChainContext(self, self.params)

    def test_no_data(self):
        assert self.ctx.getParent() == self
        assert self.ctx.getParams() is self.params
        assert self.ctx.contains("key") == False
        assert self.ctx.getData() is not None
        assert len(list(self.ctx.getData().items())) == 0

    def test_add_data(self):
        assert self.ctx.contains("key") == False
        assert self.ctx.getData() is not None

        self.ctx.add("key", "value")

        assert self.ctx.contains("key") == True
        assert self.ctx.getData() is not None

        assert self.ctx.get("key") == "value"

    def test_remove_data(self):
        assert self.ctx.contains("key2") == False
        assert self.ctx.getData() is not None

        self.ctx.add("key2", "value")

        assert self.ctx.contains("key2") == True
        assert self.ctx.getData() is not None

        assert self.ctx.get("key2") == "value"

        self.ctx.remove("key2")
        assert self.ctx.contains("key2") == False

    def test_get_default(self):
        assert self.ctx.contains("aaa") == False
        assert self.ctx.get("aaa", "default") == "default"

    def test_additional_data(self):
        assert self.ctx.getData() is not None
        assert len(list(self.ctx.getData().items())) == 0

        self.ctx.getData()["moreData"] = "data"
        assert len(list(self.ctx.getData().items())) == 1
Beispiel #3
0
#!/usr/bin/env python
import pylab

from cosmoHammer.ChainContext import ChainContext

import pycambWrapper

paramValues = [70, 0.0426, 0.122, 2.1E-009, 0.96, 0.09]

ctx = ChainContext(None, paramValues)
pyCambCore = pycambWrapper.PyCambCoreModule()
pyCambCore(ctx)

cl_tt = ctx.get(pycambWrapper.CL_TT_KEY)
cl_te = ctx.get(pycambWrapper.CL_TE_KEY)
cl_ee = ctx.get(pycambWrapper.CL_EE_KEY)
cl_bb = ctx.get(pycambWrapper.CL_BB_KEY)

pylab.subplot(1, 1, 1)
pylab.title("Power spectrum")
ell = pylab.arange(1, len(cl_tt) + 1)
pylab.semilogx(ell, cl_tt)
pylab.xlabel("$\ell$", fontsize=20)
pylab.ylabel("$\ell (\ell+1) C_\ell / 2\pi \quad [\mu K^2]$", fontsize=20)
pylab.xlim(1, 2000)

pylab.show()
#!/usr/bin/env python
from cambWrapper import CambCoreModule, CL_TT_KEY, CL_TE_KEY, CL_EE_KEY, CL_BB_KEY
from cosmoHammer.ChainContext import ChainContext

lmax = 2000
camb = CambCoreModule(lmax = lmax)
camb.setup()

params = [70, 0.0426, 0.122, 2.1E-009, 0.96, 0.09]
ctx = ChainContext(None, params)

camb(ctx)

cl_tt =ctx.get(CL_TT_KEY)
assert cl_tt.shape == (lmax-1,)
assert ctx.contains(CL_TE_KEY)
assert ctx.contains(CL_EE_KEY)
assert ctx.contains(CL_BB_KEY)
#!/usr/bin/env python
import pylab

from cosmoHammer.ChainContext import ChainContext

import pycambWrapper

paramValues = [70, 0.0426, 0.122, 2.1E-009, 0.96, 0.09]

ctx = ChainContext(None, paramValues)
pyCambCore = pycambWrapper.PyCambCoreModule()
pyCambCore(ctx)

cl_tt =ctx.get(pycambWrapper.CL_TT_KEY)
cl_te =ctx.get(pycambWrapper.CL_TE_KEY)
cl_ee =ctx.get(pycambWrapper.CL_EE_KEY)
cl_bb =ctx.get(pycambWrapper.CL_BB_KEY)


pylab.subplot(1,1,1) 
pylab.title("Power spectrum")
ell = pylab.arange(1,len(cl_tt)+1)
pylab.semilogx(ell,cl_tt)
pylab.xlabel("$\ell$", fontsize=20)
pylab.ylabel("$\ell (\ell+1) C_\ell / 2\pi \quad [\mu K^2]$", fontsize=20)
pylab.xlim(1,2000)

pylab.show()
Beispiel #6
0
#!/usr/bin/env python
from cambWrapper import CambCoreModule, CL_TT_KEY, CL_TE_KEY, CL_EE_KEY, CL_BB_KEY
from cosmoHammer.ChainContext import ChainContext

lmax = 2000
camb = CambCoreModule(lmax=lmax)
camb.setup()

params = [70, 0.0426, 0.122, 2.1E-009, 0.96, 0.09]
ctx = ChainContext(None, params)

camb(ctx)

cl_tt = ctx.get(CL_TT_KEY)
assert cl_tt.shape == (lmax - 1, )
assert ctx.contains(CL_TE_KEY)
assert ctx.contains(CL_EE_KEY)
assert ctx.contains(CL_BB_KEY)