Numerical Cosmology - NumCosmo
- Documentation
- NumCosmo project
- Latest News
- Download and Install
- Browse the sources repository
- Examples
The NumCosmo is a free software C library whose main purposes are to test cosmological models using observational data and to provide a set of tools to perform cosmological calculations. Particularly, the current version has implemented three different probes: cosmic microwave background (CMB),supernovae type Ia (SNeIa) and large scale structure (LSS) information, such as baryonic acoustic oscillations (BAO) and galaxy cluster abundance. The code supports a joint analysis of these data and the parameter space can include cosmological and phenomenological parameters. It is worth emphasizing that NumCosmo matter power spectrum and CMB codes were written independently of other implementations such as CMBFAST, CAMB, etc.
The library is structured in such way to simplify the inclusion of non-standard cosmological models. Besides the functions related to cosmological quantities, this library also implements mathematical and statistical tools. The former was developed to enable the inclusion of other probes and/or theoretical models and to optimize the codes. The statistical framework comprises algorithms which define likelihood functions, minimization, Monte Carlo, Fisher Matrix and profile likelihood methods.
Download and installation
Version 0.9.0 of NumCosmo is the latest version available from our web site:
NumCosmo uses autotools for configuration and installation. The standard procedure is
./configure && make && sudo make install
More about compilation and installation here.
There are also some pre-compiled packages in openSUSE Build Service.These are not tested yet.
Mailing Lists
Subscribe to the numcosmo-help mailing list for discussion of questions and problems about using NumCosmo.
Examples
A simple example in C. Download the source.
To compile the example use:
gcc -Wall example_simple.c -o example_simple `pkg-config numcosmo --libs --cflags`
1 #include <glib.h> 2 #include <numcosmo/numcosmo.h> 3 4 gint 5 main (gint argc, gchar *argv[]) 6 { 7 NcHICosmo *cosmo; 8 NcDistance *dist; 9 gint i; 10 11 /**************************************************************************** 12 * Initializing the library objects, this must be called before 13 * any other library function. 14 ****************************************************************************/ 15 ncm_cfg_init (); 16 17 /**************************************************************************** 18 * New homogeneous and isotropic cosmological model NcHICosmoDEXcdm. 19 ****************************************************************************/ 20 cosmo = nc_hicosmo_new_from_name (NC_TYPE_HICOSMO, "NcHICosmoDEXcdm"); 21 22 /**************************************************************************** 23 * New cosmological distance objects optimizied to perform calculations 24 * up to redshift 2.0. 25 ****************************************************************************/ 26 dist = nc_distance_new (2.0); 27 28 /**************************************************************************** 29 * Setting values for the cosmological model, those not set stay in the 30 * default values. Remeber to use the _orig_ version to set the original 31 * parameters in case when a reparametrization is used. 32 ****************************************************************************/ 33 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_H0, 70.0); 34 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_OMEGA_C, 0.25); 35 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_OMEGA_X, 0.7); 36 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_T_GAMMA0, 1.0); 37 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_OMEGA_B, 0.05); 38 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_SPECINDEX, 1.0); 39 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_SIGMA8, 0.9); 40 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_XCDM_W, -1.1); 41 42 /**************************************************************************** 43 * Printing the parameters used. 44 ****************************************************************************/ 45 printf ("# Model parameters:\n"); 46 ncm_model_params_log_all (NCM_MODEL (cosmo)); 47 48 /**************************************************************************** 49 * Printing some distances up to redshift 1.0. 50 ****************************************************************************/ 51 for (i = 0; i < 10; i++) 52 { 53 gdouble z = 1.0 / 9.0 * i; 54 gdouble cd = ncm_c_hubble_radius () * nc_distance_comoving (dist, cosmo, z); 55 printf ("% 10.8f % 20.15g\n", z, cd); 56 } 57 58 /**************************************************************************** 59 * Freeing objects. 60 ****************************************************************************/ 61 nc_distance_free (dist); 62 ncm_model_free (NCM_MODEL (cosmo)); 63 64 return 0; 65 }
This example has the following output:
# Model parameters:
70 0.25 0.7 1 0.05 1 0.9 -1.1
0.00000000 0
0.11111111 326.291354567573
0.22222222 637.56332484321
0.33333333 932.394947130311
0.44444444 1210.16934019712
0.55555556 1470.91014294491
0.66666667 1715.10326170554
0.77777778 1943.53573595738
0.88888889 2157.16638285178
1.00000000 2357.03066379095
The same example in Python. Download the source.
To try this example you must have PyGObject installed, and numcosmo built with --enable-introspection option.
1 #!/usr/bin/python2 2 3 from gi.repository import NumCosmo as Nc 4 from gi.repository import NumCosmoMath as Ncm 5 6 # 7 # Initializing the library objects, this must be called before 8 # any other library function. 9 # 10 Ncm.cfg_init () 11 12 # 13 # New homogeneous and isotropic cosmological model NcHICosmoDEXcdm 14 # 15 cosmo = Nc.HICosmo.new_from_name (Nc.HICosmo, "NcHICosmoDEXcdm") 16 17 # 18 # New cosmological distance objects optimizied to perform calculations 19 # up to redshift 2.0. 20 # 21 dist = Nc.Distance.new (2.0) 22 23 # 24 # Setting values for the cosmological model, those not set stay in the 25 # default values. Remember to use the _orig_ version to set the original 26 # parameters when a reparametrization is used. 27 # 28 29 # 30 # C-like 31 # 32 cosmo.orig_param_set (Nc.HICosmoDEParams.H0, 70.0) 33 cosmo.orig_param_set (Nc.HICosmoDEParams.OMEGA_C, 0.25) 34 cosmo.orig_param_set (Nc.HICosmoDEParams.OMEGA_X, 0.70) 35 cosmo.orig_param_set (Nc.HICosmoDEParams.T_GAMMA0, 2.72) 36 cosmo.orig_param_set (Nc.HICosmoDEParams.OMEGA_B, 0.05) 37 cosmo.orig_param_set (Nc.HICosmoDEParams.SPECINDEX, 1.00) 38 cosmo.orig_param_set (Nc.HICosmoDEParams.SIGMA8, 0.90) 39 cosmo.orig_param_set (Nc.HICosmoDEXCDMParams.W, -1.00) 40 41 # 42 # OO-like 43 # 44 cosmo.props.H0 = 70.0 45 cosmo.props.Omegab = 0.05 46 cosmo.props.Omegac = 0.25 47 cosmo.props.Omegax = 0.70 48 cosmo.props.Tgamma0 = 2.72 49 cosmo.props.ns = 1.0 50 cosmo.props.sigma8 = 0.9 51 cosmo.props.w = -1.0 52 53 # 54 # Printing the parameters used. 55 # 56 print "# Model parameters: ", 57 cosmo.params_log_all () 58 59 # 60 # Printing some distances up to redshift 1.0. 61 # 62 for i in range (0, 10): 63 z = 1.0 / 9.0 * i 64 cd = Ncm.C.hubble_radius () * dist.comoving (cosmo, z) 65 print "% 10.8f % 20.15g" % (z, cd) 66
An example of the recombination object in Python. Download the source.
To try this example you must have PyGObject installed, matplotlib matplotlib and numcosmo built with --enable-introspection option.
1 #!/usr/bin/python2 2 3 from math import * 4 from gi.repository import GObject 5 import matplotlib.pyplot as plt 6 from gi.repository import NumCosmo as Nc 7 from gi.repository import NumCosmoMath as Ncm 8 9 # 10 # Initializing the library objects, this must be called before 11 # any other library function. 12 # 13 Ncm.cfg_init () 14 15 # 16 # New homogeneous and isotropic cosmological model NcHICosmoDEXcdm 17 # 18 cosmo = Nc.HICosmo.new_from_name (Nc.HICosmo, "NcHICosmoDEXcdm") 19 20 # 21 # New recombination object configured to calculate up to redshift 22 # 10^9 and precision 10^-7. 23 # 24 recomb = Nc.Recomb.new_from_name ("NcRecombSeager{'prec':<1.0e-7>, 'zi':<1e9>}") 25 26 # 27 # Setting values for the cosmological model, those not set stay in the 28 # default values. Remeber to use the _orig_ version to set the original 29 # parameters in case when a reparametrization is used. 30 # 31 32 # 33 # C-like 34 # 35 cosmo.orig_param_set (Nc.HICosmoDEParams.H0, 70.0) 36 cosmo.orig_param_set (Nc.HICosmoDEParams.OMEGA_C, 0.25) 37 cosmo.orig_param_set (Nc.HICosmoDEParams.OMEGA_X, 0.70) 38 cosmo.orig_param_set (Nc.HICosmoDEParams.T_GAMMA0, 2.72) 39 cosmo.orig_param_set (Nc.HICosmoDEParams.OMEGA_B, 0.05) 40 cosmo.orig_param_set (Nc.HICosmoDEParams.SPECINDEX, 1.00) 41 cosmo.orig_param_set (Nc.HICosmoDEParams.SIGMA8, 0.90) 42 cosmo.orig_param_set (Nc.HICosmoDEXCDMParams.W, -1.00) 43 44 # 45 # OO-like 46 # 47 cosmo.props.H0 = 70.0 48 cosmo.props.Omegab = 0.05 49 cosmo.props.Omegac = 0.25 50 cosmo.props.Omegax = 0.70 51 cosmo.props.Tgamma0 = 2.72 52 cosmo.props.ns = 1.0 53 cosmo.props.sigma8 = 0.9 54 cosmo.props.w = -1.0 55 56 # 57 # Preparing recomb with cosmo. 58 # 59 recomb.prepare (cosmo) 60 61 # 62 # Calculating Xe, equilibrium Xe, v_tau and its derivatives. 63 # 64 x_a = [] 65 Xe_a = [] 66 Xefi_a = [] 67 v_tau_a = [] 68 dv_tau_dlambda_a = [] 69 d2v_tau_dlambda2_a = [] 70 71 for i in range (10000): 72 alpha = -log (10000.0) + (log (10000.0) - log (100.0)) / 9999.0 * i 73 Xe = recomb.Xe (cosmo, alpha) 74 x = exp (-alpha) 75 Xefi = recomb.equilibrium_Xe (cosmo, x) 76 v_tau = recomb.v_tau (cosmo, alpha) 77 dv_tau_dlambda = recomb.dv_tau_dlambda (cosmo, alpha) 78 d2v_tau_dlambda2 = recomb.d2v_tau_dlambda2 (cosmo, alpha) 79 80 x_a.append (x) 81 Xe_a.append (Xe) 82 Xefi_a.append (Xefi) 83 v_tau_a.append (-v_tau) 84 dv_tau_dlambda_a.append (-dv_tau_dlambda / 10.0) 85 d2v_tau_dlambda2_a.append (-d2v_tau_dlambda2 / 200.0) 86 87 # 88 # Ploting ionization history. 89 # 90 91 plt.title ("Ionization History") 92 plt.xscale('log') 93 plt.plot (x_a, Xe_a, 'r', label="Recombination") 94 plt.plot (x_a, Xefi_a, 'b--', label="Equilibrium") 95 plt.xlabel('$x$') 96 plt.ylabel('$X_{e^-}$') 97 plt.legend(loc=2) 98 99 plt.savefig ("recomb_Xe.png") 100 101 plt.clf () 102 103 (lambdam, lambdal, lambdau) = recomb.v_tau_lambda_features (cosmo, 2.0 * log (10.0)) 104 105 # 106 # Ploting visibility function and derivatives. 107 # 108 109 plt.title ("Visibility Function and Derivatives") 110 plt.xscale('log') 111 plt.plot (x_a, v_tau_a, 'r', label=r'$v_\tau$') 112 plt.plot (x_a, dv_tau_dlambda_a, 'b-', label=r'$\frac{1}{10}\frac{dv_\tau}{d\lambda}$') 113 plt.plot (x_a, d2v_tau_dlambda2_a, 'g--', label=r'$\frac{1}{200}\frac{d^2v_\tau}{d\lambda^2}$') 114 plt.legend() 115 plt.legend(loc=3) 116 117 # 118 # Annotating max and width. 119 # 120 121 v_tau_max = -recomb.v_tau (cosmo, lambdam) 122 123 plt.annotate (r'$v_\tau^{max}$, $z=%5.2f$' % (exp(-lambdam)-1), xy=(exp(-lambdam), v_tau_max), xycoords='data', 124 xytext=(0.1, 0.95), textcoords='axes fraction', 125 arrowprops=dict(facecolor='black', shrink=0.05)) 126 127 v_tau_u = -recomb.v_tau (cosmo, lambdau) 128 129 plt.annotate (r'$v_\tau=10^{-2}v_\tau^{max}$, $z=%5.2f$' % (exp(-lambdau)-1), xy=(exp(-lambdau), v_tau_u), xycoords='data', 130 xytext=(0.02, 0.75), textcoords='axes fraction', 131 arrowprops=dict(facecolor='black', shrink=0.05)) 132 133 v_tau_l = -recomb.v_tau (cosmo, lambdal) 134 135 plt.annotate (r'$v_\tau=10^{-2}v_\tau^{max}$, $z=%5.2f$' % (exp(-lambdal)-1), xy=(exp(-lambdal), v_tau_l), xycoords='data', 136 xytext=(0.65, 0.25), textcoords='axes fraction', 137 arrowprops=dict(facecolor='black', shrink=0.05)) 138 139 # 140 # Annotating value of zstar. 141 # 142 143 lambdastar = recomb.tau_zstar (cosmo) 144 145 plt.annotate (r'$z^\star=%5.2f$' % (exp(-lambdastar)-1), 146 xy=(0.65, 0.95), xycoords='axes fraction') 147 148 plt.savefig ("recomb_v_tau.png") 149
This example produces:

An example of Supernova Ia model fitting in Python. Download the source.
To try this example you must have PyGObject installed and numcosmo built with --enable-introspection option.
1 #!/usr/bin/python2 2 3 from math import * 4 from gi.repository import GObject 5 import matplotlib.pyplot as plt 6 from gi.repository import NumCosmo as Nc 7 from gi.repository import NumCosmoMath as Ncm 8 9 # 10 # Initializing the library objects, this must be called before 11 # any other library function. 12 # 13 Ncm.cfg_init () 14 15 # 16 # New homogeneous and isotropic cosmological model NcHICosmoDEXcdm 17 # 18 cosmo = Nc.HICosmo.new_from_name (Nc.HICosmo, "NcHICosmoDEXcdm") 19 20 # 21 # Setting values for the cosmological model, those not set stay in the 22 # default values. Remeber to use the _orig_ version to set the original 23 # parameters in case when a reparametrization is used. 24 # 25 26 # 27 # OO-like 28 # 29 cosmo.props.H0 = 70.0 30 cosmo.props.Omegab = 0.05 31 cosmo.props.Omegac = 0.25 32 cosmo.props.Omegax = 0.70 33 cosmo.props.Tgamma0 = 2.72 34 cosmo.props.ns = 1.0 35 cosmo.props.sigma8 = 0.9 36 cosmo.props.w = -1.0 37 38 # 39 # Creating a new Modelset and set cosmo as the HICosmo model to be used. 40 # 41 mset = Ncm.MSet () 42 mset.set (cosmo) 43 44 # 45 # Setting parameters Omega_c and w to be fitted and change parameter 46 # Omega_x -> Omega_k. 47 # 48 cosmo.de_omega_x2omega_k () 49 cosmo.props.Omegac_fit = True 50 cosmo.props.w_fit = True 51 52 # 53 # Creating a new Distance object optimized to redshift 2. 54 # 55 dist = Nc.Distance (zf = 2.0) 56 57 # 58 # Creating a new Data object from distance modulus catalogs. 59 # 60 snia = Nc.DataDistMu.new (dist, Nc.DataSNIAId.SIMPLE_UNION2_1) 61 62 # 63 # Creating a new Dataset and add snia to it. 64 # 65 dset = Ncm.Dataset () 66 dset.append_data (snia) 67 68 # 69 # Creating a Likelihood from the Dataset. 70 # 71 lh = Ncm.Likelihood (dataset = dset) 72 73 # 74 # Creating a Fit object of type NLOPT using the fitting algorithm ln-neldermead to 75 # fit the Modelset mset using the Likelihood lh and using a numerical differentiation 76 # algorithm (NUMDIFF_FORWARD) to obtain the gradient (if needed). 77 # 78 fit = Ncm.Fit.new (Ncm.FitType.NLOPT, "ln-neldermead", lh, mset, Ncm.FitGradType.NUMDIFF_FORWARD) 79 80 # 81 # Running the fitter printing messages. 82 # 83 fit.run (Ncm.FitRunMsgs.SIMPLE) 84 85 # 86 # Printing fitting informations. 87 # 88 fit.log_info () 89 90 # 91 # Calculating the parameters covariance using numerical differentiation. 92 # 93 fit.numdiff_m2lnL_covar () 94 95 # 96 # Printing the covariance matrix. 97 # 98 fit.log_covar ()
This example produces:
#---------------------------------------------------------------------------------- # Model fitting. Interating using: # - solver: NLOpt:ln-neldermead # - differentiation: Numerical differentiantion (forward) #............. # Minimum found with precision: 1.00000e-08 (|df|/f or |dx|) # Elapsed time: 00 days, 00:00:00.0360950 # iteration [000043] # function evaluations [000043] # gradient evaluations [000000] # degrees of freedom [000577] # m2lnL = 562.224308438599 # Fit parameters: # [ 0.230882725715637 ] [-1.00940240383148 ] #---------------------------------------------------------------------------------- # Data used: # - Union2.1 sample #---------------------------------------------------------------------------------- # Model[00]: # - XCDM - Constant EOS #---------------------------------------------------------------------------------- # Model parameters # - H0[00]: 70 [FIXED] # - Omegac[01]: 0.230882725715637 [FREE] # - Omegak[02]: 0 [FIXED] # - Tgamma0[03]: 2.72 [FIXED] # - Omegab[04]: 0.05 [FIXED] # - ns[05]: 1 [FIXED] # - sigma8[06]: 0.9 [FIXED] # - w[07]: -1.00940240383148 [FREE] #---------------------------------------------------------------------------------- # Fitted parameters covariance matrix # ------------------------------- # Omegac[0001] = 0.2309 +/- 0.07425 | 1 | -0.9653 | # w[0007] = -1.009 +/- 0.2014 | -0.9653 | 1 | # -------------------------------
An example of Supernova Ia and BAO model fitting and confidence region calculation in Python. Download the source.
To try this example you must have PyGObject installed, matplotlib matplotlib and numcosmo built with --enable-introspection option.
1 #!/usr/bin/python2 2 3 from math import * 4 from gi.repository import GObject 5 import matplotlib.pyplot as plt 6 from gi.repository import NumCosmo as Nc 7 from gi.repository import NumCosmoMath as Ncm 8 9 # 10 # Initializing the library objects, this must be called before 11 # any other library function. 12 # 13 Ncm.cfg_init () 14 15 # 16 # New homogeneous and isotropic cosmological model NcHICosmoDEXcdm 17 # 18 cosmo = Nc.HICosmo.new_from_name (Nc.HICosmo, "NcHICosmoDEXcdm") 19 20 # 21 # Setting values for the cosmological model, those not set stay in the 22 # default values. Remeber to use the _orig_ version to set the original 23 # parameters in case when a reparametrization is used. 24 # 25 26 # 27 # OO-like 28 # 29 cosmo.props.H0 = 70.0 30 cosmo.props.Omegab = 0.05 31 cosmo.props.Omegac = 0.25 32 cosmo.props.Omegax = 0.70 33 cosmo.props.Tgamma0 = 2.72 34 cosmo.props.ns = 1.0 35 cosmo.props.sigma8 = 0.9 36 cosmo.props.w = -1.0 37 38 # 39 # A new Modelset with cosmo as the HICosmo model to be used. 40 # 41 mset = Ncm.MSet () 42 mset.set (cosmo) 43 44 # 45 # Setting parameters Omega_c, Omega_x and w to be fitted (and change 46 # parameter Omega_x -> Omega_k). 47 # 48 #cosmo.de_omega_x2omega_k () 49 cosmo.props.Omegac_fit = True 50 cosmo.props.Omegax_fit = True 51 cosmo.props.w_fit = True 52 53 # 54 # A new Distance object optimized to redshift 2. 55 # 56 dist = Nc.Distance (zf = 2.0) 57 58 # 59 # A new Data object from distance modulus catalogs. 60 # A new Data object from BAO catalogs. 61 # 62 snia = Nc.DataDistMu.new (dist, Nc.DataSNIAId.SIMPLE_UNION2_1) 63 bao = Nc.data_bao_create (dist, Nc.DataBaoId.A_EISENSTEIN2005) 64 65 # 66 # A new Dataset with snia and bao set. 67 # 68 dset = Ncm.Dataset () 69 dset.append_data (snia) 70 dset.append_data (bao) 71 72 # 73 # Creating a Likelihood from the Dataset. 74 # 75 lh = Ncm.Likelihood (dataset = dset) 76 77 # 78 # Creating a Fit object of type NLOPT using the fitting algorithm ln-neldermead to 79 # fit the Modelset mset using the Likelihood lh and using a numerical differentiation 80 # algorithm (NUMDIFF_FORWARD) to obtain the gradient (if needed). 81 # 82 fit = Ncm.Fit.new (Ncm.FitType.NLOPT, "ln-neldermead", lh, mset, Ncm.FitGradType.NUMDIFF_FORWARD) 83 84 # 85 # Running the fitter printing messages. 86 # 87 fit.run (Ncm.FitRunMsgs.SIMPLE) 88 89 # 90 # Printing fitting informations. 91 # 92 fit.log_info () 93 94 # 95 # Calculating the parameters covariance using numerical differentiation. 96 # 97 fit.numdiff_m2lnL_covar () 98 99 # 100 # Printing the covariance matrix. 101 # 102 fit.log_covar () 103 104 # 105 # Creating a new Likelihood ratio test object. 106 # First we create two PIndex indicating which parameter 107 # we are going to study. 108 # 109 p1 = Ncm.MSetPIndex.new (cosmo.id (), Nc.HICosmoDEParams.OMEGA_C) 110 p2 = Ncm.MSetPIndex.new (cosmo.id (), Nc.HICosmoDEXCDMParams.W) 111 112 lhr2d = Ncm.LHRatio2d.new (fit, p1, p2) 113 114 # 115 # Calculating the confidence region using the Likelihood ratio test. 116 # Also calculate using the Fisher matrix approach. 117 # 118 cr_rg = lhr2d.conf_region (0.6826, 300.0, Ncm.FitRunMsgs.SIMPLE) 119 fisher_rg = lhr2d.fisher_border (0.6826, 300.0, Ncm.FitRunMsgs.SIMPLE) 120 121 cr_p1array = cr_rg.p1.dup_array () 122 cr_p2array = cr_rg.p2.dup_array () 123 124 fisher_p1array = fisher_rg.p1.dup_array () 125 fisher_p2array = fisher_rg.p2.dup_array () 126 127 # 128 # Ploting the confidence regions obtained from both methods. 129 # 130 131 plt.title ("Confidence regions (%f)" % (cr_rg.clevel * 100.0)) 132 plt.plot (cr_p1array, cr_p2array, 'r', label="Likelihood Ratio") 133 plt.plot (fisher_p1array, fisher_p2array, 'b-', label="Fisher Matrix") 134 135 plt.xlabel(r'$\Omega_c$') 136 plt.ylabel(r'$w$') 137 138 plt.legend(loc=4) 139 140 plt.savefig ("snia_bao_rg_omegac_w.png")
This example has the following output and figure:

#---------------------------------------------------------------------------------- # Model fitting. Interating using: # - solver: NLOpt:ln-neldermead # - differentiation: Numerical differentiantion (forward) #...................... # Minimum found with precision: 1.00000e-08 (|df|/f or |dx|) # Elapsed time: 00 days, 00:00:00.1035530 # iteration [000137] # function evaluations [000137] # gradient evaluations [000000] # degrees of freedom [000577] # m2lnL = 562.202808924736 # Fit parameters: # [ 0.225227921129909 ] [ 0.584140145983326 ] [-1.18852980893615 ] #---------------------------------------------------------------------------------- # Data used: # - Union2.1 sample # - Eisenstein 2005, BAO Sample A #---------------------------------------------------------------------------------- # Model[00]: # - XCDM - Constant EOS #---------------------------------------------------------------------------------- # Model parameters # - H0[00]: 70 [FIXED] # - Omegac[01]: 0.225227921129909 [FREE] # - Omegax[02]: 0.584140145983326 [FREE] # - Tgamma0[03]: 2.72 [FIXED] # - Omegab[04]: 0.05 [FIXED] # - ns[05]: 1 [FIXED] # - sigma8[06]: 0.9 [FIXED] # - w[07]: -1.18852980893615 [FREE] #---------------------------------------------------------------------------------- # Fitted parameters covariance matrix # ---------------------------------------------- # Omegac[0001] = 0.2252 +/- 0.01881 | 1 | 0.1347 | 0.1098 | # Omegax[0002] = 0.5841 +/- 0.4915 | 0.1347 | 1 | 0.9963 | # w[0007] = -1.189 +/- 0.9275 | 0.1098 | 0.9963 | 1 | # ---------------------------------------------- #---------------------------------------------------------------------------------- # Likelihood ratio confidence region at 68.260%, bestfit [ 0.22522792 -1.1885298]: # # looking root in interval [ 0 1.5149868]: #............ # root found at 0.51764498 with precision 1.00000000e-05. # border found at 0.51764498. #. # looking root in interval [ 7.0669608 8.6377572]: #....... # root found at 7.9006802 with precision 1.00000000e-05. # looking root in interval [ 7.1152821 8.6860784]: #...... . . . Several messages like the above. . . # root found at 14.179015 with precision 1.00000000e-05. # looking root in interval [ 13.393617 14.964413]: #..... # root found at 14.180544 with precision 1.00000000e-05. # looking root in interval [ 13.395146 14.965943]: #....... # root found at 14.182127 with precision 1.00000000e-05. # Start found at [270], ending...
Cluster abundance example in C. Download the source.
To compile the example use:
gcc -Wall example_ca.c -o example_ca `pkg-config numcosmo --libs --cflags`
1 #include <glib.h> 2 #include <numcosmo/numcosmo.h> 3 4 gint 5 main (gint argc, gchar *argv[]) 6 { 7 NcHICosmo *cosmo; 8 NcDistance *dist; 9 NcWindow *wp; 10 NcTransferFunc *tf; 11 NcMatterVar *vp; 12 NcGrowthFunc *gf; 13 NcMultiplicityFunc *mulf; 14 NcMassFunction *mf; 15 guint np = 50; 16 gint i; 17 18 /**************************************************************************** 19 * Initializing the library objects, this must be called before 20 * any other library function. 21 ****************************************************************************/ 22 ncm_cfg_init (); 23 24 /**************************************************************************** 25 * New homogeneous and isotropic cosmological model NcHICosmoDEXcdm. 26 ****************************************************************************/ 27 cosmo = nc_hicosmo_new_from_name (NC_TYPE_HICOSMO, "NcHICosmoDEXcdm"); 28 29 /**************************************************************************** 30 * New cosmological distance objects optimizied to perform calculations 31 * up to redshift 2.0. 32 ****************************************************************************/ 33 dist = nc_distance_new (2.0); 34 35 /**************************************************************************** 36 * New windown function 'NcWindowTophat' 37 ****************************************************************************/ 38 wp = nc_window_new_from_name ("NcWindowTophat"); 39 40 /**************************************************************************** 41 * New transfer function 'NcTransferFuncEH' using the Einsenstein, Hu 42 * fitting formula. 43 ****************************************************************************/ 44 tf = nc_transfer_func_new_from_name ("NcTransferFuncEH"); 45 46 /**************************************************************************** 47 * New matter variance object using FFT method for internal calculations and 48 * the window and transfer functions defined above. 49 ****************************************************************************/ 50 vp = nc_matter_var_new (NC_MATTER_VAR_FFT, wp, tf); 51 52 /**************************************************************************** 53 * New growth function 54 ****************************************************************************/ 55 gf = nc_growth_func_new (); 56 57 /**************************************************************************** 58 * New multiplicity function 'NcMultiplicityFuncTinkerMean' 59 ****************************************************************************/ 60 mulf = nc_multiplicity_func_new_from_name ("NcMultiplicityFuncTinkerMean"); 61 62 /**************************************************************************** 63 * New mass function object using the objects defined above. 64 ****************************************************************************/ 65 mf = nc_mass_function_new (dist, vp, gf, mulf); 66 67 /**************************************************************************** 68 * Setting values for the cosmological model, those not set stay in the 69 * default values. Remeber to use the _orig_ version to set the original 70 * parameters in case when a reparametrization is used. 71 ****************************************************************************/ 72 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_H0, 70.0); 73 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_OMEGA_C, 0.25); 74 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_OMEGA_X, 0.7); 75 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_T_GAMMA0, 1.0); 76 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_OMEGA_B, 0.05); 77 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_SPECINDEX, 1.0); 78 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_SIGMA8, 0.9); 79 ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_XCDM_W, -1.1); 80 81 /**************************************************************************** 82 * Printing the parameters used. 83 ****************************************************************************/ 84 printf ("# Model parameters:\n#"); 85 ncm_model_params_log_all (NCM_MODEL (cosmo)); 86 87 /**************************************************************************** 88 * Printing the growth function and its derivative with respect to z 89 * up to redshift 1. 90 ****************************************************************************/ 91 nc_growth_func_prepare (gf, cosmo); 92 93 for (i = 0; i < np; i++) 94 { 95 gdouble z = 1.0 / (np - 1.0) * i; 96 gdouble gfz = nc_growth_func_eval (gf, cosmo, z); 97 gdouble dgfz = nc_growth_func_eval_deriv (gf, cosmo, z); 98 printf ("% 10.8f % 20.15g % 20.15g\n", z, gfz, dgfz); 99 } 100 printf ("\n\n"); 101 102 /**************************************************************************** 103 * Printing the transfer function and the matter power spectrum in the 104 * kh (in unities of h/Mpc) interval [1e-3, 1e3] 105 ****************************************************************************/ 106 nc_transfer_func_prepare (tf, cosmo); 107 108 for (i = 0; i < np; i++) 109 { 110 gdouble lnkh = log (1e-3) + log (1e6) / (np - 1.0) * i; 111 gdouble tfkh = nc_transfer_func_eval (tf, cosmo, exp (lnkh)); 112 gdouble Pmkh = nc_transfer_func_matter_powerspectrum (tf, cosmo, exp (lnkh)); 113 printf ("% 10.8f % 20.15g % 20.15g\n", exp (lnkh), tfkh, Pmkh); 114 } 115 printf ("\n\n"); 116 117 /**************************************************************************** 118 * Printing the variance filtered with the tophat windown function using 119 * scales R in the interval [5, 50] at redshift 0.3. 120 * First calculates the growth function at z = 0.3 and then the spectrum 121 * amplitude from the sigma8 parameter. 122 ****************************************************************************/ 123 nc_matter_var_prepare (vp, cosmo); 124 { 125 gdouble Dz = nc_growth_func_eval (gf, cosmo, 0.3); 126 gdouble A = nc_matter_var_sigma8_sqrtvar0 (vp, cosmo); 127 gdouble prefac = Dz * Dz * A * A; 128 129 for (i = 0; i < np; i++) 130 { 131 gdouble lnR = log (5.0) + log (10.0) / (np - 1.0) * i; 132 gdouble sigma2 = prefac * nc_matter_var_var0 (vp, cosmo, lnR); 133 gdouble dsigma2_dlnR = nc_matter_var_dlnvar0_dlnR (vp, cosmo, lnR); 134 printf ("% 10.8f % 20.15g % 20.15g\n", exp (lnR), sigma2, dsigma2_dlnR); 135 } 136 printf ("\n\n"); 137 } 138 139 /**************************************************************************** 140 * Printing the mass function integrated in the mass interval [1e14, 1e16] 141 * for the redhshifts in the interval [0, 2.0] and area 200 squared degree. 142 ****************************************************************************/ 143 nc_mass_function_set_area_sd (mf, 200.0); 144 nc_mass_function_set_eval_limits (mf, cosmo, log(1e14), log(1e16), 0.0, 2.0); 145 nc_mass_function_prepare (mf, cosmo); 146 147 for (i = 0; i < np; i++) 148 { 149 gdouble z = 2.0 / (np - 1.0) * i; 150 gdouble dndz = nc_mass_function_dn_dz (mf, cosmo, log(1e14), log(1e16), z, FALSE); 151 printf ("% 10.8f % 20.15g\n", z, dndz); 152 } 153 printf ("\n\n"); 154 155 156 /**************************************************************************** 157 * Freeing objects. 158 ****************************************************************************/ 159 nc_distance_free (dist); 160 ncm_model_free (NCM_MODEL (cosmo)); 161 nc_window_free (wp); 162 nc_transfer_func_free (tf); 163 nc_matter_var_free (vp); 164 nc_growth_func_free (gf); 165 nc_multiplicity_func_free (mulf); 166 nc_mass_function_free (mf); 167 168 return 0; 169 }
This example has the following output:
# Model parameters: # 70 0.25 0.7 1 0.05 1 0.9 -1.1 0.00000000 1 -0.514645182582311 0.02040816 0.989521827230155 -0.512155427490298 0.04081633 0.979098119618428 -0.509310730457052 0.06122449 0.968735891971304 -0.506133999217271 0.08163265 0.958441692552852 -0.502647779408878 0.10204082 0.948221611387305 -0.498874222357099 0.12244898 0.938081287298275 -0.494835138070745 0.14285714 0.928025915309424 -0.490552352178394 0.16326531 0.918060256550019 -0.486046757532692 0.18367347 0.908188651680731 -0.481338496480979 0.20408163 0.898415033975097 -0.476447152385309 0.22448980 0.888742942158506 -0.471391975844945 0.24489796 0.879175535674136 -0.466191041167092 0.26530612 0.869715611611056 -0.46086158700888 0.28571429 0.86036562079852 -0.455420201103897 0.30612245 0.851127683238634 -0.449882877489654 0.32653061 0.84200360568588 -0.444264420161198 0.34693878 0.832994899324174 -0.438578802751155 0.36734694 0.824102796392762 -0.432839361153584 0.38775510 0.815328266029958 -0.427058679848391 0.40816327 0.80667203166222 -0.421248292090362 0.42857143 0.798134587624337 -0.415418985803334 0.44897959 0.789716214481579 -0.409580948260127 0.46938776 0.781416993769452 -0.403743512810795 0.48979592 0.773236824337708 -0.397915320338556 0.51020408 0.765175435067201 -0.392104312982734 0.53061224 0.75723239998386 -0.386317786156192 0.55102041 0.749407150113895 -0.380562410752784 0.57142857 0.741698987103028 -0.374844249115267 0.59183673 0.734107094038444 -0.369168818070038 0.61224490 0.726630547606273 -0.36354107404639 0.63265306 0.719268327846196 -0.357965499439271 0.65306122 0.712019328866866 -0.352446072862367 0.67346939 0.704882367667553 -0.346986368541785 0.69387755 0.697856193074738 -0.341589471243274 0.71428571 0.690939494223693 -0.336258152541685 0.73469388 0.684130907771432 -0.330994814459831 0.75510204 0.677429025204744 -0.325801494258627 0.77551020 0.670832399464354 -0.320679920856448 0.79591837 0.66433955103003 -0.315631539855434 0.81632653 0.657948973544065 -0.310657537600845 0.83673469 0.651659138971016 -0.305758866530375 0.85714286 0.645468502441459 -0.300936233372512 0.87755102 0.639375506514683 -0.296190151348566 0.89795918 0.633378585424913 -0.291520942240238 0.91836735 0.627476168505608 -0.286928757313555 0.93877551 0.621666683639976 -0.282413591560572 0.95918367 0.615948560255777 -0.277975299165827 0.97959184 0.610320232074484 -0.273613606522902 1.00000000 0.604780139583612 -0.269328125088067 0.00100000 0.999805328836874 0.00099961069557061 0.00132571 0.99966036548697 0.0013248110038449 0.00175751 0.999408916610617 0.00175543356821907 0.00232995 0.998974629521377 0.00232517613258463 0.00308884 0.998228668319402 0.00307791055504462 0.00409492 0.996956115835977 0.00407002410849081 0.00542868 0.994802993737763 0.00537239634122765 0.00719686 0.991193154320994 0.00707065170884944 0.00954095 0.985194564691879 0.00926053017245344 0.01264855 0.975287700876948 0.0120311270012985 0.01676833 0.958925135476369 0.015419106248539 0.02222996 0.931708734586102 0.0192974137879651 0.02947052 0.886491810088735 0.0231599282977442 0.03906940 0.815930668834037 0.0260101735325903 0.05179475 0.726956269760714 0.0273717325212831 0.06866488 0.652751656188497 0.0292570584059584 0.09102982 0.608453134180805 0.033700623703963 0.12067926 0.553582842935875 0.0369826388441461 0.15998587 0.477966307235999 0.0365490589605499 0.21209509 0.407543542501762 0.0352272421382249 0.28117687 0.334015235521443 0.0313698285817094 0.37275937 0.264888077550762 0.0261549198951282 0.49417134 0.202854253187564 0.0203350753857352 0.65512856 0.150128256891569 0.0147656107317776 0.86851137 0.107719872554174 0.0100778333402021 1.15139540 0.0752208251004834 0.00651479381825275 1.52641797 0.0513422137708357 0.00402367273917402 2.02358965 0.0343913610414364 0.00239343245510617 2.68269580 0.0226840078767555 0.00138041925156272 3.55648031 0.0147706213896594 0.000775921776189659 4.71486636 0.00951269449406509 0.000426654653121894 6.25055193 0.00606782572434713 0.000230136002447234 8.28642773 0.00383743951101831 0.000122025454123775 10.98541142 0.00240823254484467 6.3710816194812e-05 14.56348478 0.00150080180911841 3.28028815112764e-05 19.30697729 0.000929403783999379 1.66772008206936e-05 25.59547923 0.000572276426899725 8.382527350344e-06 33.93221772 0.000350566272802228 4.17015797585198e-06 44.98432669 0.000213756088939872 2.0554088104965e-06 59.63623317 0.000129792925234918 1.00464411637065e-06 79.06043211 7.85140104015962e-05 4.873640672225e-07 104.81131342 4.73333022366793e-05 2.34823616311431e-07 138.94954944 2.84479990994849e-05 1.12450293666329e-07 184.20699693 1.70501130001047e-05 5.35501443336509e-08 244.20530945 1.01930476529716e-05 2.5372497078206e-08 323.74575428 6.07966647435448e-06 1.19664020805526e-08 429.19342601 3.61860031217541e-06 5.61997383816258e-09 568.98660290 2.14962619374807e-06 2.62922608119628e-09 754.31200634 1.27471880566688e-06 1.22568763887568e-09 1000.00000000 7.54666527284974e-07 5.69521567404362e-10 5.00000000 1.8274174978287 -2.24929762765026 5.24056567 1.64293188219668 -2.28009947787663 5.49270571 1.47493241367498 -2.31095510706532 5.75697700 1.3221925792073 -2.34183286681469 6.03396320 1.18355153549511 -2.37270076477371 6.32427608 1.05791325775041 -2.40352736917292 6.62855683 0.944244617464068 -2.43428104986324 6.94747747 0.841574098075207 -2.46492970566601 7.28174239 0.748990090162159 -2.49544217653731 7.63208984 0.665638924715768 -2.52578787846441 7.99929360 0.590723205987652 -2.55593595388316 8.38416468 0.523499595669407 -2.58585606552141 8.78755312 0.463276879910984 -2.61551870146876 9.21034985 0.409413777456172 -2.64489339217275 9.65348864 0.361316639593754 -2.6739499764721 10.11794824 0.318437327146138 -2.70266205737228 10.60475444 0.28027072841772 -2.73100549380316 11.11498241 0.246352524257818 -2.75895817056931 11.64975905 0.216256917442029 -2.78649830826439 12.21026547 0.189594331575874 -2.81360304121439 12.79773961 0.166009225421682 -2.84024511306228 13.41347898 0.145177827321541 -2.86639976168026 14.05884349 0.126805984633142 -2.89204759424341 14.73525851 0.110626993051815 -2.91717223761638 15.44421798 0.0963995862730792 -2.94175681427814 16.18728771 0.0839060392870728 -2.96577688699737 16.96610886 0.07295030478778 -2.98920061142062 17.78240153 0.0633562382313602 -3.01199019960636 18.63796860 0.0549658740495639 -3.0341280685365 19.53469969 0.0476378264992342 -3.05559623589061 20.47457531 0.0412458222156237 -3.07633382073925 21.45967130 0.0356773551634426 -3.0962771409813 22.49216334 0.0308323789669883 -3.11537003140222 23.57433182 0.0266220242345668 -3.13354300769251 24.70856681 0.0229675229228567 -3.15069896513196 25.89737340 0.0197992636572314 -3.16667341306591 27.14337720 0.0170557865368846 -3.18126467662515 28.44933015 0.0146829227444275 -3.19422505388485 29.81811658 0.0126330691958588 -3.20516121869808 31.25275963 0.0108644371224447 -3.21348908975707 32.75642784 0.00934051005036877 -3.21826737268193 34.33244225 0.00802928574485255 -3.21889859337347 35.98428365 0.00690264753039734 -3.21549443391645 37.71560032 0.00593537466549436 -3.20976091658663 39.53021605 0.00510509654368734 -3.20401614384521 41.43213864 0.004391992685419 -3.19993910489024 43.42556869 0.00377897660332001 -3.19875396917298 45.51490890 0.003251432871344 -3.20121466693825 47.70477382 0.00279696196220972 -3.20752079294885 50.00000000 0.0024050850534294 -3.21755054030217 0.00000000 0 0.04081633 166.593553876111 0.08163265 615.595498675364 0.12244898 1274.46682676192 0.16326531 2076.70067755906 0.20408163 2962.968012134 0.24489796 3881.84589051384 0.28571429 4790.14715032561 0.32653061 5652.89636477869 0.36734694 6443.01005196235 0.40816327 7140.74456233729 0.44897959 7732.97778077429 0.48979592 8212.38825681368 0.53061224 8576.58574685379 0.57142857 8827.2385356839 0.61224490 8969.23397350714 0.65306122 9009.8988875736 0.69387755 8958.29720342208 0.73469388 8824.6142916826 0.77551020 8619.6326663454 0.81632653 8354.29763821171 0.85714286 8039.36852319812 0.89795918 7685.14854877498 0.93877551 7301.28508364848 0.97959184 6896.63120166262 1.02040816 6479.15942753275 1.06122449 6055.91877435476 1.10204082 5633.02681460608 1.14285714 5215.68926906412 1.18367347 4808.24043655454 1.22448980 4414.19865817605 1.26530612 4036.33196753622 1.30612245 3676.72980504035 1.34693878 3336.87749760777 1.38775510 3017.73082311451 1.42857143 2719.78870837676 1.46938776 2443.16238331635 1.51020408 2187.64026355105 1.55102041 1952.74734603486 1.59183673 1737.79916708241 1.63265306 1541.94995139757 1.67346939 1364.23501441291 1.71428571 1203.60759346322 1.75510204 1058.97038812295 1.79591837 929.202162688091 1.83673469 813.17981601913 1.87755102 709.796336489963 1.91836735 617.97510505145 1.95918367 536.680892784187 2.00000000 464.928124731828
An example of the cluster abundance object in Python. Download the source.
To try this example you must have PyGObject installed, matplotlib matplotlib and numcosmo built with --enable-introspection option.
1 #!/usr/bin/python2 2 3 from math import * 4 from gi.repository import GObject 5 import matplotlib.pyplot as plt 6 from gi.repository import NumCosmo as Nc 7 from gi.repository import NumCosmoMath as Ncm 8 9 # 10 # Initializing the library objects, this must be called before 11 # any other library function. 12 # 13 Ncm.cfg_init () 14 15 # 16 # New homogeneous and isotropic cosmological model NcHICosmoDEXcdm 17 # 18 cosmo = Nc.HICosmo.new_from_name (Nc.HICosmo, "NcHICosmoDEXcdm") 19 20 # 21 # New cosmological distance objects optimizied to perform calculations 22 # up to redshift 2.0. 23 # 24 dist = Nc.Distance.new (2.0) 25 26 # 27 # New windown function 'NcWindowTophat' 28 # 29 wp = Nc.Window.new_from_name ("NcWindowTophat") 30 31 # 32 # New transfer function 'NcTransferFuncEH' using the Einsenstein, Hu 33 # fitting formula. 34 # 35 tf = Nc.TransferFunc.new_from_name ("NcTransferFuncEH") 36 37 # 38 # New matter variance object using FFT method for internal calculations and 39 # the window and transfer functions defined above. 40 # 41 vp = Nc.MatterVar.new (Nc.MatterVarStrategy.FFT, wp, tf) 42 43 # 44 # New growth function 45 # 46 gf = Nc.GrowthFunc.new () 47 48 # 49 # New multiplicity function 'NcMultiplicityFuncTinkerMean' 50 # 51 mulf = Nc.MultiplicityFunc.new_from_name ("NcMultiplicityFuncTinkerMean") 52 53 # 54 # New mass function object using the objects defined above. 55 # 56 mf = Nc.MassFunction.new (dist, vp, gf, mulf) 57 58 # 59 # Setting values for the cosmological model, those not set stay in the 60 # default values. Remember to use the _orig_ version to set the original 61 # parameters when a reparametrization is used. 62 # 63 cosmo.props.H0 = 70.0 64 cosmo.props.Omegab = 0.05 65 cosmo.props.Omegac = 0.25 66 cosmo.props.Omegax = 0.70 67 cosmo.props.Tgamma0 = 2.72 68 cosmo.props.ns = 1.0 69 cosmo.props.sigma8 = 0.9 70 cosmo.props.w = -1.0 71 72 # 73 # Printing the parameters used. 74 # 75 print "# Model parameters: ", 76 cosmo.params_log_all () 77 78 # 79 # Number of points to build the plots 80 # 81 np = 2000 82 divfac = 1.0 / (np - 1.0) 83 84 # 85 # Calculating growth and its derivative in the [0, 2] redshift 86 # range. 87 # 88 za = [] 89 Da = [] 90 dDa = [] 91 92 gf.prepare (cosmo) 93 94 for i in range (0, np): 95 z = 2.0 * divfac * i 96 D = gf.eval (cosmo, z) 97 dD = gf.eval_deriv (cosmo, z) 98 za.append (z) 99 Da.append (D) 100 dDa.append (dD) 101 102 # 103 # Ploting growth function. 104 # 105 106 plt.title ("Growth Function") 107 plt.plot (za, Da, 'r', label="D") 108 plt.plot (za, dDa, 'b--', label="dD/dz") 109 plt.xlabel('$z$') 110 plt.legend(loc=2) 111 112 plt.savefig ("growth_func.png") 113 plt.clf () 114 115 # 116 # Calculating the transfer function and the matter power spectrum in the 117 # kh (in unities of h/Mpc) interval [1e-3, 1e3] 118 # 119 120 kha = [] 121 Ta = [] 122 Pma = [] 123 124 tf.prepare (cosmo) 125 126 for i in range (0, np): 127 lnkh = log (1e-4) + log (1e7) * divfac * i 128 kh = exp (lnkh) 129 T = tf.eval (cosmo, kh) 130 Pm = 1.0e3 / 7.0 * tf.matter_powerspectrum (cosmo, kh) 131 kha.append (kh) 132 Ta.append (T) 133 Pma.append (Pm) 134 135 # 136 # Ploting transfer and matter power spectrum 137 # 138 139 plt.title ("Transfer Function and Matter Power Spectrum") 140 plt.xscale('log') 141 plt.plot (kha, Ta, 'r', label="T(kh)") 142 plt.plot (kha, Pma, 'b--', label="P_m(kh)") 143 plt.xlabel('$k$') 144 plt.legend(loc=1) 145 146 plt.savefig ("transfer_func.png") 147 plt.clf () 148 149 # 150 # Calculating the variance filtered with the tophat windown function using 151 # scales R in the interval [5, 50] at redshift 0.3. 152 # First calculates the growth function at z = 0.3 and then the spectrum 153 # amplitude from the sigma8 parameter. 154 # 155 156 vp.prepare (cosmo) 157 158 Dz = gf.eval (cosmo, 0.3) 159 A = vp.sigma8_sqrtvar0 (cosmo) 160 prefact = A * A * Dz * Dz 161 162 Ra = [] 163 sigma2a = [] 164 dlnsigma2a = [] 165 166 for i in range (0, np): 167 lnR = log (5.0) + log (10.0) * divfac * i 168 R = exp (lnR) 169 sigma2 = prefact * vp.var0 (cosmo, lnR) 170 dlnsigma2 = vp.dlnvar0_dlnR (cosmo, lnR) 171 Ra.append (R) 172 sigma2a.append (sigma2) 173 dlnsigma2a.append (dlnsigma2) 174 175 # 176 # Ploting filtered matter variance 177 # 178 179 plt.title ("Variance and Variance Derivative") 180 plt.plot (Ra, sigma2a, 'r', label='$\sigma^2(\ln(R))$') 181 plt.plot (Ra, dlnsigma2a, 'b--', label='$d\ln(\sigma^2)/d\ln(R)$') 182 plt.xlabel('$R$') 183 plt.legend(loc=1) 184 185 plt.savefig ("matter_var.png") 186 plt.clf () 187 188 # 189 # Calculating the mass function integrated in the mass interval [1e14, 1e16] 190 # for the redhshifts in the interval [0, 2.0] and area 200 squared degree. 191 # 192 193 mf.set_area_sd (200.0) 194 mf.set_eval_limits (cosmo, log (1e14), log(1e16), 0.0, 2.0) 195 196 dndza = [] 197 198 for i in range (0, np): 199 dndz = mf.dn_dz (cosmo, log(1e14), log(1e16), za[i], True) 200 dndza.append (dndz) 201 202 # 203 # Ploting the mass function 204 # 205 206 plt.title ("Mass Function") 207 plt.plot (za, dndza, 'r', label='$dn/dz$') 208 plt.xlabel('$z$') 209 plt.legend(loc=1) 210 211 plt.savefig ("mass_function.png") 212 plt.clf ()
This example produces:

Contact
Please report bugs, ask questions and send comments/suggestions at numcosmo-help@nongnu.org