Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notebook/: Python 3 compatibility #271

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
12 changes: 6 additions & 6 deletions notebooks/Growth_with_w.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"def D_hypergeom(avec,csm):\n",
" bg = csm.get_background()\n",
" Om = csm.Omega0_m()\n",
" if bg.has_key('(.)rho_lambda'):\n",
" if '(.)rho_lambda' in bg:\n",
" Ol = bg['(.)rho_lambda'][-1]/bg['(.)rho_crit'][-1]\n",
" else:\n",
" Ol = bg['(.)rho_fld'][-1]/bg['(.)rho_crit'][-1]\n",
Expand All @@ -71,7 +71,7 @@
"def f_hypergeom(avec,csm):\n",
" bg = csm.get_background()\n",
" Om = csm.Omega0_m()\n",
" if bg.has_key('(.)rho_lambda'):\n",
" if '(.)rho_lambda' in bg:\n",
" Ol = bg['(.)rho_lambda'][-1]/bg['(.)rho_crit'][-1]\n",
" else:\n",
" Ol = bg['(.)rho_fld'][-1]/bg['(.)rho_crit'][-1]\n",
Expand All @@ -84,7 +84,7 @@
"def D_integral2(avec,csm):\n",
" bg = csm.get_background()\n",
" Om = csm.Omega0_m()\n",
" if bg.has_key('(.)rho_lambda'):\n",
" if '(.)rho_lambda' in bg:\n",
" Ol = bg['(.)rho_lambda'][-1]/bg['(.)rho_crit'][-1]\n",
" w0 = -1\n",
" wa = 0.0\n",
Expand Down Expand Up @@ -122,7 +122,7 @@
"\n",
"def D_linder(avec,csm):\n",
" bg = csm.get_background()\n",
" if bg.has_key('(.)rho_lambda'):\n",
" if '(.)rho_lambda' in bg:\n",
" Ol = bg['(.)rho_lambda'][-1]/bg['(.)rho_crit'][-1]\n",
" w0 = -1\n",
" wa = 0.0\n",
Expand Down Expand Up @@ -152,7 +152,7 @@
"\n",
"def D_linder2(avec,csm):\n",
" bg = csm.get_background()\n",
" if bg.has_key('(.)rho_lambda'):\n",
" if '(.)rho_lambda' in bg:\n",
" Ol = bg['(.)rho_lambda'][-1]/bg['(.)rho_crit'][-1]\n",
" w0 = -1\n",
" wa = 0.0\n",
Expand Down Expand Up @@ -314,7 +314,7 @@
"fs=14\n",
"fig, (ax1, ax2) = plt.subplots(2,1,figsize=(6,8),sharex=True,)\n",
"# gridspec_kw = {'height_ratios':[2, 1]})\n",
"for M, csm in cosmo.iteritems():\n",
"for M, csm in cosmo.items():\n",
" if M!='LCDM':\n",
" w0, wa = M.strip('()').split(',')\n",
" if float(wa)!=0.0:\n",
Expand Down
6 changes: 3 additions & 3 deletions notebooks/Thomas_PPF.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
" phi_plus_phi_ppf = ptkppf['phi']+ptkppf['psi']\n",
" axes[1].semilogx(ptkppf['a'],phi_plus_phi_ppf,label=label+'_ppf')\n",
" axes[1].semilogx(ptkfld['a'],phi_plus_phi_fld,label=label+'_fld')\n",
" print len(ptkppf['a']),len(ptkfld['a'])\n",
" print(len(ptkppf['a']), len(ptkfld['a']))\n",
" \n",
" axes[0].legend(loc='lower left',ncol=2)\n",
" axes[0].set_xlim([2,300])\n",
Expand Down Expand Up @@ -394,8 +394,8 @@
}
],
"source": [
"print 0.31*0.64**2-0.022\n",
"print 0.26*0.74**2-0.022"
"print(0.31 * 0.64**2 - 0.022)\n",
"print(0.26 * 0.74**2 - 0.022)"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions notebooks/distances.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"# Just to cross-check that Omega_Lambda is negligible \n",
"# (but not exactly zero because we neglected radiation)\n",
"derived = CDM.get_current_derived_parameters(['Omega0_lambda'])\n",
"print derived\n",
"print \"Omega_Lambda =\",derived['Omega0_lambda']"
"print(derived)\n",
"print(\"Omega_Lambda =\",derived['Omega0_lambda'])"
]
},
{
Expand All @@ -86,7 +86,7 @@
"#Get background quantities and recover their names:\n",
"baLCDM = LCDM.get_background()\n",
"baCDM = CDM.get_background()\n",
"baCDM.viewkeys()"
"baCDM.keys()"
]
},
{
Expand Down
20 changes: 10 additions & 10 deletions notebooks/many_times.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@
"# (of Hubble crossing, sound horizon crossing, etc.) at different time\n",
"#\n",
"background = M.get_background() # load background table\n",
"#print background.viewkeys()\n",
"#print(background.keys())\n",
"thermodynamics = M.get_thermodynamics() # load thermodynamics table\n",
"#print thermodynamics.viewkeys() \n",
"#print(thermodynamics.keys())\n",
"#\n",
"background_tau = background['conf. time [Mpc]'] # read conformal times in background table\n",
"background_z = background['z'] # read redshift\n",
Expand Down Expand Up @@ -173,10 +173,10 @@
"# check and inform user whether intiial arbitrary choice of z_max_pk was OK\n",
"max_z_needed = background_z_at_tau(tau[0])\n",
"if max_z_needed > z_max_pk:\n",
" print ('you must increase the value of z_max_pk to at least ',max_z_needed)\n",
" () + 1 # this strange line is just a trick to stop the script execution there\n",
" print('you must increase the value of z_max_pk to at least ', max_z_needed)\n",
" raise ValueError\n",
"else:\n",
" print ('in a next run with the same values of tau, you may decrease z_max_pk from ',z_max_pk,' to ',max_z_needed)\n",
" print('in a next run with the same values of tau, you may decrease z_max_pk from ', z_max_pk ,' to ', max_z_needed)\n",
"#\n",
"# get transfer functions at each time and build arrays Theta0(tau,k) and phi(tau,k)\n",
"#\n",
Expand All @@ -201,7 +201,7 @@
"#\n",
"# inform user of the size of the grids (related to the figure resolution)\n",
"#\n",
"print ('grid size:',len(k),len(tau),Theta0.shape)\n",
"print('grid size:', len(k), len(tau), Theta0.shape)\n",
"#\n",
"#################\n",
"#\n",
Expand All @@ -214,9 +214,9 @@
"# plot Theta0(k,tau)\n",
"#\n",
"ax_Theta = fig.add_subplot(121)\n",
"print ('> Plotting Theta_0')\n",
"print('> Plotting Theta_0')\n",
"fig_Theta = ax_Theta.pcolormesh(K,T,Theta0,cmap='coolwarm',vmin=-Theta_amp, vmax=Theta_amp) #,shading='gouraud')\n",
"print ('> Done')\n",
"print('> Done')\n",
"#\n",
"# plot lines (characteristic times and scales)\n",
"#\n",
Expand Down Expand Up @@ -264,9 +264,9 @@
"ax_phi = fig.add_subplot(122)\n",
"ax_phi.set_xlim(k[0],k[-1])\n",
"#ax_phi.pcolor(K,T,phi,cmap='coolwarm')\n",
"print ('> Plotting phi')\n",
"print('> Plotting phi')\n",
"fig_phi = ax_phi.pcolormesh(K,T,phi,cmap='coolwarm',vmin=-0., vmax=phi_amp)\n",
"print ('> Done')\n",
"print('> Done')\n",
"#\n",
"# plot lines (characteristic times and scales)\n",
"#\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/neutrinohierarchy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
"source": [
"# test of this function, returning the 3 masses for total mass of 0.1eV\n",
"m1,m2,m3 = get_masses(2.45e-3,7.50e-5,0.1,'NH')\n",
"print 'NH:',m1,m2,m3,m1+m2+m3\n",
"print('NH:',m1,m2,m3,m1+m2+m3)\n",
"m1,m2,m3 = get_masses(2.45e-3,7.50e-5,0.1,'IH')\n",
"print 'IH:',m1,m2,m3,m1+m2+m3"
"print('IH:',m1,m2,m3,m1+m2+m3)"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions notebooks/one_k.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"# load perturbations\n",
"#\n",
"all_k = M.get_perturbations() # this potentially constains scalars/tensors and all k values\n",
"print all_k['scalar'][0].viewkeys()\n",
"print(all_k['scalar'][0].keys())\n",
"# \n",
"one_k = all_k['scalar'][0] # this contains only the scalar perturbations for the requested k values\n",
"# \n",
Expand All @@ -107,14 +107,14 @@
"# get the time of decoupling\n",
"#\n",
"quantities = M.get_current_derived_parameters(['tau_rec'])\n",
"# print times.viewkeys()\n",
"# print(times.keys())\n",
"tau_rec = quantities['tau_rec']\n",
"#\n",
"# use table of background quantitites to find the time of\n",
"# Hubble crossing (k / (aH)= 2 pi), sound horizon crossing (k * rs = 2pi)\n",
"#\n",
"background = M.get_background() # load background table\n",
"#print background.viewkeys()\n",
"#print(background.keys())\n",
"#\n",
"background_tau = background['conf. time [Mpc]'] # read confromal times in background table\n",
"background_z = background['z'] # read redshift\n",
Expand Down
6 changes: 3 additions & 3 deletions notebooks/one_time.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"M.set(common_settings)\n",
"M.compute()\n",
"derived = M.get_current_derived_parameters(['z_rec','tau_rec','conformal_age'])\n",
"#print derived.viewkeys()\n",
"#print(derived.keys())\n",
"z_rec = derived['z_rec']\n",
"z_rec = int(1000.*z_rec)/1000. # round down at 4 digits after coma\n",
"M.struct_cleanup() # clean output\n",
Expand All @@ -111,7 +111,7 @@
"# load transfer functions at recombination\n",
"#\n",
"one_time = M.get_transfer(z_rec)\n",
"print one_time.viewkeys()\n",
"print(one_time.keys())\n",
"k = one_time['k (h/Mpc)']\n",
"Theta0 = 0.25*one_time['d_g']\n",
"phi = one_time['phi']\n",
Expand All @@ -129,7 +129,7 @@
"# Hubble crossing (k = 2 pi a H), sound horizon crossing (k = 2pi / rs)\n",
"#\n",
"background = M.get_background() # load background table\n",
"#print background.viewkeys()\n",
"#print(background.keys())\n",
"#\n",
"background_tau = background['conf. time [Mpc]'] # read confromal times in background table\n",
"background_z = background['z'] # read redshift\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/thermo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"M.compute()\n",
"derived = M.get_current_derived_parameters(['tau_rec','conformal_age'])\n",
"thermo = M.get_thermodynamics()\n",
"print thermo.viewkeys()"
"print(thermo.keys())"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions notebooks/varying_neff.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"# i.e. such that omega_ur = omega_gamma * coeff * Neff:\n",
"# coeff = omega_ur/omega_gamma/Neff_standard\n",
"coeff = 1.710730e-05/2.472979e-05/3.046\n",
"print \"coeff=\",coeff\n",
"print(\"coeff=\", coeff)\n",
"#\n",
"#############################################\n",
"#\n",
Expand Down Expand Up @@ -84,7 +84,7 @@
" alpha = (1.+coeff*N_ur)/(1.+coeff*3.046)\n",
" omega_cdm = (0.022032 + 0.12038)*alpha - 0.022032\n",
" h = 0.67556*math.sqrt(alpha)\n",
" print ' * Compute with %s=%e, %s=%e, %s=%e'%('N_ur',N_ur,'omega_cdm',omega_cdm,'h',h)\n",
" print(' * Compute with %s=%e, %s=%e, %s=%e' % ('N_ur', N_ur, 'omega_cdm', omega_cdm, 'h', h))\n",
" #\n",
" # call CLASS\n",
" #\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/varying_pann.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"#\n",
"for i,var in enumerate(var_array):\n",
" #\n",
" print ' * Compute with %s=%e'%(var_name,var)\n",
" print(' * Compute with %s=%e'%(var_name,var))\n",
" #\n",
" # deal with colors and legends\n",
" #\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/warmup.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"# get all C_l output\n",
"cls = LambdaCDM.lensed_cl(2500)\n",
"# To check the format of cls\n",
"cls.viewkeys()"
"cls.keys()"
]
},
{
Expand Down