Simple Python

A very simple example in Python

Running

To try this example you must have PyGObject installed, and numcosmo built with –enable-introspection option. To run the examples without installing it, follow the instructions here.

example_simple.py:

#!/usr/bin/python2

try:
  import gi
  gi.require_version('NumCosmo', '1.0')
  gi.require_version('NumCosmoMath', '1.0')
except:
  pass

import math
from gi.repository import NumCosmo as Nc
from gi.repository import NumCosmoMath as Ncm

#
#  Initializing the library objects, this must be called before 
#  any other library function.
#
Ncm.cfg_init ()

#
#  New homogeneous and isotropic cosmological model NcHICosmoDEXcdm 
#  with one massive neutrino.
#
cosmo = Nc.HICosmo.new_from_name (Nc.HICosmo, "NcHICosmoDEXcdm{'massnu-length':<1>}")
cosmo.set_reparam (Nc.HICosmoDEReparamCMB.new (cosmo.len ()))

#
#  New cosmological distance objects optimizied to perform calculations
#  up to redshift 2.0.
#
dist = Nc.Distance.new (2.0)

#
#  Setting values for the cosmological model, those not set stay in the
#  default values. Remember to use the _orig_ version to set the original
#  parameters when a reparametrization is used.
#

#
# C-like
#
cosmo.orig_param_set (Nc.HICosmoDEParams.H0,       70.00)
cosmo.orig_param_set (Nc.HICosmoDEParams.OMEGA_C,   0.25)
cosmo.orig_param_set (Nc.HICosmoDEParams.OMEGA_X,   0.70)
cosmo.orig_param_set (Nc.HICosmoDEParams.T_GAMMA0,  2.72)
cosmo.orig_param_set (Nc.HICosmoDEParams.OMEGA_B,   0.05)
cosmo.orig_param_set (Nc.HICosmoDEXCDMParams.W,    -1.10)

cosmo.orig_vparam_set (Nc.HICosmoDEVParams.M, 0, 0.06)

#
# OO-like
#
cosmo.props.H0      = 70.00
cosmo.props.Omegab  =  0.04
cosmo.props.Omegac  =  0.25
cosmo.props.Omegax  =  0.70
cosmo.props.Tgamma0 =  2.72
cosmo.props.w       = -1.10

massnu_v = Ncm.Vector.new_array ([0.06])
cosmo.props.massnu  = massnu_v

#
#  Printing the parameters used.
#
print "# Model parameters: "
cosmo.params_log_all ()

#
#  Printing some distances up to redshift 1.0.
#
N      = 20
RH_Mpc = cosmo.RH_Mpc ()

for i in range (0, N):
  z  = 1.0 / (N - 1.0) * i
  Dc = dist.comoving (cosmo, z)
  dc = RH_Mpc * Dc
  
  print "% 10.8f % 22.15g [c/H0] % 22.15g [Mpc]" % (z, Dc, dc)

example_simple2.out:

# Model parameters: 
                    70                0.1225   0.008608600366835972                  2.72                  0.24                 3.046                0.0196                  -1.1                  0.06               0.71611                     0                     1
 0.00000000                      0 [c/H0]                      0 [Mpc]
 0.05263158     0.0521439667502956 [c/H0]       223.319542313448 [Mpc]
 0.10526316      0.103255121262665 [c/H0]       442.215808634606 [Mpc]
 0.15789474      0.153258612496355 [c/H0]       656.368230713595 [Mpc]
 0.21052632       0.20209475380891 [c/H0]       865.521185618259 [Mpc]
 0.26315789      0.249718416109055 [c/H0]       1069.48139676001 [Mpc]
 0.31578947      0.296098082252844 [c/H0]       1268.11388410952 [Mpc]
 0.36842105      0.341214656957146 [c/H0]       1461.33686735442 [Mpc]
 0.42105263      0.385060124727936 [c/H0]       1649.11601814249 [Mpc]
 0.47368421      0.427636138867993 [c/H0]       1831.45841715521 [Mpc]
 0.52631579      0.468952610872608 [c/H0]        2008.4065128431 [Mpc]
 0.57894737      0.509026353121732 [c/H0]       2180.03230841629 [Mpc]
 0.63157895      0.547879812553153 [c/H0]       2346.43193848413 [Mpc]
 0.68421053      0.585539918928124 [c/H0]       2507.72073646547 [Mpc]
 0.73684211      0.622037059788446 [c/H0]       2664.02884458673 [Mpc]
 0.78947368      0.657404185553749 [c/H0]       2815.49738123781 [Mpc]
 0.84210526      0.691676041038391 [c/H0]       2962.27514975154 [Mpc]
 0.89473684      0.724888516234207 [c/H0]       3104.51585796894 [Mpc]
 0.94736842      0.757078105770327 [c/H0]         3242.375803241 [Mpc]
 1.00000000      0.788281465608702 [c/H0]       3376.01197386679 [Mpc]

Example Directory