本文整理汇总了Python中classy.Class.raw_cl方法的典型用法代码示例。如果您正苦于以下问题:Python Class.raw_cl方法的具体用法?Python Class.raw_cl怎么用?Python Class.raw_cl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类classy.Class
的用法示例。
在下文中一共展示了Class.raw_cl方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestClass
# 需要导入模块: from classy import Class [as 别名]
# 或者: from classy.Class import raw_cl [as 别名]
#.........这里部分代码省略.........
sys.stderr.write("%s = %s\n" % (key, value))
sys.stderr.write("\n")
setting = self.cosmo.set(dict(self.verbose.items() + self.scenario.items()))
self.assertTrue(setting, "Class failed to initialize with input dict")
cl_list = ["tCl", "lCl", "pCl", "nCl", "sCl"]
# Depending on the cases, the compute should fail or not
should_fail = True
output = self.scenario["output"].split()
for elem in output:
if elem in ["tCl", "pCl"]:
for elem2 in output:
if elem2 == "lCl":
should_fail = False
break
if not should_fail:
self.cosmo.compute()
else:
self.assertRaises(CosmoSevereError, self.cosmo.compute)
return
self.assertTrue(self.cosmo.state, "Class failed to go through all __init__ methods")
if self.cosmo.state:
print "--> Class is ready"
# Depending
if "output" in self.scenario.keys():
# Positive tests
output = self.scenario["output"]
for elem in output.split():
if elem in cl_list:
print "--> testing raw_cl function"
cl = self.cosmo.raw_cl(100)
self.assertIsNotNone(cl, "raw_cl returned nothing")
self.assertEqual(np.shape(cl["tt"])[0], 101, "raw_cl returned wrong size")
if elem == "mPk":
print "--> testing pk function"
pk = self.cosmo.pk(0.1, 0)
self.assertIsNotNone(pk, "pk returned nothing")
# Negative tests of output functions
if not any([elem in cl_list for elem in output.split()]):
print "--> testing absence of any Cl"
self.assertRaises(CosmoSevereError, self.cosmo.raw_cl, 100)
if "mPk" not in self.scenario["output"].split():
print "--> testing absence of mPk"
# args = (0.1, 0)
self.assertRaises(CosmoSevereError, self.cosmo.pk, 0.1, 0)
@parameterized.expand(
itertools.product(("massless", "massive", "both"), ("photons", "massless", "exact"), ("t", "s, t"))
)
def test_tensors(self, scenario, method, modes):
"""Test the new tensor mode implementation"""
self.scenario = {}
if scenario == "massless":
self.scenario.update({"N_eff": 3.046, "N_ncdm": 0})
elif scenario == "massiv":
self.scenario.update({"N_eff": 0, "N_ncdm": 2, "m_ncdm": "0.03, 0.04", "deg_ncdm": "2, 1"})
elif scenario == "both":
self.scenario.update({"N_eff": 1.5, "N_ncdm": 2, "m_ncdm": "0.03, 0.04", "deg_ncdm": "1, 0.5"})
sys.stderr.write("\n\n---------------------------------\n")
sys.stderr.write("| Test case: %s %s %s |\n" % (scenario, method, modes))
sys.stderr.write("---------------------------------\n")
示例2: Helium
# 需要导入模块: from classy import Class [as 别名]
# 或者: from classy.Class import raw_cl [as 别名]
'omega_cdm':0.12038,
'A_s':2.215e-9,
'n_s':0.9619,
'tau_reio':0.0925,
# Take fixed value for primordial Helium (instead of automatic BBN adjustment)
'YHe':0.246,
# other output and precision parameters
'l_max_scalars':5000}
###############
#
# call CLASS
#
M = Class()
M.set(common_settings)
M.compute()
cl_tot = M.raw_cl(3000)
cl_lensed = M.lensed_cl(3000)
M.struct_cleanup() # clean output
M.empty() # clean input
#
M.set(common_settings) # new input
M.set({'temperature contributions':'tsw'})
M.compute()
cl_tsw = M.raw_cl(3000)
M.struct_cleanup()
M.empty()
#
M.set(common_settings)
M.set({'temperature contributions':'eisw'})
M.compute()
cl_eisw = M.raw_cl(3000)
示例3: TestClass
# 需要导入模块: from classy import Class [as 别名]
# 或者: from classy.Class import raw_cl [as 别名]
#.........这里部分代码省略.........
self.scenario.update({'Omega_k': 0.01})
elif name == 'Negative_Omega_k':
self.scenario.update({'Omega_k': -0.01})
elif name == 'Isocurvature_modes':
self.scenario.update({'ic': 'ad,nid,cdi', 'c_ad_cdi': -0.5})
self.scenario.update(scenario)
if scenario != {}:
self.scenario.update(gauge)
self.scenario.update(nonlinear)
sys.stderr.write('\n\n---------------------------------\n')
sys.stderr.write('| Test case %s |\n' % name)
sys.stderr.write('---------------------------------\n')
for key, value in self.scenario.iteritems():
sys.stderr.write("%s = %s\n" % (key, value))
sys.stderr.write("\n")
setting = self.cosmo.set(
dict(self.verbose.items()+self.scenario.items()))
self.assertTrue(setting, "Class failed to initialize with input dict")
cl_list = ['tCl', 'lCl', 'pCl', 'nCl', 'sCl']
# Depending on the cases, the compute should fail or not
should_fail = True
output = self.scenario['output'].split()
for elem in output:
if elem in ['tCl', 'pCl']:
for elem2 in output:
if elem2 == 'lCl':
should_fail = False
break
if not should_fail:
self.cosmo.compute()
else:
self.assertRaises(CosmoSevereError, self.cosmo.compute)
return
self.assertTrue(
self.cosmo.state,
"Class failed to go through all __init__ methods")
if self.cosmo.state:
print '--> Class is ready'
# Depending
if 'output' in self.scenario.keys():
# Positive tests
output = self.scenario['output']
for elem in output.split():
if elem in cl_list:
print '--> testing raw_cl function'
cl = self.cosmo.raw_cl(100)
self.assertIsNotNone(cl, "raw_cl returned nothing")
self.assertEqual(
np.shape(cl['tt'])[0], 101,
"raw_cl returned wrong size")
if elem == 'mPk':
print '--> testing pk function'
pk = self.cosmo.pk(0.1, 0)
self.assertIsNotNone(pk, "pk returned nothing")
# Negative tests of output functions
if not any([elem in cl_list for elem in output.split()]):
print '--> testing absence of any Cl'
self.assertRaises(CosmoSevereError, self.cosmo.raw_cl, 100)
if 'mPk' not in self.scenario['output'].split():
print '--> testing absence of mPk'
#args = (0.1, 0)
self.assertRaises(CosmoSevereError, self.cosmo.pk, 0.1, 0)
print '~~~~~~~~ passed ? '
@parameterized.expand(
itertools.product(
('massless', 'massive', 'both'),
('photons', 'massless', 'exact'),
('t', 's, t')))
def test_tensors(self, scenario, method, modes):
"""Test the new tensor mode implementation"""
self.scenario = {}
if scenario == 'massless':
self.scenario.update({'N_eff': 3.046, 'N_ncdm':0})
elif scenario == 'massiv':
self.scenario.update(
{'N_eff': 0, 'N_ncdm': 2, 'm_ncdm': '0.03, 0.04',
'deg_ncdm': '2, 1'})
elif scenario == 'both':
self.scenario.update(
{'N_eff': 1.5, 'N_ncdm': 2, 'm_ncdm': '0.03, 0.04',
'deg_ncdm': '1, 0.5'})
self.scenario.update({
'tensor method': method, 'modes': modes,
'output': 'tCl, pCl'})
for key, value in self.scenario.iteritems():
sys.stderr.write("%s = %s\n" % (key, value))
sys.stderr.write("\n")
self.cosmo.set(
dict(self.verbose.items()+self.scenario.items()))
self.cosmo.compute()
示例4: TestClass
# 需要导入模块: from classy import Class [as 别名]
# 或者: from classy.Class import raw_cl [as 别名]
#.........这里部分代码省略.........
setting = self.cosmo.set(dict(self.verbose.items() + self.scenario.items()))
self.assertTrue(setting, "Class failed to initialize with input dict")
cl_dict = {"tCl": ["tt"], "lCl": ["pp"], "pCl": ["ee", "bb"]}
density_cl_list = ["nCl", "sCl"]
# 'lensing' is always set to yes. Therefore, trying to compute 'tCl' or
# 'pCl' will fail except if we also ask for 'lCl'. The flag
# 'should_fail' stores this status.
sys.stderr.write("Should")
should_fail = self.test_incompatible_input()
if should_fail:
sys.stderr.write(" fail...\n")
else:
sys.stderr.write(" not fail...\n")
if not should_fail:
self.cosmo.compute()
else:
self.assertRaises(CosmoSevereError, self.cosmo.compute)
return
self.assertTrue(self.cosmo.state, "Class failed to go through all __init__ methods")
if self.cosmo.state:
print "--> Class is ready"
# Depending
if "output" in self.scenario.keys():
# Positive tests of raw cls
output = self.scenario["output"]
for elem in output.split():
if elem in cl_dict.keys():
for cl_type in cl_dict[elem]:
sys.stderr.write("--> testing raw_cl for %s\n" % cl_type)
cl = self.cosmo.raw_cl(100)
self.assertIsNotNone(cl, "raw_cl returned nothing")
self.assertEqual(np.shape(cl[cl_type])[0], 101, "raw_cl returned wrong size")
# TODO do the same for lensed if 'lCl' is there, and for
# density cl
if elem == "mPk":
sys.stderr.write("--> testing pk function\n")
pk = self.cosmo.pk(0.1, 0)
self.assertIsNotNone(pk, "pk returned nothing")
# Negative tests of output functions
if not any([elem in cl_dict.keys() for elem in output.split()]):
sys.stderr.write("--> testing absence of any Cl\n")
self.assertRaises(CosmoSevereError, self.cosmo.raw_cl, 100)
if "mPk" not in output.split():
sys.stderr.write("--> testing absence of mPk\n")
self.assertRaises(CosmoSevereError, self.cosmo.pk, 0.1, 0)
if COMPARE_OUTPUT:
# Now, compute with Newtonian gauge, and compare the results
self.cosmo_newt.set(dict(self.verbose.items() + self.scenario.items()))
self.cosmo_newt.set({"gauge": "newtonian"})
self.cosmo_newt.compute()
# Check that the computation worked
self.assertTrue(self.cosmo_newt.state, "Class failed to go through all __init__ methods in Newtonian gauge")
self.compare_output(self.cosmo, self.cosmo_newt)
def test_incompatible_input(self):
should_fail = False
# If we have tensor modes, we must have one tensor observable,
示例5: Model
# 需要导入模块: from classy import Class [as 别名]
# 或者: from classy.Class import raw_cl [as 别名]
#.........这里部分代码省略.........
if texname:
self.set_texnames({varied_name: texname})
elif key not in self.texnames: # texname will not be set at this stage. No check required
self.set_texnames({varied_name: varied_name})
if (not update) or (key not in self.computed.keys()):
self.computed[key] = od()
for val in values:
# key = "{}={}".format(varied_name, val)
params["parameters_smg"] = inip.vary_params(params["parameters_smg"], [[index_variable, val]])
# It might be after the try to not store empty dictionaries.
# Nevertheless, I find more useful having them to keep track of
# those failed and, perhaps, to implement a method to obtain them
# with Omega_smg_debug.
d = self.computed[key][val] = {}
self.cosmo.empty()
self.cosmo.set(params)
try:
self.cosmo.compute()
except Exception, e:
print "Error: skipping {}={}".format(key, val)
if cosmo_msg:
print e
continue
d['tunned'] = self.cosmo.get_current_derived_parameters(['tuning_parameter'])['tuning_parameter']
for lst in [[back, 'back', self.cosmo.get_background],
[thermo, 'thermo', self.cosmo.get_thermodynamics],
[prim, 'prim', self.cosmo.get_thermodynamics]]:
if lst[0]:
output = lst[2]()
if lst[0][0] == 'all':
d[lst[1]] = output
else:
d[lst[1]] = {}
for item in back:
if type(item) is list:
d[lst[1]].update({item[0]: output[item[0]][item[1]]})
else:
d[lst[1]].update({item: output[item]})
if pert:
# Perturbation is tricky because it can accept two optional
# argument for get_perturbations and this method returns a
# dictionary {'kind_of_pert': [{variable: list_values}]}, where
# each item in the list is for a k (chosen in params).
if type(pert[0]) is dict:
output = self.cosmo.get_perturbations(pert[0]['z'], pert[0]['output_format'])
if pert[1] == 'all':
d['pert'] = output
else:
output = self.cosmo.get_perturbations()
if pert[0] == 'all':
d['pert'] = output
if (type(pert[0]) is not dict) and (pert[0] != 'all'):
d['pert'] = {}
for subkey, lst in output.iteritems():
d['pert'].update({subkey: []})
for n, kdic in enumerate(lst): # Each item is for a k
d['pert'][subkey].append({})
for item in pert:
if type(item) is list:
d['pert'][subkey][n].update({item[0]: kdic[item[0]][item[1]]})
else:
d['pert'][subkey][n].update({item: kdic[item]})
for i in extra:
exec('d[i] = self.cosmo.{}'.format(i))
try:
d['cl'] = self.__store_cl(self.cosmo.raw_cl())
except CosmoSevereError:
pass
try:
d['lcl'] = self.__store_cl(self.cosmo.lensed_cl())
except CosmoSevereError:
pass
try:
d['dcl'] = self.cosmo.density_cl()
except CosmoSevereError:
pass
if ("output" in self.cosmo.pars) and ('mPk' in self.cosmo.pars['output']):
k_array = np.linspace(*pk)
pk_array = np.array([self.cosmo.pk(k, 0) for k in k_array])
d['pk'] = {'k': k_array, 'pk': pk_array}
self.cosmo.struct_cleanup()
示例6: need
# 需要导入模块: from classy import Class [as 别名]
# 或者: from classy.Class import raw_cl [as 别名]
#########################
# presentation settings
ax_Cl.set_xlim([3.e-4,0.5])
ax_Cl.set_ylim([0.,8.])
ax_Cl.set_xlabel(r'$\ell/(\tau_0-\tau_{rec}) \,\,\, \mathrm{[h/Mpc]}$')
ax_Cl.set_ylabel(r'$\ell (\ell+1) C_l^{TT} / 2 \pi \,\,\, [\times 10^{10}]$')
ax_Cl.tick_params(axis='x',which='both',bottom='on',top='off',labelbottom='on',labeltop='off')
ax_Cl.grid()
#
# the x-axis will show l/(tau_0-tau_rec), so we need (tau_0-tau_rec) in units of [Mpc/h]
#
tau_0_minus_tau_rec_hMpc = (derived['conformal_age']-derived['tau_rec'])*M.h()
#
# save the total Cl's (we will plot them in the last step)
#
cl_tot = M.raw_cl(5000)
#
# call CLASS with TSW, then plot and save
#
M.struct_cleanup() # clean output
M.empty() # clean input
M.set(common_settings) # new input
M.set({'temperature contributions':'tsw'})
M.compute()
cl = M.raw_cl(5000)
#
ax_Cl.semilogx(cl['ell']/tau_0_minus_tau_rec_hMpc,1.e10*cl['ell']*(cl['ell']+1.)*cl['tt']/2./math.pi,'c-',label=r'$\mathrm{T+SW}$')
#
ax_Cl.legend(loc='right',bbox_to_anchor=(1.4, 0.5))
fig.savefig('one_time_with_cl_1.pdf',bbox_inches='tight')
#