示例#1
0
    def __init__(self,
                 massdef='mean',
                 delta_mdef=200,
                 halo_profile_model='nfw'):
        Ncm.cfg_init()

        self.backend = 'nc'

        self.set_cosmo(None)

        self.mdef_dict = {
            'mean': Nc.HaloDensityProfileMassDef.MEAN,
            'critical': Nc.HaloDensityProfileMassDef.CRITICAL,
            'virial': Nc.HaloDensityProfileMassDef.VIRIAL
        }
        self.hdpm_dict = {
            'nfw': Nc.HaloDensityProfileNFW.new,
            'einasto': Nc.HaloDensityProfileEinasto.new,
            'hernquist': Nc.HaloDensityProfileHernquist.new
        }

        self.halo_profile_model = ''
        self.massdef = ''
        self.delta_mdef = 0
        self.hdpm = None

        self.set_halo_density_profile(halo_profile_model, massdef, delta_mdef)
示例#2
0
 def __init__(self, massdef='mean', delta_mdef=200, halo_profile_model='nfw'):
     CLMModeling.__init__(self)
     # Update class attributes
     Ncm.cfg_init()
     self.backend = 'nc'
     self.mdef_dict = {
         'mean': Nc.HaloDensityProfileMassDef.MEAN,
         'critical': Nc.HaloDensityProfileMassDef.CRITICAL,
         'virial':Nc.HaloDensityProfileMassDef.VIRIAL}
     self.hdpm_dict = {
         'nfw': Nc.HaloDensityProfileNFW.new,
         'einasto': Nc.HaloDensityProfileEinasto.new,
         'hernquist': Nc.HaloDensityProfileHernquist.new}
     # Set halo profile and cosmology
     self.set_halo_density_profile(halo_profile_model, massdef, delta_mdef)
     self.set_cosmo(None)
示例#3
0
  def __init__(self, z_min, z_max, z_sigma, lnM_min, 
                lnM_max, area, observable):
    Ncm.cfg_init()
    self.cosmo = Nc.HICosmo.new_from_name(Nc.HICosmo, "NcHICosmoDEXcdm")
    dist = Nc.Distance.new(z_max*1.5)
    wp =  Nc.Window.new_from_name("NcWindowTophat")
    tf = Nc.TransferFunc.new_from_name("NcTransferFuncEH")
    vp = Nc.MatterVar.new(Nc.MatterVarStrategy.FFT, wp, tf)
    gf = Nc.GrowthFunc.new()
    mulf = Nc.MultiplicityFunc.new_from_name("NcMultiplicityFuncTinkerCrit{'Delta':<500.0>}")
    mf = Nc.MassFunction.new(dist, vp, gf, mulf)
    
    if observable == 'SZ':
        cluster_m = Nc.ClusterMass.new_from_name("NcClusterMassBenson{'M0':<3e14>, 'z0':<0.6>, 'signif-obs-min':<5.0>,'Asz':<6.24>, 'Bsz':<1.33>, 'Csz':<0.83>, 'Dsz':<0.24>}")
    elif observable == 'true_mass':
        cluster_m = Nc.ClusterMass.new_from_name("NcClusterMassNodist{'lnM-min':<% 20.15g>, 'lnM-max':<% 20.15g>}" % (lnM_min, lnM_max))
    else:
        raise NameError('Invalid observable choice. Should be ' + 
                        '"true_mass" or "SZ"')
        
    cluster_z = Nc.ClusterRedshift.new_from_name("NcClusterPhotozGaussGlobal{'pz-min':<%f>, 'pz-max':<%f>, 'z-bias':<0.0>, 'sigma0':<%f>}" % (z_min, z_max, z_sigma))
    cad = Nc.ClusterAbundance.new(mf, None, cluster_z, cluster_m)

    self.ncdata = Nc.DataClusterNCount.new(cad)
    self.mset = Ncm.MSet()
    self.mset.set(self.cosmo)
    self.mset.set(cluster_m)

    self.rng = Ncm.RNG.pool_get("example_ca_sampling");
    self.ncdata.init_from_sampling(self.mset, cluster_z, cluster_m, 
                                   area * (pi/180.0) ** 2, self.rng)

    del dist
    del vp
    del gf
    del mulf
    del mf
    del cad
    del cluster_z
    del cluster_m
示例#4
0
import math
import numpy as np
import matplotlib.pyplot as plt

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

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

Ncm.cfg_init()

#
#  New homogeneous and isotropic cosmological model NcHICosmoDEXcdm
#
cosmo = Nc.HICosmo.new_from_name(Nc.HICosmo, "NcHICosmoDEXcdm")
cosmo.omega_x2omega_k()
cosmo.param_set_by_name("Omegak", 0.0)

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

#
  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

#import threading
#from numpy import pi
import os
import os.path
import math

Ncm.cfg_init ()

z_max = 1.32
z_min = 0.3
area  = 2500

#
#  New homogeneous and isotropic cosmological model NcHICosmoDEXcdm 
#
cosmo = Nc.HICosmo.new_from_name (Nc.HICosmo, "NcHICosmoDEXcdm{'H0':<71.15>, 'Omegac':<0.218>, 'Omegab':<0.044>, 'w':<-1.01>, 'Omegac-fit':<1>, 'w-fit':<1>}")
cosmo.omega_x2omega_k ()
cosmo.param_set_by_name ("Omegak", 0.0);

(Found, w_i) = cosmo.param_index_from_name ("w")
cosmo.param_set_lower_bound (w_i, -3.0)
cosmo.param_set_upper_bound (w_i,  0.0)
示例#6
0
  import gi
  gi.require_version('NumCosmo', '1.0')
  gi.require_version('NumCosmoMath', '1.0')
except:
  pass

import math
from gi.repository import GObject
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 ModelBuilder object, defines a new model NcHIPrimExample implementing
# the Nc.HIPrim abstract class.
# 
mb = Ncm.ModelBuilder.new (Nc.HIPrim, "NcHIPrimExample", "A example primordial model")

#
# New parameter A_s to describe the spectrum amplitud (it is usually better
# to work with ln(10^10As))
#
mb.add_sparam ("A_s", "As", 0.0, 1.0, 0.1, 0.0, 1.0e-9, Ncm.ParamType.FREE)

#
# New parameter n_s to describe the spectral index
    gi.require_version('NumCosmo', '1.0')
    gi.require_version('NumCosmoMath', '1.0')
except:
    pass

from math import *
import matplotlib.pyplot as plt
from gi.repository import GObject
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
#
cosmo = Nc.HICosmo.new_from_name(Nc.HICosmo, "NcHICosmoDEXcdm")

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

#
# OO-like
#
示例#8
0
try:
  import gi
  gi.require_version('NumCosmo', '1.0')
  gi.require_version('NumCosmoMath', '1.0')
except:
  pass

from gi.repository import GObject
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 ()

#
# Instantiating a new SLine model object and setting
# some values for its parameters.
#
mrb = Ncm.ModelRosenbrock ()

#
# New Model set object including slm with parameters
# set as free.
#
mset = Ncm.MSet.empty_new ()
mset.set (mrb)
mset.param_set_all_ftype (Ncm.ParamType.FREE)
mset.prepare_fparam_map ()
示例#9
0
try:
    import gi
    gi.require_version('NumCosmo', '1.0')
    gi.require_version('NumCosmoMath', '1.0')
except:
    pass

from gi.repository import GObject
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()

dim = 10
#
# Instantiating a new SLine model object and setting
# some values for its parameters.
#
mrb = Ncm.ModelFunnel.new(dim - 1)

#
# New Model set object including slm with parameters
# set as free.
#
mset = Ncm.MSet.empty_new()
mset.set(mrb)
mset.param_set_all_ftype(Ncm.ParamType.FREE)
示例#10
0
#!/usr/bin/python2
   
#from math import *

import gi
gi.require_version('NumCosmo', '1.0')
gi.require_version('NumCosmoMath', '1.0')

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

Ncm.cfg_init ()

NT = 3           # Number of threads
NClusters = 21   # Number of clusters
NWalkers = 100     # Number of walkers / chains

# Cosmological model: XCDM, DE eqos - w = constant
cosmo = Nc.HICosmo.new_from_name (Nc.HICosmo, "NcHICosmoDEXcdm")
dist = Nc.Distance.new (4.0)
# Primordial power spectrum - power law
prim  = Nc.HIPrimPowerLaw.new ()
reion = Nc.HIReionCamb.new ()
# Transfer function 
tf    = Nc.TransferFunc.new_from_name ("NcTransferFuncEH")
# Linear matter power spectrum
ps_ml = Nc.PowspecMLTransfer.new (tf)
psf   = Ncm.PowspecFilter.new (ps_ml, Ncm.PowspecFilterType.TOPHAT)
mulf = Nc.MultiplicityFunc.new_from_name ("NcMultiplicityFuncTinkerCrit{'Delta':<500.0>}")
mf = Nc.HaloMassFunction.new (dist, psf, mulf)
示例#11
0
  pass

import timeit
import sys
import time
import math
import numpy as np
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.
#
sys.argv = Ncm.cfg_init_full (sys.argv)


cosmo = Nc.HICosmo.new_from_name (Nc.HICosmo, "NcHICosmoDEXcdm")

cosmo.props.H0      = 70.0
cosmo.props.Omegab  = 0.05
cosmo.props.Omegac  = 0.25
cosmo.props.Omegax  = 0.70
cosmo.props.Tgamma0 = 2.72
cosmo.props.w       = -1.0

#
#  Creating a new Modelset and set cosmo as the HICosmo model to be used.
#
mset = Ncm.MSet ()
示例#12
0
#
#  Creating a Fit object of type NLOPT using the fitting algorithm ln-neldermead to
#  fit the Modelset mset using the Likelihood lh and using a numerical differentiation
#  algorithm (NUMDIFF_FORWARD) to obtain the gradient (if needed).
#
fit = Ncm.Fit.new (Ncm.FitType.NLOPT, "ln-neldermead", lh, mset, Ncm.FitGradType.NUMDIFF_FORWARD)

#
# Printing fitting informations.
#
fit.log_info ()

#
# Setting single thread calculation.
#
Ncm.func_eval_set_max_threads (1)
Ncm.func_eval_log_pool_stats ()

#
# New Gaussian prior to provide the initial points for the chain.
# It was created with size 0 (number of parameters), but once 
# initialized with mset the correct size is assigned. 
#
# The initial sampler will use a diagonal covariance with the
# diagonal terms being the parameters scale set by each model.
#
init_sampler = Ncm.MSetTransKernGauss.new (0)
init_sampler.set_mset (mset)
init_sampler.set_prior_from_mset ()
init_sampler.set_cov_from_rescale (1.0)
#!/usr/bin/python2

#from math import *

import gi
gi.require_version('NumCosmo', '1.0')
gi.require_version('NumCosmoMath', '1.0')

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

Ncm.cfg_init()

NT = 3  # Number of threads
NClusters = 21  # Number of clusters
NWalkers = 100  # Number of walkers / chains

# Cosmological model: XCDM, DE eqos - w = constant
cosmo = Nc.HICosmo.new_from_name(Nc.HICosmo, "NcHICosmoDEXcdm")
dist = Nc.Distance.new(4.0)
# Primordial power spectrum - power law
prim = Nc.HIPrimPowerLaw.new()
reion = Nc.HIReionCamb.new()
# Transfer function
tf = Nc.TransferFunc.new_from_name("NcTransferFuncEH")
# Linear matter power spectrum
ps_ml = Nc.PowspecMLTransfer.new(tf)
psf = Ncm.PowspecFilter.new(ps_ml, Ncm.PowspecFilterType.TOPHAT)
mulf = Nc.MultiplicityFunc.new_from_name(
    "NcMultiplicityFuncTinkerCrit{'Delta':<500.0>}")
示例#14
0
import matplotlib.pyplot as plt
import os.path

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

from gi.repository import GObject
from gi.repository import NumCosmo as Nc
from gi.repository import NumCosmoMath as Ncm
__name___ = "NcContext"

Ncm.cfg_init()
Ncm.cfg_set_log_handler(
    lambda msg: sys.stdout.write(msg) and sys.stdout.flush())

dim = 5
np.random.seed(seed=123)
p = np.random.random_sample((dim, ))
print(p)

rng = Ncm.RNG.seeded_new(None, 123)

fmodel = Ncm.ModelMVND.new(dim)
fdata = Ncm.DataGaussCovMVND.new_full(dim, 0.1, 0.4, 10.0, -1.0, 1.0, rng)

fdata.props.use_norma = True
示例#15
0
except:
    pass

import timeit
import sys
import time
import math
import numpy as np
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.
#
sys.argv = Ncm.cfg_init_full(sys.argv)

rng = Ncm.RNG.new(None)
rng.set_random_seed(True)

mj = Ncm.MPIJobTest.new()
mj.set_rand_vector(12, rng)

ser = Ncm.Serialize.new(0)
mj.init_all_slaves(ser)

a = []
b = []
for t in np.arange(12.0):
    a.append(Ncm.Vector.new_array([t]))
    b.append(Ncm.Vector.new(1))