本文整理汇总了Python中classy.Class.cleanup方法的典型用法代码示例。如果您正苦于以下问题:Python Class.cleanup方法的具体用法?Python Class.cleanup怎么用?Python Class.cleanup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类classy.Class
的用法示例。
在下文中一共展示了Class.cleanup方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestClass
# 需要导入模块: from classy import Class [as 别名]
# 或者: from classy.Class import cleanup [as 别名]
class TestClass(unittest.TestCase):
"""
Testing Class and its wrapper classy on different cosmologies
To run it, do
~] nosetest test_class.py
It will run many times Class, on different cosmological scenarios, and
everytime testing for different output possibilities (none asked, only mPk,
etc..)
"""
def setUp(self):
"""
set up data used in the tests.
setUp is called before each test function execution.
"""
self.cosmo = Class()
self.verbose = {
'background_verbose': 1,
'thermodynamics_verbose': 1,
'perturbations_verbose': 1,
'transfer_verbose': 1,
'primordial_verbose': 1,
'spectra_verbose': 1,
'nonlinear_verbose': 1,
'lensing_verbose': 1,
'output_verbose': 1}
self.scenario = {'lensing':'yes'}
def tearDown(self):
self.cosmo.cleanup()
del self.scenario
@parameterized.expand(
itertools.product(
('LCDM',
'Mnu',
'Positive_Omega_k',
'Negative_Omega_k',
'Isocurvature_modes', ),
({'output': ''}, {'output': 'mPk'}, {'output': 'tCl'},
{'output': 'tCl pCl lCl'}, {'output': 'mPk tCl lCl', 'P_k_max_h/Mpc':10},
{'output': 'nCl sCl'}, {'output': 'tCl pCl lCl nCl sCl'}),
({'gauge': 'newtonian'}, {'gauge': 'sync'}),
({}, {'non linear': 'halofit'})))
def test_parameters(self, name, scenario, gauge, nonlinear):
"""Create a few instances based on different cosmologies"""
if name == 'Mnu':
self.scenario.update({'N_ncdm': 1, 'm_ncdm': 0.06})
elif name == 'Positive_Omega_k':
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():
#.........这里部分代码省略.........