def testAssigments(self): ini = os.path.join(os.path.dirname(__file__), '..', 'inifiles', 'planck_2018.ini') if os.path.exists(ini): pars = camb.read_ini(ini) self.assertTrue(np.abs(camb.get_background(pars).cosmomc_theta() * 100 / 1.040909 - 1) < 2e-5) pars = camb.CAMBparams() pars.set_cosmology(H0=68.5, ombh2=0.022, mnu=0, omch2=0.1) self.assertAlmostEqual(pars.omegam, (0.022 + 0.1) / 0.685 ** 2) with self.assertRaises(AttributeError): # noinspection PyPropertyAccess pars.omegam = 1 pars.InitPower.set_params(ns=0.01) data = camb.CAMBdata() data.Params = pars self.assertEqual(data.Params.InitPower.ns, pars.InitPower.ns) d = dark_energy.DarkEnergyFluid(w=-0.95) pars.DarkEnergy = d self.assertEqual(pars.DarkEnergy.w, -0.95) pars.DarkEnergy = dark_energy.AxionEffectiveFluid(w_n=0.4) data.Params = pars self.assertEqual(pars.DarkEnergy.w_n, 0.4) pars.z_outputs = [0.1, 0.4] self.assertEqual(pars.z_outputs[1], 0.4) pars.z_outputs[0] = 0.3 self.assertEqual(pars.z_outputs[0], 0.3) pars.z_outputs = pars.z_outputs pars.z_outputs = [] pars.z_outputs = None self.assertFalse(len(pars.z_outputs)) with self.assertRaises(TypeError): pars.DarkEnergy = initialpower.InitialPowerLaw() pars.NonLinear = model.NonLinear_both printstr = str(pars) self.assertTrue('Want_CMB_lensing = True' in printstr and "NonLinear = NonLinear_both" in printstr) pars.NonLinear = model.NonLinear_lens self.assertTrue(pars.NonLinear == model.NonLinear_lens) with self.assertRaises(ValueError): pars.NonLinear = 4 pars.nu_mass_degeneracies = np.zeros(3) self.assertTrue(len(pars.nu_mass_degeneracies) == 3) pars.nu_mass_degeneracies = [1, 2, 3] self.assertTrue(pars.nu_mass_degeneracies[1] == 2) pars.nu_mass_degeneracies[1] = 5 self.assertTrue(pars.nu_mass_degeneracies[1] == 5) with self.assertRaises(CAMBParamRangeError): pars.nu_mass_degeneracies = np.zeros(7) pars.nu_mass_eigenstates = 0 self.assertFalse(len((pars.nu_mass_degeneracies[:1]))) pars = camb.set_params(**{'InitPower.ns': 1.2, 'WantTransfer': True}) self.assertEqual(pars.InitPower.ns, 1.2) self.assertTrue(pars.WantTransfer) pars.DarkEnergy = None from camb.sources import GaussianSourceWindow pars = camb.CAMBparams() pars.SourceWindows = [GaussianSourceWindow(), GaussianSourceWindow(redshift=1)] self.assertEqual(pars.SourceWindows[1].redshift, 1) pars.SourceWindows[0].redshift = 2 self.assertEqual(pars.SourceWindows[0].redshift, 2) self.assertTrue(len(pars.SourceWindows) == 2) pars.SourceWindows[0] = GaussianSourceWindow(redshift=3) self.assertEqual(pars.SourceWindows[0].redshift, 3) self.assertTrue('redshift = 3.0' in str(pars)) pars.SourceWindows = pars.SourceWindows[0:1] self.assertTrue(len(pars.SourceWindows) == 1) pars.SourceWindows = [] self.assertTrue(len(pars.SourceWindows) == 0)
def testAssigments(self): ini = os.path.join(os.path.dirname(__file__), '..', 'inifiles', 'planck_2018.ini') if os.path.exists(ini): pars = camb.read_ini(ini) self.assertTrue( np.abs( camb.get_background(pars).cosmomc_theta() * 100 / 1.040909 - 1) < 2e-5) pars = camb.CAMBparams() pars.set_cosmology(H0=68.5, ombh2=0.022, mnu=0, omch2=0.1) self.assertAlmostEqual(pars.omegam, (0.022 + 0.1) / 0.685**2) with self.assertRaises(AttributeError): # noinspection PyPropertyAccess pars.omegam = 1 pars.InitPower.set_params(ns=0.01) data = camb.CAMBdata() data.Params = pars self.assertEqual(data.Params.InitPower.ns, pars.InitPower.ns) d = dark_energy.DarkEnergyFluid(w=-0.95) pars.DarkEnergy = d self.assertEqual(pars.DarkEnergy.w, -0.95) pars.DarkEnergy = dark_energy.AxionEffectiveFluid(w_n=0.4) data.Params = pars self.assertEqual(pars.DarkEnergy.w_n, 0.4) pars.z_outputs = [0.1, 0.4] self.assertEqual(pars.z_outputs[1], 0.4) pars.z_outputs[0] = 0.3 self.assertEqual(pars.z_outputs[0], 0.3) pars.z_outputs = pars.z_outputs pars.z_outputs = [] pars.z_outputs = None # noinspection PyTypeChecker self.assertFalse(len(pars.z_outputs)) with self.assertRaises(TypeError): pars.DarkEnergy = initialpower.InitialPowerLaw() pars.NonLinear = model.NonLinear_both printstr = str(pars) self.assertTrue('Want_CMB_lensing = True' in printstr and "NonLinear = NonLinear_both" in printstr) pars.NonLinear = model.NonLinear_lens self.assertTrue(pars.NonLinear == model.NonLinear_lens) with self.assertRaises(ValueError): pars.NonLinear = 4 pars.nu_mass_degeneracies = np.zeros(3) self.assertTrue(len(pars.nu_mass_degeneracies) == 3) pars.nu_mass_degeneracies = [1, 2, 3] self.assertTrue(pars.nu_mass_degeneracies[1] == 2) pars.nu_mass_degeneracies[1] = 5 self.assertTrue(pars.nu_mass_degeneracies[1] == 5) with self.assertRaises(CAMBParamRangeError): pars.nu_mass_degeneracies = np.zeros(7) pars.nu_mass_eigenstates = 0 self.assertFalse(len((pars.nu_mass_degeneracies[:1]))) pars = camb.set_params(**{'InitPower.ns': 1.2, 'WantTransfer': True}) self.assertEqual(pars.InitPower.ns, 1.2) self.assertTrue(pars.WantTransfer) pars.DarkEnergy = None pars = camb.set_params(**{ 'H0': 67, 'ombh2': 0.002, 'r': 0.1, 'Accuracy.AccurateBB': True }) self.assertEqual(pars.Accuracy.AccurateBB, True) from camb.sources import GaussianSourceWindow pars = camb.CAMBparams() pars.SourceWindows = [ GaussianSourceWindow(), GaussianSourceWindow(redshift=1) ] self.assertEqual(pars.SourceWindows[1].redshift, 1) pars.SourceWindows[0].redshift = 2 self.assertEqual(pars.SourceWindows[0].redshift, 2) self.assertTrue(len(pars.SourceWindows) == 2) pars.SourceWindows[0] = GaussianSourceWindow(redshift=3) self.assertEqual(pars.SourceWindows[0].redshift, 3) self.assertTrue('redshift = 3.0' in str(pars)) pars.SourceWindows = pars.SourceWindows[0:1] self.assertTrue(len(pars.SourceWindows) == 1) pars.SourceWindows = [] self.assertTrue(len(pars.SourceWindows) == 0) params = camb.get_valid_numerical_params() self.assertEqual( params, { 'ombh2', 'deltazrei', 'omnuh2', 'tau', 'omk', 'zrei', 'thetastar', 'nrunrun', 'meffsterile', 'nnu', 'ntrun', 'HMCode_A_baryon', 'HMCode_eta_baryon', 'HMCode_logT_AGN', 'cosmomc_theta', 'YHe', 'wa', 'cs2', 'H0', 'mnu', 'Alens', 'TCMB', 'ns', 'nrun', 'As', 'nt', 'r', 'w', 'omch2' }) params2 = camb.get_valid_numerical_params( dark_energy_model='AxionEffectiveFluid') self.assertEqual(params2.difference(params), {'fde_zc', 'w_n', 'zc', 'theta_i'})