コード例 #1
0
ファイル: 2pt_monopole.py プロジェクト: SofiaContarini/CBL
# =================================================================================================
# Example code: how to measure the angle-averaged two-point correlation function, i.e. the monopole
# =================================================================================================

### import Python modules for scientific computing ###

import os
import numpy as np

### import the CosmoBolognaLib modules ###

import CosmoBolognaLib as cbl

### define the cosmological model, with default parameters ###

cosmology = cbl.Cosmology()

### Input/Output files and directories ###

file_catalogue = ("../input/cat.dat", )
dir_output = "../output/"
dir_pairs = dir_output + "pairs/"
dir_random_cat = dir_output

os.system("mkdir -p " + dir_output + " " + dir_pairs)

### read the input galaxy catalogue (with polar coordinates: RA, Dec, redshift) ###

print("I'm reading the input catalogue...")

catalogue = cbl.Catalogue(cbl.EnumTypes._Galaxy_,
コード例 #2
0
import numpy as np
import matplotlib.pyplot as plt

# import the CosmoBolognaLib #
import CosmoBolognaLib as cbl
from CosmoBolognaLib import DoubleVector as dv

# set the CosmoBolognaLib and the current directories
cbl.SetDirs("../../", "./")

# set the cosmological model, with default parameters
cosmology = cbl.Cosmology()

# compute the dark matter power spectrum
kk = np.logspace(-4, 2, 200)
Pk = [cosmology.Pk(kk[i], "CAMB", False, 0) for i in range(len(kk))]

# get correlation function from fftlog: dir is the transformation
# direction, mu is the order of the Bessel function (see the
# documentation for other options)
dir = 1
mu = 0
rr = np.linspace(1., 200, 100)
xi = np.array(cbl.transform_FFTlog(dv(rr), dir, dv(kk), dv(Pk), mu))

# plot results
plt.plot(rr, xi * rr * rr)
plt.xlabel(r"$s$ $[$Mpc$h^{-1}]$")
plt.ylabel(r"$\xi(s)\cdot s^2$ $[$Mpc$^2h^{-2}]$")
plt.plot(rr, xi * rr * rr, '-')
コード例 #3
0
ファイル: prior.py プロジェクト: cbehren/CosmoBolognaLib
import numpy as np
import matplotlib.pyplot as plt
import CosmoBolognaLib as cbl

xmin = -10.
xmax = 10.
mean = -1.
sigma = 0.1

prior = cbl.PriorDistribution(cbl.DistributionType__Gaussian_, [mean, sigma],
                              xmin, xmax)

nExtr = 2000
sample = np.array([prior.sample(i) for i in range(nExtr)])
psample = np.array([prior(ss) for ss in sample])

plt.hist(sample, 20, normed=True)
plt.plot(sample, psample, '.')
plt.show(block=False)
コード例 #4
0
ファイル: pipeline.py プロジェクト: ready4euclid/pipeline
#-------------------#
# input/output data #
#-------------------#

HOME = os.getenv("HOME")
file_data = HOME + "/Input/data.dat"
file_catalogue = HOME + "/Input/clusterCatalog.dat"
dir_output = HOME + "/Output/"

###############################################################################

#-------------------------------#
# define the cosmological model #
#-------------------------------#

cosmology = cbl.Cosmology()

###############################################################################

#-----------------#
# detect clusters #
#-----------------#

#cbl.detectClusters(file_data, file_catalogue) [to be implemented/included]

###############################################################################

#----------------------------#
# read the cluster catalogue #
#----------------------------#
コード例 #5
0
ファイル: elg_analysis.py プロジェクト: aaorsi/ELG_analysis
    plt.plot(gal_elgs['coords'][:, 0],
             gal_elgs['coords'][:, 1],
             'o',
             markersize=3,
             color='royalblue',
             label='ELG candidates')
    plt.legend()
    plt.xlabel('RA')
    plt.ylabel('DEC')
    plt.savefig('footprint.pdf', bbox_inches='tight')

    # In[27]:

    # In[1]:

    cosmology = cbl.Cosmology()
    ran['redshift'] = np.ones(len(ran['coords'][:, 0]))
    gal_elgs['redshift'] = np.ones(len(gal_elgs['coords'][:, 0]))

    cat_objs = cbl.Catalogue(cbl.EnumTypes._Galaxy_,
                             cbl.EnumTypes._observedCoordinates_,
                             gal_elgs['coords'][:, 0], gal_elgs['coords'][:,
                                                                          1],
                             gal_elgs['redshift'], cosmology)
    ran_objs = cbl.Catalogue(cbl.EnumTypes._RandomObject_,
                             cbl.EnumTypes._observedCoordinates_,
                             ran['coords'][:, 0], ran['coords'][:, 1],
                             ran['redshift'], cosmology)

    angMin = 0.01  #// minimum angular separation
    angMax = 3.  #// maximum angular separation
コード例 #6
0
ファイル: 3pt_model.py プロジェクト: cbehren/CosmoBolognaLib
# =======================================================================
# Example code: how to compute the three-point correlation function model
# =======================================================================

import numpy as np
import matplotlib.pyplot as plt
import CosmoBolognaLib as cbl
from CosmoBolognaLib import DoubleVector as dv
import os

# set the CosmoBolognaLib and the current directories
cbl.SetDirs("../../../", "./")
''' Define the cosmology '''
cosmo = cbl.Cosmology(cbl.CosmologicalModel__Planck15_)
''' Compute Pk '''
redshift = 1
kk = np.logspace(-4, 2, 200)
Pk_DM = np.array([cosmo.Pk(_kk, "CAMB", False, redshift) for _kk in kk])
''' Parameters for 3pt signal '''
rr = dv(np.linspace(1., 300, 200))
theta = np.linspace(0, np.pi, 100)
r1, r2 = 20, 40
''' Slepian model '''
zeta_DM_s = np.array(cosmo.zeta_DM(r1, r2, theta, "Slepian", kk, Pk_DM))
q_DM_s = np.array(cosmo.Q_DM(r1, r2, theta, "Slepian", kk, Pk_DM))
''' Barriga-Gatzagnaga model '''
zeta_DM_bg = np.array(
    cosmo.zeta_DM(r1, r2, theta, "BarrigaGatzanaga", kk, Pk_DM))
q_DM_bg = np.array(cosmo.Q_DM(r1, r2, theta, "BarrigaGatzanaga", kk, Pk_DM))
'''Plot the results'''
plt.xlabel(r"$\theta/\pi$")
コード例 #7
0
# ==========================================================================
# Example code: how to compute the theoretical size function of cosmic voids
# ==========================================================================

# to ensure compatibility in Python versions 2.x and 3.x
from __future__ import print_function

# import the CosmoBolognaLib #
import CosmoBolognaLib as cbl
import numpy as np

# set the CosmoBolognaLib and the current directories
cbl.SetDirs("../../../", "./")

# define a cosmological model, using default parameters #
cosm = cbl.Cosmology()

# Minimum and maximum of effective void radii
R_min = 1.
R_max = 30.

# number of radii at which the size function is computed
n_val = 10

# list of effective void radii with logarithmic binning
RR = np.logspace(np.log10(R_min), np.log10(R_max), n_val, endpoint=True)

# redshift of the sample
zz = 0.

# effective bias of the mass tracers
コード例 #8
0
from CosmoBolognaLib import ErrorCBL

# import timer
import time

##########################################################
# just remember that parameter files do have a purpose

if (len(sys.argv) == 1):
    print("Usage: /path/to/cleaVoidCatalogue.py /path/to/parameter_file.ini")
    exit(-1)

if (len(sys.argv) > 1):
    filename = sys.argv[1]
    print(" Loading parameters from", filename)
    param = cbl.ReadParameters(filename)

else:
    print(" Using default parameters")

##########################################################
# Coordinates type selection

if param.findBool('comovingCoordinates'):
    coordinates = cbl.CoordinateType__comoving_
else:
    coordinates = cbl.CoordinateType__observed_

##########################################################
# define a cosmological model, using parameters from file #
コード例 #9
0
# ===================================================================
# Example code: how to construct a catalogue of extragalactic objects
# ===================================================================

### import the CosmoBolognaLib ###
import CosmoBolognaLib as cbl
from CosmoBolognaLib import EnumTypes as et
from CosmoBolognaLib import StringVector as sv

### define a vector of input files (in this case with dim=1) ###
file_cat = "cat.dat"
file_cat_vec = sv(1, file_cat)

### create a catalogue of galaxies, retrieving their comoving coordinates from an input file ###
catalogue = cbl.Catalogue(et._Galaxy_, et._comovingCoordinates_, file_cat_vec)
catalogue2 = cbl.Catalogue(catalogue)

### print the coordinates of the first object ###
print "The coordinates of the first galaxy in the catalogue are:", catalogue[0].xx(), catalogue[0].yy(), catalogue[0].zz()
コード例 #10
0
# =================================================================================================
# Example code: how to measure the angle-averaged two-point correlation function, i.e. the monopole
# =================================================================================================

# to ensure compatibility in Python versions 2.x and 3.x
from __future__ import print_function

# import Python modules for scientific computing
import os
import numpy as np

# import the CosmoBolognaLib modules
import CosmoBolognaLib as cbl

# define the cosmological model, with default parameters
cosmology = cbl.Cosmology(cbl.CosmologicalModel__Planck15_)

# Input/Output files and directories
file_catalogue = ("../input/cat.dat", )
dir_output = "../output/"
dir_pairs = dir_output + "pairs/"
dir_random_cat = dir_output
os.system("mkdir -p " + dir_output + " " + dir_pairs)

# read the input galaxy catalogue (with polar coordinates: RA, Dec, redshift)
print("I'm reading the input catalogue...")
catalogue = cbl.Catalogue(cbl.ObjectType__Galaxy_,
                          cbl.CoordinateType__observed_, file_catalogue,
                          cosmology)

# construct the random catalogue (with cubic geometry)
コード例 #11
0
# =================================================================
# Example code: how to measure the three-point correlation function
# =================================================================

# to ensure compatibility in Python versions 2.x and 3.x
from __future__ import print_function

# import Python modules for scientific computing
import os
import numpy as np

# import the CosmoBolognaLib modules
import CosmoBolognaLib as cbl

# define the cosmological model, with default parameters
cosmology = cbl.Cosmology(cbl.CosmologicalModel__Planck15_)

# Input/Output files and directories
HOME = os.getenv("HOME")
file_catalogue = (HOME +
                  "/CosmoBolognaLib/Examples/clustering/input/cat.dat", )
dir_output = HOME + "/CosmoBolognaLib/Examples/clustering/output/"
dir_triplets = dir_output + "triplets/"
dir_random_cat = dir_output
os.system("mkdir -p " + dir_output + " " + dir_triplets)

# read the input galaxy catalogue (with polar coordinates: RA, Dec, redshift)
print("I'm reading the input catalogue...")
catalogue = cbl.Catalogue(cbl.ObjectType__Galaxy_,
                          cbl.CoordinateType__observed_, file_catalogue,
                          cosmology)
コード例 #12
0
ファイル: catalogue.py プロジェクト: cbehren/CosmoBolognaLib
# ===================================================================
# Example code: how to construct a catalogue of extragalactic objects
# ===================================================================

# to ensure compatibility in Python versions 2.x and 3.x
from __future__ import print_function

# import the CosmoBolognaLib
import CosmoBolognaLib as cbl
from CosmoBolognaLib import StringVector as sv

# define a std::vector of input files (in this case with dim=1)
file_cat = "cat.dat"
file_cat_vec = sv(1, file_cat)

# create a catalogue of galaxies, retrieving their comoving coordinates from an input file
catalogue = cbl.Catalogue(cbl.ObjectType__Galaxy_,
                          cbl.CoordinateType__comoving_, file_cat_vec)
catalogue2 = cbl.Catalogue(catalogue)

# print the coordinates of the first object
print("The coordinates of the first galaxy in the catalogue are:",
      catalogue[0].xx(), catalogue[0].yy(), catalogue[0].zz())
コード例 #13
0
ファイル: fft_fftlog.py プロジェクト: SofiaContarini/CBL
import numpy as np
import matplotlib.pyplot as plt
import CosmoBolognaLib as cbl
from CosmoBolognaLib import DoubleVector as dv

# set the cosmological model, with default parameters
cosmology = cbl.Cosmology()

# compute the dark matter power spectrum
kk = np.logspace(-4, 2, 200)
Pk = [cosmology.Pk(kk[i], "CAMB", False, 0) for i in range(len(kk))]

# get correlation function from fftlog: dir is the transformation
# direction, mu is the order of the Bessel function (see the
# documentation for other options)
dir = 1
mu = 0
rr = np.linspace(1., 200, 100)
xi = np.array(cbl.transform_FFTlog(dv(rr), dir, dv(kk), dv(Pk), mu))

# plot results
plt.plot(rr, xi*rr*rr)
plt.xlabel(r"$s$ $[$Mpc$h^{-1}]$")
plt.ylabel(r"$\xi(s)\cdot s^2$ $[$Mpc$^2h^{-2}]$")
plt.plot(rr, xi*rr*rr, '-')

plt.show(block=False)
コード例 #14
0
ファイル: 3pt_model.py プロジェクト: SofiaContarini/CBL
import numpy as np
import matplotlib.pyplot as plt
import CosmoBolognaLib as cbl
from CosmoBolognaLib import DoubleVector as dv
from CosmoBolognaLib import EnumTypes as et
import os

print os.path.abspath(cbl.__file__)
''' Define cosmology '''
cosmo = cbl.Cosmology()
''' Compute Pk '''
redshift = 1
kk = np.logspace(-4, 2, 200)
Pk_DM = np.array([cosmo.Pk(_kk, "CAMB", False, redshift) for _kk in kk])
''' Parameters for 3pt signal '''
rr = dv(np.linspace(1., 300, 200))
theta = np.linspace(0, np.pi, 100)
r1, r2 = 20, 40
''' Slepian model '''
zeta_DM_s = np.array(cosmo.zeta_DM(r1, r2, theta, "Slepian", kk, Pk_DM))
q_DM_s = np.array(cosmo.Q_DM(r1, r2, theta, "Slepian", kk, Pk_DM))
''' Barriga-Gatzagnaga model '''
zeta_DM_bg = np.array(
    cosmo.zeta_DM(r1, r2, theta, "BarrigaGatzanaga", kk, Pk_DM))
q_DM_bg = np.array(cosmo.Q_DM(r1, r2, theta, "BarrigaGatzanaga", kk, Pk_DM))
'''Plotting results'''
plt.xlabel(r"$\theta/\pi$")
plt.ylabel(r"$\zeta(r1, r2, \theta)$")
plt.plot(theta / np.pi, zeta_DM_s, '-k', label=r"Slepian et al 2016")
plt.plot(theta / np.pi, zeta_DM_bg, '--r', label=r"Barriga-Gaztanaga 2002")
plt.legend(loc="best")
コード例 #15
0
# ==============================================================
# Example code: how to convert redshifts into comoving distances
# ==============================================================

# to ensure compatibility in Python versions 2.x and 3.x
from __future__ import print_function

# import the CosmoBolognaLib
import CosmoBolognaLib as cbl

# define a cosmological model, using default parameters
cosm = cbl.Cosmology(cbl.CosmologicalModel__Planck15_)

# compute the comoving distance at z=1
dc = cosm.D_C(1)
print('the comoving distance at z=1 is', '%.2f' % dc, 'Mpc/h')