Santiago Casas
commited on
Commit
·
e855f52
1
Parent(s):
bc65052
sh and py install scripts
Browse files- install_classy.sh +57 -0
- test_classy.py +43 -0
install_classy.sh
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#! /bin/bash
|
2 |
+
set -e # Exit immediately if a command exits with a non-zero status
|
3 |
+
set -u # Treat unset variables as an error
|
4 |
+
set -o pipefail # Pipeline fails on any command failure
|
5 |
+
|
6 |
+
echo "=== Starting CLASS installation process ==="
|
7 |
+
echo "Current directory: $(pwd)"
|
8 |
+
echo "Contents of directory: $(ls -la)"
|
9 |
+
|
10 |
+
# Git clone class only if the directory doesn't exist yet
|
11 |
+
if [ ! -d "class_public" ]; then
|
12 |
+
echo "=== Cloning CLASS repository ==="
|
13 |
+
git clone --depth 1 --single-branch --branch master https://github.com/lesgourg/class_public.git
|
14 |
+
else
|
15 |
+
echo "=== CLASS repository already exists, skipping clone ==="
|
16 |
+
fi
|
17 |
+
|
18 |
+
# Change to the class_public directory
|
19 |
+
echo "=== Changing to class_public directory ==="
|
20 |
+
if [ ! -d "class_public" ]; then
|
21 |
+
echo "ERROR: class_public directory not found!"
|
22 |
+
exit 1
|
23 |
+
fi
|
24 |
+
|
25 |
+
cd class_public/
|
26 |
+
echo "Now in: $(pwd)"
|
27 |
+
echo "Contents of class_public: $(ls -la)"
|
28 |
+
|
29 |
+
# Clean previous builds
|
30 |
+
echo "=== Cleaning previous build ==="
|
31 |
+
make clean || echo "Clean step failed, but continuing..."
|
32 |
+
|
33 |
+
# Install dependencies
|
34 |
+
echo "=== Installing Python dependencies ==="
|
35 |
+
echo "Installing numpy..."
|
36 |
+
pip install "numpy<=1.26" -v || { echo "Failed to install numpy"; exit 1; }
|
37 |
+
|
38 |
+
echo "Installing scipy..."
|
39 |
+
pip install "scipy" -v || { echo "Failed to install scipy"; exit 1; }
|
40 |
+
|
41 |
+
echo "Installing Cython..."
|
42 |
+
pip install "Cython" -v || { echo "Failed to install Cython"; exit 1; }
|
43 |
+
|
44 |
+
# Build CLASS
|
45 |
+
echo "=== Building CLASS library ==="
|
46 |
+
make -j || { echo "Failed to build CLASS"; exit 1; }
|
47 |
+
|
48 |
+
# Install the Python module
|
49 |
+
#echo "=== Installing CLASS Python module ==="
|
50 |
+
#pip install . -v || { echo "Failed to install CLASS Python module"; exit 1; }
|
51 |
+
|
52 |
+
# Verify installation
|
53 |
+
#echo "=== Verifying installation ==="
|
54 |
+
#python3 -c "from classy import Class; print('CLASS successfully imported!')" || { echo "Failed to import CLASS in Python"; exit 1; }
|
55 |
+
|
56 |
+
echo "=== CLASS installation completed successfully ==="
|
57 |
+
exit 0
|
test_classy.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import necessary modules
|
2 |
+
from classy import Class
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Define common settings for the ΛCDM model, including a fixed Helium fraction
|
7 |
+
common_settings = {
|
8 |
+
'h': 0.67810,
|
9 |
+
'omega_b': 0.02238280,
|
10 |
+
'omega_cdm': 0.1201075,
|
11 |
+
'A_s': 2.100549e-09,
|
12 |
+
'n_s': 0.9660499,
|
13 |
+
'tau_reio': 0.05430842,
|
14 |
+
'YHe': 0.24, # Set the Helium fraction explicitly
|
15 |
+
'output': 'tCl,lCl', # Include 'lCl' for lensing potential
|
16 |
+
'lensing': 'yes',
|
17 |
+
'l_max_scalars': 2500
|
18 |
+
}
|
19 |
+
|
20 |
+
# Initialize CLASS
|
21 |
+
cosmo = Class()
|
22 |
+
cosmo.set(common_settings)
|
23 |
+
cosmo.compute()
|
24 |
+
|
25 |
+
# Get the C_l's
|
26 |
+
cls = cosmo.lensed_cl(2500)
|
27 |
+
|
28 |
+
# Extract ell and C_ell^TT
|
29 |
+
ell = cls['ell'][2:] # Start from 2 to avoid the monopole and dipole
|
30 |
+
clTT = cls['tt'][2:]
|
31 |
+
|
32 |
+
# Plotting
|
33 |
+
factor = ell * (ell + 1) / (2 * np.pi) * 1e12 # Factor to convert to D_ell
|
34 |
+
|
35 |
+
plt.plot(ell, factor * clTT, label='Temperature $C_\ell^{TT}$', color='b')
|
36 |
+
plt.xlabel(r'Multipole moment $\ell$')
|
37 |
+
plt.ylabel(r'$\ell (\ell + 1) C_\ell^{TT} / 2\pi \, [\mu K^2]$')
|
38 |
+
plt.title('CMB Temperature Power Spectrum')
|
39 |
+
plt.xscale('log')
|
40 |
+
plt.yscale('log')
|
41 |
+
plt.grid(True)
|
42 |
+
plt.legend()
|
43 |
+
plt.savefig('cmb_temperature_spectrum.png') # Save the plot to a file
|