本文整理汇总了Python中classy.Class.density_cl方法的典型用法代码示例。如果您正苦于以下问题:Python Class.density_cl方法的具体用法?Python Class.density_cl怎么用?Python Class.density_cl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类classy.Class
的用法示例。
在下文中一共展示了Class.density_cl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: enumerate
# 需要导入模块: from classy import Class [as 别名]
# 或者: from classy.Class import density_cl [as 别名]
fig, axs = plt.subplots(1, 2, figsize=(14, 5))
finer_z_grid = np.linspace(0, 2, num=2000)
for i, nz in enumerate(redshiftdistributions):
ic = str(i+1)
nz_grid = nz.eval(z_grid)
finer_nz_grid = nz.eval(finer_z_grid)
axs[i].plot(finer_z_grid, finer_nz_grid, label='Gaussian Mixture')
axs[i].plot(z_grid, nz_grid, label='Histogram-ized', ls='steps')
plt.show()
# Now run Class!
cosmo = Class()
# Scenario 1
cosmo.set(dict(mainparams.items()+scenario1.items()))
cosmo.compute()
cl1 = cosmo.density_cl(mainparams['l_max_lss'])
cosmo.struct_cleanup()
cosmo.empty()
# Scenario 2
cosmo.set(dict(mainparams.items()+scenario2.items()))
cosmo.compute()
cl2 = cosmo.density_cl(mainparams['l_max_lss'])
cosmo.struct_cleanup()
cosmo.empty()
# The Cls should be very close if the histogram is binned finely
nbins = len(redshiftdistributions)
print 'Comparing accuracy of N(z) representation: multigaussian vs histograms'
for i in range(nbins*(nbins+1)/2):
err = cl1['dd'][i] / cl2['dd'][i]
print 'Accuracy of density Cls ', i+1
示例2: Model
# 需要导入模块: from classy import Class [as 别名]
# 或者: from classy.Class import density_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()