From 59abb2414d510ddfa41cd6a24f2ca7af98a391a6 Mon Sep 17 00:00:00 2001 From: LisaGoh Date: Wed, 8 Jul 2026 12:39:00 +0200 Subject: [PATCH 01/11] first commit --- cosmo_inference/.gitignore | 1 + cosmo_inference/README.md | 4 +- cosmo_inference/cfis_pipeline.sh | 66 - cosmo_inference/cosmocov_config/cosmocov.ini | 80 - .../cosmosis_config/cosmosis_pipeline.ini | 89 - ..._minsep=1_maxsep=250_nbins=20_npatch=1.ini | 124 -- ..._minsep=1_maxsep=250_nbins=20_npatch=1.ini | 124 -- ...sep=1.0_maxsep=250.0_nbins=20_npatch=1.ini | 124 -- ....0_maxsep=250.0_nbins=20_npatch=1_cell.ini | 113 -- .../cosmosis_pipeline_SP_v1.4.6.3_A_cell.ini | 114 -- ..._pipeline_SP_v1.4.6.3_leak_corr_A_cell.ini | 111 -- ...v1.4.6.3_leak_corr_HMCode_nobar_A_cell.ini | 114 -- ...ne_SP_v1.4.6.3_leak_corr_OneCov_A_cell.ini | 114 -- ...e_SP_v1.4.6.3_leak_corr_halofit_A_cell.ini | 114 -- ..._leak_corr_include_large_scales_A_cell.ini | 114 -- ...SP_v1.4.6.3_leak_corr_kmax=1Mpc_A_cell.ini | 114 -- ...SP_v1.4.6.3_leak_corr_kmax=3Mpc_A_cell.ini | 114 -- ...SP_v1.4.6.3_leak_corr_kmax=5Mpc_A_cell.ini | 114 -- ...v1.4.6.3_leak_corr_large_scales_A_cell.ini | 114 -- ...v1.4.6.3_leak_corr_small_scales_A_cell.ini | 114 -- .../cosmosis_pipeline_SP_v1.4.6.3_B_cell.ini | 111 -- ..._pipeline_SP_v1.4.6.3_leak_corr_B_cell.ini | 111 -- ...v1.4.6.3_leak_corr_HMCode_nobar_B_cell.ini | 111 -- ...ne_SP_v1.4.6.3_leak_corr_OneCov_B_cell.ini | 111 -- ...e_SP_v1.4.6.3_leak_corr_halofit_B_cell.ini | 111 -- ..._leak_corr_include_large_scales_B_cell.ini | 111 -- ...SP_v1.4.6.3_leak_corr_kmax=1Mpc_B_cell.ini | 111 -- ...SP_v1.4.6.3_leak_corr_kmax=3Mpc_B_cell.ini | 111 -- ...SP_v1.4.6.3_leak_corr_kmax=5Mpc_B_cell.ini | 111 -- ...v1.4.6.3_leak_corr_large_scales_B_cell.ini | 111 -- ...v1.4.6.3_leak_corr_small_scales_B_cell.ini | 111 -- .../cosmosis_pipeline_SP_v1.4.6.3_C_cell.ini | 114 -- ..._pipeline_SP_v1.4.6.3_leak_corr_C_cell.ini | 111 -- ...v1.4.6.3_leak_corr_HMCode_nobar_C_cell.ini | 114 -- ...ne_SP_v1.4.6.3_leak_corr_OneCov_C_cell.ini | 114 -- ...e_SP_v1.4.6.3_leak_corr_halofit_C_cell.ini | 114 -- ..._leak_corr_include_large_scales_C_cell.ini | 114 -- ...SP_v1.4.6.3_leak_corr_kmax=1Mpc_C_cell.ini | 114 -- ...SP_v1.4.6.3_leak_corr_kmax=3Mpc_C_cell.ini | 114 -- ...SP_v1.4.6.3_leak_corr_kmax=5Mpc_C_cell.ini | 114 -- ...v1.4.6.3_leak_corr_large_scales_C_cell.ini | 114 -- ...v1.4.6.3_leak_corr_small_scales_C_cell.ini | 114 -- .../priors_mock_cell_no_sys.ini | 5 - .../cosmosis_pipeline_A_ia.ini | 0 .../cosmosis_pipeline_A_ia_cell.ini | 0 .../cosmosis_pipeline_A_psf.ini | 0 .../{ => templates}/priors.ini | 0 .../{ => templates}/priors_mock.ini | 0 .../{ => templates}/priors_mock_cell.ini | 0 .../{ => templates}/priors_psf.ini | 0 .../{ => templates}/values_ia.ini | 0 .../{ => templates}/values_psf.ini | 0 cosmo_inference/cosmosis_config/values.ini | 27 - .../cosmosis_config/values_empty.ini | 27 - .../cosmosis_config/values_ia_no_sys.ini | 26 - .../cosmosis_config/values_ia_test.ini | 27 - .../cosmosis_config/values_template.ini | 23 - cosmo_inference/get_chi2.ipynb | 1391 --------------- cosmo_inference/get_chi2_cell.ipynb | 1527 ---------------- .../S8_om_sigma8_whisker.ipynb | 645 ------- .../best_fit_xipm.ipynb | 607 ------- .../contours.ipynb | 950 ---------- .../get_chi2.ipynb | 690 -------- .../get_chi2_glass_mock.ipynb | 565 ------ .../get_prior_psf_leakage.ipynb | 261 --- .../glass_mock_hist.ipynb | 586 ------- .../masking.ipynb | 132 -- .../nonlin_k_analysis.ipynb | 174 -- .../2D_cosmic_shear_unblinding/utils.py | 442 ----- cosmo_inference/notebooks/cfis_analysis.ipynb | 1065 ------------ cosmo_inference/notebooks/cfis_mcmc.ipynb | 1546 ----------------- .../notebooks/get_prior_psf_leakage.ipynb | 269 --- cosmo_inference/pipeline.sh | 131 -- cosmo_inference/scripts/2pt_like_xi_sys.py | 614 ------- .../scripts/chain_postprocessing.py | 799 --------- cosmo_inference/scripts/cosmocov_process.py | 81 - cosmo_inference/scripts/cosmosis_fitting.py | 8 +- cosmo_inference/scripts/masking.py | 319 ---- cosmo_inference/scripts/matching.py | 40 - cosmo_inference/scripts/nz_writeout.py | 26 - cosmo_inference/scripts/slurm.sh | 22 - cosmo_inference/scripts/treecorr_calc.py | 107 -- cosmo_inference/scripts/xi_sys_psf.py | 53 - papers/realspace/S8_om_sigma8_whisker.py | 559 ++++++ papers/realspace/best_fit_xipm.py | 513 ++++++ papers/realspace/contours.py | 761 ++++++++ papers/realspace/cov_masking.py | 84 + papers/realspace/get_chi2.py | 574 ++++++ papers/realspace/get_chi2_glass_mock.py | 480 +++++ papers/realspace/get_prior_psf_leakage.py | 176 ++ papers/realspace/glass_mock_hist.py | 481 +++++ papers/realspace/nonlin_k_analysis.py | 114 ++ .../realspace}/unblinding_party_plots.py | 0 workflow/rules/inference.smk | 4 +- workflow/scripts/generate_cosmocov_ini.py | 149 -- workflow/scripts/run_cosmocov_chain.sh | 90 - 96 files changed, 3751 insertions(+), 17867 deletions(-) delete mode 100644 cosmo_inference/cfis_pipeline.sh delete mode 100644 cosmo_inference/cosmocov_config/cosmocov.ini delete mode 100644 cosmo_inference/cosmosis_config/cosmosis_pipeline.ini delete mode 100644 cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.5_A_minsep=1_maxsep=250_nbins=20_npatch=1.ini delete mode 100644 cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1.ini delete mode 100644 cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1.ini delete mode 100644 cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_A_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_A_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_A_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_A_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_A_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_A_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_A_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_A_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_A_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_A_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_A_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_B_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_B_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_B_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_B_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_B_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_B_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_B_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_B_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_B_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_B_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_B_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_C_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_C_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_C_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_C_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_C_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_C_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_C_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_C_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_C_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_C_cell.ini delete mode 100755 cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_C_cell.ini delete mode 100644 cosmo_inference/cosmosis_config/priors_mock_cell_no_sys.ini rename cosmo_inference/cosmosis_config/{ => templates}/cosmosis_pipeline_A_ia.ini (100%) rename cosmo_inference/cosmosis_config/{ => templates}/cosmosis_pipeline_A_ia_cell.ini (100%) rename cosmo_inference/cosmosis_config/{ => templates}/cosmosis_pipeline_A_psf.ini (100%) rename cosmo_inference/cosmosis_config/{ => templates}/priors.ini (100%) rename cosmo_inference/cosmosis_config/{ => templates}/priors_mock.ini (100%) rename cosmo_inference/cosmosis_config/{ => templates}/priors_mock_cell.ini (100%) rename cosmo_inference/cosmosis_config/{ => templates}/priors_psf.ini (100%) rename cosmo_inference/cosmosis_config/{ => templates}/values_ia.ini (100%) rename cosmo_inference/cosmosis_config/{ => templates}/values_psf.ini (100%) delete mode 100644 cosmo_inference/cosmosis_config/values.ini delete mode 100644 cosmo_inference/cosmosis_config/values_empty.ini delete mode 100644 cosmo_inference/cosmosis_config/values_ia_no_sys.ini delete mode 100644 cosmo_inference/cosmosis_config/values_ia_test.ini delete mode 100644 cosmo_inference/cosmosis_config/values_template.ini delete mode 100644 cosmo_inference/get_chi2.ipynb delete mode 100644 cosmo_inference/get_chi2_cell.ipynb delete mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/S8_om_sigma8_whisker.ipynb delete mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/best_fit_xipm.ipynb delete mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/contours.ipynb delete mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_chi2.ipynb delete mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_chi2_glass_mock.ipynb delete mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_prior_psf_leakage.ipynb delete mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/glass_mock_hist.ipynb delete mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/masking.ipynb delete mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/nonlin_k_analysis.ipynb delete mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_unblinding/utils.py delete mode 100644 cosmo_inference/notebooks/cfis_analysis.ipynb delete mode 100644 cosmo_inference/notebooks/cfis_mcmc.ipynb delete mode 100644 cosmo_inference/notebooks/get_prior_psf_leakage.ipynb delete mode 100755 cosmo_inference/pipeline.sh delete mode 100644 cosmo_inference/scripts/2pt_like_xi_sys.py delete mode 100644 cosmo_inference/scripts/chain_postprocessing.py delete mode 100644 cosmo_inference/scripts/cosmocov_process.py delete mode 100644 cosmo_inference/scripts/masking.py delete mode 100644 cosmo_inference/scripts/matching.py delete mode 100644 cosmo_inference/scripts/nz_writeout.py delete mode 100644 cosmo_inference/scripts/slurm.sh delete mode 100644 cosmo_inference/scripts/treecorr_calc.py delete mode 100644 cosmo_inference/scripts/xi_sys_psf.py create mode 100644 papers/realspace/S8_om_sigma8_whisker.py create mode 100644 papers/realspace/best_fit_xipm.py create mode 100644 papers/realspace/contours.py create mode 100644 papers/realspace/cov_masking.py create mode 100644 papers/realspace/get_chi2.py create mode 100644 papers/realspace/get_chi2_glass_mock.py create mode 100644 papers/realspace/get_prior_psf_leakage.py create mode 100644 papers/realspace/glass_mock_hist.py create mode 100644 papers/realspace/nonlin_k_analysis.py rename {cosmo_inference/notebooks/2D_cosmic_shear_unblinding => papers/realspace}/unblinding_party_plots.py (100%) delete mode 100644 workflow/scripts/generate_cosmocov_ini.py delete mode 100644 workflow/scripts/run_cosmocov_chain.sh diff --git a/cosmo_inference/.gitignore b/cosmo_inference/.gitignore index 0b53f63e..cb5922b7 100644 --- a/cosmo_inference/.gitignore +++ b/cosmo_inference/.gitignore @@ -1,6 +1,7 @@ plots/ .ipynb_checkpoints/ data/ +cosmosis_config/output/* *.png *.pdf *.sh \ No newline at end of file diff --git a/cosmo_inference/README.md b/cosmo_inference/README.md index 6da1b94c..5d753010 100644 --- a/cosmo_inference/README.md +++ b/cosmo_inference/README.md @@ -4,7 +4,7 @@ by Lisa Goh and Sacha Guerrini, CEA Paris-Saclay This folder contains the files neccessary to run the cosmological inference pipeline on the UNIONS galaxy catalogues. ### Requirements -To run the pipeline, one would need to have installed [CosmoSIS](https://cosmosis.readthedocs.io/en/latest/) and [CosmoCov](https://github.com/CosmoLike/CosmoCov). To PSF leakage parameters, the fork of [cosmosis-standard-library](https://github.com/sachaguer/cosmosis-standard-library/) of Sacha Guerrini has to be used. +To run the pipeline, one would need to have installed [CosmoSIS](https://cosmosis.readthedocs.io/en/latest/). To sample the PSF leakage parameters, the fork of [cosmosis-standard-library](https://github.com/sachaguer/cosmosis-standard-library/) of Sacha Guerrini has to be used. ### To Run The inference pipeline is now orchestrated through Python. Run the main Snakemake workflow from the parent directory: @@ -15,7 +15,7 @@ snakemake -j inference_fiducial This will automatically execute all steps: 1. Calculate 2PCF ($\xi_{pm}$) via `cosmo_val.py` -2. Compute covariance matrices using CosmoCov +2. Compute covariance matrices using CosmoCov 3. Prepare CosmoSIS data (FITS) via `cosmosis_fitting.py` 4. Run CosmoSIS inference diff --git a/cosmo_inference/cfis_pipeline.sh b/cosmo_inference/cfis_pipeline.sh deleted file mode 100644 index dadab6fb..00000000 --- a/cosmo_inference/cfis_pipeline.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash -read -p 'SHEAR CATALOGUE: ' shear_cat -# read -p 'NZ CATALOGUE: ' nz_cat -read -p 'DATA ROOT: ' root -read -p 'OUT ROOT: ' out_root -# read -p 'BLIND:' blind -mkdir -p data/${root} - -# #################STEP 0: RUN NOTEBOOK TO ANALYSE CATALOGUE; DERIVE PLOTS################## -# #File: cfis_analysis.ipynb - -# ##################STEP 1: CALCULATE XIP/XIM (OUTPUTS TREECORR FITS CATALOG)############### -python treecorr_calc.py $shear_cat $root - -echo -e "2PCF's calculated!\n" - -# # ##################STEP 2: WRITE NZ's###################################################### -# python nz_writeout.py $nz_cat $root $blind - -# echo -e "nz's written out!\n" - -# # # # ##################STEP 3: ESTIMATE COVMATS################################################ - -# # #edit ini file -# mkdir -p data/${root}/covs - -# nz_file="data/${root}/nz_shapepipe_A.txt" - -# # sed -i "/shear_REDSHIFT_FILE/c shear_REDSHIFT_FILE : $nz_file" cosmocov.ini -# # sed -i "/clustering_REDSHIFT_FILE/c clustering_REDSHIFT_FILE : $nz_file" cosmocov.ini -# # sed -i "/outdir/c outdir : data/$root/covs/" cosmocov.ini - -# echo -e "Running CosmoCov...\n" - -# ##run cosmocov -# for i in {1..3}; -# do ../CosmoCov/covs/cov $i cosmocov.ini; -# done - -# # do postprocessing (plot covmat and write into txt file) -# f="data/${root}/covs/cov_${root}"; cat data/${root}/covs/out_cov* > $f; python cosmocov_process.py $f - -# # # # # ##################STEP 4: COMBINE########################################################## -# xip_cat="data/${root}/xiplus_${root}.fits" -# xim_cat="data/${root}/ximinus_${root}.fits" -# covmat="data/${root}/covs/cov_${root}.txt" - -# out_file="$PWD/data/${root}/cosmosis_${root}.fits" - -python cosmosis_fitting.py /n23data1/n06data/lgoh/scratch/CFIS-UNIONS/CFIS-UNIONS_dev/cosmo_inference/data/SP_v1.4_A/xiplus_SP_v1.4_A.fits /n23data1/n06data/lgoh/scratch/CFIS-UNIONS/CFIS-UNIONS_dev/cosmo_inference/data/SP_v1.4_A/ximinus_SP_v1.4_A.fits /n23data1/n06data/lgoh/scratch/CFIS-UNIONS/CFIS-UNIONS_dev/cosmo_inference/data/SP_v1.4_A/covs/cov_SP_v1.4.txt /n23data1/n06data/lgoh/scratch/CFIS-UNIONS/CFIS-UNIONS_dev/cosmo_inference/data/nz/nz_shapepipe_A.txt /n23data1/n06data/lgoh/scratch/CFIS-UNIONS/CFIS-UNIONS_dev/cosmo_inference/data/SP_v1.4_A/cosmosis_SP_v1.4_A.fits - -# # # # ##################STEP 5: RUN COSMOSIS##################################################### -# echo -e "Running CosmoSIS...\n" - -# sed -i "/SCRATCH = /c SCRATCH = $WORK/UNIONS/chains/${out_root}/" cosmosis_config/cosmosis_pipeline.ini -# sed -i "/FITS_FILE = /c FITS_FILE = ${out_file}" cosmosis_config/cosmosis_pipeline.ini -# sed -i "/filename = /c filename = %(SCRATCH)s/samples_${out_root}.txt" cosmosis_config/cosmosis_pipeline.ini - -# #submit cosmosis job to run on cluster - -# sbatch -J cfis_${root} --output=$WORK/UNIONS/cfis_${out_root}.log slurm.sh - -# echo -e "-------------PIPELINE END----------------" - -# # ##################STEP 6: RUN NOTEBOOK TO ANALYSE CONTOURS (WITH GETDIST)################## -# #File: CFIS_plotting.ipynb \ No newline at end of file diff --git a/cosmo_inference/cosmocov_config/cosmocov.ini b/cosmo_inference/cosmocov_config/cosmocov.ini deleted file mode 100644 index 0afbdc64..00000000 --- a/cosmo_inference/cosmocov_config/cosmocov.ini +++ /dev/null @@ -1,80 +0,0 @@ -# -# Cosmological parameters -# -Omega_m : 0.25 -Omega_v : 0.75 -sigma_8 : 0.8 -n_spec : 0.95 -w0 : -1 -wa : 0 -omb : 0.044 -h0 : 0.7 - - -# Survey and galaxy parameters -# -# area in degrees -# n_gal,lens_n_gal in gals/arcmin^2 - -#FOR LENSFIT -#area : 2138 -#sourcephotoz : multihisto -#lensphotoz : multihisto -#source_tomobins : 1 -#lens_tomobins : 1 -#sigma_e : 0.41016433003564806 -#source_n_gal : 10.78 - -#FOR SHAPEPIPE -; area : 3218.19 -; sourcephotoz : multihisto -; lensphotoz : multihisto -; source_tomobins : 1 -; lens_tomobins : 1 -; sigma_e : 0.491712 -; source_n_gal : 8.42 - -#FOR SHAPEPIPE 1500 -; area : 1453 -; sourcephotoz : multihisto -; lensphotoz : multihisto -; source_tomobins : 1 -; lens_tomobins : 1 -; sigma_e : 0.4808326112068524 -; source_n_gal : 7.92 - -#FOR SHAPEPIPE v1.3/v1.4 -area : 2782 -sourcephotoz : multihisto -lensphotoz : multihisto -source_tomobins : 1 -lens_tomobins : 1 -sigma_e : 0.4370966656902571 -; source_n_gal: 7.6 #v1.3 -source_n_gal : 7.18 # v1.4.1 -lens_n_gal : 7.18 - -c_footprint_file: - - -# IA parameters -IA : 1 -A_ia : 0.0 -eta_ia : 0.0 - - -# Covariance paramters -# -# tmin,tmax in arcminutes -tmin : 0.1 -tmax : 250 -ntheta : 20 -ng : 1 -cng : 1 - - -#mkdir before running! -filename : out_cov -ss : true -ls : false -ll : false \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/cosmosis_pipeline.ini b/cosmo_inference/cosmosis_config/cosmosis_pipeline.ini deleted file mode 100644 index f6b11411..00000000 --- a/cosmo_inference/cosmosis_config/cosmosis_pipeline.ini +++ /dev/null @@ -1,89 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -# Specify the directory of your cosmological CosmoSIS library -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -modules = consistency camb load_nz_fits linear_alignment projection 2pt_shear add_xi_sys 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 -timing = T -debug = T - -[runtime] -sampler = metropolis -resume = T -verbosity = debug - -[output] -format = text -lock = F - -[metropolis] -samples = 10000000 - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=all -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=takahashi -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -get_kernel_peaks = F -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[add_xi_sys] -file = %(COSMOSIS_DIR)s/shear/xi_sys/xi_sys_psf.py -data_file=%(FITS FILE)s -rho_stats_name=RHO_STATS - -[tau_from_rho] -file = %(COSMOSIS_DIR)s/shear/xi_sys/tau_from_rho.py -data_file=%(FITS_FILE)s - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like_xi_sys.py -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -data_sets=XI_PLUS XI_MINUS TAU_0_PLUS TAU_2_PLUS -like_name=2pt_like -add_xi_sys=T - -angle_range_XI_PLUS_1_1= 1.0 200.0 -angle_range_XI_MINUS_1_1= 1.0 200.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.5_A_minsep=1_maxsep=250_nbins=20_npatch=1.ini b/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.5_A_minsep=1_maxsep=250_nbins=20_npatch=1.ini deleted file mode 100644 index efcf75f7..00000000 --- a/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.5_A_minsep=1_maxsep=250_nbins=20_npatch=1.ini +++ /dev/null @@ -1,124 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -FITS_FILE = data/SP_v1.4.5_A_minsep=1_maxsep=250_nbins=20_npatch=1/cosmosis_SP_v1.4.5_A_minsep=1_maxsep=250_nbins=20_npatch=1.fits -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.5_A_minsep=1_maxsep=250_nbins=20_npatch=1 -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -priors = cosmosis_config/priors_psf.ini -values = cosmosis_config/values_psf.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic 2pt_shear add_xi_sys tau_from_rho 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/test_new_pipeline - -[polychord] -polychord_outfile_root = SP_v1.4.5_A_minsep=1_maxsep=250_nbins=20_npatch=1 -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.5_A_minsep=1_maxsep=250_nbins=20_npatch=1/samples_SP_v1.4.5_A_minsep=1_maxsep=250_nbins=20_npatch=1.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_xi_plus shear_xi_minus -verbose = F - -[add_xi_sys] -file = %(COSMOSIS_DIR)s/shear/xi_sys/xi_sys_psf.py -data_file=%(FITS_FILE)s -rho_stats_name=RHO_STATS - -[tau_from_rho] -file = %(COSMOSIS_DIR)s/shear/xi_sys/tau_from_rho.py -data_file=%(FITS_FILE)s - -[2pt_like] -add_xi_sys=T -data_sets=XI_PLUS XI_MINUS TAU_0_PLUS TAU_2_PLUS -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like_xi_sys.py -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_XI_PLUS_1_1= 3.0 150.0 -angle_range_XI_MINUS_1_1= 10.0 200.0 diff --git a/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1.ini b/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1.ini deleted file mode 100644 index 0af5b180..00000000 --- a/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1.ini +++ /dev/null @@ -1,124 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -FITS_FILE = data/SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1/cosmosis_SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1.fits -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1 -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -priors = cosmosis_config/priors_psf.ini -values = cosmosis_config/values_psf.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic 2pt_shear add_xi_sys tau_from_rho 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/test_new_pipeline - -[polychord] -polychord_outfile_root = SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1 -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1/samples_SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_xi_plus shear_xi_minus -verbose = F - -[add_xi_sys] -file = %(COSMOSIS_DIR)s/shear/xi_sys/xi_sys_psf.py -data_file=%(FITS_FILE)s -rho_stats_name=RHO_STATS - -[tau_from_rho] -file = %(COSMOSIS_DIR)s/shear/xi_sys/tau_from_rho.py -data_file=%(FITS_FILE)s - -[2pt_like] -add_xi_sys=T -data_sets=XI_PLUS XI_MINUS TAU_0_PLUS TAU_2_PLUS -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like_xi_sys.py -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_XI_PLUS_1_1= 3.0 150.0 -angle_range_XI_MINUS_1_1= 10.0 200.0 diff --git a/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1.ini b/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1.ini deleted file mode 100644 index d64ac64f..00000000 --- a/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1.ini +++ /dev/null @@ -1,124 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1 -FITS_FILE = data/SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1/cosmosis_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_psf.ini -priors = cosmosis_config/priors_psf.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic 2pt_shear shear_m_bias add_xi_sys tau_from_rho 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1 - -[polychord] -polychord_outfile_root = SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1 -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1/samples_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_xi_plus shear_xi_minus -verbose = F - -[add_xi_sys] -file = %(COSMOSIS_DIR)s/shear/xi_sys/xi_sys_psf.py -data_file=%(FITS_FILE)s -rho_stats_name=RHO_STATS - -[tau_from_rho] -file = %(COSMOSIS_DIR)s/shear/xi_sys/tau_from_rho.py -data_file=%(FITS_FILE)s - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like_xi_sys.py -data_sets=XI_PLUS XI_MINUS TAU_0_PLUS TAU_2_PLUS -add_xi_sys=T -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_XI_PLUS_1_1= 3.0 150.0 -angle_range_XI_MINUS_1_1= 10.0 200.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1_cell.ini b/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1_cell.ini deleted file mode 100644 index 34a7209f..00000000 --- a/cosmo_inference/cosmosis_config/cosmosis_pipeline_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1_cell.ini +++ /dev/null @@ -1,113 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1 -FITS_FILE = data/SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1/cosmosis_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_psf.ini -priors = cosmosis_config/priors_psf.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1_cell - - -[polychord] -polychord_outfile_root = SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1/samples_SP_v1.4.6_A_minsep=1.0_maxsep=250.0_nbins=20_npatch=1_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT_CELL -cut_zeros=F -like_name=2pt_like \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_A_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_A_cell.ini deleted file mode 100755 index 70404b87..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_A_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_A -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_A/cosmosis_SP_v1.4.6.3_A.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_A_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_A/samples_SP_v1.4.6.3_A_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_A_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_A_cell.ini deleted file mode 100755 index dad17f3d..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_A_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_A -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_A/cosmosis_SP_v1.4.6.3_leak_corr_A.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_A_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_A/samples_SP_v1.4.6.3_leak_corr_A_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020_feedback -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_A_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_A_cell.ini deleted file mode 100755 index e8c48898..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_A_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_HMCode_nobar_A -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_HMCode_nobar_A/cosmosis_SP_v1.4.6.3_leak_corr_HMCode_nobar_A.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_HMCode_nobar_A_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_HMCode_nobar_A/samples_SP_v1.4.6.3_leak_corr_HMCode_nobar_A_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020 -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_A_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_A_cell.ini deleted file mode 100755 index e686f245..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_A_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_OneCov_A -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_OneCov_A/cosmosis_SP_v1.4.6.3_leak_corr_OneCov_A.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_OneCov_A_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_OneCov_A/samples_SP_v1.4.6.3_leak_corr_OneCov_A_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_A_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_A_cell.ini deleted file mode 100755 index dd46e3e7..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_A_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_halofit_A -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_halofit_A/cosmosis_SP_v1.4.6.3_leak_corr_halofit_A.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_halofit_A_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_halofit_A/samples_SP_v1.4.6.3_leak_corr_halofit_A_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=takahashi -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_A_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_A_cell.ini deleted file mode 100755 index 507b2f9a..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_A_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_include_large_scales_A -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_include_large_scales_A/cosmosis_SP_v1.4.6.3_leak_corr_include_large_scales_A.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_include_large_scales_A_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_include_large_scales_A/samples_SP_v1.4.6.3_leak_corr_include_large_scales_A_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 0.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_A_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_A_cell.ini deleted file mode 100755 index 028e875c..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_A_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_kmax=1Mpc_A -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_kmax=1Mpc_A/cosmosis_SP_v1.4.6.3_leak_corr_kmax=1Mpc_A.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_kmax=1Mpc_A_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_kmax=1Mpc_A/samples_SP_v1.4.6.3_leak_corr_kmax=1Mpc_A_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 500.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_A_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_A_cell.ini deleted file mode 100755 index 32c45ad5..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_A_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_kmax=3Mpc_A -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_kmax=3Mpc_A/cosmosis_SP_v1.4.6.3_leak_corr_kmax=3Mpc_A.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_kmax=3Mpc_A_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_kmax=3Mpc_A/samples_SP_v1.4.6.3_leak_corr_kmax=3Mpc_A_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 1800.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_A_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_A_cell.ini deleted file mode 100755 index 92d61b20..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_A_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_kmax=5Mpc_A -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_kmax=5Mpc_A/cosmosis_SP_v1.4.6.3_leak_corr_kmax=5Mpc_A.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_kmax=5Mpc_A_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_kmax=5Mpc_A/samples_SP_v1.4.6.3_leak_corr_kmax=5Mpc_A_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 2048.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_A_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_A_cell.ini deleted file mode 100755 index aa3784c2..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_A_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_large_scales_A -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_large_scales_A/cosmosis_SP_v1.4.6.3_leak_corr_large_scales_A.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_large_scales_A_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_large_scales_A/samples_SP_v1.4.6.3_leak_corr_large_scales_A_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 800.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_A_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_A_cell.ini deleted file mode 100755 index 1aa71c5f..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_A/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_A_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_small_scales_A -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_small_scales_A/cosmosis_SP_v1.4.6.3_leak_corr_small_scales_A.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_small_scales_A_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_small_scales_A/samples_SP_v1.4.6.3_leak_corr_small_scales_A_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 800.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_B_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_B_cell.ini deleted file mode 100755 index db67430b..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_B_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_B -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_B/cosmosis_SP_v1.4.6.3_B.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_B_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_B/samples_SP_v1.4.6.3_B_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020_feedback -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_B_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_B_cell.ini deleted file mode 100755 index d1b15a8f..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_B_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_B -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_B/cosmosis_SP_v1.4.6.3_leak_corr_B.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_B_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_B/samples_SP_v1.4.6.3_leak_corr_B_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020_feedback -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_B_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_B_cell.ini deleted file mode 100755 index ccc62f9f..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_B_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_HMCode_nobar_B -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_HMCode_nobar_B/cosmosis_SP_v1.4.6.3_leak_corr_HMCode_nobar_B.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_HMCode_nobar_B_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_HMCode_nobar_B/samples_SP_v1.4.6.3_leak_corr_HMCode_nobar_B_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020 -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_B_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_B_cell.ini deleted file mode 100755 index 20b637ea..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_B_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_OneCov_B -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_OneCov_B/cosmosis_SP_v1.4.6.3_leak_corr_OneCov_B.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_OneCov_B_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_OneCov_B/samples_SP_v1.4.6.3_leak_corr_OneCov_B_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020_feedback -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_B_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_B_cell.ini deleted file mode 100755 index c3d99809..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_B_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_halofit_B -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_halofit_B/cosmosis_SP_v1.4.6.3_leak_corr_halofit_B.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_halofit_B_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_halofit_B/samples_SP_v1.4.6.3_leak_corr_halofit_B_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = takahashi -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_B_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_B_cell.ini deleted file mode 100755 index d724c837..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_B_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_include_large_scales_B -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_include_large_scales_B/cosmosis_SP_v1.4.6.3_leak_corr_include_large_scales_B.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_include_large_scales_B_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_include_large_scales_B/samples_SP_v1.4.6.3_leak_corr_include_large_scales_B_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020_feedback -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 0.0 1600.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_B_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_B_cell.ini deleted file mode 100755 index 5991d198..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_B_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_kmax=1Mpc_B -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_kmax=1Mpc_B/cosmosis_SP_v1.4.6.3_leak_corr_kmax=1Mpc_B.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_kmax=1Mpc_B_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_kmax=1Mpc_B/samples_SP_v1.4.6.3_leak_corr_kmax=1Mpc_B_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020_feedback -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 300.0 500.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_B_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_B_cell.ini deleted file mode 100755 index fb347172..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_B_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_kmax=3Mpc_B -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_kmax=3Mpc_B/cosmosis_SP_v1.4.6.3_leak_corr_kmax=3Mpc_B.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_kmax=3Mpc_B_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_kmax=3Mpc_B/samples_SP_v1.4.6.3_leak_corr_kmax=3Mpc_B_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020_feedback -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 300.0 1800.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_B_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_B_cell.ini deleted file mode 100755 index 4005c10b..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_B_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_kmax=5Mpc_B -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_kmax=5Mpc_B/cosmosis_SP_v1.4.6.3_leak_corr_kmax=5Mpc_B.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_kmax=5Mpc_B_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_kmax=5Mpc_B/samples_SP_v1.4.6.3_leak_corr_kmax=5Mpc_B_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020_feedback -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 300.0 2048.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_B_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_B_cell.ini deleted file mode 100755 index 95009a6a..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_B_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_large_scales_B -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_large_scales_B/cosmosis_SP_v1.4.6.3_leak_corr_large_scales_B.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_large_scales_B_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_large_scales_B/samples_SP_v1.4.6.3_leak_corr_large_scales_B_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020_feedback -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 300.0 800.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_B_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_B_cell.ini deleted file mode 100755 index fd6d8990..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_B/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_B_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_small_scales_B -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_small_scales_B/cosmosis_SP_v1.4.6.3_leak_corr_small_scales_B.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_small_scales_B_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_small_scales_B/samples_SP_v1.4.6.3_leak_corr_small_scales_B_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020_feedback -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 800.0 1600.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_C_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_C_cell.ini deleted file mode 100755 index 584a5fbb..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_C_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_C -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_C/cosmosis_SP_v1.4.6.3_C.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_C_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_C/samples_SP_v1.4.6.3_C_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_C_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_C_cell.ini deleted file mode 100755 index 341a4b7f..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_C_cell.ini +++ /dev/null @@ -1,111 +0,0 @@ -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_C -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_C/cosmosis_SP_v1.4.6.3_leak_corr_C.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_C_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_C/samples_SP_v1.4.6.3_leak_corr_C_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode = power -lmax = 2508 -feedback = 0 -do_reionization = F -kmin = 1e-5 -kmax = 20.0 -nk = 200 -zmax = 5.0 -zmax_background = 5.0 -nz_background = 500 -halofit_version = mead2020_feedback -nonlinear = pk -neutrino_hierarchy = normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file = %(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear = T -position-shear = F -perbin = F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets = CELL_EE -data_file = %(FITS_FILE)s -gaussian_covariance = F -covmat_name = COVMAT -cut_zeros = F -like_name = 2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 - diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_C_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_C_cell.ini deleted file mode 100755 index e2b478dd..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_HMCode_nobar_C_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_HMCode_nobar_C -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_HMCode_nobar_C/cosmosis_SP_v1.4.6.3_leak_corr_HMCode_nobar_C.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_HMCode_nobar_C_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_HMCode_nobar_C/samples_SP_v1.4.6.3_leak_corr_HMCode_nobar_C_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020 -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_C_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_C_cell.ini deleted file mode 100755 index 66e4a192..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_OneCov_C_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_OneCov_C -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_OneCov_C/cosmosis_SP_v1.4.6.3_leak_corr_OneCov_C.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_OneCov_C_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_OneCov_C/samples_SP_v1.4.6.3_leak_corr_OneCov_C_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_C_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_C_cell.ini deleted file mode 100755 index 0be94bbd..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_halofit_C_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_halofit_C -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_halofit_C/cosmosis_SP_v1.4.6.3_leak_corr_halofit_C.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_halofit_C_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_halofit_C/samples_SP_v1.4.6.3_leak_corr_halofit_C_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=takahashi -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_C_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_C_cell.ini deleted file mode 100755 index 718ce25d..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_include_large_scales_C_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_include_large_scales_C -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_include_large_scales_C/cosmosis_SP_v1.4.6.3_leak_corr_include_large_scales_C.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_include_large_scales_C_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_include_large_scales_C/samples_SP_v1.4.6.3_leak_corr_include_large_scales_C_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 0.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_C_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_C_cell.ini deleted file mode 100755 index 69f977d0..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=1Mpc_C_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_kmax=1Mpc_C -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_kmax=1Mpc_C/cosmosis_SP_v1.4.6.3_leak_corr_kmax=1Mpc_C.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_kmax=1Mpc_C_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_kmax=1Mpc_C/samples_SP_v1.4.6.3_leak_corr_kmax=1Mpc_C_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 500.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_C_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_C_cell.ini deleted file mode 100755 index 3ef25704..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=3Mpc_C_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_kmax=3Mpc_C -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_kmax=3Mpc_C/cosmosis_SP_v1.4.6.3_leak_corr_kmax=3Mpc_C.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_kmax=3Mpc_C_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_kmax=3Mpc_C/samples_SP_v1.4.6.3_leak_corr_kmax=3Mpc_C_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 1800.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_C_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_C_cell.ini deleted file mode 100755 index 0b82ecbf..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_kmax=5Mpc_C_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_kmax=5Mpc_C -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_kmax=5Mpc_C/cosmosis_SP_v1.4.6.3_leak_corr_kmax=5Mpc_C.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_kmax=5Mpc_C_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_kmax=5Mpc_C/samples_SP_v1.4.6.3_leak_corr_kmax=5Mpc_C_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 2048.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_C_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_C_cell.ini deleted file mode 100755 index 3382193d..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_large_scales_C_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_large_scales_C -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_large_scales_C/cosmosis_SP_v1.4.6.3_leak_corr_large_scales_C.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_large_scales_C_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_large_scales_C/samples_SP_v1.4.6.3_leak_corr_large_scales_C_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 300.0 800.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_C_cell.ini b/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_C_cell.ini deleted file mode 100755 index 4bc8fe6d..00000000 --- a/cosmo_inference/cosmosis_config/harmonic_space_fiducial_C/cosmosis_pipeline_SP_v1.4.6.3_leak_corr_small_scales_C_cell.ini +++ /dev/null @@ -1,114 +0,0 @@ -#parameters used elsewhere in this file -[DEFAULT] -SCRATCH = /n09data/guerrini/output_chains/SP_v1.4.6.3_leak_corr_small_scales_C -FITS_FILE = /n17data/sguerrini/sp_validation/cosmo_inference/data/SP_v1.4.6.3_leak_corr_small_scales_C/cosmosis_SP_v1.4.6.3_leak_corr_small_scales_C.fits -COSMOSIS_DIR = /home/guerrini/cosmosis-standard-library - - -[pipeline] -values = cosmosis_config/values_ia.ini -priors = cosmosis_config/priors.ini -modules = consistency sample_S8 camb load_nz_fits photoz_bias linear_alignment projection add_intrinsic shear_m_bias 2pt_like -likelihoods = 2pt_like -extra_output = cosmological_parameters/omega_lambda cosmological_parameters/S_8 cosmological_parameters/sigma_8 cosmological_parameters/omega_m -timing = T -debug = T - -[runtime] -sampler = polychord -verbosity = debug - -[test] -save_dir = %(SCRATCH)s/best_fit/ - - -[polychord] -polychord_outfile_root = SP_v1.4.6.3_leak_corr_small_scales_C_cell -live_points = 192 -feedback = 3 -resume = T -base_dir = %(SCRATCH)s/polychord - -[output] -filename = %(SCRATCH)s/SP_v1.4.6.3_leak_corr_small_scales_C/samples_SP_v1.4.6.3_leak_corr_small_scales_C_cell.txt -format = text -lock = F - -[consistency] -file = %(COSMOSIS_DIR)s/utility/consistency/consistency_interface.py -verbose = F - -[sample_S8] -file = %(COSMOSIS_DIR)s/utility/sample_sigma8/sample_S8.py - -[camb] -file = %(COSMOSIS_DIR)s/boltzmann/camb/camb_interface.py -mode=power -lmax=2508 -feedback=0 -do_reionization=F -kmin=1e-5 -kmax=20.0 -nk=200 -zmax=5.0 -zmax_background=5.0 -nz_background=500 -halofit_version=mead2020_feedback -nonlinear=pk -neutrino_hierarchy=normal -kmax_extrapolate = 500.0 - -[load_nz_fits] -file = %(COSMOSIS_DIR)s/number_density/load_nz_fits/load_nz_fits.py -nz_file =%(FITS_FILE)s -data_sets = SOURCE - -[photoz_bias] -file = %(COSMOSIS_DIR)s/number_density/photoz_bias/photoz_bias.py -mode = additive -sample = nz_source -bias_section = nofz_shifts -interpolation = cubic -output_deltaz_section_name = delta_z_out - -[linear_alignment] -file = %(COSMOSIS_DIR)s/intrinsic_alignments/la_model/linear_alignments_interface_znla.py -method = bk_corrected - -[projection] -file = %(COSMOSIS_DIR)s/structure/projection/project_2d.py -ell_min_logspaced = 1.0 -ell_max_logspaced = 25000.0 -n_ell_logspaced = 400 -shear-shear = source-source -shear-intrinsic = source-source -intrinsic-intrinsic = source-source -get_kernel_peaks = F -verbose = F - -[add_intrinsic] -file = %(COSMOSIS_DIR)s/shear/add_intrinsic/add_intrinsic.py -shear-shear=T -position-shear=F -perbin=F - -[shear_m_bias] -file = %(COSMOSIS_DIR)s/shear/shear_bias/shear_m_bias.py -m_per_bin = True -; Despite the parameter name, this can operate on xi as well as C_ell. -cl_section = shear_cl -verbose = F - -[2pt_shear] -file = %(COSMOSIS_DIR)s/shear/cl_to_xi_nicaea/nicaea_interface.so -corr_type = 0 ; shear_cl -> shear_xi - -[2pt_like] -file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py -data_sets=CELL_EE -data_file=%(FITS_FILE)s -gaussian_covariance=F -covmat_name=COVMAT -cut_zeros=F -like_name=2pt_like -angle_range_CELL_EE_1_1 = 800.0 1600.0 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/priors_mock_cell_no_sys.ini b/cosmo_inference/cosmosis_config/priors_mock_cell_no_sys.ini deleted file mode 100644 index 781ae8f7..00000000 --- a/cosmo_inference/cosmosis_config/priors_mock_cell_no_sys.ini +++ /dev/null @@ -1,5 +0,0 @@ -[cosmological_parameters] -ombh2 = gaussian 0.0244 0.00038 - -[nofz_shifts] -bias_1 = gaussian 0.0 0.013 \ No newline at end of file diff --git a/cosmo_inference/cosmosis_config/cosmosis_pipeline_A_ia.ini b/cosmo_inference/cosmosis_config/templates/cosmosis_pipeline_A_ia.ini similarity index 100% rename from cosmo_inference/cosmosis_config/cosmosis_pipeline_A_ia.ini rename to cosmo_inference/cosmosis_config/templates/cosmosis_pipeline_A_ia.ini diff --git a/cosmo_inference/cosmosis_config/cosmosis_pipeline_A_ia_cell.ini b/cosmo_inference/cosmosis_config/templates/cosmosis_pipeline_A_ia_cell.ini similarity index 100% rename from cosmo_inference/cosmosis_config/cosmosis_pipeline_A_ia_cell.ini rename to cosmo_inference/cosmosis_config/templates/cosmosis_pipeline_A_ia_cell.ini diff --git a/cosmo_inference/cosmosis_config/cosmosis_pipeline_A_psf.ini b/cosmo_inference/cosmosis_config/templates/cosmosis_pipeline_A_psf.ini similarity index 100% rename from cosmo_inference/cosmosis_config/cosmosis_pipeline_A_psf.ini rename to cosmo_inference/cosmosis_config/templates/cosmosis_pipeline_A_psf.ini diff --git a/cosmo_inference/cosmosis_config/priors.ini b/cosmo_inference/cosmosis_config/templates/priors.ini similarity index 100% rename from cosmo_inference/cosmosis_config/priors.ini rename to cosmo_inference/cosmosis_config/templates/priors.ini diff --git a/cosmo_inference/cosmosis_config/priors_mock.ini b/cosmo_inference/cosmosis_config/templates/priors_mock.ini similarity index 100% rename from cosmo_inference/cosmosis_config/priors_mock.ini rename to cosmo_inference/cosmosis_config/templates/priors_mock.ini diff --git a/cosmo_inference/cosmosis_config/priors_mock_cell.ini b/cosmo_inference/cosmosis_config/templates/priors_mock_cell.ini similarity index 100% rename from cosmo_inference/cosmosis_config/priors_mock_cell.ini rename to cosmo_inference/cosmosis_config/templates/priors_mock_cell.ini diff --git a/cosmo_inference/cosmosis_config/priors_psf.ini b/cosmo_inference/cosmosis_config/templates/priors_psf.ini similarity index 100% rename from cosmo_inference/cosmosis_config/priors_psf.ini rename to cosmo_inference/cosmosis_config/templates/priors_psf.ini diff --git a/cosmo_inference/cosmosis_config/values_ia.ini b/cosmo_inference/cosmosis_config/templates/values_ia.ini similarity index 100% rename from cosmo_inference/cosmosis_config/values_ia.ini rename to cosmo_inference/cosmosis_config/templates/values_ia.ini diff --git a/cosmo_inference/cosmosis_config/values_psf.ini b/cosmo_inference/cosmosis_config/templates/values_psf.ini similarity index 100% rename from cosmo_inference/cosmosis_config/values_psf.ini rename to cosmo_inference/cosmosis_config/templates/values_psf.ini diff --git a/cosmo_inference/cosmosis_config/values.ini b/cosmo_inference/cosmosis_config/values.ini deleted file mode 100644 index 39d1ec22..00000000 --- a/cosmo_inference/cosmosis_config/values.ini +++ /dev/null @@ -1,27 +0,0 @@ -[cosmological_parameters] -tau = 0.0544 -w = -1.0 -mnu = 0.06 -omega_k = 0.0 -wa = 0.0 -omch2 = 0.10496564589028712 -h0 = 0.7703672811295145 -ombh2 = 0.024364520846452055 -n_s = 1.0378056660322685 -s_8_input = 0.867063981537897 - -[halo_model_parameters] - -[intrinsic_alignment_parameters] -a = 1.2105355520872163 - -[shear_calibration_parameters] -m1 = -0.0019669717507113187 - -[nofz_shifts] -bias_1 = -0.05240296008081707 - -[psf_leakage_parameters] -alpha = 0.017313482956287624 -beta = 1.0863942321436328 - diff --git a/cosmo_inference/cosmosis_config/values_empty.ini b/cosmo_inference/cosmosis_config/values_empty.ini deleted file mode 100644 index 019ede84..00000000 --- a/cosmo_inference/cosmosis_config/values_empty.ini +++ /dev/null @@ -1,27 +0,0 @@ -[cosmological_parameters] -omch2 = 0.12565412726665712 -ombh2 = 0.022190866236551653 -h0 = 0.7030358726770478 -n_s = 0.9289664070330077 -tau = 0.11917908882774889 -s_8_input = 0.8305214945570943 - -[halo_model_parameters] -logt_agn = 7.557408270897992 - -[intrinsic_alignment_parameters] -a = 1.1275705902391073 - -[shear_calibration_parameters] -m1 = -0.055917714943670135 - -[nofz_shifts] -bias_1 = -0.0043115110715487015 - -[psf_leakage_parameters] -alpha = 0.004915858299931063 -beta = 0.811523998498723 - -[planck] -a_planck = 0.9998087705267193 - diff --git a/cosmo_inference/cosmosis_config/values_ia_no_sys.ini b/cosmo_inference/cosmosis_config/values_ia_no_sys.ini deleted file mode 100644 index da390032..00000000 --- a/cosmo_inference/cosmosis_config/values_ia_no_sys.ini +++ /dev/null @@ -1,26 +0,0 @@ -[cosmological_parameters] -omch2 = 0.051 0.120 0.255 -h0 = 0.64 0.7 0.82 -ombh2 = 0.019 0.023 0.026 -n_s = 0.84 0.96 1.1 -S_8_input = 0.1 0.8 1.3 - -tau = 0.0544 -w = -1.0 -mnu = 0.06 -omega_k = 0.0 -wa = 0.0 - -[halo_model_parameters] -logT_AGN = 7.3 7.5 8.0 - -[intrinsic_alignment_parameters] -A = 0.0 - -[shear_calibration_parameters] -m1 = 0.0 - -[nofz_shifts] -bias_1 = -0.1 0.0 0.1 - - diff --git a/cosmo_inference/cosmosis_config/values_ia_test.ini b/cosmo_inference/cosmosis_config/values_ia_test.ini deleted file mode 100644 index 30b2c422..00000000 --- a/cosmo_inference/cosmosis_config/values_ia_test.ini +++ /dev/null @@ -1,27 +0,0 @@ -[cosmological_parameters] -omch2 = 0.051 0.11869577244577488 0.255 -h0 = 0.64 0.6766 0.82 -ombh2 = 0.019 0.0224178568132 0.026 -n_s = 0.84 0.9665 1.1 -#S_8_input = 0.1 0.81 1.3 -S_8_input = 0.1 0.8231408713507062 1.3 - -tau = 0.054 -w = -1.0 -mnu = 0.06 -omega_k = 0.0 -wa = 0.0 - -[halo_model_parameters] -logT_AGN = 7.3 7.8 8.0 - -[intrinsic_alignment_parameters] -A = -5.0 0.0 5.0 - -[shear_calibration_parameters] -m1 = -0.1 0.0 0.1 - -[nofz_shifts] -bias_1 = -0.1 0.0 0.1 - - diff --git a/cosmo_inference/cosmosis_config/values_template.ini b/cosmo_inference/cosmosis_config/values_template.ini deleted file mode 100644 index 60ac60c6..00000000 --- a/cosmo_inference/cosmosis_config/values_template.ini +++ /dev/null @@ -1,23 +0,0 @@ -[cosmological_parameters] -omch2 = 0.01 0.12 0.3 -h0 = 0.55 0.7 0.91 -ombh2 = 0.01 0.023 0.07 -n_s = 0.87 0.96 1.07 -a_s = 0.5e-09 2.9e-09 5.0e-09 - -tau = 0.0544 -w = -1.0 -mnu = 0.06 -omega_k = 0.0 -wa = 0.0 - -[halo_model_parameters] -logt_agn = 6.5 7.81 8.5 - -[nofz_shifts] -bias_1 = -2.0 0.0 2.0 - -[intrinsic_alignment_parameters] -A = -3.0 0.0 3.0 - - diff --git a/cosmo_inference/get_chi2.ipynb b/cosmo_inference/get_chi2.ipynb deleted file mode 100644 index 69d026a2..00000000 --- a/cosmo_inference/get_chi2.ipynb +++ /dev/null @@ -1,1391 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import configparser\n", - "import os\n", - "import subprocess\n", - "\n", - "import healpy as hp\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "import scipy.stats as stats\n", - "import seaborn as sns\n", - "from astropy.io import fits\n", - "from getdist import plots\n", - "from IPython.display import Markdown, display\n", - "from scipy.interpolate import interp1d\n", - "\n", - "%matplotlib inline\n", - "# import uncertainties\n", - "\n", - "# Use paper style and seaborn with husl palette\n", - "plt.style.use(\"/home/guerrini/matplotlib_config/paper.mplstyle\")\n", - "# Set default palette - will be updated per plot as needed\n", - "sns.set_palette(\"husl\")\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "g.settings.axes_fontsize = 30\n", - "g.settings.axes_labelsize = 30\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 40\n", - "\n", - "\n", - "# SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE\n", - "root_dir = \"/n09data/guerrini/output_chains/\"\n", - "\n", - "catalog_version = \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1\"\n", - "\n", - "path_ini_files = \"/home/guerrini/sp_validation/cosmo_inference/cosmosis_config/\"\n", - "\n", - "roots = [\n", - " f\"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_{int(i)}.0_80.0_10.0_80.0\"\n", - " for i in [3, 5, 7, 10, 11]\n", - "]\n", - "\n", - "\"\"\" roots = [\n", - " \"SP_v1.4.5_A\",\n", - " #\"SP_v1.4.5_A_no_IA\",\n", - " #\"SP_v1.4.5_A_no_dz\",\n", - " #\"SP_v1.4.5_A_no_m_bias\",\n", - " \"SP_v1.4.5_A_sc_3_150\",\n", - " \"SP_v1.4.5_A_sc_3_60\",\n", - " \"SP_v1.4.5_A_sc_10_150\",\n", - " \"SP_v1.4.5_A_sc_10_60\",\n", - " \"SP_v1.4.5_A_sc_5_150\",\n", - " \"SP_v1.4.5_A_sc_7_150\",\n", - " #\"SP_v1.4.5_A_no_leakage\"\n", - "] \"\"\"\n", - "\n", - "\"\"\" roots = [\n", - " \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_10.0_80.0_10.0_80.0\",\n", - " \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_10.0_80.0_10.0_80.0_no_alpha_beta\"\n", - "] \"\"\"\n", - "\n", - "\n", - "properties = {}\n", - "\n", - "for root in roots:\n", - " config = configparser.ConfigParser()\n", - " config.optionxform = str # Preserve case sensitivity of option names\n", - " config.read(path_ini_files + f\"/cosmosis_pipeline_{root}.ini\")\n", - "\n", - " add_xi_sys = config[\"2pt_like\"][\"add_xi_sys\"]\n", - " add_xi_sys = add_xi_sys == \"T\"\n", - " lower_bound_xi_plus, upper_bound_xi_plus = map(\n", - " float, config[\"2pt_like\"][\"angle_range_XI_PLUS_1_1\"].split()\n", - " )\n", - " lower_bound_xi_minus, upper_bound_xi_minus = map(\n", - " float, config[\"2pt_like\"][\"angle_range_XI_MINUS_1_1\"].split()\n", - " )\n", - "\n", - " properties[root] = {\n", - " \"add_xi_sys\": add_xi_sys,\n", - " \"lower_bound_xi_plus\": lower_bound_xi_plus,\n", - " \"upper_bound_xi_plus\": upper_bound_xi_plus,\n", - " \"lower_bound_xi_minus\": lower_bound_xi_minus,\n", - " \"upper_bound_xi_minus\": upper_bound_xi_minus,\n", - " }\n", - "\n", - "\n", - "print(roots)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Retrieve the chains" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# MAKE PARAMNAMES FILE\n", - "\n", - "for root in roots:\n", - " with open(root_dir + \"{}/samples_{}.txt\".format(\"/\" + root, root), \"r\") as file:\n", - " params = file.readline()[1:].split(\"\\t\")[:-4]\n", - " file.close()\n", - "\n", - " with open(\n", - " root_dir + \"{}/getdist_{}.paramnames\".format(\"/\" + root, root), \"w\"\n", - " ) as file:\n", - " for i in range(len(params)):\n", - " if len(params[i].split(\"--\")) > 1:\n", - " file.write(params[i].split(\"--\")[1] + \"\\n\")\n", - " else:\n", - " file.write(params[i].split(\"--\")[0] + \"\\n\")\n", - " file.close()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# READ CHAIN\n", - "\n", - "chains = []\n", - "\n", - "for root in roots:\n", - " samples = np.loadtxt(root_dir + \"{}/samples_{}.txt\".format(root, root))\n", - " print(len(samples))\n", - " if \"nautilus\" in root:\n", - " samples = np.column_stack(\n", - " (np.exp(samples[:, -3]), samples[:, -1] - samples[:, -2], samples[:, 0:-3])\n", - " )\n", - " else:\n", - " samples = np.column_stack((samples[:, -1], samples[:, -3], samples[:, 0:-4]))\n", - " np.savetxt(root_dir + \"{}/getdist_{}.txt\".format(root, root), samples)\n", - "\n", - " chain = g.samples_for_root(\n", - " root_dir + \"{}/getdist_{}\".format(root, root),\n", - " cache=False,\n", - " settings={\"ignore_rows\": 0, \"smooth_scale_2D\": 0.3, \"smooth_scale_1D\": 0.3},\n", - " )\n", - "\n", - " chains.append(chain)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "name_list = [\n", - " \"OMEGA_M\",\n", - " \"ombh2\",\n", - " \"h0\",\n", - " \"n_s\",\n", - " \"SIGMA_8\",\n", - " \"s_8_input\",\n", - " \"logt_agn\",\n", - " \"a\",\n", - " \"m1\",\n", - " \"bias_1\",\n", - " \"alpha\",\n", - " \"beta\",\n", - "]\n", - "label_list = [\n", - " r\"\\Omega_m\",\n", - " r\"\\omega_b h^2\",\n", - " \"h_0\",\n", - " \"n_s\",\n", - " r\"\\sigma_8\",\n", - " \"S_8\",\n", - " \"log T_{AGN}\",\n", - " \"A_{IA}\",\n", - " \"m_1\",\n", - " r\"\\Delta z_1\",\n", - " \"\\\\alpha_{PSF}\",\n", - " \"\\\\beta_{PSF}\",\n", - "]\n", - "\n", - "for chain in chains:\n", - " param_names = chain.getParamNames()\n", - " for name, label in zip(name_list, label_list):\n", - " param_names.parWithName(name).label = label" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Extract the best fit parameters" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "best_fit = {}\n", - "\n", - "for root, chain in zip(roots, chains):\n", - " print(root)\n", - " likestats = chain.getLikeStats()\n", - " bestfit_idx = np.argmax(chain.loglikes)\n", - " maxlike = chain.loglikes[bestfit_idx]\n", - " print(f\"Maximum Likelihood: {maxlike:.5g}\")\n", - " best_fit[root] = {\"likelihood\": maxlike}\n", - " for i, par in enumerate(likestats.names):\n", - " best_fit[root].update(\n", - " {par.name: np.average(chain.samples[:, i], weights=chain.weights)}\n", - " )" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Run `Cosmosis` in test mode to get the data vectors" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if not os.path.exists(path_ini_files + \"/values_empty.ini\"):\n", - " content = \"\"\"[cosmological_parameters]\n", - "\n", - "tau = 0.0544\n", - "w = -1.0\n", - "massive_nu = 1\n", - "massless_nu = 2.046\n", - "omega_k = 0.0\n", - "wa = 0.0\n", - "\n", - "[halo_model_parameters]\n", - "\n", - "[intrinsic_alignment_parameters]\n", - "\n", - "[shear_calibration_parameters]\n", - "\n", - "[nofz_shifts]\n", - "\n", - "[psf_leakage_parameters]\n", - "\"\"\"\n", - "\n", - " with open(path_ini_files + \"/values_empty.ini\", \"w\") as f:\n", - " f.write(content)\n", - " f.close()\n", - "\n", - " print(\"File created successfully\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "section_map = {\n", - " \"omch2\": \"cosmological_parameters\",\n", - " \"ombh2\": \"cosmological_parameters\",\n", - " \"h0\": \"cosmological_parameters\",\n", - " \"n_s\": \"cosmological_parameters\",\n", - " \"s_8_input\": \"cosmological_parameters\",\n", - " \"logt_agn\": \"halo_model_parameters\",\n", - " \"a\": \"intrinsic_alignment_parameters\",\n", - " \"m1\": \"shear_calibration_parameters\",\n", - " \"bias_1\": \"nofz_shifts\",\n", - " \"alpha\": \"psf_leakage_parameters\",\n", - " \"beta\": \"psf_leakage_parameters\",\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "env = os.environ.copy()\n", - "env[\"LD_LIBRARY_PATH\"] = (\n", - " \"/home/guerrini/.conda/envs/sp_validation/lib/python3.9/site-packages/cosmosis/datablock:\"\n", - " + env.get(\"LD_LIBRARY_PATH\", \"\")\n", - ")\n", - "\n", - "for root in roots:\n", - " print(root)\n", - " config = configparser.ConfigParser()\n", - " config.optionxform = str # Preserve case sensitivity of option names\n", - " config.read(path_ini_files + \"/values_empty.ini\")\n", - " for param, value in best_fit[root].items():\n", - " section = section_map.get(param)\n", - " if section is None:\n", - " continue\n", - " if section not in config:\n", - " config.add_section(section)\n", - " config[section][param] = str(value)\n", - "\n", - " with open(path_ini_files + \"/values_empty.ini\", \"w\") as configfile:\n", - " config.write(configfile)\n", - "\n", - " # Modify the ini file to run in test mode at the best fit\n", - " config = configparser.ConfigParser()\n", - " config.optionxform = str # Preserve case sensitivity of option names\n", - " config.read(path_ini_files + f\"/cosmosis_pipeline_{root}.ini\")\n", - "\n", - " sampler = config[\"runtime\"][\"sampler\"]\n", - " config[\"runtime\"][\"sampler\"] = \"test\"\n", - " values = config[\"pipeline\"][\"values\"]\n", - " config[\"pipeline\"][\"values\"] = path_ini_files + \"/values_empty.ini\"\n", - "\n", - " with open(path_ini_files + f\"/cosmosis_pipeline_{root}.ini\", \"w\") as configfile:\n", - " config.write(configfile)\n", - "\n", - " # Run cosmosis\n", - " result = subprocess.run(\n", - " [\"cosmosis\", \"cosmosis_config/cosmosis_pipeline_{}.ini\".format(root)],\n", - " env=env,\n", - " capture_output=True,\n", - " text=True,\n", - " )\n", - " print(f\"STDOUT:\\n{result.stdout}\")\n", - " print(f\"STDERR:\\n{result.stderr}\")\n", - "\n", - " # Modify the ini file to the previous one\n", - " config[\"pipeline\"][\"values\"] = values\n", - " config[\"runtime\"][\"sampler\"] = sampler\n", - "\n", - " with open(path_ini_files + f\"/cosmosis_pipeline_{root}.ini\", \"w\") as configfile:\n", - " config.write(configfile)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Compute the $\\chi^2$" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "output_folder = \"/n09data/guerrini/output_chains/\"\n", - "\n", - "metrics = {}\n", - "\n", - "for root in roots:\n", - " print(root)\n", - "\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - "\n", - " # Read model tau_stats\n", - " theta_tau = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_0_plus/theta.txt\".format(root)\n", - " )\n", - " theta_tau_arcmin = theta_tau * 180 * 60 / np.pi\n", - " tau_0_model = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_0_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " tau_2_model = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_2_plus/bin_1_1.txt\".format(root)\n", - " )\n", - "\n", - " # Read the data\n", - " data = fits.open(f\"data/{catalog_version}/cosmosis_{catalog_version}.fits\")\n", - "\n", - " theta_data = data[\"XI_PLUS\"].data[\"ANG\"]\n", - " xi_plus_data = data[\"XI_PLUS\"].data[\"VALUE\"]\n", - " xi_minus_data = data[\"XI_MINUS\"].data[\"VALUE\"]\n", - " tau_0_data = data[\"TAU_0_PLUS\"].data[\"VALUE\"]\n", - " tau_2_data = data[\"TAU_2_PLUS\"].data[\"VALUE\"]\n", - "\n", - " # Load the covariance\n", - " cov = data[\"COVMAT\"].data\n", - " cov_xi = cov[0 : 2 * len(xi_plus_data), 0 : 2 * len(xi_plus_data)]\n", - " cov_tau = cov[2 * len(xi_plus_data) :, 2 * len(xi_plus_data) :]\n", - "\n", - " # interpolate the model\n", - " interp_xi_plus = interp1d(\n", - " theta_arcmin, shear_xi_plus, kind=\"cubic\", fill_value=\"extrapolate\"\n", - " )\n", - " interp_xi_minus = interp1d(\n", - " theta_arcmin, shear_xi_minus, kind=\"cubic\", fill_value=\"extrapolate\"\n", - " )\n", - "\n", - " xi_plus_model = interp_xi_plus(theta_data)\n", - " if add_xi_sys:\n", - " xi_plus_model += xi_sys_plus\n", - " xi_minus_model = interp_xi_minus(theta_data)\n", - " if add_xi_sys:\n", - " xi_minus_model += xi_sys_minus\n", - "\n", - " # Concatenate the data vector\n", - " xi_data = np.concatenate((xi_plus_data, xi_minus_data))\n", - " xi_model = np.concatenate((xi_plus_model, xi_minus_model))\n", - "\n", - " tau_data = np.concatenate((tau_0_data, tau_2_data))\n", - " tau_model = np.concatenate((tau_0_model, tau_2_model))\n", - "\n", - " # Apply scale cuts\n", - " mask_xi_plus = (theta_data > lower_bound_xi_plus) & (\n", - " theta_data < upper_bound_xi_plus\n", - " )\n", - " mask_xi_minus = (theta_data > lower_bound_xi_minus) & (\n", - " theta_data < upper_bound_xi_minus\n", - " )\n", - " mask = np.concatenate((mask_xi_plus, mask_xi_minus))\n", - "\n", - " xi_data = xi_data[mask]\n", - " xi_model = xi_model[mask]\n", - " cov_xi = cov_xi[mask][:, mask]\n", - "\n", - " xi_plus_chi2 = np.dot(\n", - " (xi_model - xi_data), np.dot(np.linalg.inv(cov_xi), (xi_model - xi_data))\n", - " )\n", - " tau_chi2 = np.dot(\n", - " (tau_model - tau_data), np.dot(np.linalg.inv(cov_tau), (tau_model - tau_data))\n", - " )\n", - " n_dof_xi = np.sum(mask)\n", - " n_dof_tau = len(tau_0_data) + len(tau_2_data)\n", - " p_value_xi = 1 - stats.chi2.cdf(xi_plus_chi2, n_dof_xi)\n", - " p_value_tau = 1 - stats.chi2.cdf(tau_chi2, n_dof_tau)\n", - " chi2_tot = xi_plus_chi2 + tau_chi2\n", - " n_dof_tot = n_dof_xi + n_dof_tau\n", - " p_value_tot = 1 - stats.chi2.cdf(chi2_tot, n_dof_tot)\n", - "\n", - " metrics[root] = {\n", - " \"chi2_xi\": xi_plus_chi2,\n", - " \"n_dof_xi\": n_dof_xi,\n", - " \"p_value_xi\": p_value_xi,\n", - " \"chi2_tau\": tau_chi2,\n", - " \"n_dof_tau\": n_dof_tau,\n", - " \"p_value_tau\": p_value_tau,\n", - " \"chi2_tot\": chi2_tot,\n", - " \"n_dof_tot\": n_dof_tot,\n", - " \"p_value_tot\": p_value_tot,\n", - " }\n", - " print(\"Done!\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def get_latex_table(metrics):\n", - " latex_lines = [\n", - " r\"\\begin{tabular}{lccc|ccc|ccc}\",\n", - " r\"\\hline\",\n", - " r\"Root & $\\chi^2_{\\xi^+}$/dof & $p_{\\xi^+}$ & \"\n", - " r\"$\\chi^2_\\tau$/dof & $p_\\tau$ & $\\chi^2_{\\text{tot}}$/dof & $p_{\\text{tot}}$ \\\\\",\n", - " r\"\\hline\",\n", - " ]\n", - "\n", - " for root, vals in metrics.items():\n", - " escaped = root.replace(\"_\", r\"\\_\")\n", - " line = (\n", - " f\"{escaped} & \"\n", - " f\"{vals['chi2_xi']:.2f}/{vals['n_dof_xi']} & {vals['p_value_xi']:.5f} & \"\n", - " f\"{vals['chi2_tau']:.2f}/{vals['n_dof_tau']} & {vals['p_value_tau']:.5f} & \"\n", - " f\"{vals['chi2_tot']:.2f}/{vals['n_dof_tot']} & {vals['p_value_tot']:.5f} \\\\\\\\\"\n", - " )\n", - " latex_lines.append(line)\n", - "\n", - " latex_lines.append(r\"\\hline\")\n", - " latex_lines.append(r\"\\end{tabular}\")\n", - "\n", - " # Print LaTeX table\n", - " print(\"\\n\".join(latex_lines))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "get_latex_table(metrics)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def display_markdown(metrics):\n", - " # Build Markdown table\n", - " header = (\n", - " \"| Root | $\\\\chi^2$ (ξ⁺) / dof | p-val (ξ⁺) | $\\\\chi^2$ (τ) / dof | p-val (τ) | $\\\\chi^2$ (tot) / dof | p-val (tot) |\\n\"\n", - " \"|------|----------------|------------|---------------|------------|------------------|--------------|\\n\"\n", - " )\n", - "\n", - " rows = []\n", - " for root, vals in metrics.items():\n", - " row = f\"| `{root}` \"\n", - " row += f\"| {vals['chi2_xi']:.2f} / {vals['n_dof_xi']} \"\n", - " row += f\"| {vals['p_value_xi']:.5f} \"\n", - " row += f\"| {vals['chi2_tau']:.2f} / {vals['n_dof_tau']} \"\n", - " row += f\"| {vals['p_value_tau']:.5f} \"\n", - " row += f\"| {vals['chi2_tot']:.2f} / {vals['n_dof_tot']} \"\n", - " row += f\"| {vals['p_value_tot']:.5f} |\"\n", - " rows.append(row)\n", - "\n", - " # Display in Jupyter\n", - " display(Markdown(header + \"\\n\".join(rows)))\n", - " return header + \"\\n\".join(rows)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "markdown_source = display_markdown(metrics)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "markdown_source" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Plot the best-fit of each model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "data = fits.open(\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{catalog_version}/cosmosis_SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1.fits\"\n", - ")\n", - "xi_plus = data[\"XI_PLUS\"].data\n", - "xi_minus = data[\"XI_MINUS\"].data\n", - "cov_mat = data[\"COVMAT\"].data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "plt.figure(figsize=(15, 15))\n", - "\n", - "plt.subplot(211)\n", - "\n", - "plt.errorbar(\n", - " xi_plus[\"ANG\"],\n", - " xi_plus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[:20],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - ")\n", - "\n", - "plt.ylabel(r\"$\\xi_{+}$\", fontsize=26)\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "\n", - "plt.subplot(212)\n", - "\n", - "plt.errorbar(\n", - " xi_minus[\"ANG\"],\n", - " xi_minus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[20:40],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - ")\n", - "\n", - "plt.xlabel(r\"$\\theta$ [arcmin]\", fontsize=26)\n", - "plt.ylabel(r\"$\\xi_{-}$\", fontsize=26)\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.legend(fontsize=15)\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def plot_best_fit(\n", - " root_to_plot,\n", - " colours,\n", - " savefile,\n", - " theta_min=1.0,\n", - " theta_max=250.0,\n", - " multiply_theta=False,\n", - " plot_xi_sys=True,\n", - "):\n", - " data = fits.open(\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{catalog_version}/cosmosis_{catalog_version}.fits\"\n", - " )\n", - " xi_plus = data[\"XI_PLUS\"].data\n", - " xi_minus = data[\"XI_MINUS\"].data\n", - " cov_mat = data[\"COVMAT\"].data\n", - "\n", - " plt.figure(figsize=(15, 15))\n", - "\n", - " plt.subplot(211)\n", - "\n", - " y_plot_xi_plus = (\n", - " xi_plus[\"VALUE\"] if not multiply_theta else xi_plus[\"ANG\"] * xi_plus[\"VALUE\"]\n", - " )\n", - " y_errorbar = (\n", - " xi_plus[\"ANG\"] * np.sqrt(np.diag(cov_mat))[:20]\n", - " if multiply_theta\n", - " else np.sqrt(np.diag(cov_mat))[:20]\n", - " )\n", - " plt.errorbar(\n", - " xi_plus[\"ANG\"],\n", - " y_plot_xi_plus,\n", - " yerr=y_errorbar,\n", - " fmt=\"o\",\n", - " label=f\"{catalog_version} data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - " )\n", - "\n", - " for root, color in zip(root_to_plot, colours):\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/theta.txt\".format(root)\n", - " )\n", - " theta_xi_sys_arcmin = theta_xi_sys * 180 * 60 / np.pi\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - " xi_plus_model = shear_xi_plus[mask]\n", - " if add_xi_sys:\n", - " xi_plus_model += np.interp(\n", - " theta_arcmin[mask], theta_xi_sys_arcmin, xi_sys_plus\n", - " )\n", - "\n", - " y_plot = theta_arcmin[mask] * xi_plus_model if multiply_theta else xi_plus_model\n", - " plt.plot(theta_arcmin[mask], y_plot, color=color, label=root, alpha=0.5)\n", - " if plot_xi_sys and add_xi_sys:\n", - " y_plot_xi_sys = (\n", - " theta_xi_sys_arcmin * xi_sys_plus if multiply_theta else xi_sys_plus\n", - " )\n", - " plt.plot(\n", - " theta_xi_sys_arcmin,\n", - " y_plot_xi_sys,\n", - " color=color,\n", - " linestyle=\"-.\",\n", - " alpha=0.5,\n", - " )\n", - " plt.axvline(x=lower_bound_xi_plus, color=color, linestyle=\"--\", alpha=0.3)\n", - " plt.axvline(x=upper_bound_xi_plus, color=color, linestyle=\"--\", alpha=0.3)\n", - "\n", - " y_label = r\"$\\xi_{+}$\" if not multiply_theta else r\"$\\theta \\xi_{+}$\"\n", - " plt.ylabel(y_label, fontsize=26)\n", - " plt.xscale(\"log\")\n", - " plt.yscale(\"log\")\n", - " plt.legend(loc=\"lower left\", fontsize=8)\n", - "\n", - " plt.subplot(212)\n", - "\n", - " y_plot_xi_minus = (\n", - " xi_minus[\"VALUE\"] if not multiply_theta else xi_minus[\"ANG\"] * xi_minus[\"VALUE\"]\n", - " )\n", - " y_errorbar = (\n", - " xi_minus[\"ANG\"] * np.sqrt(np.diag(cov_mat))[20:40]\n", - " if multiply_theta\n", - " else np.sqrt(np.diag(cov_mat))[20:40]\n", - " )\n", - " plt.errorbar(\n", - " xi_minus[\"ANG\"],\n", - " y_plot_xi_minus,\n", - " yerr=y_errorbar,\n", - " fmt=\"o\",\n", - " label=f\"{catalog_version} data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - " )\n", - "\n", - " for root, color in zip(root_to_plot, colours):\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/theta.txt\".format(root)\n", - " )\n", - " theta_xi_sys_arcmin = theta_xi_sys * 180 * 60 / np.pi\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - " xi_minus_model = shear_xi_minus[mask]\n", - " if add_xi_sys:\n", - " xi_minus_model += np.interp(\n", - " theta_arcmin[mask], theta_xi_sys_arcmin, xi_sys_minus\n", - " )\n", - "\n", - " y_plot = (\n", - " theta_arcmin[mask] * xi_minus_model if multiply_theta else xi_minus_model\n", - " )\n", - " plt.plot(theta_arcmin[mask], y_plot, color=color, label=root, alpha=0.5)\n", - " if plot_xi_sys and add_xi_sys:\n", - " y_plot_xi_sys = (\n", - " theta_xi_sys_arcmin * xi_sys_minus if multiply_theta else xi_sys_minus\n", - " )\n", - " plt.plot(\n", - " theta_xi_sys_arcmin,\n", - " y_plot_xi_sys,\n", - " color=color,\n", - " linestyle=\"-.\",\n", - " alpha=0.5,\n", - " )\n", - " plt.axvline(x=lower_bound_xi_minus, color=color, linestyle=\"--\", alpha=0.3)\n", - " plt.axvline(x=upper_bound_xi_minus, color=color, linestyle=\"--\", alpha=0.3)\n", - "\n", - " plt.xlabel(r\"$\\theta$ [arcmin]\", fontsize=26)\n", - " y_label = r\"$\\xi_{-}$\" if not multiply_theta else r\"$\\theta \\xi_{-}$\"\n", - " plt.ylabel(y_label, fontsize=26)\n", - " plt.xscale(\"log\")\n", - " plt.yscale(\"log\")\n", - " plt.legend(loc=\"lower left\", fontsize=8)\n", - "\n", - " if savefile is not None:\n", - " plt.savefig(savefile, bbox_inches=\"tight\")\n", - "\n", - " plt.show()\n", - "\n", - "\n", - "def plot_best_fit_ratio(\n", - " root_to_plot, colours, savefile, theta_min=1.0, theta_max=250.0\n", - "):\n", - " data = fits.open(\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{catalog_version}/cosmosis_{catalog_version}.fits\"\n", - " )\n", - " xi_plus = data[\"XI_PLUS\"].data\n", - " xi_minus = data[\"XI_MINUS\"].data\n", - " cov_mat = data[\"COVMAT\"].data\n", - "\n", - " plt.figure(figsize=(15, 15))\n", - "\n", - " plt.subplot(211)\n", - "\n", - " root = roots[0]\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/theta.txt\".format(root)\n", - " )\n", - " theta_xi_sys_arcmin = theta_xi_sys * 180 * 60 / np.pi\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - " xi_plus_model_fiducial = shear_xi_plus[mask]\n", - " if add_xi_sys:\n", - " xi_plus_model_fiducial += np.interp(\n", - " theta_arcmin[mask], theta_xi_sys_arcmin, xi_sys_plus\n", - " )\n", - "\n", - " plt.errorbar(\n", - " xi_plus[\"ANG\"],\n", - " xi_plus[\"VALUE\"]\n", - " / np.interp(xi_plus[\"ANG\"], theta_arcmin[mask], xi_plus_model_fiducial),\n", - " yerr=np.sqrt(np.diag(cov_mat))[:20]\n", - " / np.abs(np.interp(xi_plus[\"ANG\"], theta_arcmin[mask], xi_plus_model_fiducial)),\n", - " fmt=\"o\",\n", - " label=f\"{catalog_version} data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - " )\n", - "\n", - " for root, color in zip(root_to_plot, colours):\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/theta.txt\".format(root)\n", - " )\n", - " theta_xi_sys_arcmin = theta_xi_sys * 180 * 60 / np.pi\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - " xi_plus_model = shear_xi_plus[mask]\n", - " if add_xi_sys:\n", - " xi_plus_model += np.interp(\n", - " theta_arcmin[mask], theta_xi_sys_arcmin, xi_sys_plus\n", - " )\n", - "\n", - " alpha = 1.0 if root == roots[0] else 0.5\n", - " plt.plot(\n", - " theta_arcmin[mask],\n", - " xi_plus_model / xi_plus_model_fiducial,\n", - " color=color,\n", - " label=root,\n", - " alpha=alpha,\n", - " )\n", - " plt.axvline(x=lower_bound_xi_plus, color=color, linestyle=\"--\", alpha=0.3)\n", - " plt.axvline(x=upper_bound_xi_plus, color=color, linestyle=\"--\", alpha=0.3)\n", - "\n", - " plt.ylabel(r\"$\\xi_{+}/\\xi_{+, \\text{fid}}$\", fontsize=26)\n", - " plt.xscale(\"log\")\n", - " # plt.yscale('log')\n", - " plt.legend(loc=\"lower left\", fontsize=8)\n", - "\n", - " plt.subplot(212)\n", - "\n", - " root = roots[0]\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/theta.txt\".format(root)\n", - " )\n", - " theta_xi_sys_arcmin = theta_xi_sys * 180 * 60 / np.pi\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - " xi_minus_model_fiducial = shear_xi_minus[mask]\n", - " if add_xi_sys:\n", - " xi_minus_model_fiducial += np.interp(\n", - " theta_arcmin[mask], theta_xi_sys_arcmin, xi_sys_minus\n", - " )\n", - "\n", - " plt.errorbar(\n", - " xi_minus[\"ANG\"],\n", - " xi_minus[\"VALUE\"]\n", - " / np.interp(xi_minus[\"ANG\"], theta_arcmin[mask], xi_minus_model_fiducial),\n", - " yerr=np.sqrt(np.diag(cov_mat))[20:40]\n", - " / np.abs(\n", - " np.interp(xi_minus[\"ANG\"], theta_arcmin[mask], xi_minus_model_fiducial)\n", - " ),\n", - " fmt=\"o\",\n", - " label=f\"{catalog_version} data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - " )\n", - "\n", - " for root, color in zip(root_to_plot, colours):\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/theta.txt\".format(root)\n", - " )\n", - " theta_xi_sys_arcmin = theta_xi_sys * 180 * 60 / np.pi\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - " xi_minus_model = shear_xi_minus[mask]\n", - " if add_xi_sys:\n", - " xi_minus_model += np.interp(\n", - " theta_arcmin[mask], theta_xi_sys_arcmin, xi_sys_minus\n", - " )\n", - "\n", - " alpha = 1.0 if root == roots[0] else 0.5\n", - " plt.plot(\n", - " theta_arcmin[mask],\n", - " xi_minus_model / xi_minus_model_fiducial,\n", - " color=color,\n", - " label=root,\n", - " alpha=alpha,\n", - " )\n", - " plt.axvline(x=lower_bound_xi_minus, color=color, linestyle=\"--\", alpha=0.3)\n", - " plt.axvline(x=upper_bound_xi_minus, color=color, linestyle=\"--\", alpha=0.3)\n", - "\n", - " plt.xlabel(r\"$\\theta$ [arcmin]\", fontsize=26)\n", - " plt.ylabel(r\"$\\xi_{-}/\\xi_{-, \\text{fid}}$\", fontsize=26)\n", - " plt.xscale(\"log\")\n", - " plt.ylim(0, 2)\n", - " # plt.yscale('log')\n", - " plt.legend(loc=\"lower left\", fontsize=8)\n", - "\n", - " if savefile is not None:\n", - " plt.savefig(savefile, bbox_inches=\"tight\")\n", - "\n", - " plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "root_to_plot = [\n", - " \"SP_v1.4.5_A\",\n", - " # \"SP_v1.4.5_A_no_IA\",\n", - " # \"SP_v1.4.5_A_no_dz\",\n", - " # \"SP_v1.4.5_A_no_m_bias\",\n", - " \"SP_v1.4.5_A_sc_3_150\",\n", - " \"SP_v1.4.5_A_sc_3_60\",\n", - " \"SP_v1.4.5_A_sc_10_150\",\n", - " \"SP_v1.4.5_A_sc_10_60\",\n", - " \"SP_v1.4.5_A_sc_5_150\",\n", - " \"SP_v1.4.5_A_sc_7_150\",\n", - " # \"SP_v1.4.5_A_no_leakage\"\n", - "]\n", - "\n", - "root_to_plot = [\n", - " f\"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_{int(i)}.0_80.0_10.0_80.0\"\n", - " for i in [3, 5, 7, 10, 11]\n", - "]\n", - "\n", - "\"\"\" root_to_plot = [\n", - " \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_10.0_80.0_10.0_80.0\",\n", - " \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_10.0_80.0_10.0_80.0_no_alpha_beta\"\n", - "] \"\"\"\n", - "\n", - "\n", - "colours = [\n", - " \"cornflowerblue\",\n", - " \"salmon\",\n", - " \"darkorange\",\n", - " \"forestgreen\",\n", - " \"turquoise\",\n", - " \"darkviolet\",\n", - " \"crimson\",\n", - " \"gold\",\n", - " \"lightcoral\",\n", - " \"mediumseagreen\",\n", - " \"lightsteelblue\",\n", - " \"black\",\n", - " \"silver\",\n", - " \"peru\",\n", - " \"maroon\",\n", - " \"olive\",\n", - "]\n", - "\n", - "savefile = None\n", - "\n", - "plot_best_fit(root_to_plot, colours, savefile, multiply_theta=True, plot_xi_sys=False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "root_to_plot = [\n", - " \"SP_v1.4.5_A\",\n", - " # \"SP_v1.4.5_A_no_IA\",\n", - " # \"SP_v1.4.5_A_no_dz\",\n", - " # \"SP_v1.4.5_A_no_m_bias\",\n", - " \"SP_v1.4.5_A_sc_3_150\",\n", - " \"SP_v1.4.5_A_sc_3_60\",\n", - " \"SP_v1.4.5_A_sc_10_150\",\n", - " \"SP_v1.4.5_A_sc_10_60\",\n", - " \"SP_v1.4.5_A_sc_5_150\",\n", - " \"SP_v1.4.5_A_sc_7_150\",\n", - " # \"SP_v1.4.5_A_no_leakage\"\n", - "]\n", - "\n", - "\"\"\" root_to_plot = [\n", - " f\"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_{int(i)}.0_80.0_10.0_80.0\" for i in [3, 5, 7, 10, 11]\n", - "] \"\"\"\n", - "\n", - "root_to_plot = [\n", - " \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_10.0_80.0_10.0_80.0\",\n", - " \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_10.0_80.0_10.0_80.0_no_alpha_beta\",\n", - "]\n", - "\n", - "\n", - "colours = [\n", - " \"red\",\n", - " \"salmon\",\n", - " \"darkorange\",\n", - " \"forestgreen\",\n", - " \"turquoise\",\n", - " \"darkviolet\",\n", - " \"crimson\",\n", - " \"gold\",\n", - " \"lightcoral\",\n", - " \"mediumseagreen\",\n", - " \"lightsteelblue\",\n", - " \"black\",\n", - " \"silver\",\n", - " \"peru\",\n", - " \"maroon\",\n", - " \"olive\",\n", - "]\n", - "\n", - "savefile = \"best_fit_ratio_w_wo_leakage.png\"\n", - "\n", - "plot_best_fit_ratio(root_to_plot, colours, savefile)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def plot_best_fit_tau(root_to_plot, colours, savefile, theta_min=1.0, theta_max=250.0):\n", - " data = fits.open(\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{catalog_version}/cosmosis_{catalog_version}.fits\"\n", - " )\n", - " tau_0 = data[\"TAU_0_PLUS\"].data\n", - " tau_2 = data[\"TAU_2_PLUS\"].data\n", - " cov_mat = data[\"COVMAT\"].data\n", - "\n", - " plt.figure(figsize=(15, 15))\n", - "\n", - " plt.subplot(211)\n", - "\n", - " plt.errorbar(\n", - " tau_0[\"ANG\"],\n", - " tau_0[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[40:60],\n", - " fmt=\"o\",\n", - " label=f\"{catalog_version} data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - " )\n", - "\n", - " for root, color in zip(root_to_plot, colours):\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_0_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " tau_0_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_0_plus/bin_1_1.txt\".format(root)\n", - " )\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - "\n", - " plt.plot(\n", - " theta_arcmin[mask], tau_0_plus[mask], color=color, label=root, alpha=0.5\n", - " )\n", - "\n", - " plt.ylabel(r\"$\\tau_0$\", fontsize=26)\n", - " plt.xscale(\"log\")\n", - " # plt.yscale('log')\n", - " plt.legend(loc=\"upper right\", fontsize=8)\n", - "\n", - " plt.subplot(212)\n", - "\n", - " y_plot_tau_2 = tau_2[\"ANG\"] * tau_2[\"VALUE\"]\n", - " y_errorbar = tau_2[\"ANG\"] * np.sqrt(np.diag(cov_mat))[60:80]\n", - " plt.errorbar(\n", - " tau_2[\"ANG\"],\n", - " y_plot_tau_2,\n", - " yerr=y_errorbar,\n", - " fmt=\"o\",\n", - " label=f\"{catalog_version} data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - " )\n", - "\n", - " for root, color in zip(root_to_plot, colours):\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_2_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " tau_2_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_2_plus/bin_1_1.txt\".format(root)\n", - " )\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - "\n", - " plt.plot(\n", - " theta_arcmin[mask],\n", - " theta_arcmin[mask] * tau_2_plus[mask],\n", - " color=color,\n", - " label=root,\n", - " alpha=0.5,\n", - " )\n", - "\n", - " plt.xlabel(r\"$\\theta$ [arcmin]\", fontsize=26)\n", - " plt.ylabel(r\"$\\theta \\tau_2$\", fontsize=26)\n", - " plt.xscale(\"log\")\n", - " # plt.yscale('log')\n", - " plt.legend(loc=\"upper left\", fontsize=8)\n", - "\n", - " if savefile is not None:\n", - " plt.savefig(savefile, bbox_inches=\"tight\")\n", - "\n", - " plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "root_to_plot = [\n", - " \"SP_v1.4.5_A\",\n", - " # \"SP_v1.4.5_A_no_IA\",\n", - " # \"SP_v1.4.5_A_no_dz\",\n", - " # \"SP_v1.4.5_A_no_m_bias\",\n", - " \"SP_v1.4.5_A_sc_3_150\",\n", - " \"SP_v1.4.5_A_sc_3_60\",\n", - " \"SP_v1.4.5_A_sc_10_150\",\n", - " \"SP_v1.4.5_A_sc_10_60\",\n", - " \"SP_v1.4.5_A_sc_5_150\",\n", - " \"SP_v1.4.5_A_sc_7_150\",\n", - " # \"SP_v1.4.5_A_no_leakage\"\n", - "]\n", - "\n", - "root_to_plot = [\n", - " f\"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_{int(i)}.0_80.0_10.0_80.0\"\n", - " for i in [3, 5, 7, 10, 11]\n", - "]\n", - "\n", - "colours = [\n", - " \"red\",\n", - " \"salmon\",\n", - " \"darkorange\",\n", - " \"forestgreen\",\n", - " \"turquoise\",\n", - " \"darkviolet\",\n", - " \"crimson\",\n", - " \"gold\",\n", - " \"lightcoral\",\n", - " \"mediumseagreen\",\n", - " \"lightsteelblue\",\n", - " \"black\",\n", - " \"silver\",\n", - " \"peru\",\n", - " \"maroon\",\n", - " \"olive\",\n", - "]\n", - "\n", - "savefile = \"best_fit_tau_new_binning.png\"\n", - "\n", - "plot_best_fit_tau(root_to_plot, colours, savefile)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pseudo_cell = fits.open(\n", - " \"/home/guerrini/sp_validation/cosmo_val/output/pseudo_cl_SP_v1.4.5.fits\"\n", - ")[1].data\n", - "cov_pseudo_cell = fits.open(\n", - " \"/home/guerrini/sp_validation/cosmo_val/output/pseudo_cl_cov_SP_v1.4.5.fits\"\n", - ")\n", - "\n", - "theory_ell = np.loadtxt(\n", - " \"/n09data/guerrini/output_chains/best_fit/SP_v1.4.5_A/shear_cl/ell.txt\"\n", - ")\n", - "theory_cell = np.loadtxt(\n", - " \"/n09data/guerrini/output_chains/best_fit/SP_v1.4.5_A/shear_cl/bin_1_1.txt\"\n", - ")\n", - "\n", - "pw = hp.pixwin(1024, lmax=2048)\n", - "\n", - "plt.errorbar(\n", - " pseudo_cell[\"ELL\"],\n", - " pseudo_cell[\"ELL\"] * pseudo_cell[\"EE\"],\n", - " yerr=pseudo_cell[\"ELL\"] * np.sqrt(np.diag(cov_pseudo_cell[\"COVAR_EE_EE\"].data)),\n", - " capsize=2,\n", - " c=\"k\",\n", - " fmt=\"o\",\n", - " markersize=2,\n", - ")\n", - "\n", - "mask = (theory_ell > 0.1) & (theory_ell < 2048)\n", - "plt.plot(\n", - " theory_ell[mask],\n", - " theory_ell[mask]\n", - " * theory_cell[mask]\n", - " * np.interp(theory_ell[mask], np.arange(0, 2049), pw) ** 2,\n", - " c=\"r\",\n", - " label=\"best-fit $\\\\theta \\\\in [3-200]$\",\n", - ")\n", - "\n", - "plt.xlabel(r\"$\\ell$\", fontsize=26)\n", - "plt.ylabel(r\"$\\ell C_\\ell^{EE}$\", fontsize=26)\n", - "plt.legend()\n", - "plt.savefig(\"SP_v1.4.5_A_cell.png\")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cov_pseudo_cell.info()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "sp_validation_3.11", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/cosmo_inference/get_chi2_cell.ipynb b/cosmo_inference/get_chi2_cell.ipynb deleted file mode 100644 index c97748d1..00000000 --- a/cosmo_inference/get_chi2_cell.ipynb +++ /dev/null @@ -1,1527 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "\n", - "# Trick to plot with tex\n", - "os.environ[\"LD_LIBRARY_PATH\"] = \"\"\n", - "os.environ[\"CONDA_PREFIX\"] = \"/home/guerrini/.conda/envs/sp_validation\"\n", - "\n", - "import configparser\n", - "import subprocess\n", - "\n", - "import healpy as hp\n", - "import matplotlib.pyplot as plt\n", - "import matplotlib.scale as mscale\n", - "import matplotlib.ticker as ticker\n", - "import matplotlib.transforms as mtransforms\n", - "import numpy as np\n", - "import scipy.stats as stats\n", - "import seaborn as sns\n", - "from astropy.io import fits\n", - "from getdist import plots\n", - "from IPython.display import Markdown, display\n", - "from scipy.interpolate import interp1d\n", - "\n", - "plt.style.use(\"../papers/harmonic/matplotlib_config/paper.mplstyle\")\n", - "\n", - "plt.rcParams[\"text.usetex\"] = True\n", - "\n", - "sns.set_palette(\"husl\")\n", - "\n", - "\n", - "class SquareRootScale(mscale.ScaleBase):\n", - " \"\"\"\n", - " ScaleBase class for generating square root scale.\n", - "\n", - " Usage example: axis.set_yscale('squareroot')\n", - "\n", - " \"\"\"\n", - "\n", - " name = \"squareroot\"\n", - "\n", - " def __init__(self, axis, **kwargs):\n", - " mscale.ScaleBase.__init__(self, axis, **kwargs)\n", - "\n", - " def set_default_locators_and_formatters(self, axis):\n", - " axis.set_major_locator(ticker.AutoLocator())\n", - " axis.set_major_formatter(ticker.ScalarFormatter())\n", - " axis.set_minor_locator(ticker.NullLocator())\n", - " axis.set_minor_formatter(ticker.NullFormatter())\n", - "\n", - " def limit_range_for_scale(self, vmin, vmax, minpos):\n", - " return max(0.0, vmin), vmax\n", - "\n", - " class SquareRootTransform(mtransforms.Transform):\n", - " input_dims = 1\n", - " output_dims = 1\n", - " is_separable = True\n", - "\n", - " def transform_non_affine(self, a):\n", - " return np.array(a) ** 0.5\n", - "\n", - " def inverted(self):\n", - " return SquareRootScale.InvertedSquareRootTransform()\n", - "\n", - " class InvertedSquareRootTransform(mtransforms.Transform):\n", - " input_dims = 1\n", - " output_dims = 1\n", - " is_separable = True\n", - "\n", - " def transform(self, a):\n", - " return np.array(a) ** 2\n", - "\n", - " def inverted(self):\n", - " return SquareRootScale.SquareRootTransform()\n", - "\n", - " def get_transform(self):\n", - " return self.SquareRootTransform()\n", - "\n", - "\n", - "mscale.register_scale(SquareRootScale)\n", - "%matplotlib inline\n", - "# import uncertainties\n", - "\n", - "plt.rc(\"mathtext\", fontset=\"stix\")\n", - "plt.rc(\"font\", family=\"sans-serif\")\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "g.settings.axes_fontsize = 30\n", - "g.settings.axes_labelsize = 30\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 40\n", - "\n", - "\n", - "# SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE\n", - "root_dir = \"/n09data/guerrini/output_chains/\"\n", - "\n", - "catalog_version = \"SP_v1.4.6_leak_corr_cell\"\n", - "catalog_version_real_space = \"SP_v1.4.6_leak_corr_A_10_80\"\n", - "\n", - "path_ini_files = \"/home/guerrini/sp_validation/cosmo_inference/cosmosis_config/\"\n", - "\n", - "roots = [\n", - " \"SP_v1.4.6_leak_corr_A_lmin=300_lmax=1600_cell\",\n", - " \"SP_v1.4.6_leak_corr_B_lmin=300_lmax=1600_cell\",\n", - " \"SP_v1.4.6_leak_corr_C_lmin=300_lmax=1600_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_10_80\",\n", - " # f\"SP_v1.4.6_leak_corr_A_kmax=5Mpc_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_kmax=3Mpc_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_kmax=1Mpc_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_include_large_scales_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_small_scales_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_large_scales_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_halofit_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_HMCode_nobar_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_OneCov_cell\",\n", - " \"SP_v1.4.6_A_fid_cell\",\n", - "]\n", - "\n", - "labels = [\n", - " r\"UNIONS $C_\\ell$, Blind A\",\n", - " r\"UNIONS $C_\\ell$, Blind B\",\n", - " r\"UNIONS $C_\\ell$, Blind C\",\n", - " r\"UNIONS $\\xi_\\pm(\\vartheta)$, (Goh et al., 2026)\",\n", - " # rf\"$k_\\mathrm{{max}}=5 h$ Mpc$^{{-1}}$, $\\ell_\\mathrm{{max}}=2048$\",\n", - " r\"$k_\\mathrm{max}=3 h$ Mpc$^{-1}$, $\\ell_\\mathrm{max}=1800$\",\n", - " r\"$k_\\mathrm{max}=1 h$ Mpc$^{-1}$, $\\ell_\\mathrm{max}=500$\",\n", - " r\"Include Large Scales, $\\ell_\\mathrm{max}=1600$\",\n", - " \"Small Scales only\",\n", - " \"Large Scales only\",\n", - " r\"Halofit\",\n", - " r\"HMCode no baryons\",\n", - " \"OneCovariance only\",\n", - " \"No leakage correction\",\n", - "]\n", - "\n", - "bases = [\n", - " \"harmonic\",\n", - " \"harmonic\",\n", - " \"harmonic\",\n", - " \"configuration\",\n", - " \"harmonic\",\n", - " \"harmonic\",\n", - " \"harmonic\",\n", - " \"harmonic\",\n", - " \"harmonic\",\n", - " \"harmonic\",\n", - " \"harmonic\",\n", - " \"harmonic\",\n", - " \"harmonic\",\n", - " \"harmonic\",\n", - "]\n", - "\n", - "\n", - "properties = {}\n", - "\n", - "for i, root in enumerate(roots):\n", - " config = configparser.ConfigParser()\n", - " config.optionxform = str # Preserve case sensitivity of option names\n", - " config.read(path_ini_files + f\"/cosmosis_pipeline_{root}.ini\")\n", - "\n", - " try:\n", - " lower_bound_cell_ee, upper_bound_cell_ee = map(\n", - " float, config[\"2pt_like\"][\"angle_range_CELL_EE_1_1\"].split()\n", - " )\n", - "\n", - " properties[root] = {\n", - " \"lower_bound_cell_ee\": lower_bound_cell_ee,\n", - " \"upper_bound_cell_ee\": upper_bound_cell_ee,\n", - " }\n", - " except KeyError:\n", - " properties[root] = {\"lower_bound_cell_ee\": 0.0, \"upper_bound_cell_ee\": 2048.0}\n", - "\n", - " if bases[i] == \"configuration\":\n", - " # Also save the scale cuts in theta for xi\n", - " add_xi_sys = config[\"2pt_like\"][\"add_xi_sys\"]\n", - " add_xi_sys = add_xi_sys == \"T\"\n", - " lower_bound_xi_plus, upper_bound_xi_plus = map(\n", - " float, config[\"2pt_like\"][\"angle_range_XI_PLUS_1_1\"].split()\n", - " )\n", - " lower_bound_xi_minus, upper_bound_xi_minus = map(\n", - " float, config[\"2pt_like\"][\"angle_range_XI_MINUS_1_1\"].split()\n", - " )\n", - "\n", - " properties[root].update(\n", - " {\n", - " \"add_xi_sys\": add_xi_sys,\n", - " \"lower_bound_xi_plus\": lower_bound_xi_plus,\n", - " \"upper_bound_xi_plus\": upper_bound_xi_plus,\n", - " \"lower_bound_xi_minus\": lower_bound_xi_minus,\n", - " \"upper_bound_xi_minus\": upper_bound_xi_minus,\n", - " }\n", - " )\n", - "\n", - "\n", - "print(roots)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Retrieve the chains" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# MAKE PARAMNAMES FILE\n", - "\n", - "for root in roots:\n", - " with open(root_dir + \"{}/samples_{}.txt\".format(\"/\" + root, root), \"r\") as file:\n", - " params = file.readline()[1:].split(\"\\t\")[:-4]\n", - " file.close()\n", - "\n", - " with open(\n", - " root_dir + \"{}/getdist_{}.paramnames\".format(\"/\" + root, root), \"w\"\n", - " ) as file:\n", - " for i in range(len(params)):\n", - " if len(params[i].split(\"--\")) > 1:\n", - " file.write(params[i].split(\"--\")[1] + \"\\n\")\n", - " else:\n", - " file.write(params[i].split(\"--\")[0] + \"\\n\")\n", - " file.close()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# READ CHAIN\n", - "\n", - "chains = []\n", - "\n", - "for root in roots:\n", - " samples = np.loadtxt(root_dir + \"{}/samples_{}.txt\".format(root, root))\n", - " print(len(samples))\n", - " if \"nautilus\" in root:\n", - " samples = np.column_stack(\n", - " (np.exp(samples[:, -3]), samples[:, -1] - samples[:, -2], samples[:, 0:-3])\n", - " )\n", - " else:\n", - " samples = np.column_stack((samples[:, -1], samples[:, -3], samples[:, 0:-4]))\n", - " np.savetxt(root_dir + \"{}/getdist_{}.txt\".format(root, root), samples)\n", - "\n", - " chain = g.samples_for_root(\n", - " root_dir + \"{}/getdist_{}\".format(root, root),\n", - " cache=False,\n", - " settings={\"ignore_rows\": 0, \"smooth_scale_2D\": 0.3, \"smooth_scale_1D\": 0.3},\n", - " )\n", - "\n", - " chains.append(chain)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "name_list = [\n", - " \"OMEGA_M\",\n", - " \"ombh2\",\n", - " \"h0\",\n", - " \"n_s\",\n", - " \"SIGMA_8\",\n", - " \"s_8_input\",\n", - " \"logt_agn\",\n", - " \"a\",\n", - " \"m1\",\n", - " \"bias_1\",\n", - "]\n", - "label_list = [\n", - " r\"\\Omega_m\",\n", - " r\"\\omega_b h^2\",\n", - " \"h_0\",\n", - " \"n_s\",\n", - " r\"\\sigma_8\",\n", - " \"S_8\",\n", - " \"log T_{AGN}\",\n", - " \"A_{IA}\",\n", - " \"m_1\",\n", - " r\"\\Delta z_1\",\n", - "]\n", - "\n", - "for chain in chains:\n", - " param_names = chain.getParamNames()\n", - " for name, label in zip(name_list, label_list):\n", - " param_names.parWithName(name).label = label" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Extract the best fit parameters" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "best_fit = {}\n", - "\n", - "for root, chain in zip(roots, chains):\n", - " print(root)\n", - " likestats = chain.getLikeStats()\n", - " bestfit_idx = np.argmax(chain.loglikes)\n", - " maxlike = chain.loglikes[bestfit_idx]\n", - " print(f\"Maximum Likelihood: {maxlike:.5g}\")\n", - " best_fit[root] = {\"likelihood\": maxlike}\n", - " margestats = chain.getMargeStats()\n", - " s8_stats = margestats.parWithName(\"S_8\")\n", - " sigma8_stats = margestats.parWithName(\"SIGMA_8\")\n", - " omegam_stats = margestats.parWithName(\"OMEGA_M\")\n", - " a_ia_stats = margestats.parWithName(\"a\")\n", - "\n", - " best_fit[root].update(\n", - " {\n", - " \"S_8_mean\": s8_stats.mean,\n", - " \"S_8_lower\": s8_stats.mean - s8_stats.limits[0].lower,\n", - " \"S_8_upper\": s8_stats.limits[0].upper - s8_stats.mean,\n", - " \"sigma_8_mean\": sigma8_stats.mean,\n", - " \"sigma_8_lower\": sigma8_stats.mean - sigma8_stats.limits[0].lower,\n", - " \"sigma_8_upper\": sigma8_stats.limits[0].upper - sigma8_stats.mean,\n", - " \"omega_m_mean\": omegam_stats.mean,\n", - " \"omega_m_lower\": omegam_stats.mean - omegam_stats.limits[0].lower,\n", - " \"omega_m_upper\": omegam_stats.limits[0].upper - omegam_stats.mean,\n", - " \"A_IA_mean\": a_ia_stats.mean,\n", - " \"A_IA_lower\": a_ia_stats.mean - a_ia_stats.limits[0].lower,\n", - " \"A_IA_upper\": a_ia_stats.limits[0].upper - a_ia_stats.mean,\n", - " }\n", - " )\n", - " try:\n", - " t_agn_stats = margestats.parWithName(\"logt_agn\")\n", - " best_fit[root].update(\n", - " {\n", - " \"logt_agn_mean\": t_agn_stats.mean,\n", - " \"logt_agn_lower\": t_agn_stats.mean - t_agn_stats.limits[0].lower,\n", - " \"logt_agn_upper\": t_agn_stats.limits[0].upper - t_agn_stats.mean,\n", - " }\n", - " )\n", - " except Exception:\n", - " pass\n", - " for i, par in enumerate(likestats.names):\n", - " best_fit[root].update(\n", - " {par.name: np.average(chain.samples[:, i], weights=chain.weights)}\n", - " )" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Run `Cosmosis` in test mode to get the data vectors" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if not os.path.exists(path_ini_files + \"/values_empty.ini\"):\n", - " content = \"\"\"[cosmological_parameters]\n", - "\n", - "tau = 0.0544\n", - "w = -1.0\n", - "mnu = 0.06\n", - "omega_k = 0.0\n", - "wa = 0.0\n", - "\n", - "[halo_model_parameters]\n", - "\n", - "[intrinsic_alignment_parameters]\n", - "\n", - "[shear_calibration_parameters]\n", - "\n", - "[nofz_shifts]\n", - "\n", - "[psf_leakage_parameters]\n", - "\"\"\"\n", - "\n", - " with open(path_ini_files + \"/values_empty.ini\", \"w\") as f:\n", - " f.write(content)\n", - " f.close()\n", - "\n", - " print(\"File created successfully\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "section_map = {\n", - " \"omch2\": \"cosmological_parameters\",\n", - " \"ombh2\": \"cosmological_parameters\",\n", - " \"h0\": \"cosmological_parameters\",\n", - " \"n_s\": \"cosmological_parameters\",\n", - " \"s_8_input\": \"cosmological_parameters\",\n", - " \"logt_agn\": \"halo_model_parameters\",\n", - " \"a\": \"intrinsic_alignment_parameters\",\n", - " \"m1\": \"shear_calibration_parameters\",\n", - " \"bias_1\": \"nofz_shifts\",\n", - " \"alpha\": \"psf_leakage_parameters\",\n", - " \"beta\": \"psf_leakage_parameters\",\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "env = os.environ.copy()\n", - "env[\"LD_LIBRARY_PATH\"] = (\n", - " \"/home/guerrini/.conda/envs/sp_validation/lib/python3.9/site-packages/cosmosis/datablock:\"\n", - " + env.get(\"LD_LIBRARY_PATH\", \"\")\n", - ")\n", - "\n", - "for root in roots:\n", - " print(root)\n", - " config = configparser.ConfigParser()\n", - " config.optionxform = str # Preserve case sensitivity of option names\n", - " config.read(path_ini_files + \"/values_empty.ini\")\n", - " for param, value in best_fit[root].items():\n", - " section = section_map.get(param)\n", - " if section is None:\n", - " continue\n", - " if section not in config:\n", - " config.add_section(section)\n", - " config[section][param] = str(value)\n", - "\n", - " with open(path_ini_files + \"/values_empty.ini\", \"w\") as configfile:\n", - " config.write(configfile)\n", - "\n", - " # Modify the ini file to run in test mode at the best fit\n", - " config = configparser.ConfigParser()\n", - " config.optionxform = str # Preserve case sensitivity of option names\n", - " config.read(path_ini_files + f\"/cosmosis_pipeline_{root}.ini\")\n", - "\n", - " sampler = config[\"runtime\"][\"sampler\"]\n", - " config[\"runtime\"][\"sampler\"] = \"test\"\n", - " values = config[\"pipeline\"][\"values\"]\n", - " config[\"pipeline\"][\"values\"] = path_ini_files + \"/values_empty.ini\"\n", - "\n", - " with open(path_ini_files + f\"/cosmosis_pipeline_{root}.ini\", \"w\") as configfile:\n", - " config.write(configfile)\n", - "\n", - " # Run cosmosis\n", - " result = subprocess.run(\n", - " [\"cosmosis\", \"cosmosis_config/cosmosis_pipeline_{}.ini\".format(root)],\n", - " env=env,\n", - " capture_output=True,\n", - " text=True,\n", - " )\n", - " print(f\"STDOUT:\\n{result.stdout}\")\n", - " print(f\"STDERR:\\n{result.stderr}\")\n", - "\n", - " # Modify the ini file to the previous one\n", - " config[\"pipeline\"][\"values\"] = values\n", - " config[\"runtime\"][\"sampler\"] = sampler\n", - "\n", - " with open(path_ini_files + f\"/cosmosis_pipeline_{root}.ini\", \"w\") as configfile:\n", - " config.write(configfile)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Compute the $\\chi^2$" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "output_folder = \"/n09data/guerrini/output_chains/\"\n", - "\n", - "metrics = {}\n", - "\n", - "for i, root in enumerate(roots):\n", - " print(root)\n", - "\n", - " base = bases[i]\n", - "\n", - " if base == \"harmonic\":\n", - " # Remove cell from the end of root\n", - " root_cell_removed = root.replace(\"_cell\", \"\")\n", - "\n", - " lower_bound_cell_ee = properties[root][\"lower_bound_cell_ee\"]\n", - " upper_bound_cell_ee = properties[root][\"upper_bound_cell_ee\"]\n", - " print(upper_bound_cell_ee)\n", - "\n", - " # Read the results\n", - " ell = np.loadtxt(output_folder + \"best_fit/{}/shear_cl/ell.txt\".format(root))\n", - " shear_cl = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_cl/bin_1_1.txt\".format(root)\n", - " )\n", - "\n", - " # Read the data\n", - " data = fits.open(f\"data/{root_cell_removed}/cosmosis_{root}.fits\")\n", - "\n", - " ell_data = data[\"CELL_EE\"].data[\"ANG\"]\n", - " cell_data = data[\"CELL_EE\"].data[\"VALUE\"]\n", - "\n", - " # Load the covariance\n", - " cov = data[\"COVMAT\"].data\n", - " cov_cell = cov\n", - "\n", - " # interpolate the model\n", - " interp_cell_ee = interp1d(ell, shear_cl, kind=\"cubic\", fill_value=\"extrapolate\")\n", - "\n", - " cell_model = interp_cell_ee(ell_data)\n", - "\n", - " # Apply scale cuts\n", - " mask_cell = (ell_data > lower_bound_cell_ee) & (ell_data < upper_bound_cell_ee)\n", - " cell_data = cell_data[mask_cell]\n", - " cell_model = cell_model[mask_cell]\n", - " cov_cell = cov_cell[mask_cell][:, mask_cell]\n", - "\n", - " cell_chi2 = np.dot(\n", - " (cell_model - cell_data),\n", - " np.dot(np.linalg.inv(cov_cell), (cell_model - cell_data)),\n", - " )\n", - " n_dof_cell = np.sum(mask_cell)\n", - " print(n_dof_cell)\n", - " n_dof_cell -= 9\n", - " p_value_cell = 1 - stats.chi2.cdf(cell_chi2, n_dof_cell)\n", - "\n", - " metrics[root] = {\n", - " \"chi2\": cell_chi2,\n", - " \"n_dof\": n_dof_cell,\n", - " \"p_value\": p_value_cell,\n", - " }\n", - "\n", - " elif base == \"configuration\":\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - "\n", - " # Read model tau_stats\n", - " theta_tau = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_0_plus/theta.txt\".format(root)\n", - " )\n", - " theta_tau_arcmin = theta_tau * 180 * 60 / np.pi\n", - " tau_0_model = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_0_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " tau_2_model = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_2_plus/bin_1_1.txt\".format(root)\n", - " )\n", - "\n", - " # Read the data\n", - " data = fits.open(\n", - " f\"data/{catalog_version_real_space}/cosmosis_{catalog_version_real_space}.fits\"\n", - " )\n", - "\n", - " theta_data = data[\"XI_PLUS\"].data[\"ANG\"]\n", - " xi_plus_data = data[\"XI_PLUS\"].data[\"VALUE\"]\n", - " xi_minus_data = data[\"XI_MINUS\"].data[\"VALUE\"]\n", - " tau_0_data = data[\"TAU_0_PLUS\"].data[\"VALUE\"]\n", - " tau_2_data = data[\"TAU_2_PLUS\"].data[\"VALUE\"]\n", - "\n", - " # Load the covariance\n", - " cov = data[\"COVMAT\"].data\n", - " cov_xi = cov[0 : 2 * len(xi_plus_data), 0 : 2 * len(xi_plus_data)]\n", - " cov_tau = cov[2 * len(xi_plus_data) :, 2 * len(xi_plus_data) :]\n", - "\n", - " # interpolate the model\n", - " interp_xi_plus = interp1d(\n", - " theta_arcmin, shear_xi_plus, kind=\"cubic\", fill_value=\"extrapolate\"\n", - " )\n", - " interp_xi_minus = interp1d(\n", - " theta_arcmin, shear_xi_minus, kind=\"cubic\", fill_value=\"extrapolate\"\n", - " )\n", - "\n", - " xi_plus_model = interp_xi_plus(theta_data)\n", - " if add_xi_sys:\n", - " xi_plus_model += xi_sys_plus\n", - " xi_minus_model = interp_xi_minus(theta_data)\n", - " if add_xi_sys:\n", - " xi_minus_model += xi_sys_minus\n", - "\n", - " # Concatenate the data vector\n", - " xi_data = np.concatenate((xi_plus_data, xi_minus_data))\n", - " xi_model = np.concatenate((xi_plus_model, xi_minus_model))\n", - "\n", - " tau_data = np.concatenate((tau_0_data, tau_2_data))\n", - " tau_model = np.concatenate((tau_0_model, tau_2_model))\n", - "\n", - " # Apply scale cuts\n", - " mask_xi_plus = (theta_data > lower_bound_xi_plus) & (\n", - " theta_data < upper_bound_xi_plus\n", - " )\n", - " mask_xi_minus = (theta_data > lower_bound_xi_minus) & (\n", - " theta_data < upper_bound_xi_minus\n", - " )\n", - " mask = np.concatenate((mask_xi_plus, mask_xi_minus))\n", - "\n", - " xi_data = xi_data[mask]\n", - " xi_model = xi_model[mask]\n", - " cov_xi = cov_xi[mask][:, mask]\n", - "\n", - " xi_plus_chi2 = np.dot(\n", - " (xi_model - xi_data), np.dot(np.linalg.inv(cov_xi), (xi_model - xi_data))\n", - " )\n", - " tau_chi2 = np.dot(\n", - " (tau_model - tau_data),\n", - " np.dot(np.linalg.inv(cov_tau), (tau_model - tau_data)),\n", - " )\n", - " n_dof_xi = np.sum(mask)\n", - " n_dof_xi -= 11\n", - " n_dof_tau = len(tau_0_data) + len(tau_2_data)\n", - " p_value_xi = 1 - stats.chi2.cdf(xi_plus_chi2, n_dof_xi)\n", - " p_value_tau = 1 - stats.chi2.cdf(tau_chi2, n_dof_tau)\n", - " chi2_tot = xi_plus_chi2 + tau_chi2\n", - " n_dof_tot = n_dof_xi + n_dof_tau\n", - " p_value_tot = 1 - stats.chi2.cdf(chi2_tot, n_dof_tot)\n", - "\n", - " metrics[root] = {\"chi2\": xi_plus_chi2, \"n_dof\": n_dof_xi, \"p_value\": p_value_xi}\n", - "\n", - " print(\"Done!\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def get_latex_table(metrics):\n", - " latex_lines = [\n", - " r\"\\begin{tabular}{|l|c|c|c|c|c|c|c|}\",\n", - " r\"\\hline\",\n", - " r\"Experiment name & $S_8$ & $\\Omega_m$ & $\\sigma_8$ & $A_\\mathrm{IA}$ & $\\log T_\\mathrm{AGN}$ & $\\chi^2$/dof & PTE \\\\ \",\n", - " r\"\\hline\",\n", - " ]\n", - "\n", - " for i, (root, vals) in enumerate(metrics.items()):\n", - " label = labels[i]\n", - " best_fit_vals = best_fit[root]\n", - " log_t_agn_mean = best_fit_vals.get(\"logt_agn_mean\", None)\n", - "\n", - " if log_t_agn_mean is None:\n", - " logt_agn_mean_str = \"N/A\"\n", - " else:\n", - " logt_agn_mean_str = f\"${best_fit_vals['logt_agn_mean']:.3f}^{{+{best_fit_vals['logt_agn_upper']:.3f}}}_{{-{best_fit_vals['logt_agn_lower']:.3f}}}$\"\n", - " line = (\n", - " f\"{label} & \"\n", - " rf\" ${best_fit_vals['S_8_mean']:.3f}^{{+{best_fit_vals['S_8_upper']:.3f}}}_{{-{best_fit_vals['S_8_lower']:.3f}}}$ & \"\n", - " rf\" ${best_fit_vals['omega_m_mean']:.3f}^{{+{best_fit_vals['omega_m_upper']:.3f}}}_{{-{best_fit_vals['omega_m_lower']:.3f}}}$ & \"\n", - " rf\" ${best_fit_vals['sigma_8_mean']:.3f}^{{+{best_fit_vals['sigma_8_upper']:.3f}}}_{{-{best_fit_vals['sigma_8_lower']:.3f}}}$ & \"\n", - " rf\" ${best_fit_vals['A_IA_mean']:.3f}^{{+{best_fit_vals['A_IA_upper']:.3f}}}_{{-{best_fit_vals['A_IA_lower']:.3f}}}$ & \"\n", - " rf\" {logt_agn_mean_str} & \"\n", - " f\"{vals['chi2']:.2f}/{vals['n_dof']} & {vals['p_value']:.5f} \\\\\\\\\"\n", - " )\n", - " latex_lines.append(line)\n", - "\n", - " latex_lines.append(r\"\\hline\")\n", - " latex_lines.append(r\"\\end{tabular}\")\n", - "\n", - " # Print LaTeX table\n", - " print(\"\\n\".join(latex_lines))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "get_latex_table(metrics)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def display_markdown(metrics):\n", - " # Build Markdown table\n", - " header = (\n", - " \"| Root | $\\\\chi^2$ ($C_\\\\ell$) / dof | p-val ($C_\\\\ell$) |\\n\"\n", - " \"|------|----------------|------------|\\n\"\n", - " )\n", - "\n", - " rows = []\n", - " for root, vals in metrics.items():\n", - " row = f\"| `{root}` \"\n", - " row += f\"| {vals['chi2']:.2f} / {vals['n_dof']} \"\n", - " row += f\"| {vals['p_value']:.5f} \"\n", - " rows.append(row)\n", - "\n", - " # Display in Jupyter\n", - " display(Markdown(header + \"\\n\".join(rows)))\n", - " return header + \"\\n\".join(rows)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "markdown_source = display_markdown(metrics)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "markdown_source" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Plot the best-fit of each model" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "catalog_version = \"SP_v1.4.6_leak_corr_A_lmin=300_lmax=1600\"\n", - "data = fits.open(\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{catalog_version}/cosmosis_{catalog_version}_cell.fits\"\n", - ")\n", - "cell_ee = data[\"CELL_EE\"].data\n", - "cov_mat = data[\"COVMAT\"].data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fig, ax = plt.subplots(1, 1, figsize=(15, 8))\n", - "\n", - "ell = cell_ee[\"ANG\"]\n", - "cell = cell_ee[\"VALUE\"]\n", - "\n", - "ax.errorbar(\n", - " ell,\n", - " ell * cell,\n", - " yerr=ell * np.sqrt(np.diag(cov)),\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - ")\n", - "ax.set_xlabel(r\"$\\ell$\")\n", - "ax.set_ylabel(r\"$\\ell C_\\ell$\")\n", - "ax.set_xlim(ell.min() - 10, ell.max() + 100)\n", - "ax.set_xscale(\"squareroot\")\n", - "ax.set_xticks(np.array([100, 400, 900, 1600]))\n", - "ax.minorticks_on()\n", - "ax.tick_params(axis=\"x\", which=\"minor\", length=2, width=0.8)\n", - "minor_ticks = [i * 10 for i in range(1, 10)] + [i * 100 for i in range(1, 21)]\n", - "ax.xaxis.set_ticks(minor_ticks, minor=True)\n", - "\n", - "plt.legend(fontsize=15)\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def plot_best_fit(\n", - " data_points,\n", - " root_to_plot,\n", - " line_args,\n", - " savefile,\n", - " ell_min=10.0,\n", - " ell_max=2048.0,\n", - " multiply_ell=True,\n", - " loc_legend=\"best\",\n", - " bbox_to_anchor=None,\n", - " label_data=\"Fiducial data\",\n", - " labels=None,\n", - "):\n", - " data = fits.open(\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{data_points}/cosmosis_{data_points}_cell.fits\"\n", - " )\n", - " cell_ee = data[\"CELL_EE\"].data\n", - " cov_mat = data[\"COVMAT\"].data\n", - "\n", - " if labels is None:\n", - " labels = root_to_plot\n", - "\n", - " fig, ax = plt.subplots(1, 1, figsize=(8, 5))\n", - "\n", - " ell, cell = cell_ee[\"ANG\"], cell_ee[\"VALUE\"]\n", - " ax.errorbar(\n", - " ell,\n", - " ell * cell,\n", - " yerr=ell * np.sqrt(np.diag(cov_mat)),\n", - " fmt=\"o\",\n", - " label=label_data,\n", - " color=\"black\",\n", - " capsize=2,\n", - " )\n", - "\n", - " for idx, (label, root) in enumerate(zip(labels, root_to_plot)):\n", - " # Read the results\n", - " ell = np.loadtxt(output_folder + \"best_fit/{}/shear_cl/ell.txt\".format(root))\n", - " shear_cl = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_cl/bin_1_1.txt\".format(root)\n", - " )\n", - "\n", - " mask = (ell > ell_min) & (ell < ell_max)\n", - "\n", - " ax.plot(\n", - " ell[mask],\n", - " ell[mask] * shear_cl[mask] if multiply_ell else shear_cl[mask],\n", - " label=label,\n", - " **line_args[idx],\n", - " )\n", - "\n", - " # Plot the scale cuts for different k_max\n", - " ax.axvline(x=1800, color=\"black\", linestyle=\"--\", alpha=0.5)\n", - " ax.axvline(x=2048, color=\"black\", linestyle=\"--\", alpha=1.0)\n", - " ax.axvline(x=500, color=\"black\", linestyle=\"--\", alpha=0.3)\n", - "\n", - " # Add labels directly under the tick\n", - " ax.text(\n", - " 1740,\n", - " 0.90,\n", - " r\"$k_\\mathrm{max} = 3 h$ Mpc$^{-1}$\",\n", - " transform=ax.get_xaxis_transform(),\n", - " ha=\"center\",\n", - " va=\"top\",\n", - " fontsize=14,\n", - " rotation=90,\n", - " )\n", - "\n", - " ax.text(\n", - " 1978,\n", - " 0.90,\n", - " r\"$k_\\mathrm{max} = 5 h$ Mpc$^{-1}$\",\n", - " transform=ax.get_xaxis_transform(),\n", - " ha=\"center\",\n", - " va=\"top\",\n", - " fontsize=14,\n", - " rotation=90,\n", - " )\n", - "\n", - " ax.text(\n", - " 470,\n", - " 0.90,\n", - " r\"$k_\\mathrm{max} = 1 h$ Mpc$^{-1}$\",\n", - " transform=ax.get_xaxis_transform(),\n", - " ha=\"center\",\n", - " va=\"top\",\n", - " fontsize=14,\n", - " rotation=90,\n", - " )\n", - "\n", - " ell, cell = cell_ee[\"ANG\"], cell_ee[\"VALUE\"]\n", - " ax.set_ylabel(r\"$\\ell C_\\ell \\times 10^{-7}$\", fontsize=20)\n", - " ax.set_xlabel(r\"Multipole $\\ell$\", fontsize=20)\n", - " ax.set_xlim(ell.min() - 10, ell.max() + 100)\n", - " ax.set_xscale(\"squareroot\")\n", - " ax.set_xticks(np.array([100, 400, 900, 1600]))\n", - " ax.minorticks_on()\n", - " ax.tick_params(axis=\"x\", which=\"minor\", length=2, width=0.8)\n", - " minor_ticks = [i * 10 for i in range(1, 10)] + [i * 100 for i in range(1, 21)]\n", - " ax.xaxis.set_ticks(minor_ticks, minor=True)\n", - " ax.tick_params(axis=\"both\", which=\"major\", labelsize=14)\n", - " ax.tick_params(axis=\"both\", which=\"minor\", labelsize=10)\n", - " ax.yaxis.get_offset_text().set_visible(False)\n", - "\n", - " plt.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor, fontsize=11)\n", - "\n", - " if savefile is not None:\n", - " plt.savefig(savefile, bbox_inches=\"tight\")\n", - "\n", - " plt.show()\n", - "\n", - "\n", - "def plot_best_fit_ratio(\n", - " root_to_plot, colours, savefile, theta_min=1.0, theta_max=250.0\n", - "):\n", - " data = fits.open(\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{catalog_version}/cosmosis_{catalog_version}.fits\"\n", - " )\n", - " xi_plus = data[\"XI_PLUS\"].data\n", - " xi_minus = data[\"XI_MINUS\"].data\n", - " cov_mat = data[\"COVMAT\"].data\n", - "\n", - " plt.figure(figsize=(15, 15))\n", - "\n", - " plt.subplot(211)\n", - "\n", - " root = roots[0]\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/theta.txt\".format(root)\n", - " )\n", - " theta_xi_sys_arcmin = theta_xi_sys * 180 * 60 / np.pi\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - " xi_plus_model_fiducial = shear_xi_plus[mask]\n", - " if add_xi_sys:\n", - " xi_plus_model_fiducial += np.interp(\n", - " theta_arcmin[mask], theta_xi_sys_arcmin, xi_sys_plus\n", - " )\n", - "\n", - " plt.errorbar(\n", - " xi_plus[\"ANG\"],\n", - " xi_plus[\"VALUE\"]\n", - " / np.interp(xi_plus[\"ANG\"], theta_arcmin[mask], xi_plus_model_fiducial),\n", - " yerr=np.sqrt(np.diag(cov_mat))[:20]\n", - " / np.abs(np.interp(xi_plus[\"ANG\"], theta_arcmin[mask], xi_plus_model_fiducial)),\n", - " fmt=\"o\",\n", - " label=f\"{catalog_version} data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - " )\n", - "\n", - " for root, color in zip(root_to_plot, colours):\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/theta.txt\".format(root)\n", - " )\n", - " theta_xi_sys_arcmin = theta_xi_sys * 180 * 60 / np.pi\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - " xi_plus_model = shear_xi_plus[mask]\n", - " if add_xi_sys:\n", - " xi_plus_model += np.interp(\n", - " theta_arcmin[mask], theta_xi_sys_arcmin, xi_sys_plus\n", - " )\n", - "\n", - " alpha = 1.0 if root == roots[0] else 0.5\n", - " plt.plot(\n", - " theta_arcmin[mask],\n", - " xi_plus_model / xi_plus_model_fiducial,\n", - " color=color,\n", - " label=root,\n", - " alpha=alpha,\n", - " )\n", - " plt.axvline(x=lower_bound_xi_plus, color=color, linestyle=\"--\", alpha=0.3)\n", - " plt.axvline(x=upper_bound_xi_plus, color=color, linestyle=\"--\", alpha=0.3)\n", - "\n", - " plt.ylabel(r\"$\\xi_{+}/\\xi_{+, \\text{fid}}$\", fontsize=26)\n", - " plt.xscale(\"log\")\n", - " # plt.yscale('log')\n", - " plt.legend(loc=\"lower left\", fontsize=8)\n", - "\n", - " plt.subplot(212)\n", - "\n", - " root = roots[0]\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/theta.txt\".format(root)\n", - " )\n", - " theta_xi_sys_arcmin = theta_xi_sys * 180 * 60 / np.pi\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - " xi_minus_model_fiducial = shear_xi_minus[mask]\n", - " if add_xi_sys:\n", - " xi_minus_model_fiducial += np.interp(\n", - " theta_arcmin[mask], theta_xi_sys_arcmin, xi_sys_minus\n", - " )\n", - "\n", - " plt.errorbar(\n", - " xi_minus[\"ANG\"],\n", - " xi_minus[\"VALUE\"]\n", - " / np.interp(xi_minus[\"ANG\"], theta_arcmin[mask], xi_minus_model_fiducial),\n", - " yerr=np.sqrt(np.diag(cov_mat))[20:40]\n", - " / np.abs(\n", - " np.interp(xi_minus[\"ANG\"], theta_arcmin[mask], xi_minus_model_fiducial)\n", - " ),\n", - " fmt=\"o\",\n", - " label=f\"{catalog_version} data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - " )\n", - "\n", - " for root, color in zip(root_to_plot, colours):\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = np.loadtxt(\n", - " output_folder + \"best_fit/{}/xi_sys/theta.txt\".format(root)\n", - " )\n", - " theta_xi_sys_arcmin = theta_xi_sys * 180 * 60 / np.pi\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - " xi_minus_model = shear_xi_minus[mask]\n", - " if add_xi_sys:\n", - " xi_minus_model += np.interp(\n", - " theta_arcmin[mask], theta_xi_sys_arcmin, xi_sys_minus\n", - " )\n", - "\n", - " alpha = 1.0 if root == roots[0] else 0.5\n", - " plt.plot(\n", - " theta_arcmin[mask],\n", - " xi_minus_model / xi_minus_model_fiducial,\n", - " color=color,\n", - " label=root,\n", - " alpha=alpha,\n", - " )\n", - " plt.axvline(x=lower_bound_xi_minus, color=color, linestyle=\"--\", alpha=0.3)\n", - " plt.axvline(x=upper_bound_xi_minus, color=color, linestyle=\"--\", alpha=0.3)\n", - "\n", - " plt.xlabel(r\"$\\theta$ [arcmin]\", fontsize=26)\n", - " plt.ylabel(r\"$\\xi_{-}/\\xi_{-, \\text{fid}}$\", fontsize=26)\n", - " plt.xscale(\"log\")\n", - " plt.ylim(0, 2)\n", - " # plt.yscale('log')\n", - " plt.legend(loc=\"lower left\", fontsize=8)\n", - "\n", - " if savefile is not None:\n", - " plt.savefig(savefile, bbox_inches=\"tight\")\n", - "\n", - " plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "plt.rcParams.update({\"font.family\": \"serif\"})\n", - "\n", - "root_to_plot = [\n", - " \"SP_v1.4.6_leak_corr_A_lmin=300_lmax=1600_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_halofit_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_10_80\",\n", - "]\n", - "\n", - "labels = [\n", - " r\"UNIONS $C_\\ell$, Blind A\",\n", - " r\"UNIONS $C_\\ell$, Halofit\",\n", - " r\"UNIONS $\\xi_\\pm(\\vartheta)$ (Goh et al., 2026)\",\n", - "]\n", - "\n", - "line_args = [\n", - " {\"color\": \"royalblue\", \"linestyle\": \"-\"},\n", - " {\"color\": \"royalblue\", \"linestyle\": \"--\"},\n", - " {\"color\": \"orange\", \"linestyle\": \"-\"},\n", - "]\n", - "\n", - "log_legend = \"lower center\"\n", - "bbox_to_anchor = (0.685, 0.70)\n", - "\n", - "savefile = \"../papers/harmonic/plots/paperplot_Cell_EE_and_best_fit.png\"\n", - "\n", - "plot_best_fit(\n", - " catalog_version,\n", - " root_to_plot,\n", - " line_args,\n", - " savefile,\n", - " labels=labels,\n", - " loc_legend=log_legend,\n", - " bbox_to_anchor=bbox_to_anchor,\n", - ")\n", - "\n", - "savefile = \"../papers/harmonic/plots/paperplot_Cell_EE_and_best_fit.pdf\"\n", - "\n", - "plot_best_fit(\n", - " catalog_version,\n", - " root_to_plot,\n", - " line_args,\n", - " savefile,\n", - " labels=labels,\n", - " loc_legend=log_legend,\n", - " bbox_to_anchor=bbox_to_anchor,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "root_to_plot = [\n", - " \"SP_v1.4.6_leak_corr_A_small_scales_cell\",\n", - " \"SP_v1.4.6_leak_corr_A_large_scales_cell\",\n", - "]\n", - "\n", - "labels = [r\"Small scales only\", r\"Large scales only\"]\n", - "\n", - "line_args = [\n", - " {\"color\": \"royalblue\", \"linestyle\": \"-\"},\n", - " {\"color\": \"royalblue\", \"linestyle\": \"--\"},\n", - "]\n", - "\n", - "savefile = \"../papers/harmonic/plots/small_vs_large_scale.png\"\n", - "\n", - "plot_best_fit(catalog_version, root_to_plot, line_args, savefile, labels=labels)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# DEPRECATED code\n", - "\n", - "root_to_plot = [\n", - " \"SP_v1.4.5_A\",\n", - " # \"SP_v1.4.5_A_no_IA\",\n", - " # \"SP_v1.4.5_A_no_dz\",\n", - " # \"SP_v1.4.5_A_no_m_bias\",\n", - " \"SP_v1.4.5_A_sc_3_150\",\n", - " \"SP_v1.4.5_A_sc_3_60\",\n", - " \"SP_v1.4.5_A_sc_10_150\",\n", - " \"SP_v1.4.5_A_sc_10_60\",\n", - " \"SP_v1.4.5_A_sc_5_150\",\n", - " \"SP_v1.4.5_A_sc_7_150\",\n", - " # \"SP_v1.4.5_A_no_leakage\"\n", - "]\n", - "\n", - "\"\"\" root_to_plot = [\n", - " f\"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_{int(i)}.0_80.0_10.0_80.0\" for i in [3, 5, 7, 10, 11]\n", - "] \"\"\"\n", - "\n", - "root_to_plot = [\n", - " \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_10.0_80.0_10.0_80.0\",\n", - " \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_10.0_80.0_10.0_80.0_no_alpha_beta\",\n", - "]\n", - "\n", - "\n", - "colours = [\n", - " \"red\",\n", - " \"salmon\",\n", - " \"darkorange\",\n", - " \"forestgreen\",\n", - " \"turquoise\",\n", - " \"darkviolet\",\n", - " \"crimson\",\n", - " \"gold\",\n", - " \"lightcoral\",\n", - " \"mediumseagreen\",\n", - " \"lightsteelblue\",\n", - " \"black\",\n", - " \"silver\",\n", - " \"peru\",\n", - " \"maroon\",\n", - " \"olive\",\n", - "]\n", - "\n", - "savefile = \"best_fit_ratio_w_wo_leakage.png\"\n", - "\n", - "plot_best_fit_ratio(root_to_plot, colours, savefile)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def plot_best_fit_tau(root_to_plot, colours, savefile, theta_min=1.0, theta_max=250.0):\n", - " data = fits.open(\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{catalog_version}/cosmosis_{catalog_version}.fits\"\n", - " )\n", - " tau_0 = data[\"TAU_0_PLUS\"].data\n", - " tau_2 = data[\"TAU_2_PLUS\"].data\n", - " cov_mat = data[\"COVMAT\"].data\n", - "\n", - " plt.figure(figsize=(15, 15))\n", - "\n", - " plt.subplot(211)\n", - "\n", - " plt.errorbar(\n", - " tau_0[\"ANG\"],\n", - " tau_0[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[40:60],\n", - " fmt=\"o\",\n", - " label=f\"{catalog_version} data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - " )\n", - "\n", - " for root, color in zip(root_to_plot, colours):\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_0_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " tau_0_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_0_plus/bin_1_1.txt\".format(root)\n", - " )\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - "\n", - " plt.plot(\n", - " theta_arcmin[mask], tau_0_plus[mask], color=color, label=root, alpha=0.5\n", - " )\n", - "\n", - " plt.ylabel(r\"$\\tau_0$\", fontsize=26)\n", - " plt.xscale(\"log\")\n", - " # plt.yscale('log')\n", - " plt.legend(loc=\"upper right\", fontsize=8)\n", - "\n", - " plt.subplot(212)\n", - "\n", - " y_plot_tau_2 = tau_2[\"ANG\"] * tau_2[\"VALUE\"]\n", - " y_errorbar = tau_2[\"ANG\"] * np.sqrt(np.diag(cov_mat))[60:80]\n", - " plt.errorbar(\n", - " tau_2[\"ANG\"],\n", - " y_plot_tau_2,\n", - " yerr=y_errorbar,\n", - " fmt=\"o\",\n", - " label=f\"{catalog_version} data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - " )\n", - "\n", - " for root, color in zip(root_to_plot, colours):\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_2_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " tau_2_plus = np.loadtxt(\n", - " output_folder + \"best_fit/{}/tau_2_plus/bin_1_1.txt\".format(root)\n", - " )\n", - "\n", - " mask = (theta_arcmin > theta_min) & (theta_arcmin < theta_max)\n", - "\n", - " plt.plot(\n", - " theta_arcmin[mask],\n", - " theta_arcmin[mask] * tau_2_plus[mask],\n", - " color=color,\n", - " label=root,\n", - " alpha=0.5,\n", - " )\n", - "\n", - " plt.xlabel(r\"$\\theta$ [arcmin]\", fontsize=26)\n", - " plt.ylabel(r\"$\\theta \\tau_2$\", fontsize=26)\n", - " plt.xscale(\"log\")\n", - " # plt.yscale('log')\n", - " plt.legend(loc=\"upper left\", fontsize=8)\n", - "\n", - " if savefile is not None:\n", - " plt.savefig(savefile, bbox_inches=\"tight\")\n", - "\n", - " plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "root_to_plot = [\n", - " \"SP_v1.4.5_A\",\n", - " # \"SP_v1.4.5_A_no_IA\",\n", - " # \"SP_v1.4.5_A_no_dz\",\n", - " # \"SP_v1.4.5_A_no_m_bias\",\n", - " \"SP_v1.4.5_A_sc_3_150\",\n", - " \"SP_v1.4.5_A_sc_3_60\",\n", - " \"SP_v1.4.5_A_sc_10_150\",\n", - " \"SP_v1.4.5_A_sc_10_60\",\n", - " \"SP_v1.4.5_A_sc_5_150\",\n", - " \"SP_v1.4.5_A_sc_7_150\",\n", - " # \"SP_v1.4.5_A_no_leakage\"\n", - "]\n", - "\n", - "root_to_plot = [\n", - " f\"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_{int(i)}.0_80.0_10.0_80.0\"\n", - " for i in [3, 5, 7, 10, 11]\n", - "]\n", - "\n", - "colours = [\n", - " \"red\",\n", - " \"salmon\",\n", - " \"darkorange\",\n", - " \"forestgreen\",\n", - " \"turquoise\",\n", - " \"darkviolet\",\n", - " \"crimson\",\n", - " \"gold\",\n", - " \"lightcoral\",\n", - " \"mediumseagreen\",\n", - " \"lightsteelblue\",\n", - " \"black\",\n", - " \"silver\",\n", - " \"peru\",\n", - " \"maroon\",\n", - " \"olive\",\n", - "]\n", - "\n", - "savefile = \"best_fit_tau_new_binning.png\"\n", - "\n", - "plot_best_fit_tau(root_to_plot, colours, savefile)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "pseudo_cell = fits.open(\n", - " \"/home/guerrini/sp_validation/cosmo_val/output/pseudo_cl_SP_v1.4.5.fits\"\n", - ")[1].data\n", - "cov_pseudo_cell = fits.open(\n", - " \"/home/guerrini/sp_validation/cosmo_val/output/pseudo_cl_cov_SP_v1.4.5.fits\"\n", - ")\n", - "\n", - "theory_ell = np.loadtxt(\n", - " \"/n09data/guerrini/output_chains/best_fit/SP_v1.4.5_A/shear_cl/ell.txt\"\n", - ")\n", - "theory_cell = np.loadtxt(\n", - " \"/n09data/guerrini/output_chains/best_fit/SP_v1.4.5_A/shear_cl/bin_1_1.txt\"\n", - ")\n", - "\n", - "pw = hp.pixwin(1024, lmax=2048)\n", - "\n", - "plt.errorbar(\n", - " pseudo_cell[\"ELL\"],\n", - " pseudo_cell[\"ELL\"] * pseudo_cell[\"EE\"],\n", - " yerr=pseudo_cell[\"ELL\"] * np.sqrt(np.diag(cov_pseudo_cell[\"COVAR_EE_EE\"].data)),\n", - " capsize=2,\n", - " c=\"k\",\n", - " fmt=\"o\",\n", - " markersize=2,\n", - ")\n", - "\n", - "mask = (theory_ell > 0.1) & (theory_ell < 2048)\n", - "plt.plot(\n", - " theory_ell[mask],\n", - " theory_ell[mask]\n", - " * theory_cell[mask]\n", - " * np.interp(theory_ell[mask], np.arange(0, 2049), pw) ** 2,\n", - " c=\"r\",\n", - " label=\"best-fit $\\\\theta \\\\in [3-200]$\",\n", - ")\n", - "\n", - "plt.xlabel(r\"$\\ell$\", fontsize=26)\n", - "plt.ylabel(r\"$\\ell C_\\ell^{EE}$\", fontsize=26)\n", - "plt.legend()\n", - "plt.savefig(\"SP_v1.4.5_A_cell.png\")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "cov_pseudo_cell.info()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "sp_validation", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/S8_om_sigma8_whisker.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/S8_om_sigma8_whisker.ipynb deleted file mode 100644 index 7a4fd5d2..00000000 --- a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/S8_om_sigma8_whisker.ipynb +++ /dev/null @@ -1,645 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "0", - "metadata": {}, - "source": [ - "# Whisker plot\n", - "\n", - "This notebook plots the whisker plot of $S_8$, $\\Omega_m$ and $\\sigma_8$" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "import sys\n", - "\n", - "# Trick to plot with tex\n", - "os.environ[\"LD_LIBRARY_PATH\"] = \"\"\n", - "os.environ[\"CONDA_PREFIX\"] = \"/home/guerrini/.conda/envs/sp_validation_3.11\"\n", - "\n", - "sys.path.append(\"/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/\")\n", - "\n", - "import sys\n", - "import warnings\n", - "\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "import seaborn as sns\n", - "from getdist import plots\n", - "\n", - "sys.path.append(\"/home/guerrini/sp_validation/cosmo_inference/scripts\")\n", - "\n", - "import chain_postprocessing as cp\n", - "\n", - "plt.style.use(\"/home/guerrini/matplotlib_config/paper.mplstyle\")\n", - "\n", - "plt.rc(\"text\", usetex=True)\n", - "\n", - "sns.set_palette(\"husl\")\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "g.settings.axes_fontsize = 60\n", - "g.settings.axes_labelsize = 60\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 60\n", - "\n", - "%matplotlib inline\n", - "\n", - "# SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE\n", - "root_dir = \"/n09data/guerrini/output_chains/\"\n", - "root_external = f\"{root_dir}/ext_data/\"\n", - "blind = \"B\"\n", - "\n", - "roots = [\n", - " f\"SP_v1.4.6.3_{blind}_fiducial_config\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}\",\n", - " \"Planck18\",\n", - " \"DES Y6\",\n", - " \"KiDS-Legacy_bandpowers\",\n", - " \"KiDS-Legacy_cosebis\",\n", - " \"KiDS-Legacy_xipm\",\n", - " \"HSC_Y3\",\n", - " \"HSC_Y3_cell\",\n", - " f\"SP_v1.4.6.3_{blind}_small_scales_config\",\n", - " f\"SP_v1.4.6.3_{blind}_flat_alpha_beta_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_xi_sys_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_leak_corr_config\",\n", - " f\"SP_v1.4.6.3_{blind}_flat_delta_z_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_delta_z_config\",\n", - " f\"SP_v1.4.6.3_{blind}_flat_ia_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_ia_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_m_bias_config\",\n", - " f\"SP_v1.4.6.3_{blind}_unmasked_covmat_config\",\n", - " f\"SP_v1.4.6.3_{blind}_halofit_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_baryons_config\",\n", - " f\"SP_v1.4.6.3_{blind}_nautilus_config\",\n", - " f\"SP_v1.4.6.3_{blind}_planck_config\",\n", - " f\"SP_v1.4.6.3_{blind}_planck_desi_config\",\n", - "]\n", - "\n", - "legend_labels = [\n", - " r\"UNIONS-3500 $\\xi_{\\pm}(\\theta)$ (This work)\",\n", - " r\"UNIONS-3500 $C_\\ell$ (Guerrini et al. 2026)\",\n", - " r\"$\\textit{Planck}$ 2018\",\n", - " r\"DES Y6 $\\xi_{\\pm}$, NLA\",\n", - " r\"KiDS-Legacy Bandpowers ($C_{\\rm E}$)\",\n", - " r\"KiDS-Legacy COSEBIs ($E_n$)\",\n", - " r\"KiDS-Legacy $\\xi_{\\pm}(\\theta)$\",\n", - " r\"HSC-Y3 $\\xi_{\\pm}(\\theta)$\",\n", - " r\"HSC-Y3 $C_\\ell$\",\n", - " r\"$\\xi_+$ small scales, $\\theta$=[5,83] arcmin\",\n", - " r\"Flat $\\alpha_{\\rm{PSF}}$ and $\\beta_{\\rm{PSF}}$ priors\",\n", - " r\"No $\\xi^{\\rm sys}_{\\pm}$\",\n", - " r\"No leakage correction\",\n", - " r\"Flat $\\Delta z$ priors\",\n", - " r\"No $\\Delta z$\",\n", - " r\"Flat $A_{\\rm IA}$ prior\",\n", - " r\"No $A_{\\rm IA}$\",\n", - " r\"No $m$ bias\",\n", - " r\"Unmasked covmat\",\n", - " r\"$\\texttt{Halofit}$\",\n", - " r\"$\\texttt{HMCode}$ no baryons\",\n", - " r\"Nautilus sampler\",\n", - " r\"UNIONS-3500 + $\\textit{Planck}$\",\n", - " r\"UNIONS-3500 + $\\textit{Planck}$ + DESI BAO\",\n", - "]\n", - "\n", - "categories = [\n", - " \"configuration\",\n", - " \"harmonic\",\n", - " \"external\",\n", - " \"external\",\n", - " \"external\",\n", - " \"external\",\n", - " \"external\",\n", - " \"external\",\n", - " \"external\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - " \"configuration\",\n", - "]\n", - "colours = [\n", - " \"darkorange\",\n", - " \"royalblue\",\n", - " \"violet\",\n", - " \"black\",\n", - " \"black\",\n", - " \"black\",\n", - " \"black\",\n", - " \"black\",\n", - " \"black\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - " \"forestgreen\",\n", - "]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2", - "metadata": {}, - "outputs": [], - "source": [ - "chains = []\n", - "for i, root in enumerate(roots):\n", - " category = categories[i]\n", - " if root == \"DES Y6\":\n", - " continue\n", - " if category != \"external\":\n", - " if category == \"configuration\":\n", - " path_samples = os.path.join(root_dir, f\"{root}/samples_{root}.txt\")\n", - " path_getdist = os.path.join(root_dir, f\"{root}/getdist_{root}\")\n", - " elif category == \"harmonic\":\n", - " path_samples = os.path.join(\n", - " root_dir, f\"{root}/{root}/samples_{root}_cell.txt\"\n", - " )\n", - " path_getdist = os.path.join(root_dir, f\"{root}/{root}/getdist_{root}\")\n", - " elif category == \"external_compute_sample\":\n", - " path_samples = os.path.join(root_dir, f\"ext_data/{root}/samples_{root}.txt\")\n", - " path_getdist = os.path.join(root_dir, f\"ext_data/{root}/getdist_{root}\")\n", - " else:\n", - " raise ValueError(f\"The category, {category}, of {root} is not correct\")\n", - " if \"nautilus\" not in root:\n", - " cp.load_samples_and_write_paramnames(\n", - " path_samples, path_getdist + \".paramnames\"\n", - " )\n", - " cp.write_samples_getdist_format(path_samples, path_getdist + \".txt\")\n", - " else:\n", - " cp.load_samples_and_write_paramnames(\n", - " path_samples, path_getdist + \".paramnames\", chain_type=\"nautilus\"\n", - " )\n", - " cp.write_samples_getdist_format(\n", - " path_samples, path_getdist + \".txt\", chain_type=\"nautilus\"\n", - " )\n", - " chains.append(cp.load_chain(path_getdist, smoothing_scale=0.5))\n", - " else:\n", - " path_getdist = os.path.join(root_dir, f\"ext_data/{root}/getdist_{root}\")\n", - " chains.append(cp.load_chain(path_getdist))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3", - "metadata": {}, - "outputs": [], - "source": [ - "name_list = [\n", - " \"OMEGA_M\",\n", - " \"ombh2\",\n", - " \"h0\",\n", - " \"n_s\",\n", - " \"SIGMA_8\",\n", - " \"S_8\",\n", - " \"s_8_input\",\n", - " \"logt_agn\",\n", - " \"a\",\n", - " \"m1\",\n", - " \"bias_1\",\n", - "]\n", - "label_list = [\n", - " r\"\\Omega_{\\rm m}\",\n", - " r\"\\omega_b h^2\",\n", - " r\"h_0\",\n", - " r\"n_s\",\n", - " r\"\\sigma_8\",\n", - " r\"S_8\",\n", - " r\"S_8\",\n", - " r\"\\log T_{\\rm AGN}\",\n", - " r\"A_{\\rm IA}\",\n", - " r\"m_1\",\n", - " r\"\\Delta z_1\",\n", - "]\n", - "\n", - "for i, chain in enumerate(chains):\n", - " print(legend_labels[i])\n", - " param_names = chain.getParamNames()\n", - " for name, label in zip(name_list, label_list):\n", - " try:\n", - " param_names.parWithName(name).label = label\n", - " except Exception:\n", - " warnings.warn(f\"Parameter {name} not found in chain {roots[i]}.\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4", - "metadata": {}, - "outputs": [], - "source": [ - "# Micro management of external chains\n", - "\n", - "# Account for the missing parameter conventions\n", - "\n", - "idx = roots.index(\"KiDS-Legacy_xipm\")\n", - "cp.derive_parameter_S8(chains[idx])\n", - "\n", - "idx = roots.index(\"KiDS-Legacy_bandpowers\")\n", - "cp.derive_parameter_S8(chains[idx])\n", - "\n", - "idx = roots.index(\"KiDS-Legacy_cosebis\")\n", - "cp.derive_parameter_S8(chains[idx])\n", - "\n", - "# OMEGA_M not in HSC_Y3_cell\n", - "idx = roots.index(\"HSC_Y3_cell\")\n", - "cp.adjust_paramname_chain(chains[idx], \"omega_m\", \"OMEGA_M\", r\"\\Omega_{\\rm m}\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5", - "metadata": {}, - "outputs": [], - "source": [ - "param_values = np.array(\n", - " [\n", - " \"# Expt\",\n", - " \"Colour\",\n", - " \"S8_Mean\",\n", - " \"S8_low\",\n", - " \"S8_high\",\n", - " \"sigma_8_Mean\",\n", - " \"sigma_8_low\",\n", - " \"sigma_8_high\",\n", - " \"Omega_m_Mean\",\n", - " \"Omega_m_low\",\n", - " \"Omega_m_high\",\n", - " ]\n", - ")\n", - "escaped = np.char.replace(legend_labels, \"\\\\\", \"\\\\\\\\\")\n", - "\n", - "for i, root in enumerate(roots):\n", - " chain = chains[i]\n", - " if root == \"DES Y6\":\n", - " param_values = np.vstack(\n", - " (\n", - " param_values,\n", - " [\n", - " escaped[i],\n", - " colours[i],\n", - " 0.798,\n", - " 0.015,\n", - " 0.014,\n", - " 0.763,\n", - " 0.057,\n", - " 0.050,\n", - " 0.332,\n", - " 0.040,\n", - " 0.035,\n", - " ],\n", - " )\n", - " )\n", - " else:\n", - " best_fit_params = cp.extract_best_fit_params(chain, best_fit_method=\"2Dkde\")\n", - " margestats = chain.getMargeStats()\n", - "\n", - " s8_stats = margestats.parWithName(\"S_8\")\n", - " sigma8_stats = margestats.parWithName(\"SIGMA_8\")\n", - " omegam_stats = margestats.parWithName(\"OMEGA_M\")\n", - "\n", - " param_values = np.vstack(\n", - " (\n", - " param_values,\n", - " [\n", - " escaped[i],\n", - " colours[i],\n", - " best_fit_params[\"S_8\"],\n", - " best_fit_params[\"S_8\"] - s8_stats.limits[0].lower,\n", - " s8_stats.limits[0].upper - best_fit_params[\"S_8\"],\n", - " best_fit_params[\"SIGMA_8\"],\n", - " best_fit_params[\"SIGMA_8\"] - sigma8_stats.limits[0].lower,\n", - " sigma8_stats.limits[0].upper - best_fit_params[\"SIGMA_8\"],\n", - " best_fit_params[\"OMEGA_M\"],\n", - " best_fit_params[\"OMEGA_M\"] - omegam_stats.limits[0].lower,\n", - " omegam_stats.limits[0].upper - best_fit_params[\"OMEGA_M\"],\n", - " ],\n", - " )\n", - " )\n", - "print(param_values)\n", - "np.savetxt(\n", - " f\"{root_dir}/param_values.txt\",\n", - " param_values,\n", - " fmt=[\"%s\" for i in range(11)],\n", - " delimiter=\";\",\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6", - "metadata": {}, - "outputs": [], - "source": [ - "# Load the value of the parameters\n", - "cosmo = np.loadtxt(\n", - " f\"{root_dir}/param_values.txt\",\n", - " dtype={\n", - " \"names\": (\n", - " \"Expt\",\n", - " \"colour\",\n", - " \"s8_mean\",\n", - " \"s8_low\",\n", - " \"s8_high\",\n", - " \"sigma8_mean\",\n", - " \"sigma8_low\",\n", - " \"sigma8_high\",\n", - " \"omegam_mean\",\n", - " \"omegam_low\",\n", - " \"omegam_high\",\n", - " ),\n", - " \"formats\": (\n", - " \"U250\",\n", - " \"U20\",\n", - " \"U20\",\n", - " \"U20\",\n", - " \"U20\",\n", - " \"U20\",\n", - " \"U20\",\n", - " \"U20\",\n", - " \"U20\",\n", - " \"U20\",\n", - " \"U20\",\n", - " ),\n", - " },\n", - " skiprows=1,\n", - " delimiter=\";\",\n", - ")\n", - "expt = np.char.replace(cosmo[\"Expt\"], \"\\\\\\\\\", \"\\\\\")\n", - "colours = cosmo[\"colour\"]\n", - "s8_mean = cosmo[\"s8_mean\"].astype(np.float64)\n", - "s8_low = cosmo[\"s8_low\"].astype(np.float64)\n", - "s8_high = cosmo[\"s8_high\"].astype(np.float64)\n", - "sigma8_mean = cosmo[\"sigma8_mean\"].astype(np.float64)\n", - "sigma8_low = cosmo[\"sigma8_low\"].astype(np.float64)\n", - "sigma8_high = cosmo[\"sigma8_high\"].astype(np.float64)\n", - "omegam_mean = cosmo[\"omegam_mean\"].astype(np.float64)\n", - "omegam_low = cosmo[\"omegam_low\"].astype(np.float64)\n", - "omegam_high = cosmo[\"omegam_high\"].astype(np.float64)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7", - "metadata": {}, - "outputs": [], - "source": [ - "from matplotlib.gridspec import GridSpec\n", - "\n", - "fig = plt.figure(figsize=(13, 8))\n", - "gs = GridSpec(1, 3, width_ratios=[1, 0.5, 0.5])\n", - "ax1 = fig.add_subplot(gs[0])\n", - "ax2 = fig.add_subplot(gs[1], sharey=ax1)\n", - "ax3 = fig.add_subplot(gs[2], sharey=ax1)\n", - "\n", - "axs = [ax1, ax2, ax3]\n", - "\n", - "params = [\n", - " (s8_mean, s8_low, s8_high, r\"$S_8$\"),\n", - " (sigma8_mean, sigma8_low, sigma8_high, r\"$\\sigma_8$\"),\n", - " (omegam_mean, omegam_low, omegam_high, r\"$\\Omega_{\\rm m}$\"),\n", - "]\n", - "reference = r\"UNIONS-3500 $\\xi_{\\pm}(\\theta)$ (This work)\"\n", - "\n", - "separation_after = [\n", - " r\"UNIONS-3500 $C_\\ell$ (Guerrini et al. 2026)\",\n", - " r\"HSC-Y3 $C_\\ell$\",\n", - " r\"$\\xi_+$ small scales, $\\theta$=[5,83] arcmin\",\n", - " r\"Unmasked covmat\",\n", - " r\"$\\texttt{HMCode}$ no baryons\",\n", - " r\"Nautilus sampler\",\n", - "]\n", - "list_section_index = [r\"(ii)\", r\"(iii)\", r\"(iv)\", r\"(v)\", r\"(vi)\", r\"(vii)\"]\n", - "\n", - "preliminary_watermark = False\n", - "blind_axes = False\n", - "row_spacing = 0.2\n", - "\n", - "index_ref = np.where(expt == reference)[0][0]\n", - "\n", - "y = np.arange(len(expt))\n", - "for ax, param in zip(axs, params):\n", - " means, lows, highs, label = param\n", - " for i, mean, low, high, color in zip(y, means, lows, highs, colours):\n", - " ax.errorbar(\n", - " mean,\n", - " 0.05 + i * row_spacing,\n", - " xerr=np.array([low, high])[:, None],\n", - " fmt=\"o\",\n", - " color=color,\n", - " ecolor=color,\n", - " elinewidth=2,\n", - " capsize=3,\n", - " )\n", - " ax.set_xlabel(label, fontsize=14)\n", - "\n", - " ax.grid(False)\n", - " ax.tick_params(axis=\"y\", left=False, labelleft=False)\n", - " if label == r\"$S_8$\":\n", - " ax.axvspan(\n", - " s8_mean[index_ref] - s8_low[index_ref],\n", - " s8_mean[index_ref] + s8_high[index_ref],\n", - " color=colours[index_ref],\n", - " alpha=0.2,\n", - " )\n", - " ax.set_xlim(0.6, 1.35)\n", - " if blind_axes:\n", - " ref_tick = np.mean(s8_mean[:4])\n", - " ax.set_xticks([ref_tick + i * 0.1 for i in range(-5, 5)], labels=[])\n", - " elif label == r\"$\\sigma_8$\":\n", - " ax.axvspan(\n", - " sigma8_mean[index_ref] - sigma8_low[index_ref],\n", - " sigma8_mean[index_ref] + sigma8_high[index_ref],\n", - " color=colours[index_ref],\n", - " alpha=0.2,\n", - " )\n", - " ax.set_xlim(0.5, 1.35)\n", - " if blind_axes:\n", - " ref_tick = np.mean(sigma8_mean[:4])\n", - " ax.set_xticks([ref_tick + i * 0.2 for i in range(-2, 2)], labels=[])\n", - " elif label == r\"$\\Omega_{\\rm m}$\":\n", - " ax.axvspan(\n", - " omegam_mean[index_ref] - omegam_low[index_ref],\n", - " omegam_mean[index_ref] + omegam_high[index_ref],\n", - " color=colours[index_ref],\n", - " alpha=0.2,\n", - " )\n", - " ax.set_xlim(0.1, 0.5)\n", - " if blind_axes:\n", - " ref_tick = np.mean(omegam_mean[:4])\n", - " ax.set_xticks([ref_tick + i * 0.1 for i in range(-2, 3)], labels=[])\n", - "\n", - "\n", - "ax1.set_yticks(0.01 + y * row_spacing)\n", - "ax1.set_yticklabels([])\n", - "for label, color in zip(expt, colours):\n", - " if \"This work\" in label:\n", - " label_bold = (\n", - " r\"$\\bf{UNIONS}$-$\\bf{3500}$ $\\xi_{\\pm}(\\theta)$ $\\bf{(This\\ work)}$\"\n", - " )\n", - " ax1.text(\n", - " -0.6,\n", - " 0.05 + row_spacing * np.where(expt == label)[0][0],\n", - " label_bold,\n", - " fontsize=12,\n", - " ha=\"left\",\n", - " va=\"center\",\n", - " color=color,\n", - " )\n", - " else:\n", - " ax1.text(\n", - " -0.6,\n", - " 0.05 + row_spacing * np.where(expt == label)[0][0],\n", - " label,\n", - " fontsize=12,\n", - " ha=\"left\",\n", - " va=\"center\",\n", - " color=color,\n", - " )\n", - " if label != reference:\n", - " index = np.where(expt == label)[0][0]\n", - " s8_tension = cp.get_sigma_tension(\n", - " s8_mean[index],\n", - " s8_low[index],\n", - " s8_high[index],\n", - " s8_mean[index_ref],\n", - " s8_low[index_ref],\n", - " s8_high[index_ref],\n", - " )\n", - " sign_str = \"+\" if s8_tension > 0 else \"-\"\n", - " ax1.text(\n", - " 1.32,\n", - " 0.05 + row_spacing * index,\n", - " rf\"${sign_str}{np.abs(s8_tension):.2f}\" + r\"\\, \\sigma$\",\n", - " fontsize=10,\n", - " ha=\"right\",\n", - " va=\"center\",\n", - " color=color,\n", - " )\n", - "# Add separation lines\n", - "for i, sep in enumerate(separation_after):\n", - " print(sep)\n", - " index_sep = np.where(expt == sep)[0][0]\n", - " ax2.axhline(\n", - " row_spacing * (index_sep + 1) - 0.07,\n", - " color=\"black\",\n", - " linestyle=\"dotted\",\n", - " linewidth=1,\n", - " )\n", - " ax3.axhline(\n", - " row_spacing * (index_sep + 1) - 0.07,\n", - " color=\"black\",\n", - " linestyle=\"dotted\",\n", - " linewidth=1,\n", - " )\n", - " ax1.axhline(\n", - " row_spacing * (index_sep + 1) - 0.07,\n", - " xmin=-1.8,\n", - " color=\"black\",\n", - " linestyle=\"dotted\",\n", - " linewidth=1,\n", - " clip_on=False,\n", - " )\n", - " ax1.text(\n", - " -0.61,\n", - " row_spacing * (index_sep + 1) + 0.05,\n", - " list_section_index[i],\n", - " fontsize=12,\n", - " fontweight=\"bold\",\n", - " va=\"center\",\n", - " ha=\"right\",\n", - " )\n", - "\n", - "\n", - "# --- Add section label (i)) ---\n", - "ax1.text(-0.61, 0.05, r\"(i)\", fontsize=12, fontweight=\"bold\", va=\"center\", ha=\"right\")\n", - "\n", - "if preliminary_watermark:\n", - " plt.figtext(\n", - " 0.5,\n", - " 0.5,\n", - " \"PRELIMINARY\",\n", - " fontsize=50,\n", - " color=\"gray\",\n", - " ha=\"center\",\n", - " va=\"center\",\n", - " alpha=0.3,\n", - " rotation=330,\n", - " )\n", - "\n", - "plt.gca().invert_yaxis()\n", - "\n", - "plt.tight_layout()\n", - "\n", - "# plt.savefig(\"./plots/whisker_plot.png\", dpi=300)\n", - "# #Save pdf\n", - "plt.savefig(\"../Plots/S8_whisker_plot.pdf\", bbox_inches=\"tight\")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "my_env", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/best_fit_xipm.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/best_fit_xipm.ipynb deleted file mode 100644 index d6ed4c01..00000000 --- a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/best_fit_xipm.ipynb +++ /dev/null @@ -1,607 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "0", - "metadata": {}, - "source": [ - "# Best-fit $\\xi_\\pm$\n", - "\n", - "This notebook plots the best-fit 2PCFs for the fiducial and other cases" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "import sys\n", - "\n", - "sys.path.append(\"/home/guerrini/sp_validation/cosmo_inference/scripts\")\n", - "\n", - "import chain_postprocessing as cp\n", - "import matplotlib.pyplot as plt\n", - "import matplotlib.scale as mscale\n", - "import numpy as np\n", - "import seaborn as sns\n", - "from astropy.io import fits\n", - "from getdist import plots\n", - "\n", - "plt.style.use(\"/home/guerrini/matplotlib_config/paper.mplstyle\")\n", - "\n", - "from sp_validation.rho_tau import SquareRootScale\n", - "\n", - "mscale.register_scale(SquareRootScale)\n", - "\n", - "plt.rcParams[\"text.usetex\"] = True\n", - "\n", - "sns.set_palette(\"husl\")\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "g.settings.axes_fontsize = 40\n", - "g.settings.axes_labelsize = 40\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 50\n", - "\n", - "# Directory where the chains are located\n", - "root_dir = \"/n09data/guerrini/output_chains\"\n", - "\n", - "# THE BLIND TO USE FOR THE PLOTS\n", - "blind = \"B\"\n", - "catalog_version = \"SP_v1.4.6.3\"\n", - "fiducial_root_cell = f\"SP_v1.4.6.3_leak_corr_{blind}\"\n", - "label_fiducial_cell = r\"UNIONS $C_{\\ell}$\"\n", - "fiducial_root_xi_data = f\"SP_v1.4.6.3_leak_corr_{blind}_masked\"\n", - "fiducial_root_xi_chains = f\"SP_v1.4.6.3_{blind}_fiducial_config\"\n", - "label_fiducial_xi = r\"UNIONS $\\xi_{\\pm}$\"\n", - "\n", - "# Path to the ini files used\n", - "path_ini_files = \"/home/guerrini/sp_validation/cosmo_inference/cosmosis_config\"\n", - "path_datavectors = \"/home/guerrini/sp_validation/cosmo_inference/data/\"\n", - "path_output_chains = \"/n09data/guerrini/output_chains/\"\n", - "\n", - "\n", - "data_cell = fits.open(\n", - " os.path.join(\n", - " path_datavectors, f\"{fiducial_root_cell}/cosmosis_{fiducial_root_cell}.fits\"\n", - " )\n", - ")\n", - "\n", - "data_xi = fits.open(\n", - " os.path.join(\n", - " path_datavectors,\n", - " f\"SP_v1.4.6.3_config/SP_v1.4.6.3_{blind}/cosmosis_{fiducial_root_xi_data}.fits\",\n", - " )\n", - ")\n", - "\n", - "%matplotlib inline" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2", - "metadata": {}, - "outputs": [], - "source": [ - "# Perform the computation for the fiducial of Cell\n", - "path_samples_fiducial_cell = os.path.join(\n", - " path_output_chains,\n", - " fiducial_root_cell,\n", - " fiducial_root_cell,\n", - " f\"samples_{fiducial_root_cell}_cell.txt\",\n", - ")\n", - "path_gd_fiducial_cell = os.path.join(\n", - " path_output_chains,\n", - " fiducial_root_cell,\n", - " fiducial_root_cell,\n", - " f\"getdist_{fiducial_root_cell}_cell\",\n", - ")\n", - "cp.load_samples_and_write_paramnames(\n", - " path_samples_fiducial_cell, path_gd_fiducial_cell + \".paramnames\"\n", - ")\n", - "cp.write_samples_getdist_format(\n", - " path_samples_fiducial_cell, path_gd_fiducial_cell + \".txt\", chain_type=\"polychord\"\n", - ")\n", - "\n", - "chain_fiducial_cell = cp.load_chain(path_gd_fiducial_cell, smoothing_scale=0.5)\n", - "\n", - "best_fit_params_fiducial_cell = cp.extract_best_fit_params(\n", - " chain_fiducial_cell, best_fit_method=\"2Dkde\"\n", - ")\n", - "\n", - "cp.compute_best_fit(\n", - " path_ini_files,\n", - " best_fit_params_fiducial_cell,\n", - " fiducial_root_cell,\n", - " is_harmonic=True,\n", - " blind=blind,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3", - "metadata": {}, - "outputs": [], - "source": [ - "# Perform the computation for the fiducial of xi\n", - "path_samples_fiducial_xi = os.path.join(\n", - " path_output_chains,\n", - " fiducial_root_xi_chains,\n", - " f\"samples_{fiducial_root_xi_chains}.txt\",\n", - ")\n", - "\n", - "path_gd_fiducial_xi = os.path.join(\n", - " path_output_chains, fiducial_root_xi_chains, f\"getdist_{fiducial_root_xi_chains}\"\n", - ")\n", - "cp.load_samples_and_write_paramnames(\n", - " path_samples_fiducial_xi, path_gd_fiducial_xi + \".paramnames\"\n", - ")\n", - "cp.write_samples_getdist_format(\n", - " path_samples_fiducial_xi, path_gd_fiducial_xi + \".txt\", chain_type=\"polychord\"\n", - ")\n", - "\n", - "chain_fiducial_xi = cp.load_chain(path_gd_fiducial_xi, smoothing_scale=0.5)\n", - "\n", - "best_fit_params_fiducial_xi = cp.extract_best_fit_params(\n", - " chain_fiducial_xi, best_fit_method=\"2Dkde\"\n", - ")\n", - "\n", - "ini_file_root = os.path.join(\n", - " path_ini_files,\n", - " f\"config_space_v1.4.6.3_fiducial/pipeline/blind_{blind}/fiducial.ini\",\n", - ")\n", - "cp.compute_best_fit(\n", - " path_ini_files,\n", - " best_fit_params_fiducial_xi,\n", - " fiducial_root_xi_chains,\n", - " is_harmonic=False,\n", - " blind=blind,\n", - " ini_file_root=ini_file_root,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4", - "metadata": {}, - "outputs": [], - "source": [ - "# Make the plot for the best-fit datavector for Cell EE\n", - "root_to_plot = [\n", - " fiducial_root_xi_chains,\n", - " fiducial_root_cell,\n", - "]\n", - "\n", - "labels = [\n", - " r\"UNIONS $\\xi_\\pm(\\theta)$\",\n", - " r\"UNIONS $C_\\ell$\",\n", - "]\n", - "\n", - "line_args = [\n", - " {\"color\": \"royalblue\", \"linestyle\": \"-\"},\n", - " {\"color\": \"orange\", \"linestyle\": \"-\"},\n", - "]\n", - "\n", - "properties = {}\n", - "\n", - "properties = cp.update_properties_w_roots(\n", - " properties, fiducial_root_cell, path_ini_files, with_configuration=False\n", - ")\n", - "properties = cp.update_properties_w_roots(\n", - " properties,\n", - " fiducial_root_xi_chains,\n", - " path_ini_files,\n", - " with_configuration=True,\n", - " path_to_this_ini=ini_file_root,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5", - "metadata": {}, - "outputs": [], - "source": [ - "root_to_plot = [fiducial_root_cell, fiducial_root_xi_chains]\n", - "labels = [r\"Best fit $C_\\ell$\", r\"Best fit $\\xi_\\pm(\\theta)$\"]\n", - "path_best_fit_xi_theta = os.path.join(\n", - " path_output_chains, fiducial_root_xi_chains, \"best_fit/shear_xi_plus/theta.txt\"\n", - ")\n", - "\n", - "theta_rad = np.loadtxt(path_best_fit_xi_theta)\n", - "theta_min = 1\n", - "theta_max = 250\n", - "\n", - "cp.compute_best_fit_xi_from_cell(\n", - " path_output_chains, fiducial_root_cell, best_fit_params_fiducial_cell, theta_rad\n", - ")\n", - "\n", - "data = fits.open(\n", - " os.path.join(\n", - " path_datavectors,\n", - " f\"SP_v1.4.6.3_config/SP_v1.4.6.3_{blind}/cosmosis_{fiducial_root_xi_data}.fits\",\n", - " )\n", - ")\n", - "bbox_to_anchor_xip = (0.685, 0.09)\n", - "bbox_to_anchor_xim = (0.3, 0.65)\n", - "xi_p_data = data[\"XI_PLUS\"].data\n", - "xi_m_data = data[\"XI_MINUS\"].data\n", - "cov_mat = data[\"COVMAT\"].data\n", - "\n", - "# Plot hyperparameter\n", - "loc_legend = \"lower center\"\n", - "\n", - "fig, [ax, ax2] = plt.subplots(1, 2, figsize=(20, 8))\n", - "\n", - "theta, xi_p, xi_m = xi_p_data[\"ANG\"], xi_p_data[\"VALUE\"], xi_m_data[\"VALUE\"]\n", - "ax.errorbar(\n", - " theta,\n", - " theta * xi_p,\n", - " yerr=theta * np.sqrt(np.diag(cov_mat[: len(theta), : len(theta)])),\n", - " fmt=\"o\",\n", - " label=r\"UNIONS $\\xi_+$ data\",\n", - " color=\"black\",\n", - " capsize=2,\n", - ")\n", - "ax2.errorbar(\n", - " theta,\n", - " theta * xi_m,\n", - " yerr=theta\n", - " * np.sqrt(\n", - " np.diag(cov_mat[len(theta) : 2 * len(theta), len(theta) : 2 * len(theta)])\n", - " ),\n", - " fmt=\"o\",\n", - " label=r\"UNIONS $\\xi_-$ data\",\n", - " color=\"black\",\n", - " capsize=2,\n", - ")\n", - "\n", - "for idx, (label, root) in enumerate(zip(labels, root_to_plot)):\n", - " # Read the results\n", - " theta = (\n", - " (\n", - " np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " )\n", - " * 180\n", - " / np.pi\n", - " * 60\n", - " )\n", - " xi_plus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_minus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " if r\"$C_\\ell$\" not in label:\n", - " xi_sys_plus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = (\n", - " np.loadtxt(path_output_chains + \"{}/best_fit/xi_sys/theta.txt\".format(root))\n", - " * 180\n", - " / np.pi\n", - " * 60\n", - " )\n", - "\n", - " xi_sys_plus = np.interp(theta, theta_xi_sys, xi_sys_plus)\n", - " xi_sys_minus = np.interp(theta, theta_xi_sys, xi_sys_minus)\n", - " xi_plus += xi_sys_plus\n", - " xi_minus += xi_sys_minus\n", - "\n", - " mask = (theta > theta_min) & (theta < theta_max)\n", - " theta = theta[mask]\n", - " ax.plot(\n", - " theta,\n", - " theta * xi_plus[mask],\n", - " label=r\"Best fit $\\xi_+(\\theta)$\",\n", - " **line_args[idx],\n", - " lw=2.5,\n", - " )\n", - " ax.plot(\n", - " theta,\n", - " theta * xi_sys_plus[mask],\n", - " label=r\"Best fit $\\xi^{\\rm sys}_{+}(\\theta)$\",\n", - " c=\"r\",\n", - " )\n", - " ax2.plot(\n", - " theta,\n", - " theta * xi_minus[mask],\n", - " label=r\"Best fit $\\xi_-(\\theta)$\",\n", - " **line_args[idx],\n", - " lw=2.5,\n", - " )\n", - " ax2.plot(\n", - " theta,\n", - " theta * xi_sys_minus[mask],\n", - " label=r\"Best fit $\\xi^{\\rm sys}_{-}(\\theta)$\",\n", - " c=\"r\",\n", - " )\n", - "\n", - " else:\n", - " mask = (theta > theta_min) & (theta < theta_max)\n", - " theta = theta[mask]\n", - " ax.plot(theta, theta * xi_plus[mask], label=label, **line_args[idx], lw=2.5)\n", - " ax2.plot(theta, theta * xi_minus[mask], label=label, **line_args[idx], lw=2.5)\n", - "# XI PLUS PLOT SETTINGS\n", - "\n", - "# Plot the scale cuts for different k_max\n", - "ax.axvline(x=5, color=\"gray\", linestyle=\"--\", alpha=0.7)\n", - "ax.axhline(y=0, color=\"black\", linestyle=\"--\", alpha=0.7)\n", - "\n", - "ymin = ax.get_ylim()[0]\n", - "ymax = ax.get_ylim()[1]\n", - "# Shadowing cut scaled\n", - "ax.fill_betweenx(y=[ymin, ymax], x1=0, x2=12, color=\"gray\", alpha=0.2)\n", - "ax.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color=\"gray\", alpha=0.2)\n", - "\n", - "ax.set_ylim(ymin, ymax)\n", - "\n", - "# Add labels directly under the tick\n", - "ax.text(\n", - " 4.5,\n", - " 0.47e-4,\n", - " r\"$k_\\mathrm{max} = 1 h$ Mpc$^{-1}$\",\n", - " ha=\"center\",\n", - " va=\"top\",\n", - " fontsize=20,\n", - " rotation=90,\n", - ")\n", - "\n", - "ax.set_ylabel(r\"$\\theta \\xi_\\pm$\", fontsize=26)\n", - "ax.set_xlabel(r\"$\\theta$ (arcmin)\", fontsize=26)\n", - "ax.set_xlim([theta.min() - 0.1, theta.max() + 20])\n", - "ax.set_title(r\"$\\xi_+(\\theta)$\", fontsize=26)\n", - "ax.set_xscale(\"log\")\n", - "ax.set_xticks(np.array([1, 10, 100]))\n", - "ax.tick_params(axis=\"x\", which=\"minor\", length=2, width=0.8)\n", - "ax.tick_params(axis=\"both\", which=\"major\", labelsize=24)\n", - "ax.tick_params(axis=\"both\", which=\"minor\", labelsize=20)\n", - "ax.yaxis.get_offset_text().set_fontsize(24)\n", - "ax.ticklabel_format(axis=\"y\", style=\"sci\", scilimits=(0, 0))\n", - "ax.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xip, fontsize=20)\n", - "\n", - "# XI_MINUS PLOT SETTINGS\n", - "\n", - "# Plot the scale cuts for different k_max\n", - "ax2.axvline(x=50, color=\"gray\", linestyle=\"--\", alpha=0.7)\n", - "ax2.axhline(y=0, color=\"black\", linestyle=\"--\", alpha=0.7)\n", - "\n", - "ymin = ax2.get_ylim()[0]\n", - "ymax = ax2.get_ylim()[1]\n", - "# Shadowing cut scaled\n", - "ax2.fill_betweenx(y=[ymin, ymax], x1=0, x2=12, color=\"gray\", alpha=0.2)\n", - "ax2.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color=\"gray\", alpha=0.2)\n", - "\n", - "ax2.set_ylim(ymin, ymax)\n", - "\n", - "# Add labels directly under the tick\n", - "ax2.text(\n", - " 45,\n", - " 1.15e-4,\n", - " r\"$k_\\mathrm{max} = 1 h$ Mpc$^{-1}$\",\n", - " ha=\"center\",\n", - " va=\"top\",\n", - " fontsize=20,\n", - " rotation=90,\n", - ")\n", - "\n", - "# ax2.set_ylabel(r'$\\theta \\xi_-$', fontsize=16)\n", - "ax2.set_xlabel(r\"$\\theta$ (arcmin)\", fontsize=26)\n", - "ax2.set_xlim([theta.min() - 0.1, theta.max() + 20])\n", - "ax2.set_xscale(\"log\")\n", - "ax2.set_title(r\"$\\xi_-(\\theta)$\", fontsize=26)\n", - "ax2.set_xticks(np.array([1, 10, 100]))\n", - "ax2.tick_params(axis=\"x\", which=\"minor\", length=2, width=0.8)\n", - "ax2.tick_params(axis=\"both\", which=\"major\", labelsize=24)\n", - "ax2.tick_params(axis=\"both\", which=\"minor\", labelsize=20)\n", - "ax2.yaxis.get_offset_text().set_fontsize(24)\n", - "ax2.ticklabel_format(axis=\"y\", style=\"sci\", scilimits=(0, 0))\n", - "ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20)\n", - "\n", - "plt.savefig(\n", - " \"/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/best_fit_xipm_SP_v1.4.6.3_B.pdf\",\n", - " bbox_inches=\"tight\",\n", - ")\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6", - "metadata": {}, - "outputs": [], - "source": [ - "root_to_plot = [fiducial_root_xi_chains]\n", - "labels = [r\"Best fit $\\tau_{0,2}(\\theta)$\"]\n", - "\n", - "bbox_to_anchor_xip = (0.285, 0.7)\n", - "bbox_to_anchor_xim = (0.3, 0.65)\n", - "tau0_data = data[\"TAU_0_PLUS\"].data\n", - "tau2_data = data[\"TAU_2_PLUS\"].data\n", - "cov_mat = data[\"COVMAT\"].data\n", - "\n", - "# Plot hyperparameter\n", - "\n", - "fig, [ax, ax2] = plt.subplots(1, 2, figsize=(20, 8))\n", - "\n", - "theta, tau0, tau2 = tau0_data[\"ANG\"], tau0_data[\"VALUE\"], tau2_data[\"VALUE\"]\n", - "ax.errorbar(\n", - " theta,\n", - " theta * tau0,\n", - " yerr=theta\n", - " * np.sqrt(\n", - " np.diag(\n", - " cov_mat[2 * len(theta) : 3 * len(theta), 2 * len(theta) : 3 * len(theta)]\n", - " )\n", - " ),\n", - " fmt=\"o\",\n", - " label=r\"UNIONS $\\tau_{0,+}$\",\n", - " color=\"black\",\n", - " capsize=2,\n", - ")\n", - "ax2.errorbar(\n", - " theta,\n", - " theta * tau2,\n", - " yerr=theta\n", - " * np.sqrt(\n", - " np.diag(\n", - " cov_mat[3 * len(theta) : 4 * len(theta), 3 * len(theta) : 4 * len(theta)]\n", - " )\n", - " ),\n", - " fmt=\"o\",\n", - " label=r\"UNIONS $\\tau_{2,+}$\",\n", - " color=\"black\",\n", - " capsize=2,\n", - ")\n", - "\n", - "for idx, (label, root) in enumerate(zip(labels, root_to_plot)):\n", - " # Read the results\n", - " theta = (\n", - " (\n", - " np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/tau_0_plus/theta.txt\".format(root)\n", - " )\n", - " )\n", - " * 180\n", - " / np.pi\n", - " * 60\n", - " )\n", - " tau0_plus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/tau_0_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " tau2_plus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/tau_2_plus/bin_1_1.txt\".format(root)\n", - " )\n", - "\n", - " mask = (theta > theta_min) & (theta < theta_max)\n", - " theta = theta[mask]\n", - " ax.plot(\n", - " theta,\n", - " theta * tau0_plus[mask],\n", - " label=r\"Best fit $\\tau_{0,+}(\\theta)$\",\n", - " c=\"orange\",\n", - " lw=2.5,\n", - " )\n", - " ax2.plot(\n", - " theta,\n", - " theta * tau2_plus[mask],\n", - " label=r\"Best fit $\\tau_{2,+}(\\theta)$\",\n", - " c=\"orange\",\n", - " lw=2.5,\n", - " )\n", - "\n", - "# XI PLUS PLOT SETTINGS\n", - "\n", - "# Plot the scale cuts for different k_max\n", - "ax.axhline(y=0, color=\"black\", linestyle=\"--\", alpha=0.7)\n", - "\n", - "ymin = ax.get_ylim()[0]\n", - "ymax = ax.get_ylim()[1]\n", - "\n", - "ax.set_ylim(ymin, ymax)\n", - "\n", - "ax.set_ylabel(r\"$\\theta\\tau_{0,2}$\", fontsize=26)\n", - "ax.set_xlabel(r\"$\\theta$ (arcmin)\", fontsize=26)\n", - "ax.set_xlim([theta.min() - 0.1, theta.max() + 20])\n", - "ax.set_title(r\"$\\tau_{0,+}(\\theta)$\", fontsize=26)\n", - "ax.set_xscale(\"log\")\n", - "ax.set_xticks(np.array([1, 10, 100]))\n", - "ax.tick_params(axis=\"x\", which=\"minor\", length=2, width=0.8)\n", - "ax.tick_params(axis=\"both\", which=\"major\", labelsize=24)\n", - "ax.tick_params(axis=\"both\", which=\"minor\", labelsize=20)\n", - "ax.yaxis.get_offset_text().set_fontsize(24)\n", - "ax.ticklabel_format(axis=\"y\", style=\"sci\", scilimits=(0, 0))\n", - "ax.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xip, fontsize=20)\n", - "\n", - "# XI_MINUS PLOT SETTINGS\n", - "\n", - "# Plot the scale cuts for different k_max\n", - "ax2.axhline(y=0, color=\"black\", linestyle=\"--\", alpha=0.7)\n", - "\n", - "ymin = ax2.get_ylim()[0]\n", - "ymax = ax2.get_ylim()[1]\n", - "# Shadowing cut scaled\n", - "ax2.fill_betweenx(\n", - " y=[ymin, ymax],\n", - " x1=0,\n", - " x2=12,\n", - " color=\"gray\",\n", - " alpha=0.2,\n", - " label=r\"$B$-mode informed scale cut\",\n", - ")\n", - "ax2.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color=\"gray\", alpha=0.2)\n", - "\n", - "ax2.set_ylim(ymin, ymax)\n", - "\n", - "# ax2.set_ylabel(r'$\\theta \\xi_-$', fontsize=16)\n", - "ax2.set_xlabel(r\"$\\theta$ (arcmin)\", fontsize=26)\n", - "ax2.set_xlim([theta.min() - 0.1, theta.max() + 20])\n", - "ax2.set_xscale(\"log\")\n", - "ax2.set_title(r\"$\\tau_{2,+}(\\theta)$\", fontsize=26)\n", - "ax2.set_xticks(np.array([1, 10, 100]))\n", - "ax2.tick_params(axis=\"x\", which=\"minor\", length=2, width=0.8)\n", - "ax2.tick_params(axis=\"both\", which=\"major\", labelsize=24)\n", - "ax2.tick_params(axis=\"both\", which=\"minor\", labelsize=20)\n", - "ax2.yaxis.get_offset_text().set_fontsize(24)\n", - "ax2.ticklabel_format(axis=\"y\", style=\"sci\", scilimits=(0, 0))\n", - "ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20)\n", - "\n", - "plt.savefig(\n", - " \"/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/best_fit_tau_02_SP_v1.4.6.3_B.pdf\",\n", - " bbox_inches=\"tight\",\n", - ")\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "jupytext": { - "cell_metadata_filter": "-all", - "main_language": "python", - "notebook_metadata_filter": "-all" - }, - "kernelspec": { - "display_name": "my_env", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/contours.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/contours.ipynb deleted file mode 100644 index e95be1b5..00000000 --- a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/contours.ipynb +++ /dev/null @@ -1,950 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "0", - "metadata": {}, - "source": [ - "# 2D contour plots\n", - "\n", - "This notebook produces the plots for all the 2D contours in the results section." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1", - "metadata": {}, - "outputs": [], - "source": [ - "import os.path\n", - "\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "import seaborn as sns\n", - "from astropy.io import fits\n", - "from getdist import plots\n", - "\n", - "plt.style.use(\"/home/guerrini/matplotlib_config/paper.mplstyle\")\n", - "\n", - "plt.rcParams[\"text.usetex\"] = True\n", - "\n", - "sns.set_palette(\"husl\")\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "g.settings.axes_fontsize = 70\n", - "g.settings.axes_labelsize = 80\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 70\n", - "\n", - "\n", - "# SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE\n", - "\n", - "root_dir = \"/n09data/guerrini/output_chains/\"\n", - "path_datavectors = \"/home/guerrini/sp_validation/cosmo_inference/data/\"\n", - "path_output_chains = \"/n09data/guerrini/output_chains/\"\n", - "\n", - "data = fits.open(\n", - " os.path.join(\n", - " path_datavectors,\n", - " \"SP_v1.4.6.3_config/SP_v1.4.6.3_B/cosmosis_SP_v1.4.6.3_leak_corr_B_masked.fits\",\n", - " )\n", - ")\n", - "\n", - "roots_fid = {\n", - " \"SP_v1.4.6.3_leak_corr_B\": r\"UNIONS-3500 $C_\\ell$\",\n", - " \"SP_v1.4.6.3_B_fiducial_config\": r\"UNIONS-3500 $\\xi_\\pm$ (This work) \",\n", - " \"KiDS-Legacy_xipm\": r\"KiDS-Legacy $\\xi_\\pm$\",\n", - " \"HSC_Y3\": r\"HSC-Y3 $\\xi_\\pm$\",\n", - " \"Planck18\": r\"$\\textit{Planck}$ 2018\",\n", - "}\n", - "\n", - "roots_full = {\n", - " \"SP_v1.4.6.3_B_fiducial_config\": r\"UNIONS-3500 $\\xi_\\pm$ (This work) \",\n", - "}\n", - "\n", - "roots_ia = {\n", - " \"SP_v1.4.6.3_B_fiducial_config\": r\"Gaussian $A_{\\rm{IA}}$ prior\",\n", - " \"SP_v1.4.6.3_B_flat_ia_config\": r\"Flat $A_{\\rm{IA}}$ prior\",\n", - " \"SP_v1.4.6.3_B_no_ia_config\": r\"No IA\",\n", - "}\n", - "\n", - "roots_ext = {\n", - " \"SP_v1.4.6.3_B_fiducial_config\": r\"UNIONS-3500 $\\xi_\\pm$\",\n", - " \"SP_v1.4.6.3_B_planck_config\": r\"UNIONS-3500 $\\xi_\\pm$ + CMB\",\n", - " \"SP_v1.4.6.3_B_planck_desi_config\": r\"UNIONS-3500 $\\xi_\\pm$ + CMB + BAO\",\n", - " \"Planck18\": r\"$\\textit{Planck}$ 2018\",\n", - "}\n", - "\n", - "roots_dz = {\n", - " \"SP_v1.4.6.3_B_fiducial_config\": r\"Gaussian $\\Delta z$ prior\",\n", - " \"SP_v1.4.6.3_B_flat_delta_z_config\": r\"Flat $\\Delta z$ prior\",\n", - " \"SP_v1.4.6.3_B_no_delta_z_config\": r\"No $\\Delta z$ modelling\",\n", - "}\n", - "\n", - "roots_psf = {\n", - " \"SP_v1.4.6.3_B_flat_alpha_beta_config\": r\"Flat $\\alpha$ and $\\beta$ priors\",\n", - " \"SP_v1.4.6.3_B_fiducial_config\": r\"Gaussian $\\alpha$ and $\\beta$ priors\",\n", - " \"SP_v1.4.6.3_B_no_xi_sys_config\": r\"No $\\xi^{\\rm sys}$ included\",\n", - " \"SP_v1.4.6.3_B_no_leak_corr_config\": r\"No object-wise leakage correction\",\n", - "}\n", - "\n", - "roots_scale = {\n", - " \"SP_v1.4.6.3_B_fiducial_config\": r\"$\\xi_+$: $\\theta=[12,83]$\",\n", - " \"SP_v1.4.6.3_B_small_scales_config\": r\"$\\xi_+$: $\\theta=[5,83]$\",\n", - "}\n", - "\n", - "roots_nonlin = {\n", - " \"SP_v1.4.6.3_B_fiducial_config\": r\"Fiducial (\\texttt{HMCode2020}, $\\log(T_{\\rm AGN})$)\",\n", - " \"SP_v1.4.6.3_B_no_baryons_config\": r\"\\texttt{HMCode2020} no baryons\",\n", - " \"SP_v1.4.6.3_B_halofit_config\": r\"\\texttt{Halofit}\",\n", - "}\n", - "roots = roots_ext" - ] - }, - { - "cell_type": "markdown", - "id": "2", - "metadata": {}, - "source": [ - "## Retrieve the chains" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3", - "metadata": {}, - "outputs": [], - "source": [ - "# READ CHAIN\n", - "\n", - "chains = []\n", - "\n", - "for i, root in enumerate(list(roots.keys())):\n", - " burnin = 0\n", - " if \"SP\" not in root:\n", - " chain = g.samples_for_root(\n", - " root_dir + \"ext_data/{}/getdist_{}\".format(root, root),\n", - " cache=False,\n", - " settings={\n", - " \"ignore_rows\": burnin,\n", - " # 'smooth_scale_2D':0.2,\n", - " # 'smooth_scale_1D':0.2\n", - " },\n", - " )\n", - " p = chain.getParams()\n", - " if hasattr(p, \"S_8\") == False:\n", - " omega_m = chain.getParams().OMEGA_M\n", - " sigma_8 = chain.getParams().SIGMA_8\n", - "\n", - " s_8 = sigma_8 * (omega_m / 0.3) ** 0.5\n", - "\n", - " chain.addDerived(s_8, name=\"S_8\", label=r\"S_8\")\n", - "\n", - " p = chain.paramNames.parWithName(\"S_8\")\n", - "\n", - " elif \"config\" in root:\n", - " if os.path.isfile(root_dir + \"{}/getdist_{}.txt\".format(root, root)) == False:\n", - " samples = np.loadtxt(root_dir + \"{}/samples_{}.txt\".format(root, root))\n", - "\n", - " if \"nautilus\" in root:\n", - " weights = np.exp(samples[:, -3])\n", - " neglogL = samples[:, -2] - samples[:, -1]\n", - "\n", - " samples = np.column_stack((weights, neglogL, samples[:, 0:-3]))\n", - " elif \"mh\" in root:\n", - " samples = np.column_stack(\n", - " (\n", - " np.ones_like(samples[:, -1]),\n", - " np.log(samples[:, -1]) - np.log(samples[:, -2]),\n", - " samples[:, 0:-2],\n", - " )\n", - " )\n", - " burnin = 0.3\n", - " else:\n", - " samples = np.column_stack(\n", - " (samples[:, -1], samples[:, -3], samples[:, 0:-4])\n", - " )\n", - "\n", - " np.savetxt(root_dir + \"{}/getdist_{}.txt\".format(root, root), samples)\n", - "\n", - " chain = g.samples_for_root(\n", - " root_dir + \"{}/getdist_{}\".format(root, root),\n", - " cache=False,\n", - " settings={\n", - " \"ignore_rows\": burnin,\n", - " # 'smooth_scale_2D':0.2,\n", - " # 'smooth_scale_1D':0.2\n", - " },\n", - " )\n", - " else:\n", - " if (\n", - " os.path.isfile(\n", - " root_dir + \"{}/{}/getdist_{}_cell.txt\".format(root, root, root)\n", - " )\n", - " == False\n", - " ):\n", - " samples = np.loadtxt(\n", - " root_dir + \"{}/{}/samples_{}_cell.txt\".format(root, root, root)\n", - " )\n", - "\n", - " if \"nautilus\" in root:\n", - " weights = np.exp(samples[:, -3])\n", - " neglogL = samples[:, -2] - samples[:, -1]\n", - "\n", - " samples = np.column_stack((weights, neglogL, samples[:, 0:-3]))\n", - " elif \"mh\" in root:\n", - " samples = np.column_stack(\n", - " (\n", - " np.ones_like(samples[:, -1]),\n", - " np.log(samples[:, -1]) - np.log(samples[:, -2]),\n", - " samples[:, 0:-2],\n", - " )\n", - " )\n", - " burnin = 0.3\n", - " else:\n", - " samples = np.column_stack(\n", - " (samples[:, -1], samples[:, -3], samples[:, 0:-4])\n", - " )\n", - "\n", - " np.savetxt(\n", - " root_dir + \"{}/{}/getdist_{}_cell.txt\".format(root, root, root), samples\n", - " )\n", - "\n", - " chain = g.samples_for_root(\n", - " root_dir + \"{}/{}/getdist_{}_cell\".format(root, root, root),\n", - " cache=False,\n", - " settings={\n", - " \"ignore_rows\": burnin,\n", - " # 'smooth_scale_2D':0.2,\n", - " # 'smooth_scale_1D':0.2\n", - " },\n", - " )\n", - " p = chain.getParams()\n", - "\n", - " chains.append(chain)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4", - "metadata": {}, - "outputs": [], - "source": [ - "name_list = [\n", - " \"OMEGA_M\",\n", - " \"ombh2\",\n", - " \"h0\",\n", - " \"n_s\",\n", - " \"SIGMA_8\",\n", - " \"S_8\",\n", - " \"logt_agn\",\n", - " \"a\",\n", - " \"m1\",\n", - " \"bias_1\",\n", - " \"alpha\",\n", - " \"beta\",\n", - " \"omch2\",\n", - "]\n", - "label_list = [\n", - " r\"\\Omega_{\\rm m}\",\n", - " r\"\\omega_{\\rm b}\",\n", - " r\"h\",\n", - " r\"n_{\\rm s}\",\n", - " r\"\\sigma_8\",\n", - " r\"S_8\",\n", - " r\"\\log T_{\\rm AGN}\",\n", - " r\"A_{\\rm IA}\",\n", - " r\"m_1\",\n", - " r\"\\Delta z\",\n", - " r\"\\alpha_{\\rm PSF}\",\n", - " r\"\\beta_{\\rm PSF}\",\n", - " r\"\\omega_{\\rm c}\",\n", - "]\n", - "\n", - "for chain in chains:\n", - " param_names = chain.getParamNames()\n", - " p = chain.getParams()\n", - " for name, label in zip(name_list, label_list):\n", - " if hasattr(p, name):\n", - " param_names.parWithName(name).label = label\n", - "\n", - "legend_labels = list(roots.values())" - ] - }, - { - "cell_type": "markdown", - "id": "5", - "metadata": {}, - "source": [ - "## Plot the chains" - ] - }, - { - "cell_type": "markdown", - "id": "6", - "metadata": {}, - "source": [ - "### FIDUCIAL PLOT" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7", - "metadata": {}, - "outputs": [], - "source": [ - "%matplotlib inline\n", - "\n", - "colours = [\n", - " \"royalblue\",\n", - " \"orange\",\n", - " \"crimson\",\n", - " \"forestgreen\",\n", - " \"indigo\",\n", - "]\n", - "\n", - "linestyle = [\"solid\", \"solid\", \"solid\", \"solid\", \"solid\"]\n", - "\n", - "line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)]\n", - "\n", - "# FIDUCIAL PLOT\n", - "g.triangle_plot(\n", - " chains,\n", - " [\"SIGMA_8\", \"S_8\", \"OMEGA_M\"], #\n", - " legend_labels=legend_labels,\n", - " line_args=line_args,\n", - " contour_colors=colours,\n", - " label_order=[1, 0, 2, 3, 4],\n", - " filled=[True, True, False, False, True],\n", - ")\n", - "\n", - "g.export(\"../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot.pdf\")" - ] - }, - { - "cell_type": "markdown", - "id": "8", - "metadata": {}, - "source": [ - "### FULL PLOT" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9", - "metadata": {}, - "outputs": [], - "source": [ - "%matplotlib inline\n", - "\n", - "g.settings.axes_fontsize = 40\n", - "g.settings.axes_labelsize = 50\n", - "\n", - "colours = [\n", - " \"orange\",\n", - "]\n", - "\n", - "linestyle = [\n", - " \"solid\",\n", - "]\n", - "\n", - "line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)]\n", - "\n", - "# FIDUCIAL PLOT\n", - "g.triangle_plot(\n", - " chains,\n", - " [\n", - " \"OMEGA_M\",\n", - " \"ombh2\",\n", - " \"h0\",\n", - " \"n_s\",\n", - " \"SIGMA_8\",\n", - " \"S_8\",\n", - " \"logt_agn\",\n", - " \"a\",\n", - " \"m1\",\n", - " \"bias_1\",\n", - " ],\n", - " legend_labels=legend_labels,\n", - " line_args=line_args,\n", - " contour_colors=colours,\n", - " filled=True,\n", - ")\n", - "\n", - "g.export(\"../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_full.pdf\")" - ] - }, - { - "cell_type": "markdown", - "id": "10", - "metadata": {}, - "source": [ - "### IA PLOT" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "11", - "metadata": {}, - "outputs": [], - "source": [ - "colours = [\n", - " \"orange\",\n", - " \"royalblue\",\n", - " \"forestgreen\",\n", - "]\n", - "\n", - "linestyle = [\n", - " \"solid\",\n", - " \"solid\",\n", - " \"solid\",\n", - "]\n", - "\n", - "line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)]\n", - "\n", - "g.triangle_plot(\n", - " chains,\n", - " [\"S_8\", \"OMEGA_M\", \"a\"], #\n", - " legend_labels=legend_labels,\n", - " line_args=line_args,\n", - " contour_args={\"alpha\": 0.6},\n", - " contour_colors=colours,\n", - " filled=[True, False, True],\n", - ")\n", - "\n", - "g.export(\"../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_ia.pdf\")" - ] - }, - { - "cell_type": "markdown", - "id": "12", - "metadata": {}, - "source": [ - "### PSF PLOT" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "13", - "metadata": {}, - "outputs": [], - "source": [ - "colours = [\n", - " \"royalblue\",\n", - " \"orange\",\n", - " \"hotpink\",\n", - " \"slategray\",\n", - "]\n", - "\n", - "linestyle = [\n", - " \"solid\",\n", - " \"solid\",\n", - " \"solid\",\n", - " \"solid\",\n", - "]\n", - "\n", - "line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)]\n", - "\n", - "g.triangle_plot(\n", - " chains,\n", - " [\"S_8\", \"OMEGA_M\", \"alpha\", \"beta\"], #\n", - " legend_labels=legend_labels,\n", - " line_args=line_args,\n", - " contour_args=[{\"alpha\": 1}, {\"alpha\": 0.6}, {\"alpha\": 0.8}, {\"alpha\": 0.8}],\n", - " contour_colors=colours,\n", - " legend_loc=\"upper right\",\n", - " label_order=[1, 0, 2, 3],\n", - " filled=[False, True, True, True],\n", - ")\n", - "\n", - "g.subplots[3, 2].scatter(\n", - " 0.005, 0.81, color=\"k\", marker=\"X\", s=400, label=\"Fiducial config best-fit\"\n", - ")\n", - "g.subplots[3, 2].scatter(\n", - " 0.022, 0.798, color=\"k\", marker=\"P\", s=400, label=\"Fiducial config best-fit\"\n", - ")\n", - "\n", - "g.export(\"../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_psf.pdf\")" - ] - }, - { - "cell_type": "markdown", - "id": "14", - "metadata": {}, - "source": [ - "### DELTA Z PLOT" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "15", - "metadata": {}, - "outputs": [], - "source": [ - "colours = [\n", - " \"orange\",\n", - " \"royalblue\",\n", - " \"indigo\",\n", - "]\n", - "\n", - "linestyle = [\n", - " \"solid\",\n", - " \"solid\",\n", - " \"solid\",\n", - "]\n", - "\n", - "line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)]\n", - "g.triangle_plot(\n", - " chains,\n", - " [\"S_8\", \"OMEGA_M\", \"bias_1\"], #\n", - " legend_labels=legend_labels,\n", - " line_args=line_args,\n", - " contour_args=[{\"alpha\": 1.0}, {\"alpha\": 0.9}, {\"alpha\": 0.5}],\n", - " contour_colors=colours,\n", - " filled=[True, False, True],\n", - ")\n", - "\n", - "g.export(\"../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_dz.pdf\")" - ] - }, - { - "cell_type": "markdown", - "id": "16", - "metadata": {}, - "source": [ - "### EXTERNAL DATA" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "17", - "metadata": {}, - "outputs": [], - "source": [ - "colours = [\n", - " \"orange\",\n", - " \"royalblue\",\n", - " \"crimson\",\n", - " \"forestgreen\",\n", - "]\n", - "\n", - "linestyle = [\n", - " \"solid\",\n", - " \"solid\",\n", - " \"solid\",\n", - " \"solid\",\n", - " \"solid\",\n", - "]\n", - "\n", - "line_args = [dict(color=col, ls=ls) for col, ls in zip(colours, linestyle)]\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=10)\n", - "g.settings.axes_fontsize = 25\n", - "g.settings.axes_labelsize = 25\n", - "g.settings.legend_fontsize = 22\n", - "\n", - "g.plot_2d(\n", - " chains,\n", - " [\"S_8\", \"OMEGA_M\", \"SIGMA_8\"], #\n", - " line_args=line_args,\n", - " contour_colors=colours,\n", - " legend_labels=legend_labels,\n", - " alphas=[0.7, 1.0, 1.0, 1.0],\n", - " filled=[True, True, True, False],\n", - ")\n", - "\n", - "g.add_y_bands(0.2975, 0.0086, alpha2=0, color=\"k\", label=\"BAO\")\n", - "g.add_legend(legend_labels, legend_loc=\"upper right\")\n", - "\n", - "g.export(\"../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_ext.pdf\")" - ] - }, - { - "cell_type": "markdown", - "id": "18", - "metadata": {}, - "source": [ - "### Small scales" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "19", - "metadata": {}, - "outputs": [], - "source": [ - "%matplotlib inline\n", - "\n", - "colours = [\n", - " \"orange\",\n", - " \"dodgerblue\",\n", - "]\n", - "\n", - "linestyle = [\n", - " \"solid\",\n", - " \"solid\",\n", - "]\n", - "\n", - "line_args = [dict(color=col, ls=ls) for col, ls in zip(colours, linestyle)]\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=9)\n", - "g.settings.axes_fontsize = 25\n", - "g.settings.axes_labelsize = 25\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 30\n", - "\n", - "g.plot_2d(\n", - " chains,\n", - " [\"S_8\", \"OMEGA_M\"], #\n", - " line_args=line_args,\n", - " contour_args=[{\"alpha\": 0.7}, {\"alpha\": 1.0}],\n", - " contour_colors=colours,\n", - " filled=[True, True],\n", - ")\n", - "g.add_legend(legend_labels, legend_loc=\"upper right\")\n", - "\n", - "g.export(\"../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_scales.pdf\")" - ] - }, - { - "cell_type": "markdown", - "id": "20", - "metadata": {}, - "source": [ - "### BBN Prior" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "21", - "metadata": {}, - "outputs": [], - "source": [ - "%matplotlib inline\n", - "\n", - "from getdist.gaussian_mixtures import Gaussian1D\n", - "\n", - "colours = [\n", - " \"orange\",\n", - " \"royalblue\",\n", - "]\n", - "\n", - "linestyle = [\n", - " \"solid\",\n", - " \"solid\",\n", - "]\n", - "\n", - "line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)]\n", - "\n", - "# BBN PRIOR\n", - "bbn_prior = Gaussian1D(\n", - " mean=0.02218,\n", - " sigma=0.00055,\n", - " name=\"ombh2\",\n", - " labels=[r\"\\omega_{\\rm b}\"],\n", - " label=\"BBN prior\",\n", - ")\n", - "bbn_chain = bbn_prior.MCSamples(3000, label=\"BBN prior\")\n", - "\n", - "g.triangle_plot(\n", - " chains + [bbn_chain],\n", - " name_list,\n", - " legend_labels=legend_labels,\n", - " line_args=line_args,\n", - " contour_colors=colours,\n", - " filled=[True, False],\n", - ")" - ] - }, - { - "cell_type": "markdown", - "id": "22", - "metadata": {}, - "source": [ - "## Plot the best-fit $\\xi_\\pm$" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "23", - "metadata": {}, - "outputs": [], - "source": [ - "xi_p_data = data[\"XI_PLUS\"].data\n", - "xi_m_data = data[\"XI_MINUS\"].data\n", - "cov_mat = data[\"COVMAT\"].data\n", - "\n", - "labels = roots_scale.values()\n", - "\n", - "bbox_to_anchor_xip = (0.685, 0.09)\n", - "bbox_to_anchor_xim = (0.3, 0.65)\n", - "theta_min = 1.0\n", - "theta_max = 250.0\n", - "loc_legend = \"lower center\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "24", - "metadata": {}, - "outputs": [], - "source": [ - "colours = [\n", - " \"orange\",\n", - " \"dodgerblue\",\n", - "]\n", - "\n", - "linestyle = [\n", - " \"solid\",\n", - " \"solid\",\n", - "]\n", - "\n", - "line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)]\n", - "\n", - "labels = roots_scale.values()\n", - "\n", - "fig, ax = plt.subplots(1, 1, figsize=(11, 7))\n", - "\n", - "theta, xi_p, xi_m = xi_p_data[\"ANG\"], xi_p_data[\"VALUE\"], xi_m_data[\"VALUE\"]\n", - "ax.errorbar(\n", - " theta,\n", - " theta * xi_p,\n", - " yerr=theta * np.sqrt(np.diag(cov_mat[: len(theta), : len(theta)])),\n", - " fmt=\"o\",\n", - " color=\"black\",\n", - " capsize=2,\n", - ")\n", - "\n", - "for idx, (label, root) in enumerate(zip(labels, roots_scale)):\n", - " # Read the results\n", - " theta = (\n", - " (\n", - " np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " )\n", - " * 180\n", - " / np.pi\n", - " * 60\n", - " )\n", - " xi_plus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_minus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = (\n", - " np.loadtxt(path_output_chains + \"{}/best_fit/xi_sys/theta.txt\".format(root))\n", - " * 180\n", - " / np.pi\n", - " * 60\n", - " )\n", - "\n", - " xi_sys_plus = np.interp(theta, theta_xi_sys, xi_sys_plus)\n", - " xi_sys_minus = np.interp(theta, theta_xi_sys, xi_sys_minus)\n", - " xi_plus += xi_sys_plus\n", - " xi_minus += xi_sys_minus\n", - "\n", - " mask = (theta > theta_min) & (theta < theta_max)\n", - " theta = theta[mask]\n", - " ax.plot(theta, theta * xi_plus[mask], label=label, **line_args[idx])\n", - "\n", - "ymin = ax.get_ylim()[0]\n", - "ymax = ax.get_ylim()[1]\n", - "\n", - "ax.fill_betweenx(y=[ymin, ymax], x1=0, x2=12, color=\"gray\", alpha=0.2)\n", - "ax.fill_betweenx(y=[ymin, ymax], x1=0, x2=5, color=\"gray\", alpha=0.7)\n", - "ax.fill_betweenx(y=[ymin, ymax], x1=83, x2=300, color=\"gray\", alpha=0.2)\n", - "\n", - "ax.set_ylim(ymin, ymax)\n", - "\n", - "ax.set_ylabel(r\"$\\theta \\xi_\\pm$\", fontsize=26)\n", - "ax.set_xlabel(r\"$\\theta$ (arcmin)\", fontsize=26)\n", - "ax.set_xlim([theta.min() - 0.1, theta.max() + 20])\n", - "ax.set_title(r\"$\\xi_+(\\theta)$\", fontsize=26)\n", - "ax.set_xscale(\"log\")\n", - "ax.set_xticks(np.array([1, 10, 100]))\n", - "ax.tick_params(axis=\"x\", which=\"minor\", length=2, width=0.8)\n", - "ax.tick_params(axis=\"both\", which=\"major\", labelsize=24)\n", - "ax.tick_params(axis=\"both\", which=\"minor\", labelsize=20)\n", - "ax.yaxis.get_offset_text().set_fontsize(24)\n", - "ax.ticklabel_format(axis=\"y\", style=\"sci\", scilimits=(0, 0))\n", - "ax.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xip, fontsize=20)\n", - "\n", - "\n", - "plt.savefig(\"./../Plots/scale_cut_xipm_SP_v1.4.6.3_B.pdf\", bbox_inches=\"tight\")\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "25", - "metadata": {}, - "outputs": [], - "source": [ - "labels = roots_nonlin.values()\n", - "\n", - "colours = [\"orange\", \"hotpink\", \"teal\"]\n", - "\n", - "linestyle = [\"solid\", \"solid\", \"dashed\"]\n", - "\n", - "line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)]\n", - "\n", - "fig, [ax, ax2] = plt.subplots(2, 1, figsize=(11, 14))\n", - "\n", - "theta, xi_p, xi_m = xi_p_data[\"ANG\"], xi_p_data[\"VALUE\"], xi_m_data[\"VALUE\"]\n", - "ax.errorbar(\n", - " theta,\n", - " theta * xi_p,\n", - " yerr=theta * np.sqrt(np.diag(cov_mat[: len(theta), : len(theta)])),\n", - " fmt=\"o\",\n", - " color=\"black\",\n", - " capsize=2,\n", - ")\n", - "ax2.errorbar(\n", - " theta,\n", - " theta * xi_m,\n", - " yerr=theta\n", - " * np.sqrt(\n", - " np.diag(cov_mat[len(theta) : 2 * len(theta), len(theta) : 2 * len(theta)])\n", - " ),\n", - " fmt=\"o\",\n", - " color=\"black\",\n", - " capsize=2,\n", - ")\n", - "\n", - "for idx, (label, root) in enumerate(zip(labels, roots_nonlin)):\n", - " # Read the results\n", - " theta = (\n", - " (\n", - " np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " )\n", - " * 180\n", - " / np.pi\n", - " * 60\n", - " )\n", - " xi_plus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_minus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - " xi_sys_plus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " path_output_chains + \"{}/best_fit/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - " theta_xi_sys = (\n", - " np.loadtxt(path_output_chains + \"{}/best_fit/xi_sys/theta.txt\".format(root))\n", - " * 180\n", - " / np.pi\n", - " * 60\n", - " )\n", - "\n", - " xi_sys_plus = np.interp(theta, theta_xi_sys, xi_sys_plus)\n", - " xi_sys_minus = np.interp(theta, theta_xi_sys, xi_sys_minus)\n", - " xi_plus += xi_sys_plus\n", - " xi_minus += xi_sys_minus\n", - "\n", - " mask = (theta > theta_min) & (theta < theta_max)\n", - " theta = theta[mask]\n", - " ax.plot(theta, theta * xi_plus[mask], label=label, **line_args[idx])\n", - " ax2.plot(theta, theta * xi_minus[mask], label=label, **line_args[idx])\n", - "\n", - "ymin = ax.get_ylim()[0]\n", - "ymax = ax.get_ylim()[1]\n", - "ax.fill_betweenx(y=[ymin, ymax], x1=0, x2=12, color=\"gray\", alpha=0.2)\n", - "ax.fill_betweenx(y=[ymin, ymax], x1=83, x2=300, color=\"gray\", alpha=0.2)\n", - "\n", - "ax.set_ylim(ymin, ymax)\n", - "\n", - "ax.set_ylabel(r\"$\\theta \\xi_\\pm$\", fontsize=26)\n", - "ax.set_xlabel(r\"$\\theta$ (arcmin)\", fontsize=26)\n", - "ax.set_xlim([theta.min() - 0.1, theta.max() + 20])\n", - "ax.set_title(r\"$\\xi_+(\\theta)$\", fontsize=26)\n", - "ax.set_xscale(\"log\")\n", - "ax.set_xticks(np.array([1, 10, 100]))\n", - "ax.tick_params(axis=\"x\", which=\"minor\", length=2, width=0.8)\n", - "ax.tick_params(axis=\"both\", which=\"major\", labelsize=24)\n", - "ax.tick_params(axis=\"both\", which=\"minor\", labelsize=20)\n", - "ax.yaxis.get_offset_text().set_fontsize(24)\n", - "ax.ticklabel_format(axis=\"y\", style=\"sci\", scilimits=(0, 0))\n", - "\n", - "\n", - "ymin = ax2.get_ylim()[0]\n", - "ymax = ax2.get_ylim()[1]\n", - "ax2.fill_betweenx(y=[ymin, ymax], x1=0, x2=12, color=\"gray\", alpha=0.2)\n", - "ax2.fill_betweenx(y=[ymin, ymax], x1=83, x2=3000, color=\"gray\", alpha=0.2)\n", - "\n", - "ax2.set_ylim(ymin, ymax)\n", - "ax2.set_xlabel(r\"$\\theta$ (arcmin)\", fontsize=26)\n", - "ax2.set_xlim([theta.min() - 0.1, theta.max()])\n", - "ax2.set_xscale(\"log\")\n", - "ax2.set_title(r\"$\\xi_-(\\vartheta)$\", fontsize=26)\n", - "ax2.set_xticks(np.array([1, 10, 100]))\n", - "ax2.tick_params(axis=\"x\", which=\"minor\", length=2, width=0.8)\n", - "ax2.tick_params(axis=\"both\", which=\"major\", labelsize=24)\n", - "ax2.tick_params(axis=\"both\", which=\"minor\", labelsize=20)\n", - "ax2.yaxis.get_offset_text().set_fontsize(24)\n", - "ax2.ticklabel_format(axis=\"y\", style=\"sci\", scilimits=(0, 0))\n", - "ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20)\n", - "\n", - "plt.savefig(\"./../Plots/nonlin_xipm_SP_v1.4.6.3_B.pdf\", bbox_inches=\"tight\")\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "26", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "my_env", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_chi2.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_chi2.ipynb deleted file mode 100644 index f124e4cd..00000000 --- a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_chi2.ipynb +++ /dev/null @@ -1,690 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import configparser\n", - "import os\n", - "import re\n", - "import subprocess\n", - "import sys\n", - "\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "import scipy.stats as stats\n", - "from astropy.io import fits\n", - "from getdist import plots\n", - "from IPython.display import Markdown, display\n", - "from scipy.interpolate import interp1d\n", - "\n", - "sys.path.append(\"/home/guerrini/sp_validation/cosmo_inference/scripts\")\n", - "\n", - "import chain_postprocessing\n", - "\n", - "%matplotlib inline\n", - "\n", - "plt.rc(\"mathtext\", fontset=\"stix\")\n", - "plt.rc(\"font\", family=\"sans-serif\")\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "g.settings.axes_fontsize = 30\n", - "g.settings.axes_labelsize = 30\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 40\n", - "\n", - "# #SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE\n", - "root_dir = \"/n09data/guerrini/output_chains/\"\n", - "blind = \"B\"\n", - "\n", - "roots = [\n", - " f\"SP_v1.4.6.3_{blind}_fiducial_config\",\n", - " f\"SP_v1.4.6.3_{blind}_small_scales_config\",\n", - " f\"SP_v1.4.6.3_{blind}_flat_alpha_beta_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_xi_sys_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_leak_corr_config\",\n", - " f\"SP_v1.4.6.3_{blind}_flat_delta_z_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_delta_z_config\",\n", - " f\"SP_v1.4.6.3_{blind}_flat_ia_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_ia_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_m_bias_config\",\n", - " f\"SP_v1.4.6.3_{blind}_unmasked_covmat_config\",\n", - " f\"SP_v1.4.6.3_{blind}_halofit_config\",\n", - " f\"SP_v1.4.6.3_{blind}_no_baryons_config\",\n", - " f\"SP_v1.4.6.3_{blind}_nautilus_config\",\n", - " f\"SP_v1.4.6.3_{blind}_planck_config\",\n", - " f\"SP_v1.4.6.3_{blind}_planck_desi_config\",\n", - "]\n", - "\n", - "catalog_versions = [\n", - " f\"SP_v1.4.6.3_config/SP_v1.4.6.3_{blind}\",\n", - "]\n", - "\n", - "catalog_sub_versions = [\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - " f\"SP_v1.4.6.3_leak_corr_{blind}_masked\",\n", - "]\n", - "output_folder = \"/n09data/guerrini/output_chains/\"\n", - "\n", - "path_ini_files = \"/home/guerrini/sp_validation/cosmo_inference/cosmosis_config/\"\n", - "\n", - "\n", - "ini_roots = [\n", - " f\"blind_{blind}/fiducial\",\n", - " f\"blind_{blind}/small_scales\",\n", - " f\"blind_{blind}/flat_alpha_beta\",\n", - " f\"blind_{blind}/no_xi_sys\",\n", - " f\"blind_{blind}/no_leak_corr\",\n", - " f\"blind_{blind}/flat_delta_z\",\n", - " f\"blind_{blind}/no_delta_z\",\n", - " f\"blind_{blind}/flat_ia\",\n", - " f\"blind_{blind}/no_ia\",\n", - " f\"blind_{blind}/no_m_bias\",\n", - " f\"blind_{blind}/unmasked_covmat\",\n", - " f\"blind_{blind}/halofit\",\n", - " f\"blind_{blind}/no_baryons\",\n", - " f\"blind_{blind}/nautilus\",\n", - " f\"blind_{blind}/planck\",\n", - " f\"blind_{blind}/planck_desi\",\n", - "]\n", - "\n", - "properties = {}\n", - "\n", - "for i, root in enumerate(roots):\n", - " print(root)\n", - " config = configparser.ConfigParser()\n", - " config.optionxform = str # Preserve case sensitivity of option names\n", - " config.read(\n", - " path_ini_files\n", - " + \"config_space_v1.4.6.3_fiducial/pipeline/\"\n", - " + ini_roots[i]\n", - " + \".ini\"\n", - " )\n", - " add_xi_sys = config[\"2pt_like\"][\"add_xi_sys\"]\n", - " lower_bound_xi_plus, upper_bound_xi_plus = map(\n", - " float, config[\"2pt_like\"][\"angle_range_XI_PLUS_1_1\"].split()\n", - " )\n", - " lower_bound_xi_minus, upper_bound_xi_minus = map(\n", - " float, config[\"2pt_like\"][\"angle_range_XI_MINUS_1_1\"].split()\n", - " )\n", - "\n", - " properties[root] = {\n", - " \"add_xi_sys\": add_xi_sys,\n", - " \"lower_bound_xi_plus\": lower_bound_xi_plus,\n", - " \"upper_bound_xi_plus\": upper_bound_xi_plus,\n", - " \"lower_bound_xi_minus\": lower_bound_xi_minus,\n", - " \"upper_bound_xi_minus\": upper_bound_xi_minus,\n", - " }" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Retrieve the chains" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# READ CHAIN\n", - "\n", - "chains = []\n", - "\n", - "for i, root in enumerate(roots):\n", - " burnin = 0\n", - "\n", - " if os.path.isfile(root_dir + \"{}/getdist_{}.txt\".format(root, root)) == False:\n", - " samples = np.loadtxt(root_dir + \"{}/samples_{}.txt\".format(root, root))\n", - "\n", - " if \"nautilus\" in root:\n", - " samples = np.column_stack(\n", - " (\n", - " np.exp(samples[:, -3]),\n", - " samples[:, -1] - samples[:, -2],\n", - " samples[:, 0:-3],\n", - " )\n", - " )\n", - " elif \"mh\" in root:\n", - " samples = np.column_stack(\n", - " (\n", - " np.ones_like(samples[:, -1]),\n", - " np.log(samples[:, -1]) - np.log(samples[:, -2]),\n", - " samples[:, 0:-2],\n", - " )\n", - " )\n", - " burnin = 0.3\n", - " else:\n", - " samples = np.column_stack(\n", - " (samples[:, -1], samples[:, -3], samples[:, 0:-4])\n", - " )\n", - "\n", - " np.savetxt(root_dir + \"{}/getdist_{}.txt\".format(root, root), samples)\n", - "\n", - " chain = g.samples_for_root(\n", - " root_dir + \"{}/getdist_{}\".format(root, root),\n", - " cache=False,\n", - " settings={\n", - " \"ignore_rows\": burnin,\n", - " \"smooth_scale_2D\": 0.5,\n", - " \"smooth_scale_1D\": 0.5,\n", - " },\n", - " )\n", - " p = chain.getParams()\n", - "\n", - " chains.append(chain)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "param_list = [\n", - " \"OMEGA_M\",\n", - " \"ombh2\",\n", - " \"h0\",\n", - " \"n_s\",\n", - " \"SIGMA_8\",\n", - " \"s_8_input\",\n", - " \"logt_agn\",\n", - " \"a\",\n", - " \"m1\",\n", - " \"bias_1\",\n", - " \"alpha\",\n", - " \"beta\",\n", - " \"omch2\",\n", - " \"m\",\n", - " \"a_planck\",\n", - "]\n", - "label_list = [\n", - " r\"\\Omega_m\",\n", - " r\"\\omega_b\",\n", - " \"h_0\",\n", - " \"n_s\",\n", - " r\"\\sigma_8\",\n", - " \"S_8\",\n", - " \"log T_{AGN}\",\n", - " \"A_{IA}\",\n", - " \"m_1\",\n", - " r\"\\Delta z_1\",\n", - " \"\\\\alpha_{PSF}\",\n", - " \"\\\\beta_{PSF}\",\n", - " r\"\\omega_c\",\n", - " \"M\",\n", - " \"A_{\\rm Planck}\",\n", - "]\n", - "\n", - "for chain in chains:\n", - " param_names = chain.getParamNames()\n", - " for name, label in zip(param_list, label_list):\n", - " if param_names.parWithName(name) is not None:\n", - " param_names.parWithName(name).label = label" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Extract the best fit parameters" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "best_fit = {}\n", - "\n", - "for root, chain in zip(roots, chains):\n", - " print(root)\n", - " p = chain.getParams()\n", - "\n", - " best_fit[root] = chain_postprocessing.extract_best_fit_params(\n", - " chain, best_fit_method=\"2Dkde\"\n", - " )\n", - "\n", - " for param_name in best_fit[root].keys():\n", - " high_68, low_68, high_95, low_95 = chain_postprocessing.compute_limits(\n", - " chain, param_name\n", - " )\n", - " if param_name == \"S_8\":\n", - " print(f\"{best_fit[root][param_name]}\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Run `Cosmosis` in test mode to get the data vectors" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if not os.path.exists(path_ini_files + \"/values_empty.ini\"):\n", - " content = \"\"\"[cosmological_parameters]\n", - "\n", - "tau = 0.0544\n", - "w = -1.0\n", - "mnu = 0.06\n", - "omega_k = 0.0\n", - "wa = 0.0\n", - "\n", - "[halo_model_parameters]\n", - "\n", - "[intrinsic_alignment_parameters]\n", - "\n", - "[shear_calibration_parameters]\n", - "\n", - "[nofz_shifts]\n", - "\n", - "[psf_leakage_parameters]\n", - "\"\"\"\n", - "\n", - " with open(path_ini_files + \"/values_empty.ini\", \"w\") as f:\n", - " f.write(content)\n", - " f.close()\n", - "\n", - " print(\"File created successfully\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "section_map = {\n", - " \"omch2\": \"cosmological_parameters\",\n", - " \"ombh2\": \"cosmological_parameters\",\n", - " \"h0\": \"cosmological_parameters\",\n", - " \"n_s\": \"cosmological_parameters\",\n", - " \"tau\": \"cosmological_parameters\",\n", - " \"s_8_input\": \"cosmological_parameters\",\n", - " \"logt_agn\": \"halo_model_parameters\",\n", - " \"a\": \"intrinsic_alignment_parameters\",\n", - " \"m1\": \"shear_calibration_parameters\",\n", - " \"bias_1\": \"nofz_shifts\",\n", - " \"alpha\": \"psf_leakage_parameters\",\n", - " \"beta\": \"psf_leakage_parameters\",\n", - " \"m\": \"supernova_params\",\n", - " \"a_planck\": \"planck\",\n", - "}\n", - "\n", - "best_fit[\"SP_v1.4.6.3_B_no_ia_config\"][\"a\"] = 0" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "env = os.environ.copy()\n", - "env[\"LD_LIBRARY_PATH\"] = (\n", - " \"/home/guerrini/.conda/envs/sp_validation/lib/python3.9/site-packages/cosmosis/datablock:\"\n", - " + env.get(\"LD_LIBRARY_PATH\", \"\")\n", - ")\n", - "\n", - "for i, root in enumerate(roots):\n", - " print(root)\n", - " config = configparser.ConfigParser()\n", - " config.optionxform = str # Preserve case sensitivity of option names\n", - "\n", - " for param, section in section_map.items():\n", - " # Check if this parameter exists for the current root\n", - " if param in best_fit[root]:\n", - " value = best_fit[root][param]\n", - "\n", - " if section not in config:\n", - " config.add_section(section)\n", - "\n", - " config[section][param] = str(value)\n", - "\n", - " with open(path_ini_files + \"/values_empty.ini\", \"w\") as configfile:\n", - " config.write(configfile)\n", - "\n", - " # Modify the ini file to run in test mode at the best fit\n", - " config = configparser.ConfigParser()\n", - " config.optionxform = str # Preserve case sensitivity of option names\n", - "\n", - " ini_file = path_ini_files + \"config_space_v1.4.6.3_fiducial/pipeline/{}.ini\".format(\n", - " ini_roots[i]\n", - " )\n", - " config.read(ini_file)\n", - "\n", - " sampler = config[\"runtime\"][\"sampler\"]\n", - " config[\"runtime\"][\"sampler\"] = \"test\"\n", - " values = config[\"pipeline\"][\"values\"]\n", - " config[\"pipeline\"][\"values\"] = path_ini_files + \"/values_empty.ini\"\n", - " config[\"DEFAULT\"][\"FITS_FILE\"] = (\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{catalog_versions[0]}/cosmosis_{catalog_sub_versions[i]}.fits\"\n", - " )\n", - " config[\"test\"][\"save_dir\"] = root_dir + \"{}/best_fit\".format(root)\n", - "\n", - " with open(ini_file, \"w\") as configfile:\n", - " config.write(configfile)\n", - "\n", - " # Run cosmosis\n", - " result = subprocess.run(\n", - " [\"cosmosis\", ini_file], env=env, capture_output=True, text=True\n", - " )\n", - " print(f\"STDOUT:\\n{result.stdout}\")\n", - " print(f\"STDERR:\\n{result.stderr}\")\n", - "\n", - " # Modify the ini file to the previous one\n", - " config[\"pipeline\"][\"values\"] = values\n", - " config[\"runtime\"][\"sampler\"] = sampler\n", - "\n", - " with open(ini_file, \"w\") as configfile:\n", - " config.write(configfile)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Compute the $\\chi^2$" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "metrics = {}\n", - "\n", - "for idx, root in enumerate(roots):\n", - " print(root)\n", - " match = re.search(r\"corr_([A-Za-z])\", root)\n", - " if match:\n", - " blind = match.group(1)\n", - "\n", - " add_xi_sys = properties[root][\"add_xi_sys\"]\n", - " print(f\"add_xi_sys: {add_xi_sys}\")\n", - " lower_bound_xi_plus = properties[root][\"lower_bound_xi_plus\"]\n", - " upper_bound_xi_plus = properties[root][\"upper_bound_xi_plus\"]\n", - " lower_bound_xi_minus = properties[root][\"lower_bound_xi_minus\"]\n", - " upper_bound_xi_minus = properties[root][\"upper_bound_xi_minus\"]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder + \"{}/best_fit/shear_xi_plus/theta.txt\".format(root)\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder + \"{}/best_fit/shear_xi_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder + \"{}/best_fit/shear_xi_minus/bin_1_1.txt\".format(root)\n", - " )\n", - "\n", - " if add_xi_sys == \"T\":\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder + \"{}/best_fit/xi_sys/shear_xi_plus.txt\".format(root)\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder + \"{}/best_fit/xi_sys/shear_xi_minus.txt\".format(root)\n", - " )\n", - "\n", - " theta_tau = np.loadtxt(\n", - " output_folder + \"{}/best_fit/tau_0_plus/theta.txt\".format(root)\n", - " )\n", - " theta_tau_arcmin = theta_tau * 180 * 60 / np.pi\n", - " tau_0_model = np.loadtxt(\n", - " output_folder + \"{}/best_fit/tau_0_plus/bin_1_1.txt\".format(root)\n", - " )\n", - " tau_2_model = np.loadtxt(\n", - " output_folder + \"{}/best_fit/tau_2_plus/bin_1_1.txt\".format(root)\n", - " )\n", - "\n", - " data = fits.open(\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{catalog_versions[0]}/cosmosis_{catalog_sub_versions[idx]}.fits\"\n", - " )\n", - "\n", - " tau_0_data = data[\"TAU_0_PLUS\"].data[\"VALUE\"]\n", - " tau_2_data = data[\"TAU_2_PLUS\"].data[\"VALUE\"]\n", - "\n", - " theta_data = data[\"XI_PLUS\"].data[\"ANG\"]\n", - " xi_plus_data = data[\"XI_PLUS\"].data[\"VALUE\"]\n", - " xi_minus_data = data[\"XI_MINUS\"].data[\"VALUE\"]\n", - "\n", - " # Load the covariance\n", - " cov = data[\"COVMAT\"].data\n", - " cov_xi = cov[0 : 2 * len(xi_plus_data), 0 : 2 * len(xi_plus_data)]\n", - " cov_tau = cov[2 * len(xi_plus_data) :, 2 * len(xi_plus_data) :]\n", - "\n", - " # interpolate the model\n", - " interp_xi_plus = interp1d(\n", - " theta_arcmin, shear_xi_plus, kind=\"cubic\", fill_value=\"extrapolate\"\n", - " )\n", - " interp_xi_minus = interp1d(\n", - " theta_arcmin, shear_xi_minus, kind=\"cubic\", fill_value=\"extrapolate\"\n", - " )\n", - "\n", - " xi_plus_model = interp_xi_plus(theta_data)\n", - " if add_xi_sys:\n", - " xi_plus_model += xi_sys_plus\n", - " xi_minus_model = interp_xi_minus(theta_data)\n", - " if add_xi_sys:\n", - " xi_minus_model += xi_sys_minus\n", - "\n", - " # Concatenate the data vector\n", - " xi_data = np.concatenate((xi_plus_data, xi_minus_data))\n", - " xi_model = np.concatenate((xi_plus_model, xi_minus_model))\n", - "\n", - " tau_data = np.concatenate((tau_0_data, tau_2_data))\n", - " tau_model = np.concatenate((tau_0_model, tau_2_model))\n", - "\n", - " # Apply scale cuts\n", - " mask_xi_plus = (theta_data > lower_bound_xi_plus) & (\n", - " theta_data < upper_bound_xi_plus\n", - " )\n", - " mask_xi_minus = (theta_data > lower_bound_xi_minus) & (\n", - " theta_data < upper_bound_xi_minus\n", - " )\n", - " mask = np.concatenate((mask_xi_plus, mask_xi_minus))\n", - "\n", - " xi_data = xi_data[mask]\n", - " xi_model = xi_model[mask]\n", - " cov_xi = cov_xi[mask][:, mask]\n", - "\n", - " cov_xi_plus = cov[0 : len(xi_plus_data), 0 : len(xi_plus_data)]\n", - " cov_xi_plus = cov_xi_plus[mask_xi_plus][:, mask_xi_plus]\n", - " cov_xi_minus = cov[\n", - " len(xi_plus_data) : 2 * len(xi_minus_data),\n", - " len(xi_plus_data) : 2 * len(xi_minus_data),\n", - " ]\n", - " cov_xi_minus = cov_xi_minus[mask_xi_minus][:, mask_xi_minus]\n", - "\n", - " xi_plus_chi2 = np.dot(\n", - " (xi_plus_model[mask_xi_plus] - xi_plus_data[mask_xi_plus]),\n", - " np.dot(\n", - " np.linalg.inv(cov_xi_plus),\n", - " (xi_plus_model[mask_xi_plus] - xi_plus_data[mask_xi_plus]),\n", - " ),\n", - " )\n", - " xi_minus_chi2 = np.dot(\n", - " (xi_minus_model[mask_xi_minus] - xi_minus_data[mask_xi_minus]),\n", - " np.dot(\n", - " np.linalg.inv(cov_xi_minus),\n", - " (xi_minus_model[mask_xi_minus] - xi_minus_data[mask_xi_minus]),\n", - " ),\n", - " )\n", - " xi_chi2 = np.dot(\n", - " (xi_model - xi_data), np.dot(np.linalg.inv(cov_xi), (xi_model - xi_data))\n", - " )\n", - " tau_chi2 = np.dot(\n", - " (tau_model - tau_data), np.dot(np.linalg.inv(cov_tau), (tau_model - tau_data))\n", - " )\n", - " n_dof_xi_plus = np.sum(mask_xi_plus)\n", - " n_dof_xi_minus = np.sum(mask_xi_minus)\n", - " n_dof_tau = len(tau_0_data) + len(tau_2_data)\n", - " p_value_xi_plus = 1 - stats.chi2.cdf(xi_plus_chi2, n_dof_xi_plus)\n", - " p_value_xi_minus = 1 - stats.chi2.cdf(xi_minus_chi2, n_dof_xi_minus)\n", - " p_value_xi = 1 - stats.chi2.cdf(xi_chi2, n_dof_xi_plus + n_dof_xi_minus)\n", - " p_value_tau = 1 - stats.chi2.cdf(tau_chi2, n_dof_tau)\n", - " chi2_tot = xi_plus_chi2 + xi_minus_chi2 + tau_chi2\n", - " n_dof_tot = n_dof_xi_plus + n_dof_xi_minus + n_dof_tau\n", - " p_value_tot = 1 - stats.chi2.cdf(chi2_tot, n_dof_tot)\n", - "\n", - " metrics[root] = {\n", - " \"chi2_xi_plus\": xi_plus_chi2,\n", - " \"n_dof_xi_plus\": n_dof_xi_plus,\n", - " \"p_value_xi_plus\": p_value_xi_plus,\n", - " \"chi2_xi_minus\": xi_minus_chi2,\n", - " \"n_dof_xi_minus\": n_dof_xi_minus,\n", - " \"p_value_xi_minus\": p_value_xi_minus,\n", - " \"chi2_xi\": xi_chi2,\n", - " \"p_value_xi\": p_value_xi,\n", - " \"chi2_tau\": tau_chi2,\n", - " \"n_dof_tau\": n_dof_tau,\n", - " \"p_value_tau\": p_value_tau,\n", - " \"chi2_tot\": chi2_tot,\n", - " \"n_dof_tot\": n_dof_tot,\n", - " \"p_value_tot\": p_value_tot,\n", - " }\n", - " print(\"Done!\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def get_latex_table(metrics):\n", - " latex_lines = [\n", - " r\"\\begin{tabular}{lccc|ccc|ccc}\",\n", - " r\"\\hline\",\n", - " r\"Root & $\\chi^2_{\\xi^+}$/dof & $p_{\\xi^+}$ & $\\chi^2_{\\xi^-}$/dof & $p_{\\xi^+}$ & $\\chi^2_{\\xi}$/dof & $p_{\\xi}$ &\"\n", - " r\"$\\chi^2_\\tau$/dof & $p_\\tau$ & $\\chi^2_{\\text{tot}}$/dof & $p_{\\text{tot}}$ \\\\\",\n", - " r\"\\hline\",\n", - " ]\n", - "\n", - " for root, vals in metrics.items():\n", - " escaped = root.replace(\"_\", r\"\\_\")\n", - " line = (\n", - " f\"{escaped} & \"\n", - " f\"{vals['chi2_xi_plus']:.2f}/{vals['n_dof_xi_plus']} & {vals['p_value_xi_plus']:.3g} & \"\n", - " f\"{vals['chi2_xi_minus']:.2f}/{vals['n_dof_xi_minus']} & {vals['p_value_xi_minus']:.3g} & \"\n", - " f\"{vals['chi2_xi']:.2f}/{vals['n_dof_xi_plus'] + vals['n_dof_xi_minus']} & {vals['p_value_xi']:.3g} &\"\n", - " f\"{vals['chi2_tau']:.2f}/{vals['n_dof_tau']} & {vals['p_value_tau']:.3g} & \"\n", - " f\"{vals['chi2_tot']:.2f}/{vals['n_dof_tot']} & {vals['p_value_tot']:.3g} \\\\\\\\\"\n", - " )\n", - " latex_lines.append(line)\n", - "\n", - " latex_lines.append(r\"\\hline\")\n", - " latex_lines.append(r\"\\end{tabular}\")\n", - "\n", - " # Print LaTeX table\n", - " print(\"\\n\".join(latex_lines))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "get_latex_table(metrics)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def display_markdown(metrics):\n", - " # Build Markdown table\n", - " header = (\n", - " \"| Root | $\\\\chi^2$ (ξ⁺) / dof | p-val (ξ⁺) |$\\\\chi^2$ (ξ-) / dof | p-val (ξ-) | $\\\\chi^2$ (ξ) / dof | p-val (ξ) | $\\\\chi^2$ (τ) / dof | p-val (τ) | $\\\\chi^2$ (tot) / dof | p-val (tot) |\\n\"\n", - " \"|------|----------------|------------|----------------|------------|------------|---------------|------------|------------|------------------|--------------|\\n\"\n", - " )\n", - "\n", - " rows = []\n", - " for root, vals in metrics.items():\n", - " row = f\"| `{root}` \"\n", - " row += f\"| {vals['chi2_xi_plus']:.2f} / {vals['n_dof_xi_plus']} \"\n", - " row += f\"| {vals['p_value_xi_plus']:.5f} \"\n", - " row += f\"| {vals['chi2_xi_minus']:.2f} / {vals['n_dof_xi_minus']} \"\n", - " row += f\"| {vals['p_value_xi_minus']:.5f} \"\n", - " row += f\"| {vals['chi2_xi']:.2f} / {vals['n_dof_xi_minus'] + vals['n_dof_xi_plus']} \"\n", - " row += f\"| {vals['p_value_xi']:.5f} \"\n", - " row += f\"| {vals['chi2_tau']:.2f} / {vals['n_dof_tau']} \"\n", - " row += f\"| {vals['p_value_tau']:.5f} \"\n", - " row += f\"| {vals['chi2_tot']:.2f} / {vals['n_dof_tot']} \"\n", - " row += f\"| {vals['p_value_tot']:.5f} |\"\n", - " rows.append(row)\n", - "\n", - " # Display in Jupyter\n", - " display(Markdown(header + \"\\n\".join(rows)))\n", - " return header + \"\\n\".join(rows)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "markdown_source = display_markdown(metrics)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "my_env", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_chi2_glass_mock.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_chi2_glass_mock.ipynb deleted file mode 100644 index ddd66cd0..00000000 --- a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_chi2_glass_mock.ipynb +++ /dev/null @@ -1,565 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import configparser\n", - "import os\n", - "import subprocess\n", - "import sys\n", - "\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "\n", - "# Make the plot\n", - "import seaborn as sns\n", - "from astropy.io import fits\n", - "from getdist import plots\n", - "from scipy.interpolate import interp1d\n", - "from scipy.stats import chi2\n", - "\n", - "sys.path.append(\"/home/guerrini/sp_validation/cosmo_inference/scripts\")\n", - "\n", - "import chain_postprocessing\n", - "\n", - "%matplotlib inline\n", - "\n", - "plt.style.use(\"/home/guerrini/matplotlib_config/paper.mplstyle\")\n", - "\n", - "plt.rcParams[\"axes.labelsize\"] = 18\n", - "plt.rcParams[\"xtick.labelsize\"] = 18\n", - "plt.rcParams[\"ytick.labelsize\"] = 18\n", - "\n", - "plt.rcParams[\"text.usetex\"] = True\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "g.settings.axes_fontsize = 30\n", - "g.settings.axes_labelsize = 30\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 40\n", - "\n", - "# #SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE\n", - "\n", - "root_dir = \"/n09data/guerrini/glass_mock_chains/\"\n", - "\n", - "# Version of the glass mock chain run\n", - "chain_version = \"v6\"\n", - "\n", - "# Path to the glass mock data vectors\n", - "root_glass_dv = (\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/glass_mocks/{chain_version}/\"\n", - ")\n", - "\n", - "# Choose the best-fit method\n", - "best_fit_method = \"2Dkde\"\n", - "\n", - "# Create the list of mocks\n", - "max_sim = 350\n", - "failed_simulations = [82, 83, 281, 282, 283, 284, 285, 286, 287]\n", - "roots = [f\"glass_mock_{chain_version}_{str(i).zfill(5)}\" for i in range(1, max_sim + 1)]\n", - "roots = [root for root in roots if int(root.split(\"_\")[-1]) not in failed_simulations]\n", - "\n", - "catalog_versions = [\n", - " \"SP_v1.4.6.3_config/SP_v1.4.6.3_A\",\n", - "]\n", - "\n", - "output_folder_chains = \"/n23data1/n06data/lgoh/scratch/temp/\"\n", - "path_ini_files = \"/home/guerrini/sp_validation/cosmo_inference/cosmosis_config/\"\n", - "output_fig_path = (\n", - " \"/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/\"\n", - ")\n", - "\n", - "ini_root = \"blind_A/fiducial\"\n", - "\n", - "lower_bound_xi = 12\n", - "upper_bound_xi = 83" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Retrieve the chains" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# READ CHAIN\n", - "\n", - "chains = []\n", - "best_fit = {}\n", - "\n", - "for i, root in enumerate(roots):\n", - " burnin = 0\n", - "\n", - " if os.path.isfile(f\"{root_dir}/{root}/{root}/getdist_{root}.txt\") == True:\n", - " chain = g.samples_for_root(\n", - " f\"{root_dir}/{root}/{root}/getdist_{root}\",\n", - " cache=False,\n", - " settings={\n", - " \"ignore_rows\": burnin,\n", - " \"smooth_scale_2D\": 0.5,\n", - " \"smooth_scale_1D\": 0.5,\n", - " },\n", - " )\n", - " p = chain.getParams()\n", - "\n", - " best_fit[root] = chain_postprocessing.extract_best_fit_params(\n", - " chain, best_fit_method=\"2Dkde\"\n", - " )" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "param_list = [\n", - " \"OMEGA_M\",\n", - " \"ombh2\",\n", - " \"h0\",\n", - " \"n_s\",\n", - " \"SIGMA_8\",\n", - " \"s_8_input\",\n", - " \"logt_agn\",\n", - " \"a\",\n", - " \"m1\",\n", - " \"bias_1\",\n", - " \"alpha\",\n", - " \"beta\",\n", - " \"omch2\",\n", - " \"m\",\n", - " \"a_planck\",\n", - "]\n", - "label_list = [\n", - " r\"\\Omega_m\",\n", - " r\"\\omega_b\",\n", - " \"h_0\",\n", - " \"n_s\",\n", - " r\"\\sigma_8\",\n", - " \"S_8\",\n", - " \"log T_{AGN}\",\n", - " \"A_{IA}\",\n", - " \"m_1\",\n", - " r\"\\Delta z_1\",\n", - " \"\\\\alpha_{PSF}\",\n", - " \"\\\\beta_{PSF}\",\n", - " r\"\\omega_c\",\n", - " \"M\",\n", - " \"A_{\\rm Planck}\",\n", - "]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Run `Cosmosis` in test mode to get the data vectors" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if not os.path.exists(path_ini_files + \"/values_empty.ini\"):\n", - " content = \"\"\"[cosmological_parameters]\n", - "\n", - "tau = 0.0544\n", - "w = -1.0\n", - "mnu = 0.06\n", - "omega_k = 0.0\n", - "wa = 0.0\n", - "\n", - "[halo_model_parameters]\n", - "\n", - "[intrinsic_alignment_parameters]\n", - "\n", - "[shear_calibration_parameters]\n", - "\n", - "[nofz_shifts]\n", - "\n", - "[psf_leakage_parameters]\n", - "\"\"\"\n", - "\n", - " with open(path_ini_files + \"/values_empty.ini\", \"w\") as f:\n", - " f.write(content)\n", - " f.close()\n", - "\n", - " print(\"File created successfully\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "section_map = {\n", - " \"omch2\": \"cosmological_parameters\",\n", - " \"ombh2\": \"cosmological_parameters\",\n", - " \"h0\": \"cosmological_parameters\",\n", - " \"n_s\": \"cosmological_parameters\",\n", - " \"s_8_input\": \"cosmological_parameters\",\n", - " \"logt_agn\": \"halo_model_parameters\",\n", - " \"a\": \"intrinsic_alignment_parameters\",\n", - " \"m1\": \"shear_calibration_parameters\",\n", - " \"bias_1\": \"nofz_shifts\",\n", - " \"alpha\": \"psf_leakage_parameters\",\n", - " \"beta\": \"psf_leakage_parameters\",\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "env = os.environ.copy()\n", - "env[\"LD_LIBRARY_PATH\"] = (\n", - " \"/home/guerrini/.conda/envs/sp_validation/lib/python3.9/site-packages/cosmosis/datablock:\"\n", - " + env.get(\"LD_LIBRARY_PATH\", \"\")\n", - ")\n", - "for i, root in enumerate(roots):\n", - " print(root)\n", - " config = configparser.ConfigParser()\n", - " config.optionxform = str # Preserve case sensitivity of option names\n", - "\n", - " for param, section in section_map.items():\n", - " # Check if this parameter exists for the current root\n", - " if param in best_fit[root]:\n", - " value = best_fit[root][param]\n", - "\n", - " if section not in config:\n", - " config.add_section(section)\n", - "\n", - " config[section][param] = str(value)\n", - "\n", - " with open(path_ini_files + \"/values_empty.ini\", \"w\") as configfile:\n", - " config.write(configfile)\n", - "\n", - " # Modify the ini file to run in test mode at the best fit\n", - " config = configparser.ConfigParser()\n", - " config.optionxform = str # Preserve case sensitivity of option names\n", - "\n", - " ini_file = (\n", - " path_ini_files + f\"config_space_v1.4.6.3_fiducial/pipeline/{ini_root}.ini\"\n", - " )\n", - " config.read(ini_file)\n", - "\n", - " sampler = config[\"runtime\"][\"sampler\"]\n", - " config[\"runtime\"][\"sampler\"] = \"test\"\n", - " values = config[\"pipeline\"][\"values\"]\n", - " config[\"pipeline\"][\"values\"] = path_ini_files + \"/values_empty.ini\"\n", - " config[\"DEFAULT\"][\"FITS_FILE\"] = (\n", - " f\"{root_glass_dv}/glass_mock_{root[-5:]}/cosmosis_glass_mock_v6_{root[-5:]}.fits\"\n", - " )\n", - " config[\"test\"][\"save_dir\"] = output_folder_chains + f\"{root}/best_fit_config\"\n", - "\n", - " with open(ini_file, \"w\") as configfile:\n", - " config.write(configfile)\n", - "\n", - " # Run cosmosis\n", - " result = subprocess.run(\n", - " [\"cosmosis\", ini_file], env=env, capture_output=True, text=True\n", - " )\n", - " # print(f\"STDOUT:\\n{result.stdout}\")\n", - " # print(f\"STDERR:\\n{result.stderr}\")\n", - "\n", - " # Modify the ini file to the previous one\n", - " config[\"pipeline\"][\"values\"] = values\n", - " config[\"runtime\"][\"sampler\"] = sampler\n", - "\n", - " with open(ini_file, \"w\") as configfile:\n", - " config.write(configfile)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "xi_plus_chi2s = np.array([])\n", - "xi_minus_chi2s = np.array([])\n", - "xi_chi2s = np.array([])\n", - "tau_chi2s = np.array([])\n", - "chi2_tots = np.array([])\n", - "\n", - "\n", - "for idx, root in enumerate(roots):\n", - " print(root)\n", - "\n", - " data = fits.open(\n", - " f\"{root_glass_dv}/glass_mock_{root[-5:]}/cosmosis_glass_mock_v6_{root[-5:]}.fits\"\n", - " )\n", - "\n", - " tau_0_data = data[\"TAU_0_PLUS\"].data[\"VALUE\"]\n", - " tau_2_data = data[\"TAU_2_PLUS\"].data[\"VALUE\"]\n", - "\n", - " theta_data = data[\"XI_PLUS\"].data[\"ANG\"]\n", - " xi_plus_data = data[\"XI_PLUS\"].data[\"VALUE\"]\n", - " xi_minus_data = data[\"XI_MINUS\"].data[\"VALUE\"]\n", - " xi_data = np.concatenate((xi_plus_data, xi_minus_data))\n", - "\n", - " tau_data = np.concatenate((tau_0_data, tau_2_data))\n", - "\n", - " # Apply scale cuts\n", - " mask_xi_plus = (theta_data > lower_bound_xi) & (theta_data < upper_bound_xi)\n", - " mask_xi_minus = (theta_data > lower_bound_xi) & (theta_data < upper_bound_xi)\n", - " mask = np.concatenate((mask_xi_plus, mask_xi_minus))\n", - " # Load the covariance\n", - " cov = data[\"COVMAT\"].data\n", - " cov_xi = cov[0 : 2 * len(xi_plus_data), 0 : 2 * len(xi_plus_data)]\n", - " cov_tau = cov[\n", - " 2 * len(xi_plus_data) : 4 * len(xi_plus_data),\n", - " 2 * len(xi_plus_data) : 4 * len(xi_plus_data),\n", - " ]\n", - " xi_data = xi_data[mask]\n", - " cov_xi = cov_xi[mask][:, mask]\n", - "\n", - " cov_xi_plus = cov[0 : len(xi_plus_data), 0 : len(xi_plus_data)]\n", - " cov_xi_plus = cov_xi_plus[mask_xi_plus][:, mask_xi_plus]\n", - " cov_xi_minus = cov[\n", - " len(xi_plus_data) : 2 * len(xi_minus_data),\n", - " len(xi_plus_data) : 2 * len(xi_minus_data),\n", - " ]\n", - " cov_xi_minus = cov_xi_minus[mask_xi_minus][:, mask_xi_minus]\n", - "\n", - " # Read the results\n", - " theta = np.loadtxt(\n", - " output_folder_chains + f\"{root}/best_fit_config/shear_xi_plus/theta.txt\"\n", - " )\n", - " theta_arcmin = theta * 180 * 60 / np.pi\n", - " shear_xi_plus = np.loadtxt(\n", - " output_folder_chains + f\"{root}/best_fit_config/shear_xi_plus/bin_1_1.txt\"\n", - " )\n", - " shear_xi_minus = np.loadtxt(\n", - " output_folder_chains + f\"{root}/best_fit_config/shear_xi_minus/bin_1_1.txt\"\n", - " )\n", - "\n", - " xi_sys_plus = np.loadtxt(\n", - " output_folder_chains + f\"{root}/best_fit_config/xi_sys/shear_xi_plus.txt\"\n", - " )\n", - " xi_sys_minus = np.loadtxt(\n", - " output_folder_chains + f\"{root}/best_fit_config/xi_sys/shear_xi_minus.txt\"\n", - " )\n", - "\n", - " theta_tau = np.loadtxt(\n", - " output_folder_chains + f\"{root}/best_fit_config/tau_0_plus/theta.txt\"\n", - " )\n", - " theta_tau_arcmin = theta_tau * 180 * 60 / np.pi\n", - " tau_0_model = np.loadtxt(\n", - " output_folder_chains + f\"{root}/best_fit_config/tau_0_plus/bin_1_1.txt\"\n", - " )\n", - " tau_2_model = np.loadtxt(\n", - " output_folder_chains + f\"{root}/best_fit_config/tau_2_plus/bin_1_1.txt\"\n", - " )\n", - "\n", - " # interpolate the model\n", - " interp_xi_plus = interp1d(\n", - " theta_arcmin, shear_xi_plus, kind=\"cubic\", fill_value=\"extrapolate\"\n", - " )\n", - " interp_xi_minus = interp1d(\n", - " theta_arcmin, shear_xi_minus, kind=\"cubic\", fill_value=\"extrapolate\"\n", - " )\n", - "\n", - " xi_plus_model = interp_xi_plus(theta_data)\n", - " xi_plus_model += xi_sys_plus\n", - " xi_minus_model = interp_xi_minus(theta_data)\n", - " xi_minus_model += xi_sys_minus\n", - "\n", - " xi_model = np.concatenate((xi_plus_model, xi_minus_model))\n", - " tau_model = np.concatenate((tau_0_model, tau_2_model))\n", - " xi_model = xi_model[mask]\n", - "\n", - " xi_plus_chi2 = np.dot(\n", - " (xi_plus_model[mask_xi_plus] - xi_plus_data[mask_xi_plus]),\n", - " np.dot(\n", - " np.linalg.inv(cov_xi_plus),\n", - " (xi_plus_model[mask_xi_plus] - xi_plus_data[mask_xi_plus]),\n", - " ),\n", - " )\n", - " xi_minus_chi2 = np.dot(\n", - " (xi_minus_model[mask_xi_minus] - xi_minus_data[mask_xi_minus]),\n", - " np.dot(\n", - " np.linalg.inv(cov_xi_minus),\n", - " (xi_minus_model[mask_xi_minus] - xi_minus_data[mask_xi_minus]),\n", - " ),\n", - " )\n", - " xi_chi2 = np.dot(\n", - " (xi_model - xi_data), np.dot(np.linalg.inv(cov_xi), (xi_model - xi_data))\n", - " )\n", - " tau_chi2 = np.dot(\n", - " (tau_model - tau_data), np.dot(np.linalg.inv(cov_tau), (tau_model - tau_data))\n", - " )\n", - " chi2_tot = xi_plus_chi2 + xi_minus_chi2 + tau_chi2\n", - "\n", - " xi_plus_chi2s = np.append(xi_plus_chi2s, xi_plus_chi2)\n", - " xi_minus_chi2s = np.append(xi_minus_chi2s, xi_minus_chi2)\n", - " xi_chi2s = np.append(xi_chi2s, xi_chi2)\n", - " tau_chi2s = np.append(tau_chi2s, tau_chi2)\n", - " chi2_tots = np.append(chi2_tots, chi2_tot)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fig, [ax1, ax2] = plt.subplots(2, 1, figsize=(7, 10))\n", - "chi2_fiducial = -2 * -37.560916821678894\n", - "dof, loc, scale = chi2.fit(chi2_tots, floc=0)\n", - "\n", - "print(f\"Best-fit dof: {dof:.3e}\")\n", - "counts, bin_edges = np.histogram(chi2_tots, bins=25, density=True)\n", - "\n", - "sns.histplot(\n", - " chi2_tots,\n", - " ax=ax1,\n", - " kde=False,\n", - " bins=bin_edges,\n", - " stat=\"density\",\n", - " label=r\"$\\chi^2$ for \\texttt{GLASS} mocks best-fits\",\n", - " color=\"green\",\n", - " alpha=0.3,\n", - ")\n", - "\n", - "# Compute the p-value\n", - "\n", - "# 1. Get in which bin the chi2 of the fiducial falls\n", - "bin_index = np.digitize(chi2_fiducial, bin_edges)\n", - "\n", - "# 2. Compute the p-value as the integral of the tail of the histogram\n", - "p_value = np.sum(counts[bin_index:]) * np.diff(bin_edges)[0]\n", - "\n", - "print(f\"P-value: {p_value}\")\n", - "\n", - "ax1.axvline(chi2_fiducial, color=\"red\", label=r\"$\\chi^2$ of the fiducial\", lw=2)\n", - "\n", - "mantissa, exponent = np.frexp(p_value)\n", - "pte_string = rf\"${{\\rm PTE}} = {p_value:.4f}$\"\n", - "print(f\"mantissa: {mantissa}, exponent: {exponent}\")\n", - "x_text = 78\n", - "y_text = max(counts) * 0.95\n", - "ax1.text(\n", - " x_text,\n", - " y_text,\n", - " pte_string,\n", - " fontsize=15,\n", - " bbox=dict(facecolor=\"wheat\", alpha=0.8, edgecolor=\"black\"),\n", - ")\n", - "\n", - "chi2_string = rf\"${{\\rm Eff. dof}}= {dof:.1f}$\"\n", - "y_text = max(counts) * 0.85\n", - "ax1.text(\n", - " x_text,\n", - " y_text,\n", - " chi2_string,\n", - " fontsize=15,\n", - " bbox=dict(facecolor=\"wheat\", alpha=0.8, edgecolor=\"black\"),\n", - ")\n", - "\n", - "ax1.set_xlabel(r\"$\\chi^2_{\\rm tot}$\")\n", - "ax1.set_ylabel(\"Density\")\n", - "\n", - "chi2_fiducial = 9.5\n", - "dof, loc, scale = chi2.fit(xi_chi2s, floc=0)\n", - "\n", - "print(f\"Best-fit dof: {dof:.3e}\")\n", - "counts, bin_edges = np.histogram(xi_chi2s, bins=25, density=True)\n", - "\n", - "sns.histplot(\n", - " xi_chi2s,\n", - " ax=ax2,\n", - " kde=False,\n", - " bins=bin_edges,\n", - " stat=\"density\",\n", - " label=r\"$\\chi^2$ for \\texttt{GLASS} mocks best-fits\",\n", - " color=\"pink\",\n", - " alpha=0.5,\n", - ")\n", - "\n", - "# Compute the p-value\n", - "\n", - "# 1. Get in which bin the chi2 of the fiducial falls\n", - "bin_index = np.digitize(chi2_fiducial, bin_edges)\n", - "\n", - "# 2. Compute the p-value as the integral of the tail of the histogram\n", - "p_value = np.sum(counts[bin_index:]) * np.diff(bin_edges)[0]\n", - "\n", - "print(f\"P-value: {p_value}\")\n", - "\n", - "ax2.axvline(chi2_fiducial, color=\"red\", label=r\"$\\chi^2$ of the fiducial\", lw=2)\n", - "\n", - "mantissa, exponent = np.frexp(p_value)\n", - "print(f\"mantissa: {mantissa}, exponent: {exponent}\")\n", - "pte_string = rf\"${{\\rm PTE}} = {p_value:.4f}$\"\n", - "# rf\"${{\\rm PTE}} = {mantissa:.2f} \\times 10^{{{exponent}}}$\" if exponent != 0 else\n", - "x_text = 17.5\n", - "y_text = max(counts) * 0.95\n", - "ax2.text(\n", - " x_text,\n", - " y_text,\n", - " pte_string,\n", - " fontsize=15,\n", - " bbox=dict(facecolor=\"wheat\", alpha=0.8, edgecolor=\"black\"),\n", - ")\n", - "\n", - "chi2_string = rf\"${{\\rm Eff. dof}}= {dof:.1f}$\"\n", - "y_text = max(counts) * 0.85\n", - "ax2.text(\n", - " x_text,\n", - " y_text,\n", - " chi2_string,\n", - " fontsize=15,\n", - " bbox=dict(facecolor=\"wheat\", alpha=0.8, edgecolor=\"black\"),\n", - ")\n", - "\n", - "ax2.set_xlabel(r\"$\\chi^2 (\\xi_\\pm)$\")\n", - "ax2.set_ylabel(\"Density\")\n", - "fig.savefig(f\"{output_fig_path}/chi2_glass_mocks_p_value_xi_tau.pdf\")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "my_env", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_prior_psf_leakage.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_prior_psf_leakage.ipynb deleted file mode 100644 index ad6f5fd1..00000000 --- a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/get_prior_psf_leakage.ipynb +++ /dev/null @@ -1,261 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "0", - "metadata": {}, - "source": [ - "# Covariance matrix and PSF leakage\n", - "\n", - "This notebook plots the combined covariance matrix, and samples and plots the 2D marginalised posteriors of the PSF leakage parameters $\\alpha$ and $\\beta$." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "\n", - "if not os.path.exists(\"./Plots\"):\n", - " os.makedirs(\"./Plots\")\n", - "\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "import seaborn as sns\n", - "from astropy.io import fits\n", - "from getdist import MCSamples, plots\n", - "from shear_psf_leakage.rho_tau_stat import PSFErrorFit, RhoStat, TauStat\n", - "\n", - "# Use paper style and seaborn with husl palette\n", - "plt.style.use(\"/home/guerrini/matplotlib_config/paper.mplstyle\")\n", - "# Set default palette - will be updated per plot as needed\n", - "sns.set_palette(\"husl\")\n", - "%matplotlib inline\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "g.settings.axes_fontsize = 30\n", - "g.settings.axes_labelsize = 30\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 25\n", - "\n", - "ver = \"v1.4.6.3\"\n", - "blind = \"B\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2", - "metadata": {}, - "outputs": [], - "source": [ - "data_path = f\"/home/guerrini/sp_validation/cosmo_inference/data/SP_{ver}_config/\"\n", - "\n", - "path_cosmo_val = \"/home/guerrini/sp_validation/cosmo_val/output/\"\n", - "\n", - "roots = [f\"SP_{ver}_{blind}\", f\"SP_{ver}_leak_corr_{blind}\"]\n", - "\n", - "labels = [f\"SP_{ver}_{blind}\", f\"SP_{ver}_leak_corr_{blind}\"]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3", - "metadata": {}, - "outputs": [], - "source": [ - "data_vectors = []\n", - "\n", - "for root in roots:\n", - " data_vectors.append(\n", - " fits.open(data_path + f\"SP_{ver}_{blind}/cosmosis_{root}_masked.fits\")\n", - " )" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4", - "metadata": {}, - "outputs": [], - "source": [ - "def cov_to_corr(cov):\n", - " \"\"\"Convert a covariance matrix to a correlation matrix.\"\"\"\n", - " d = np.sqrt(np.diag(cov))\n", - " corr = cov / np.outer(d, d)\n", - " corr[cov == 0] = 0\n", - " return corr" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5", - "metadata": {}, - "outputs": [], - "source": [ - "# Print the covariance matrix for each root\n", - "for i, root in enumerate(roots):\n", - " print(f\"Covariance matrix for {labels[i]}:\")\n", - " cov = data_vectors[i][\"COVMAT\"].data\n", - "\n", - " n_bins = cov.shape[0] // 4\n", - "\n", - " fig, ax = plt.subplots(figsize=(10, 8))\n", - "\n", - " im = ax.imshow(cov_to_corr(cov), vmin=-1, vmax=1, cmap=\"seismic\")\n", - " ax.set_aspect(\"equal\")\n", - " ax.set_yticks(np.array([10, 30, 50, 70]))\n", - " ax.set_yticklabels(\n", - " [\n", - " r\"$\\xi_+(\\vartheta)$\",\n", - " r\"$\\xi_-(\\vartheta)$\",\n", - " r\"$\\tau_0(\\vartheta)$\",\n", - " r\"$\\tau_2(\\vartheta)$\",\n", - " ]\n", - " )\n", - " ax.set_xticks(np.array([10, 30, 50, 70]))\n", - " ax.set_xticklabels(\n", - " [\n", - " r\"$\\xi_+(\\vartheta)$\",\n", - " r\"$\\xi_-(\\vartheta)$\",\n", - " r\"$\\tau_0(\\vartheta)$\",\n", - " r\"$\\tau_2(\\vartheta)$\",\n", - " ],\n", - " rotation=45,\n", - " )\n", - " fig.colorbar(im, ax=ax)\n", - "\n", - " plt.savefig(f\"./Plots/cov_matrix_{root}.png\", bbox_inches=\"tight\", dpi=300)\n", - " plt.show()\n", - " print(\"\\n\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6", - "metadata": {}, - "outputs": [], - "source": [ - "# Create dummy rho and tau stat handler.\n", - "\n", - "# Inference of the xi_sys parameters\n", - "sep_units = \"arcmin\"\n", - "coord_units = \"degrees\"\n", - "theta_min = 1.0\n", - "theta_max = 250\n", - "nbins = 20\n", - "\n", - "\n", - "TreeCorrConfig_xi = {\n", - " \"ra_units\": coord_units,\n", - " \"dec_units\": coord_units,\n", - " \"min_sep\": theta_min,\n", - " \"max_sep\": theta_max,\n", - " \"sep_units\": sep_units,\n", - " \"nbins\": nbins,\n", - " \"var_method\": \"jackknife\",\n", - "}\n", - "\n", - "rho_stats_handler = RhoStat(output=\".\", treecorr_config=TreeCorrConfig_xi, verbose=True)\n", - "\n", - "tau_stats_handler = TauStat(\n", - " catalogs=rho_stats_handler.catalogs,\n", - " output=\".\",\n", - " treecorr_config=TreeCorrConfig_xi,\n", - " verbose=True,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7", - "metadata": {}, - "outputs": [], - "source": [ - "# Create a PSFErrorFit instance\n", - "psf_fitter = PSFErrorFit(\n", - " rho_stats_handler,\n", - " tau_stats_handler,\n", - " path_cosmo_val + \"rho_tau_stats/\",\n", - " use_eta=False,\n", - ")\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "\n", - "g.settings.axes_fontsize = 30\n", - "g.settings.axes_labelsize = 30\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 40\n", - "\n", - "chains = []\n", - "\n", - "# Load rho-, tau-statistics, and cov_tau from the data_vector\n", - "for i, root in enumerate(roots):\n", - " print(\"Sampling PSF parameters for \", labels[i])\n", - " path_rho = f\"rho_stats_{root}.fits\"\n", - " path_tau = f\"tau_stats_{root}.fits\"\n", - " path_cov_rho = f\"cov_rho_{root}.npy\"\n", - " path_cov_tau = f\"cov_tau_{root}_th.npy\"\n", - " psf_fitter.load_rho_stat(path_rho)\n", - " psf_fitter.load_tau_stat(path_tau)\n", - " psf_fitter.load_covariance(path_cov_rho, cov_type=\"rho\")\n", - " psf_fitter.load_covariance(path_cov_tau, cov_type=\"tau\")\n", - " samples_lq, _, _ = psf_fitter.get_least_squares_params_samples(\n", - " npatch=None, apply_debias=False\n", - " )\n", - "\n", - " samples_gd = MCSamples(\n", - " samples=samples_lq, names=[r\"\\alpha\", r\"\\beta\"], labels=[r\"\\alpha\", r\"\\beta\"]\n", - " )\n", - "\n", - " chains.append(samples_gd)\n", - "\n", - "g.triangle_plot(\n", - " chains,\n", - " filled=True,\n", - " legend_labels=labels,\n", - " legend_loc=\"upper right\",\n", - ")\n", - "\n", - "# plt.savefig(f\"./Plots/psf_leakage_params.png\", bbox_inches='tight', dpi=300)\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "my_env", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/glass_mock_hist.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/glass_mock_hist.ipynb deleted file mode 100644 index 32f89a18..00000000 --- a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/glass_mock_hist.ipynb +++ /dev/null @@ -1,586 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "id": "0", - "metadata": { - "lines_to_next_cell": 2 - }, - "outputs": [], - "source": [ - "import IPython\n", - "\n", - "ipython = IPython.get_ipython()\n", - "\n", - "if ipython is not None:\n", - " ipython.run_line_magic(\"load_ext\", \"autoreload\")\n", - " ipython.run_line_magic(\"autoreload\", \"2\")\n", - "\n", - "import os\n", - "\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "import seaborn as sns\n", - "from getdist import plots\n", - "from tqdm import tqdm\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=7)\n", - "g.settings.axes_fontsize = 15\n", - "g.settings.axes_labelsize = 15\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 15\n", - "\n", - "if os.path.exists(\"/home/guerrini/matplotlib_config/paper.mplstyle\"):\n", - " plt.style.use(\"/home/guerrini/matplotlib_config/paper.mplstyle\")\n", - "\n", - "# Set default palette - will be updated per plot as needed\n", - "sns.set_palette(\"husl\")\n", - "\n", - "if ipython is not None:\n", - " ipython.run_line_magic(\"matplotlib\", \"inline\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1", - "metadata": { - "lines_to_next_cell": 1 - }, - "outputs": [], - "source": [ - "root_dir = \"/n09data/guerrini/glass_mock_chains/\"\n", - "chain_version = \"v6\"\n", - "num_sims = 350\n", - "\n", - "roots = [f\"glass_mock_{chain_version}_{i + 1:05d}\" for i in range(num_sims)]\n", - "\n", - "\n", - "# # %%\n", - "def load_samples_and_write_paramames(root_dir, root, chain_type=\"configuration\"):\n", - " assert chain_type in [\"configuration\", \"harmonic\"], (\n", - " \"chain_type must be 'configuration' or 'harmonic'\"\n", - " )\n", - "\n", - " if chain_type == \"configuration\":\n", - " path_samples = root_dir + \"{}/{}/samples_{}.txt\".format(\"/\" + root, root, root)\n", - " path_paramnames = root_dir + \"{}/{}/getdist_{}.paramnames\".format(\n", - " \"/\" + root, root, root\n", - " )\n", - " else:\n", - " path_samples = root_dir + \"{}/{}/samples_{}_cell.txt\".format(\n", - " \"/\" + root, root, root\n", - " )\n", - " path_paramnames = root_dir + \"{}/{}/getdist_{}_cell.paramnames\".format(\n", - " \"/\" + root, root, root\n", - " )\n", - "\n", - " with open(path_samples, \"r\") as file:\n", - " params = file.readline()[1:].split(\"\\t\")[:-4]\n", - " file.close()\n", - "\n", - " with open(path_paramnames, \"w\") as file:\n", - " for i in range(len(params)):\n", - " if len(params[i].split(\"--\")) > 1:\n", - " file.write(params[i].split(\"--\")[1] + \"\\n\")\n", - " else:\n", - " file.write(params[i].split(\"--\")[0] + \"\\n\")\n", - " file.close()\n", - "\n", - "\n", - "def write_samples_getdist_format(root_dir, root, chain_type=\"configuration\"):\n", - " assert chain_type in [\"configuration\", \"harmonic\"], (\n", - " \"chain_type must be 'configuration' or 'harmonic'\"\n", - " )\n", - "\n", - " if chain_type == \"configuration\":\n", - " path_samples = root_dir + \"{}/{}/samples_{}.txt\".format(\"/\" + root, root, root)\n", - " path_gd_samples = root_dir + \"{}/{}/getdist_{}.txt\".format(\n", - " \"/\" + root, root, root\n", - " )\n", - " path_gd = root_dir + \"{}/{}/getdist_{}\".format(root, root, root)\n", - " else:\n", - " path_samples = root_dir + \"{}/{}/samples_{}_cell.txt\".format(\n", - " \"/\" + root, root, root\n", - " )\n", - " path_gd_samples = root_dir + \"{}/{}/getdist_{}_cell.txt\".format(\n", - " \"/\" + root, root, root\n", - " )\n", - " path_gd = root_dir + \"{}/{}/getdist_{}_cell\".format(root, root, root)\n", - "\n", - " samples = np.loadtxt(\n", - " path_samples,\n", - " )\n", - " if \"nautilus\" in root:\n", - " samples = np.column_stack(\n", - " (np.exp(samples[:, -3]), samples[:, -1] - samples[:, -2], samples[:, 0:-3])\n", - " )\n", - " else:\n", - " samples = np.column_stack((samples[:, -1], samples[:, -2], samples[:, 0:-4]))\n", - " np.savetxt(path_gd_samples, samples)\n", - "\n", - " chain = g.samples_for_root(\n", - " path_gd,\n", - " cache=False,\n", - " settings={\"ignore_rows\": 0.0, \"smooth_scale_2D\": 0.5, \"smooth_scale_1D\": 0.5},\n", - " )\n", - "\n", - " return chain\n", - "\n", - "\n", - "def extract_param_chain(chain, param_names):\n", - " margestats = chain.getMargeStats()\n", - " likestats = chain.getLikeStats()\n", - "\n", - " param_values = {}\n", - " for param_name in param_names:\n", - " if param_name not in chain.getParamNames().list():\n", - " raise ValueError(f\"Parameter {param_name} not found in chain.\")\n", - "\n", - " param_stats = margestats.parWithName(param_name)\n", - " param_values[param_name] = {\n", - " \"mean\": param_stats.mean,\n", - " \"1sigma_minus\": param_stats.mean - param_stats.limits[0].lower,\n", - " \"1sigma_plus\": param_stats.limits[0].upper - param_stats.mean,\n", - " \"2sigma_minus\": param_stats.mean - param_stats.limits[1].lower,\n", - " \"2sigma_plus\": param_stats.limits[1].upper - param_stats.mean,\n", - " }\n", - "\n", - " param_stats = likestats.parWithName(param_name)\n", - " param_names_getdist = chain.getParamNames()\n", - " par = param_names_getdist.parWithName(param_name)\n", - " kde = chain.get1DDensity(par, num_bins=1000)\n", - " kde_map = kde.x[np.argmax(kde.P)]\n", - " param_values[param_name].update(\n", - " {\n", - " \"MAP\": kde_map,\n", - " }\n", - " )\n", - "\n", - " par = chain.getParamNames().parWithName(\"S_8\")\n", - " par_om = chain.getParamNames().parWithName(\"OMEGA_M\")\n", - " kde = chain.get2DDensity(par, par_om, fine_bins_2D=1000)\n", - " s8_kde_map = kde.x[np.unravel_index(np.argmax(kde.P), kde.P.shape)[1]]\n", - " om_kde_map = kde.y[np.unravel_index(np.argmax(kde.P), kde.P.shape)[0]]\n", - " param_values[\"S_8\"].update(\n", - " {\n", - " \"MAP_2D\": s8_kde_map,\n", - " }\n", - " )\n", - " param_values[\"OMEGA_M\"].update(\n", - " {\n", - " \"MAP_2D\": om_kde_map,\n", - " }\n", - " )\n", - "\n", - " return param_values\n", - "\n", - "\n", - "def concatenate_param_stats(name, param_values, verbose=False):\n", - " output = [name]\n", - " for key in param_values.keys():\n", - " param_stat = param_values[key]\n", - " if verbose:\n", - " print(\n", - " f\"{name} - {key}: {param_stat['mean']:.4f} +{param_stat['1sigma_plus']:.4f}/-{param_stat['1sigma_minus']:.4f} (1σ), +{param_stat['2sigma_plus']:.4f}/-{param_stat['2sigma_minus']:.4f} (2σ)\"\n", - " )\n", - "\n", - " param_list = [\n", - " param_stat[\"mean\"],\n", - " param_stat[\"1sigma_minus\"],\n", - " param_stat[\"1sigma_plus\"],\n", - " param_stat[\"2sigma_minus\"],\n", - " param_stat[\"2sigma_plus\"],\n", - " param_stat[\"MAP\"],\n", - " ]\n", - "\n", - " if key == \"S_8\":\n", - " param_list.append(param_stat[\"MAP_2D\"])\n", - "\n", - " if key == \"OMEGA_M\":\n", - " param_list.append(param_stat[\"MAP_2D\"])\n", - "\n", - " output += param_list\n", - "\n", - " return output\n", - "\n", - "\n", - "def merge_param_stats(params_configuration, params_harmonic):\n", - " merged_params = {}\n", - " for key in params_configuration.keys():\n", - " if key in params_harmonic:\n", - " merged_params[key] = {\n", - " \"configuration\": params_configuration[key],\n", - " \"harmonic\": params_harmonic[key],\n", - " }\n", - " return merged_params\n", - "\n", - "\n", - "def concatenate_merge_params(name, merged_params, verbose=False):\n", - " output = [name]\n", - " for key in merged_params.keys():\n", - " param_config = merged_params[key][\"configuration\"]\n", - " param_harm = merged_params[key][\"harmonic\"]\n", - "\n", - " if verbose:\n", - " print(\n", - " f\"{name} - {key} (Configuration): {param_config['mean']:.4f} +{param_config['1sigma_plus']:.4f}/-{param_config['1sigma_minus']:.4f} (1σ), +{param_config['2sigma_plus']:.4f}/-{param_config['2sigma_minus']:.4f} (2σ)\"\n", - " )\n", - " print(\n", - " f\"{name} - {key} (Harmonic): {param_harm['mean']:.4f} +{param_harm['1sigma_plus']:.4f}/-{param_harm['1sigma_minus']:.4f} (1σ), +{param_harm['2sigma_plus']:.4f}/-{param_harm['2sigma_minus']:.4f} (2σ)\"\n", - " )\n", - "\n", - " param_list = [\n", - " param_config[\"mean\"],\n", - " param_config[\"1sigma_minus\"],\n", - " param_config[\"1sigma_plus\"],\n", - " param_config[\"2sigma_minus\"],\n", - " param_config[\"2sigma_plus\"],\n", - " param_config[\"MAP\"],\n", - " param_harm[\"mean\"],\n", - " param_harm[\"1sigma_minus\"],\n", - " param_harm[\"1sigma_plus\"],\n", - " param_harm[\"2sigma_minus\"],\n", - " param_harm[\"2sigma_plus\"],\n", - " param_harm[\"MAP\"],\n", - " ]\n", - "\n", - " output += param_list\n", - "\n", - " return output" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2", - "metadata": { - "lines_to_next_cell": 0 - }, - "outputs": [], - "source": [ - "chain_harmonic = []\n", - "chain_config = []\n", - "\n", - "for i, root in enumerate(tqdm(roots)):\n", - " if os.path.isfile(f\"{root_dir}/{root}/{root}/getdist_{root}.txt\"):\n", - " # Load samples and write paramnames for harmonic space\n", - " load_samples_and_write_paramames(root_dir, root, chain_type=\"harmonic\")\n", - " write_samples_getdist_format(root_dir, root, chain_type=\"harmonic\")\n", - " chain_harm = g.samples_for_root(\n", - " root_dir + f\"/{root}/{root}/getdist_{root}_cell\",\n", - " cache=False,\n", - " settings={\n", - " \"ignore_rows\": 0.0,\n", - " \"smooth_scale_2D\": 0.5,\n", - " \"smooth_scale_1D\": 0.5,\n", - " },\n", - " )\n", - " chain_harmonic.append(chain_harm)\n", - "\n", - " # Load samples and write paramnames for harmonic space\n", - " load_samples_and_write_paramames(root_dir, root, chain_type=\"configuration\")\n", - " write_samples_getdist_format(root_dir, root, chain_type=\"configuration\")\n", - " chain_conf = g.samples_for_root(\n", - " root_dir + f\"/{root}/{root}/getdist_{root}\",\n", - " cache=False,\n", - " settings={\n", - " \"ignore_rows\": 0.0,\n", - " \"smooth_scale_2D\": 0.5,\n", - " \"smooth_scale_1D\": 0.5,\n", - " },\n", - " )\n", - " chain_config.append(chain_conf)\n", - "# # %%\n", - "param_names = [\"S_8\", \"OMEGA_M\", \"SIGMA_8\", \"a\"]\n", - "\n", - "output_mocks_harm = np.array(\n", - " [\n", - " \"Name\",\n", - " \"S8_mean\",\n", - " \"S8_1sigma_minus\",\n", - " \"S8_1sigma_plus\",\n", - " \"S8_2sigma_minus\",\n", - " \"S8_2sigma_plus\",\n", - " \"S8_MAP\",\n", - " \"S8_MAP_2D\",\n", - " \"OMEGA_M_mean\",\n", - " \"OMEGA_M_1sigma_minus\",\n", - " \"OMEGA_M_1sigma_plus\",\n", - " \"OMEGA_M_2sigma_minus\",\n", - " \"OMEGA_M_2sigma_plus\",\n", - " \"OMEGA_M_MAP\",\n", - " \"OMEGA_M_MAP_2D\",\n", - " \"SIGMA_8_mean\",\n", - " \"SIGMA_8_1sigma_minus\",\n", - " \"SIGMA_8_1sigma_plus\",\n", - " \"SIGMA_8_2sigma_minus\",\n", - " \"SIGMA_8_2sigma_plus\",\n", - " \"SIGMA_8_MAP\",\n", - " \"a_mean\",\n", - " \"a_1sigma_minus\",\n", - " \"a_1sigma_plus\",\n", - " \"a_2sigma_minus\",\n", - " \"a_2sigma_plus\",\n", - " \"a_MAP\",\n", - " ]\n", - ")\n", - "\n", - "output_mocks_config = np.array(\n", - " [\n", - " \"Name\",\n", - " \"S8_mean\",\n", - " \"S8_1sigma_minus\",\n", - " \"S8_1sigma_plus\",\n", - " \"S8_2sigma_minus\",\n", - " \"S8_2sigma_plus\",\n", - " \"S8_MAP\",\n", - " \"S8_MAP_2D\",\n", - " \"OMEGA_M_mean\",\n", - " \"OMEGA_M_1sigma_minus\",\n", - " \"OMEGA_M_1sigma_plus\",\n", - " \"OMEGA_M_2sigma_minus\",\n", - " \"OMEGA_M_2sigma_plus\",\n", - " \"OMEGA_M_MAP\",\n", - " \"OMEGA_M_MAP_2D\",\n", - " \"SIGMA_8_mean\",\n", - " \"SIGMA_8_1sigma_minus\",\n", - " \"SIGMA_8_1sigma_plus\",\n", - " \"SIGMA_8_2sigma_minus\",\n", - " \"SIGMA_8_2sigma_plus\",\n", - " \"SIGMA_8_MAP\",\n", - " \"a_mean\",\n", - " \"a_1sigma_minus\",\n", - " \"a_1sigma_plus\",\n", - " \"a_2sigma_minus\",\n", - " \"a_2sigma_plus\",\n", - " \"a_MAP\",\n", - " ]\n", - ")\n", - "\n", - "for i, root in enumerate(tqdm(roots[:-1])):\n", - " param_values_harm = extract_param_chain(chain_harmonic[i], param_names)\n", - "\n", - " param_harm = concatenate_param_stats(root, param_values_harm, verbose=False)\n", - "\n", - " output_mocks_harm = np.vstack((output_mocks_harm, param_harm))\n", - "\n", - " param_values_config = extract_param_chain(chain_config[i], param_names)\n", - "\n", - " param_config = concatenate_param_stats(root, param_values_config, verbose=False)\n", - "\n", - " output_mocks_config = np.vstack((output_mocks_config, param_config))\n", - "\n", - "np.savetxt(\n", - " f\"summary_parameter_constraints_harmonic_space_{chain_version}.txt\",\n", - " output_mocks_harm,\n", - " fmt=\"%s\",\n", - " delimiter=\";\",\n", - ")\n", - "np.savetxt(\n", - " f\"summary_parameter_constraints_configuration_space_{chain_version}.txt\",\n", - " output_mocks_config,\n", - " fmt=\"%s\",\n", - " delimiter=\";\",\n", - ")\n", - "print(\n", - " f\"Saved summary of parameter constraints for harmonic space in summary_parameter_constraints_harmonic_space_{chain_version}.txt\"\n", - ")\n", - "print(\n", - " f\"Saved summary of parameter constraints for configuration space in summary_parameter_constraints_configuration_space_{chain_version}.txt\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3", - "metadata": { - "lines_to_next_cell": 0 - }, - "outputs": [], - "source": [ - "import pandas as pd\n", - "\n", - "output_df_harm = pd.read_csv(\n", - " f\"summary_parameter_constraints_harmonic_space_{chain_version}.txt\",\n", - " delimiter=\";\",\n", - " skiprows=1,\n", - " names=output_mocks_harm[0],\n", - ")\n", - "\n", - "output_df_config = pd.read_csv(\n", - " f\"summary_parameter_constraints_configuration_space_{chain_version}.txt\",\n", - " delimiter=\";\",\n", - " skiprows=1,\n", - " names=output_mocks_config[0],\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4", - "metadata": {}, - "outputs": [], - "source": [ - "# Define the true value of the parameters\n", - "from astropy.cosmology import Planck18 as planck\n", - "\n", - "Omega_m_fid = planck.Om0\n", - "sigma_8_fid = 0.8102\n", - "s8_fid = sigma_8_fid * (Omega_m_fid / 0.3) ** 0.5\n", - "h = planck.h\n", - "Omega_b_fig = planck.Ob0\n", - "n_s_fid = 0.9665\n", - "print(\n", - " f\"Fiducial values: Omega_m = {Omega_m_fid}, sigma_8 = {sigma_8_fid}, S_8 = {s8_fid}\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5", - "metadata": {}, - "outputs": [], - "source": [ - "sns.histplot(\n", - " output_df_harm[\"S8_mean\"] - output_df_config[\"S8_mean\"],\n", - " kde=True,\n", - " bins=30,\n", - " label=\"Mean\",\n", - ")\n", - "# sns.histplot(\n", - "# output_df_harm[\"S8_MAP\"]-output_df_config[\"S8_MAP\"],\n", - "# kde=True,\n", - "# bins=20,\n", - "# label=\"MAP\",\n", - "# )\n", - "sns.histplot(\n", - " output_df_harm[\"S8_MAP_2D\"] - output_df_config[\"S8_MAP_2D\"],\n", - " kde=True,\n", - " bins=30,\n", - " label=\"2D Mode\",\n", - " alpha=0.5,\n", - ")\n", - "plt.axvline(0, color=\"black\", linestyle=\"--\")\n", - "plt.legend(fontsize=12)\n", - "\n", - "plt.xlabel(r\"$\\Delta S_8$\")\n", - "plt.savefig(\n", - " \"/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/S8_comparison_harmonic_vs_configuration.pdf\",\n", - " bbox_inches=\"tight\",\n", - ")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6", - "metadata": {}, - "outputs": [], - "source": [ - "output_df_config[\"S8_MAP_2D\"].shape\n", - "output_df_harm[\"S8_MAP_2D\"].shape" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7", - "metadata": { - "lines_to_next_cell": 2 - }, - "outputs": [], - "source": [ - "# Create JointGrid\n", - "g = sns.JointGrid(\n", - " x=output_df_config[\"OMEGA_M_MAP_2D\"],\n", - " y=output_df_config[\"S8_MAP_2D\"],\n", - " height=7,\n", - " ratio=5,\n", - " space=0,\n", - ")\n", - "\n", - "# Main 2D histogram\n", - "sns.histplot(\n", - " x=output_df_config[\"OMEGA_M_MAP_2D\"],\n", - " y=output_df_config[\"S8_MAP_2D\"],\n", - " bins=25,\n", - " cmap=\"Greens\",\n", - " cbar=False,\n", - " ax=g.ax_joint,\n", - ")\n", - "\n", - "# Marginal histograms\n", - "sns.histplot(\n", - " x=output_df_config[\"OMEGA_M_MAP_2D\"], bins=25, color=\"#2ca25f\", ax=g.ax_marg_x\n", - ")\n", - "sns.histplot(y=output_df_config[\"S8_MAP_2D\"], bins=25, color=\"#2ca25f\", ax=g.ax_marg_y)\n", - "\n", - "# Add dashed reference lines\n", - "g.ax_joint.axvline(Omega_m_fid, color=\"k\", linestyle=\"--\")\n", - "g.ax_joint.axhline(s8_fid, color=\"k\", linestyle=\"--\")\n", - "\n", - "# Labels\n", - "g.set_axis_labels(\n", - " r\"$\\Omega_m$ estimated from mocks (Configuration space)\",\n", - " r\"$S_8$ estimated from mocks (Configuration space)\",\n", - ")\n", - "\n", - "# Optional styling tweaks\n", - "g.ax_joint.tick_params(labelsize=12)\n", - "plt.savefig(\n", - " \"/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/S8_vs_OmegaM_configuration_space_mocks.pdf\",\n", - " bbox_inches=\"tight\",\n", - ")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "jupytext": { - "cell_metadata_filter": "-all", - "main_language": "python", - "notebook_metadata_filter": "-all" - }, - "kernelspec": { - "display_name": "my_env", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/masking.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/masking.ipynb deleted file mode 100644 index b0dd4bbc..00000000 --- a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/masking.ipynb +++ /dev/null @@ -1,132 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Covmat mask analysis\n", - "\n", - "This notebook creates the plots to look at the ratio of the covaraiance matrices when applying the mask or not" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "\n", - "import healpy as hp\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "import seaborn as sns\n", - "\n", - "plt.style.use(\"/home/guerrini/matplotlib_config/paper.mplstyle\")\n", - "\n", - "plt.rcParams[\"axes.labelsize\"] = 18\n", - "plt.rcParams[\"xtick.labelsize\"] = 18\n", - "plt.rcParams[\"ytick.labelsize\"] = 18\n", - "\n", - "plt.rcParams[\"text.usetex\"] = True\n", - "sns.set_palette(\"husl\")\n", - "\n", - "cat_dir = \"/n17data/UNIONS/WL/v1.4.x/\"\n", - "catalog_ver = \"v1.4.6.3\"\n", - "blind = \"B\"\n", - "\n", - "nside = 8192\n", - "npix = hp.nside2npix(nside)\n", - "\n", - "data_dir = \"/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/data/\"\n", - "curr_dir = os.getcwd()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# PLOT 2D MAP OF COVMAT masked vs unmasked RATIOS\n", - "nbins = 20\n", - "ndata = nbins * 2\n", - "full_ratio = np.zeros((ndata, ndata))\n", - "\n", - "cov = np.loadtxt(data_dir + f\"/covs/cov_SP_{catalog_ver}_{blind}.txt\")\n", - "cov_masked = np.loadtxt(data_dir + f\"/covs/cov_masked_SP_{catalog_ver}_{blind}.txt\")\n", - "\n", - "for i in range(ndata):\n", - " for j in range(ndata):\n", - " full_ratio[i][j] = cov_masked[i][j] / cov[i][j]\n", - "\n", - "fig = plt.figure()\n", - "ax = fig.add_subplot(1, 1, 1)\n", - "extent = (0, ndata, ndata, 0)\n", - "\n", - "vmin, vmax = np.percentile(full_ratio, [1, 99])\n", - "\n", - "im3 = ax.imshow(full_ratio, cmap=\"RdBu_r\", vmin=vmin, vmax=vmax, extent=extent)\n", - "\n", - "cbar = fig.colorbar(im3, ax=ax, fraction=0.046, pad=0.04)\n", - "\n", - "ax.text(int(ndata / 4), ndata + 5, r\"$\\xi_+$\", fontsize=15)\n", - "ax.text(3 * int(ndata / 4), ndata + 5, r\"$\\xi_-$\", fontsize=15)\n", - "ax.text(-8, int(ndata / 4), r\"$\\xi_+$\", fontsize=15, rotation=90)\n", - "ax.text(-8, 3 * int(ndata / 4), r\"$\\xi_-$\", fontsize=15, rotation=90)\n", - "ax.set_xticks([0, 10, 20, 30, 40])\n", - "ax.set_yticks([0, 10, 20, 30, 40])\n", - "ax.set_yticklabels([\"1'\", \"125'\", \"250'\", \"125'\", \"250'\"])\n", - "ax.set_xticklabels([\"1'\", \"125'\", \"250'\", \"125'\", \"250'\"])\n", - "plt.axvline(x=int(ndata / 2), color=\"white\", linewidth=1.0)\n", - "plt.axhline(y=int(ndata / 2), color=\"white\", linewidth=1.0)\n", - "\n", - "plt.savefig(\n", - " f\"{curr_dir}/../Plots/covmat_masked_unmasked_ratio_{catalog_ver}_{blind}.pdf\",\n", - " bbox_inches=\"tight\",\n", - ")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "theta = np.linspace(1, 250, 20)\n", - "plt.axhline(y=1, color=\"k\", ls=\"--\")\n", - "plt.plot(theta, np.diag(cov_masked)[:20] / np.diag(cov)[:20], label=r\"$\\xi_+$\")\n", - "plt.plot(theta, np.diag(cov_masked)[20:] / np.diag(cov)[20:], label=r\"$\\xi_-$\")\n", - "\n", - "plt.xlabel(r\"$\\theta$ (arcmin)\")\n", - "plt.ylabel(\"Cov masked / Cov unmasked\")\n", - "plt.legend(fontsize=20)\n", - "plt.savefig(\n", - " f\"{curr_dir}/../Plots/covmat_masked_unmasked_ratio_diag.pdf\", bbox_inches=\"tight\"\n", - ")" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "my_env", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/nonlin_k_analysis.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/nonlin_k_analysis.ipynb deleted file mode 100644 index 4ab9c3c5..00000000 --- a/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/nonlin_k_analysis.ipynb +++ /dev/null @@ -1,174 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Nonlinear $k$ contributions\n", - "\n", - "This notebook plots the 2D heatmap of ratio of scale contributions to the $\\xi_\\pm$ 2PCF given angular scale $\\theta$ and wavenumber $k$." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "\n", - "import matplotlib.pylab as plt\n", - "import numpy as np\n", - "import seaborn as sns\n", - "\n", - "plt.style.use(\"/home/guerrini/matplotlib_config/paper.mplstyle\")\n", - "\n", - "plt.rcParams[\"text.usetex\"] = True\n", - "\n", - "plt.rcParams.update(\n", - " {\n", - " \"font.size\": 20,\n", - " \"axes.titlesize\": 21,\n", - " \"axes.labelsize\": 20,\n", - " \"xtick.labelsize\": 20,\n", - " \"ytick.labelsize\": 20,\n", - " \"legend.fontsize\": 20,\n", - " \"figure.titlesize\": 21,\n", - " }\n", - ")\n", - "sns.set_palette(\"husl\")\n", - "\n", - "blind = \"B\"\n", - "ver = \"v1.4.6.3\"\n", - "\n", - "%matplotlib inline\n", - "\n", - "data_dir = \"/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/data/\"\n", - "curr_dir = os.getcwd()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Plotting from script" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Read the 2D array from the text file\n", - "\n", - "file_headers = [\"xip_%s_%s\" % (ver, blind), \"xim_%s_%s\" % (ver, blind)]\n", - "\n", - "for f in file_headers:\n", - " xis = np.loadtxt(data_dir + f\"theta_k_{f}.txt\")\n", - " xis_reshaped = xis.reshape(-1, 201)\n", - " sorted_xis = xis_reshaped[np.argsort(xis_reshaped[:, 0])]\n", - "\n", - " np.savetxt(data_dir + f\"theta_k_{f}_sorted.txt\", sorted_xis)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fig, axs = plt.subplots(2, 1, figsize=(8, 10))\n", - "\n", - "# --- k grid ---\n", - "h = 0.6766\n", - "k_plot = np.logspace(-4, 2, 200)\n", - "\n", - "file_header = \"%s_%s\" % (ver, blind)\n", - "\n", - "xi_thetas = np.loadtxt(data_dir + f\"theta_k_xip_{file_header}_sorted.txt\")\n", - "thetas = xi_thetas[:, 0]\n", - "xis = xi_thetas[:, 1:]\n", - "\n", - "# normalise\n", - "xi_plot = xis / np.max(xis, axis=1, keepdims=True)\n", - "\n", - "T, K = np.meshgrid(thetas, k_plot)\n", - "\n", - "axs[0].contour(T, K, xi_plot.T, levels=[0.9], colors=\"red\", linewidths=1.7)\n", - "pcm = axs[0].pcolormesh(T, K, xi_plot.T, shading=\"auto\", cmap=\"viridis\")\n", - "pcm.set_rasterized(True)\n", - "\n", - "axs[0].axvline(5, color=\"k\", ls=\"dashed\", lw=1.2)\n", - "axs[0].axvline(12, color=\"white\", ls=\"dashed\", lw=1.6)\n", - "axs[0].axhline(1, color=\"k\", ls=\"dashed\", lw=1.2) # converted to h/Mpc space if needed\n", - "axs[0].axhline(0.425, color=\"white\", ls=\"dashed\", lw=1.6)\n", - "\n", - "axs[0].set_yscale(\"log\")\n", - "axs[0].set_xlabel(r\"$\\theta\\ \\mathrm{(arcmin)}$\")\n", - "axs[0].set_ylabel(r\"$k\\ (h$ Mpc$^{-1})$\")\n", - "\n", - "axs[0].set_title(r\"$\\xi_+$\")\n", - "\n", - "xi_thetas = np.loadtxt(data_dir + f\"theta_k_xim_{file_header}_sorted.txt\")\n", - "thetas = xi_thetas[:, 0]\n", - "xis = xi_thetas[:, 1:]\n", - "\n", - "xi_plot = xis / np.max(xis, axis=1, keepdims=True)\n", - "\n", - "T, K = np.meshgrid(thetas, k_plot)\n", - "\n", - "axs[1].contour(T, K, xi_plot.T, levels=[0.9], colors=\"red\", linewidths=1.7)\n", - "pcm = axs[1].pcolormesh(T, K, xi_plot.T, shading=\"nearest\", cmap=\"viridis\")\n", - "pcm.set_rasterized(True)\n", - "\n", - "axs[1].axvline(12, color=\"white\", ls=\"dashed\", lw=1.6)\n", - "axs[1].axhline(2.85, color=\"white\", ls=\"dashed\", lw=1.6)\n", - "\n", - "\n", - "axs[1].set_yscale(\"log\")\n", - "axs[1].set_xlabel(r\"$\\theta\\ \\mathrm{(arcmin)}$\")\n", - "axs[1].set_ylabel(r\"$k\\ (h$ Mpc$^{-1})$\")\n", - "axs[1].set_title(r\"$\\xi_-$\")\n", - "\n", - "\n", - "fig.tight_layout()\n", - "\n", - "cbar_ax = fig.add_axes([0.99, 0.15, 0.02, 0.7])\n", - "cbar = fig.colorbar(pcm, cax=cbar_ax)\n", - "\n", - "fig.savefig(\n", - " curr_dir + f\"/../Plots/theta_k_xip_xim_{ver}_{blind}.pdf\", bbox_inches=\"tight\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "my_env", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_unblinding/utils.py b/cosmo_inference/notebooks/2D_cosmic_shear_unblinding/utils.py deleted file mode 100644 index 8c2fb9e5..00000000 --- a/cosmo_inference/notebooks/2D_cosmic_shear_unblinding/utils.py +++ /dev/null @@ -1,442 +0,0 @@ -""" -Useful scripts to perform the plots for the unblinding party. -""" - -import configparser -import os -import sys - -# Append any useful folder in the path -sys.path.append("/home/guerrini/sp_validation/cosmo_inference/scripts/") - -import matplotlib.pyplot as plt -import matplotlib.scale as mscale -import numpy as np -from astropy.io import fits - -from sp_validation.rho_tau import SquareRootScale - -mscale.register_scale(SquareRootScale) - - -def read_config(path_ini_files, root, thisfile=None): - config = configparser.ConfigParser() - config.optionxform = str - if thisfile is not None: - read_path = thisfile - else: - read_path = os.path.join(path_ini_files, f"{root}.ini") - config.read(read_path) - return config - - -def update_properties_w_roots( - properties, root, path_ini_files, path_to_this_ini=None, with_configuration=False -): - config = read_config(path_ini_files, root, thisfile=path_to_this_ini) - - try: - lower_bound_cell_ee, upper_bound_cell_ee = map( - float, config["2pt_like"]["angle_range_CELL_EE_1_1"].split() - ) - properties[root].update( - { - "lower_bound_cell_ee": lower_bound_cell_ee, - "upper_bound_cell_ee": upper_bound_cell_ee, - } - ) - except KeyError: - properties[root] = {"lower_bound_cell_ee": 0.0, "upper_bound_cell_ee": 2048} - - if with_configuration: - # Also save the scale cuts in theta for xi - add_xi_sys = config["2pt_like"]["add_xi_sys"] - add_xi_sys = add_xi_sys == "T" - lower_bound_xi_plus, upper_bound_xi_plus = map( - float, config["2pt_like"]["angle_range_XI_PLUS_1_1"].split() - ) - lower_bound_xi_minus, upper_bound_xi_minus = map( - float, config["2pt_like"]["angle_range_XI_MINUS_1_1"].split() - ) - - properties[root].update( - { - "add_xi_sys": add_xi_sys, - "lower_bound_xi_plus": lower_bound_xi_plus, - "upper_bound_xi_plus": upper_bound_xi_plus, - "lower_bound_xi_minus": lower_bound_xi_minus, - "upper_bound_xi_minus": upper_bound_xi_minus, - } - ) - return properties - - -def plot_best_fit( - data_points, - root_to_plot, - output_folder, - line_args, - savefile, - ell_min=10.0, - ell_max=2048.0, - multiply_ell=True, - loc_legend="best", - bbox_to_anchor=None, - label_data="Fiducial data", - labels=None, - properties=None, - paths_to_bestfit=None, -): - data = fits.open( - f"/home/guerrini/sp_validation/cosmo_inference/data/{data_points}/cosmosis_{data_points}.fits" - ) - cell_ee = data["CELL_EE"].data - cov_mat = data["COVMAT"].data - - if labels is None: - labels = root_to_plot - - fig, ax = plt.subplots(1, 1, figsize=(8, 5)) - - ell, cell = cell_ee["ANG"], cell_ee["VALUE"] - ax.errorbar( - ell, - ell * cell, - yerr=ell * np.sqrt(np.diag(cov_mat)), - fmt="o", - label=label_data, - color="black", - capsize=2, - ) - - for idx, (label, root) in enumerate(zip(labels, root_to_plot)): - # Read the results - if paths_to_bestfit is None: - ell = np.loadtxt( - output_folder - + "{}/best_fit/shear_cl/ell.txt".format( - root, - ) - ) - shear_cl = np.loadtxt( - output_folder - + "{}/best_fit/shear_cl/bin_1_1.txt".format( - root, - ) - ) - else: - ell = np.loadtxt(paths_to_bestfit[idx] + "best_fit/shear_cl/ell.txt") - shear_cl = np.loadtxt( - paths_to_bestfit[idx] + "best_fit/shear_cl/bin_1_1.txt" - ) - - mask = (ell > ell_min) & (ell < ell_max) - - ax.plot( - ell[mask], - ell[mask] * shear_cl[mask] if multiply_ell else shear_cl[mask], - label=label, - **line_args[idx], - ) - - # Plot the scale cuts for different k_max - ax.axvline(x=1800, color="black", linestyle="--", alpha=0.5) - ax.axvline(x=2048, color="black", linestyle="--", alpha=1.0) - ax.axvline(x=500, color="black", linestyle="--", alpha=0.3) - - ymin = ax.get_ylim()[0] - ymax = ax.get_ylim()[1] - # Shadowing cut scaled - ax.fill_betweenx( - y=[ymin, ymax], - x1=0, - x2=300, - color="gray", - alpha=0.2, - label=r"$B$-mode informed scale cut", - ) - ax.fill_betweenx(y=[ymin, ymax], x1=1600, x2=2048, color="gray", alpha=0.2) - - ax.set_ylim(ymin, ymax) - - # Add labels directly under the tick - ax.text( - 1740, - 0.90, - r"$k_\mathrm{max} = 3 h$ Mpc$^{-1}$", - transform=ax.get_xaxis_transform(), - ha="center", - va="top", - fontsize=14, - rotation=90, - ) - - ax.text( - 1978, - 0.90, - r"$k_\mathrm{max} = 5 h$ Mpc$^{-1}$", - transform=ax.get_xaxis_transform(), - ha="center", - va="top", - fontsize=14, - rotation=90, - ) - - ax.text( - 470, - 0.90, - r"$k_\mathrm{max} = 1 h$ Mpc$^{-1}$", - transform=ax.get_xaxis_transform(), - ha="center", - va="top", - fontsize=14, - rotation=90, - ) - - ell, cell = cell_ee["ANG"], cell_ee["VALUE"] - ax.set_ylabel(r"$\ell C_\ell \times 10^{-7}$", fontsize=20) - ax.set_xlabel(r"Multipole $\ell$", fontsize=20) - ax.set_xlim(ell.min() - 10, ell.max() + 100) - ax.set_xscale("squareroot") - ax.set_xticks(np.array([100, 400, 900, 1600])) - ax.minorticks_on() - ax.tick_params(axis="x", which="minor", length=2, width=0.8) - minor_ticks = [i * 10 for i in range(1, 10)] + [i * 100 for i in range(1, 21)] - ax.xaxis.set_ticks(minor_ticks, minor=True) - ax.tick_params(axis="both", which="major", labelsize=14) - ax.tick_params(axis="both", which="minor", labelsize=10) - ax.yaxis.get_offset_text().set_visible(False) - - plt.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor, fontsize=11) - - if savefile is not None: - plt.savefig(savefile, bbox_inches="tight") - - plt.show() - - -def plot_best_fit_config( - data, - root_to_plot, - output_folder, - line_args, - savefile, - theta_min=1.0, - theta_max=250.0, - multiply_theta=True, - loc_legend="best", - bbox_to_anchor_xip=None, - bbox_to_anchor_xim=None, - label_data="Fiducial data", - labels=None, - properties=None, - paths_to_bestfit=None, -): - - data = fits.open(data) - - xi_p_data = data["XI_PLUS"].data - xi_m_data = data["XI_MINUS"].data - cov_mat = data["COVMAT"].data - - # Plot hyperparameter - loc_legend = "lower center" - - fig, [ax, ax2] = plt.subplots(2, 1, figsize=(8, 9)) - - theta, xi_p, xi_m = xi_p_data["ANG"], xi_p_data["VALUE"], xi_m_data["VALUE"] - ax.errorbar( - theta, - theta * xi_p, - yerr=theta * np.sqrt(np.diag(cov_mat[: len(theta), : len(theta)])), - fmt="o", - label=r"UNIONS $\xi_+$ data", - color="black", - capsize=2, - ) - ax2.errorbar( - theta, - theta * xi_m, - yerr=theta - * np.sqrt( - np.diag(cov_mat[len(theta) : 2 * len(theta), len(theta) : 2 * len(theta)]) - ), - fmt="o", - label=r"UNIONS $\xi_-$ data", - color="black", - capsize=2, - ) - - for idx, (label, root) in enumerate(zip(labels, root_to_plot)): - # Read the results - if paths_to_bestfit is None: - theta = ( - ( - np.loadtxt( - output_folder - + "{}/best_fit/shear_xi_plus/theta.txt".format(root) - ) - ) - * 180 - / np.pi - * 60 - ) - xi_plus = np.loadtxt( - output_folder + "{}/best_fit/shear_xi_plus/bin_1_1.txt".format(root) - ) - xi_minus = np.loadtxt( - output_folder + "{}/best_fit/shear_xi_minus/bin_1_1.txt".format(root) - ) - if r"$C_\ell$" not in label: - xi_sys_plus = np.loadtxt( - output_folder + "{}/best_fit/xi_sys/shear_xi_plus.txt".format(root) - ) - xi_sys_minus = np.loadtxt( - output_folder + "{}/best_fit/xi_sys/shear_xi_minus.txt".format(root) - ) - theta_xi_sys = ( - np.loadtxt( - output_folder + "{}/best_fit/xi_sys/theta.txt".format(root) - ) - * 180 - / np.pi - * 60 - ) - xi_plus += np.interp(theta, theta_xi_sys, xi_sys_plus) - xi_minus += np.interp(theta, theta_xi_sys, xi_sys_minus) - else: - theta = ( - (np.loadtxt(paths_to_bestfit[idx] + "best_fit/shear_xi_plus/theta.txt")) - * 180 - / np.pi - * 60 - ) - xi_plus = np.loadtxt( - paths_to_bestfit[idx] + "best_fit/shear_xi_plus/bin_1_1.txt" - ) - xi_minus = np.loadtxt( - paths_to_bestfit[idx] + "best_fit/shear_xi_minus/bin_1_1.txt" - ) - if r"$C_\ell$" not in label: - xi_sys_plus = np.loadtxt( - output_folder + "{}/best_fit/xi_sys/shear_xi_plus.txt".format(root) - ) - xi_sys_minus = np.loadtxt( - output_folder + "{}/best_fit/xi_sys/shear_xi_minus.txt".format(root) - ) - theta_xi_sys = ( - np.loadtxt( - output_folder + "{}/best_fit/xi_sys/theta.txt".format(root) - ) - * 180 - / np.pi - * 60 - ) - xi_plus += np.interp(theta, theta_xi_sys, xi_sys_plus) - xi_minus += np.interp(theta, theta_xi_sys, xi_sys_minus) - - mask = (theta > theta_min) & (theta < theta_max) - theta = theta[mask] - ax.plot( - theta, - theta * xi_plus[mask] if multiply_theta else xi_plus[mask], - label=label, - **line_args[idx], - ) - ax2.plot( - theta, - theta * xi_minus[mask] if multiply_theta else xi_minus[mask], - label=label, - **line_args[idx], - ) - - # XI PLUS PLOT SETTINGS - - # Plot the scale cuts for different k_max - ax.axvline(x=3.2, color="black", linestyle="--", alpha=0.7) - - ymin = ax.get_ylim()[0] - ymax = ax.get_ylim()[1] - # Shadowing cut scaled - ax.fill_betweenx( - y=[ymin, ymax], - x1=0, - x2=12, - color="gray", - alpha=0.2, - label=r"$B$-mode informed scale cut", - ) - ax.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color="gray", alpha=0.2) - - ax.set_ylim(ymin, ymax) - - # Add labels directly under the tick - ax.text( - 2.9, - 1.23e-4, - r"$k_\mathrm{max} = 1 h$ Mpc$^{-1}$", - ha="center", - va="top", - fontsize=14, - rotation=90, - ) - - # ax.set_ylabel('$\theta \xi_+$', fontsize=16) - # ax.set_xlabel('$\theta$', fontsize=16) - ax.set_xlim([theta.min() - 0.1, theta.max() + 20]) - ax.set_xscale("log") - ax.set_xticks(np.array([1, 10, 100])) - ax.tick_params(axis="x", which="minor", length=2, width=0.8) - ax.tick_params(axis="both", which="major", labelsize=14) - ax.tick_params(axis="both", which="minor", labelsize=10) - ax.yaxis.get_offset_text().set_fontsize(14) - ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) - ax.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xip, fontsize=12) - - # XI_MINUS PLOT SETTINGS - - # Plot the scale cuts for different k_max - ax2.axvline(x=24, color="black", linestyle="--", alpha=0.7) - - ymin = ax2.get_ylim()[0] - ymax = ax2.get_ylim()[1] - # Shadowing cut scaled - ax2.fill_betweenx( - y=[ymin, ymax], - x1=0, - x2=12, - color="gray", - alpha=0.2, - label=r"$B$-mode informed scale cut", - ) - ax2.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color="gray", alpha=0.2) - - ax2.set_ylim(ymin, ymax) - - # Add labels directly under the tick - ax2.text( - 21.8, - 1.15e-4, - r"$k_\mathrm{max} = 1 h$ Mpc$^{-1}$", - ha="center", - va="top", - fontsize=14, - rotation=90, - ) - - ax2.set_ylabel(r"$\theta \xi_-$", fontsize=16) - ax2.set_xlabel(r"$\theta$", fontsize=16) - ax2.set_xlim([theta.min() - 0.1, theta.max() + 20]) - ax2.set_xscale("log") - ax2.set_xticks(np.array([1, 10, 100])) - ax2.tick_params(axis="x", which="minor", length=2, width=0.8) - ax2.tick_params(axis="both", which="major", labelsize=14) - ax2.tick_params(axis="both", which="minor", labelsize=10) - ax2.yaxis.get_offset_text().set_fontsize(14) - ax2.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) - ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=12) - - if savefile is not None: - plt.savefig(savefile, bbox_inches="tight") - - plt.show() diff --git a/cosmo_inference/notebooks/cfis_analysis.ipynb b/cosmo_inference/notebooks/cfis_analysis.ipynb deleted file mode 100644 index ee93f4ec..00000000 --- a/cosmo_inference/notebooks/cfis_analysis.ipynb +++ /dev/null @@ -1,1065 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "0", - "metadata": {}, - "source": [ - "# Analysis of a CFIS shear catalogue\n", - "First steps. Analysing both ShapePipe and Lensfit catalogues, for all blinds A,B and C" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "import ipywidgets as widgets\n", - "import matplotlib.pylab as plt\n", - "import numpy as np\n", - "import pandas as pd\n", - "import pyccl as ccl\n", - "import treecorr\n", - "from astropy.io import fits\n", - "from ipywidgets import interact\n", - "\n", - "%matplotlib inline\n", - "plt.rcParams.update({\"font.size\": 20, \"figure.figsize\": [12, 10]})\n", - "plt.rc(\"mathtext\", fontset=\"stix\")\n", - "plt.rc(\"font\", family=\"sans-serif\")\n", - "\n", - "# SPECIFY DIRECTORIES AND CATALOGUE PATHS\n", - "work_dir = \"/home/mkilbing/astro/data/UNIONS/v1.x/ShapePipe\"\n", - "\n", - "cat_dict = {\n", - " 1: {\n", - " \"dir\": work_dir + \"/Lensfit/lensfit_goldshape_2022v1.fits\",\n", - " \"label\": \"LF_full\",\n", - " \"e1_bias\": 0,\n", - " \"e2_bias\": 0,\n", - " \"ls\": \"solid\",\n", - " \"colour\": \"g\",\n", - " },\n", - " 2: {\n", - " \"dir\": work_dir + \"/ShapePipe/unions_shapepipe_2022_v1.0.fits\",\n", - " \"label\": \"SP_full\",\n", - " \"e1_bias\": 0,\n", - " \"e2_bias\": 0,\n", - " \"ls\": \"solid\",\n", - " \"colour\": \"b\",\n", - " },\n", - " 3: {\n", - " \"dir\": work_dir + \"/matched_LF_SP/masked_matched_lensfit_goldshape_2022v1.fits\",\n", - " \"label\": \"LF_matched_SP\",\n", - " \"e1_bias\": 3.939e-4,\n", - " \"e2_bias\": 6.482e-5,\n", - " \"ls\": \"dotted\",\n", - " \"colour\": \"g\",\n", - " },\n", - " 4: {\n", - " \"dir\": work_dir\n", - " + \"/matched_LF_SP/masked_matched_unions_shapepipe_extended_2022_v1.0.fits\",\n", - " \"label\": \"SP_matched_LF\",\n", - " \"e1_bias\": -5.6726e-5,\n", - " \"e2_bias\": 8.218e-4,\n", - " \"ls\": \"dotted\",\n", - " \"colour\": \"b\",\n", - " },\n", - " 5: {\n", - " \"dir\": work_dir + \"/matched_LF_SP/matched_footprint_shapepipe.fits\",\n", - " \"label\": \"SP Match LF Footprint\",\n", - " \"e1_bias\": 0,\n", - " \"e2_bias\": 0,\n", - " \"ls\": \"dashed\",\n", - " \"colour\": \"b\",\n", - " },\n", - " 6: {\n", - " \"dir\": work_dir + \"/cfis-shapepipe.parquet\",\n", - " \"label\": \"SP Match MegaPipe\",\n", - " \"e1_bias\": 0,\n", - " \"e2_bias\": 0,\n", - " \"ls\": \"dashdot\",\n", - " \"colour\": \"b\",\n", - " },\n", - " 7: {\n", - " \"dir\": work_dir + \"/ShapePipe/shapepipe_1500_goldshape_v1.fits\",\n", - " \"label\": \"SP_1500\",\n", - " \"e1_bias\": 7.156105098141909e-06,\n", - " \"e2_bias\": -6.00816359759969e-06,\n", - " \"ls\": \"dotted\",\n", - " \"colour\": \"b\",\n", - " },\n", - " 8: {\n", - " \"dir\": work_dir + \"/ShapePipe/unions_shapepipe_2022_v1.0.4.fits\",\n", - " \"label\": \"SP_cut_Fabian\",\n", - " \"e1_bias\": 0.0,\n", - " \"e2_bias\": 0.0,\n", - " \"ls\": \"dashdot\",\n", - " \"colour\": \"pink\",\n", - " },\n", - " 9: {\n", - " \"dir\": work_dir + \"/ShapePipe/unions_shapepipe_psf_2022_v1.0.2.fits\",\n", - " \"label\": \"SP_PSF\",\n", - " \"e1_bias\": 0.0,\n", - " \"e2_bias\": 0.0,\n", - " \"ls\": \"dashdot\",\n", - " \"colour\": \"b\",\n", - " },\n", - " 10: {\n", - " \"dir\": work_dir + \"/unions_shapepipe_2022_v1.3.fits\",\n", - " \"label\": \"SP_v1.3\",\n", - " \"e1_bias\": 0.0,\n", - " \"e2_bias\": 0.0,\n", - " \"ls\": \"dashdot\",\n", - " \"colour\": \"r\",\n", - " },\n", - " 11: {\n", - " \"dir\": work_dir + \"/ShapePipe/unions_shapepipe_star_2022_v1.3.fits\",\n", - " \"label\": \"SP_v1.3\",\n", - " \"e1_bias\": 0.0,\n", - " \"e2_bias\": 0.0,\n", - " \"ls\": \"dashdot\",\n", - " \"colour\": \"b\",\n", - " },\n", - " 12: {\n", - " \"dir\": work_dir + \"/unions_shapepipe_2024_v1.4.1.fits\",\n", - " \"label\": \"SP_v1.4.1\",\n", - " \"e1_bias\": 0.0,\n", - " \"e2_bias\": 0.0,\n", - " \"ls\": \"dashdot\",\n", - " \"colour\": \"b\",\n", - " },\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2", - "metadata": {}, - "outputs": [], - "source": [ - "# CATALOGUE OPTIONS:\n", - "# 1: LensFit Full\n", - "# 2: ShapePipe Full\n", - "# 3: LF Match SP\n", - "# 4: SP Match LF\n", - "# 5: SP Matched in LF footprint\n", - "# 6: SP Match MegaPipe\n", - "# 7: SP 1500deg2 (Axel's)\n", - "# 8: SP cut on large gals\n", - "# 12: SP psfex v1.4.1\n", - "\n", - "cat_options = [10, 12]\n", - "\n", - "dfs = []\n", - "\n", - "for cat_option in cat_options:\n", - " if cat_option == 6:\n", - " df = pd.read_parquet(cat_dict[cat_option][\"dir\"], engine=\"pyarrow\")\n", - " df = df.replace([np.inf, -np.inf], np.nan).dropna(axis=0)\n", - " else:\n", - " with fits.open(cat_dict[cat_option][\"dir\"]) as data:\n", - " df = pd.DataFrame(data[1].data)\n", - " if cat_option == 7:\n", - " df = df.rename(columns={\"g1\": \"e1\", \"g2\": \"e2\"})\n", - " if cat_option == 8 or cat_option == 10:\n", - " df = df.rename(columns={\"RA\": \"ra\", \"Dec\": \"dec\"})\n", - " if cat_option == 12:\n", - " df = df.rename(\n", - " columns={\"RA\": \"ra\", \"Dec\": \"dec\", \"e1\": \"e1_prev\", \"e2\": \"e2_prev\"}\n", - " )\n", - " df = df.rename(columns={\"e1_noleakage\": \"e1\", \"e2_noleakage\": \"e2\"})\n", - " dfs.append(df)" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "id": "3", - "metadata": {}, - "source": [ - "## Catalogue Analysis" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4", - "metadata": {}, - "outputs": [], - "source": [ - "for cat in cat_options:\n", - " plt.plot(df[\"ra\"], df[\"dec\"], \".\", label=cat_dict[cat][\"label\"])\n", - "plt.xlabel(\"RA [deg]\")\n", - "plt.ylabel(\"DEC [deg]\")\n", - "plt.legend(loc=\"upper right\")\n", - "# plt.savefig('plots/3500deg^2_plot.pdf',dpi=100)\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5", - "metadata": {}, - "outputs": [], - "source": [ - "# Ellipticity histograms\n", - "plt.rcParams.update({\"font.size\": 20, \"figure.figsize\": [22, 7]})\n", - "\n", - "fig, axs = plt.subplots(1, 2)\n", - "nbins = 200\n", - "\n", - "for idx, cat in enumerate(cat_options):\n", - " (n, bins, _) = axs[0].hist(\n", - " dfs[idx][\"e1\"],\n", - " bins=nbins,\n", - " density=True,\n", - " histtype=\"step\",\n", - " weights=dfs[idx][\"w\"],\n", - " label=\"e1 %s\" % cat_dict[cat][\"label\"],\n", - " )\n", - "axs[0].set_xlabel(r\"$e_1$\")\n", - "axs[0].legend()\n", - "axs[0].set_xlim([-1.5, 1.5])\n", - "\n", - "# axs[0].set_ylim([0,2e4])\n", - "\n", - "for idx, cat in enumerate(cat_options):\n", - " (n, bins, _) = axs[1].hist(\n", - " dfs[idx][\"e2\"],\n", - " bins=nbins,\n", - " density=True,\n", - " histtype=\"step\",\n", - " weights=dfs[idx][\"w\"],\n", - " label=\"e2 {}\".format(cat_dict[cat][\"label\"]),\n", - " )\n", - " print(\n", - " \"e1 sigma {}: {}\".format(\n", - " cat_dict[cat][\"label\"], np.std(dfs[idx][\"e1_noleakage\"])\n", - " )\n", - " )\n", - " print(\n", - " \"e2 sigma {}: {}\".format(\n", - " cat_dict[cat][\"label\"], np.std(dfs[idx][\"e2_noleakage\"])\n", - " )\n", - " )\n", - " print(\n", - " \"e1 bias {}: {}\".format(\n", - " cat_dict[cat][\"label\"],\n", - " np.average(\n", - " np.array(dfs[idx][\"e1_noleakage\"]), weights=np.array(dfs[idx][\"w\"])\n", - " ),\n", - " )\n", - " )\n", - " print(\n", - " \"e2 bias {}: {}\".format(\n", - " cat_dict[cat][\"label\"],\n", - " np.average(\n", - " np.array(dfs[idx][\"e2_noleakage\"]), weights=np.array(dfs[idx][\"w\"])\n", - " ),\n", - " )\n", - " )\n", - "axs[1].set_xlabel(r\"$e_2$\")\n", - "axs[1].legend()\n", - "axs[1].set_xlim([-1.5, 1.5])\n", - "# axs[1].set_ylim([0,2e4])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6", - "metadata": {}, - "outputs": [], - "source": [ - "# Mag histograms\n", - "\n", - "plt.rcParams.update({\"font.size\": 20, \"figure.figsize\": [15, 10]})\n", - "\n", - "for idx, cat in enumerate(cat_options):\n", - " (n, bins, _) = plt.hist(\n", - " dfs[idx][\"mag\"],\n", - " bins=200,\n", - " density=False,\n", - " histtype=\"step\",\n", - " weights=dfs[idx][\"w\"],\n", - " label=\"Mag %s\" % cat_dict[cat][\"label\"],\n", - " )\n", - "\n", - "plt.xlim([19, 26])\n", - "plt.xlabel(\"Mag\")\n", - "plt.legend(loc=\"upper left\")" - ] - }, - { - "cell_type": "markdown", - "id": "7", - "metadata": { - "tags": [] - }, - "source": [ - "## Plot n(z)'s from file\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "8", - "metadata": {}, - "outputs": [], - "source": [ - "# nz_lf = fits.open(work_dir + '/nz/blind_nz_cfis_lensfit_goldshape_2022v1.fits')[1].data\n", - "nz = fits.open(work_dir + \"/nz/blind_nz_cfis_shapepipe_2022v1.fits\")[1].data\n", - "\n", - "# nz_lf_matched = fits.open(work_dir + '/nz/nz_masked_matched_lensfit_goldshape_2022v1.fits')[1].data\n", - "# nz_sp_matched = fits.open(work_dir + '/nz/nz_masked_matched_unions_shapepipe_extended_2022_v1.0.fits')[1].data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9", - "metadata": { - "tags": [] - }, - "outputs": [], - "source": [ - "# FULL CATALOGUE NZ'S\n", - "from matplotlib.ticker import StrMethodFormatter\n", - "\n", - "blinds = [\"A\", \"B\", \"C\"]\n", - "\n", - "# for blind in blinds:\n", - "# z1 = nz_lf['Z_%s' %blind]\n", - "\n", - "# (n,bins,_)= plt.hist(z1, bins=200, range=(0,5.0), density=True, histtype='step', weights=None,label='LensFit Blind %s' %blind)\n", - "# # n_lf.append(list(n))\n", - "# # bins_lf.append(list(bins))\n", - "\n", - "# plt.xlabel('Redshifts')\n", - "# plt.ylabel('n(z)')\n", - "# print(\"zmin = \",min(z1))\n", - "# print(\"zmax = \",max(z1))\n", - "# plt.legend(fontsize=20)\n", - "# # plt.savefig('plots/Lensfit_nz_all_blinds.pdf' )\n", - "# plt.show()\n", - "#####################################################################################################\n", - "for blind in blinds:\n", - " z = nz[\"Z_%s\" % blind]\n", - " bins = np.linspace(0, 5, 100)\n", - "\n", - " y, edges = np.histogram(z, bins, density=True, weights=nz[\"som_w\"])\n", - " centers = 0.5 * (edges[1:] + edges[:-1])\n", - " plt.plot(centers, y, \"-o\", markersize=4, label=\"Blind %s\" % blind, alpha=0.7)\n", - "\n", - " # (n,bins,_)= plt.hist(z2, bins=50, range=(0,5.0), density=True, histtype='step',weights=nz['som_w'],label='Blind %s' %blind,alpha=0.5)\n", - " # n_sp.append(list(n))\n", - " # bins_sp.append(list(bins))\n", - "\n", - " plt.xlabel(r\"$z$\")\n", - " plt.ylabel(r\"$n(z)$\")\n", - " plt.ylim([0, 1.7])\n", - " plt.xlim([0, 5])\n", - " plt.grid(True)\n", - " plt.gca().xaxis.set_major_formatter(StrMethodFormatter(\"{x:,.1f}\"))\n", - " # print(\"zmin = \",min(z))\n", - " # print(\"zmax = \",max(z))\n", - " plt.legend(fontsize=20)\n", - " plt.savefig(\"../plots/unions_nz.pdf\", bbox_inches=\"tight\")\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "id": "10", - "metadata": { - "tags": [] - }, - "source": [ - "## Compute shear-shear correlation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "11", - "metadata": {}, - "outputs": [], - "source": [ - "# Create TreeCorr catalogue\n", - "treecorr.set_omp_threads(8)\n", - "\n", - "sep_units = \"arcmin\"\n", - "theta_min = 1\n", - "theta_max = 200\n", - "\n", - "TreeCorrConfig = {\n", - " \"ra_units\": \"degrees\",\n", - " \"dec_units\": \"degrees\",\n", - " \"max_sep\": str(theta_max),\n", - " \"min_sep\": str(theta_min),\n", - " \"sep_units\": sep_units,\n", - " \"nbins\": 20,\n", - " \"var_method\": \"jackknife\",\n", - "}\n", - "\n", - "cat_ggs = []\n", - "for idx, cat in enumerate(cat_options):\n", - " cat_gal = treecorr.Catalog(\n", - " ra=dfs[idx][\"ra\"],\n", - " dec=dfs[idx][\"dec\"],\n", - " g1=dfs[idx][\"e1\"] - cat_dict[cat][\"e1_bias\"],\n", - " g2=dfs[idx][\"e2\"] - cat_dict[cat][\"e2_bias\"],\n", - " w=dfs[idx][\"w\"],\n", - " ra_units=\"degrees\",\n", - " dec_units=\"degrees\",\n", - " npatch=50,\n", - " )\n", - " gg = treecorr.GGCorrelation(TreeCorrConfig)\n", - " gg.process(cat_gal)\n", - " cat_ggs.append(gg)\n", - " print(\"done for cat %s\" % cat)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "12", - "metadata": {}, - "outputs": [], - "source": [ - "plt.rcParams.update({\"font.size\": 25, \"figure.figsize\": [10, 7]})\n", - "\n", - "ax1 = plt.subplot(111)\n", - "for idx, cat in enumerate(cat_options):\n", - " ax1.plot(\n", - " cat_ggs[idx].meanr,\n", - " cat_ggs[idx].npairs,\n", - " label=r\"$n_{pairs}$ %s\" % (cat_dict[cat][\"label\"]),\n", - " ls=cat_dict[cat][\"ls\"],\n", - " color=cat_dict[cat][\"colour\"],\n", - " )\n", - "ax1.set_xlabel(rf\"$\\theta$ [{sep_units}]\")\n", - "ax1.set_ylabel(r\"$n_{pairs}$\")\n", - "plt.show()\n", - "\n", - "ax2 = plt.subplot(111)\n", - "for idx, cat in enumerate(cat_options):\n", - " ax2.errorbar(\n", - " cat_ggs[idx].meanr,\n", - " cat_ggs[idx].xip,\n", - " yerr=np.sqrt(cat_ggs[idx].varxip),\n", - " label=r\"$\\xi_+$ %s\" % (cat_dict[cat][\"label\"]),\n", - " ls=cat_dict[cat][\"ls\"],\n", - " color=cat_dict[cat][\"colour\"],\n", - " )\n", - " ax2.axvspan(0, 10, color=\"gray\", alpha=0.3)\n", - " # ax2.axvspan(100,200,color='gray', alpha=0.3)\n", - "\n", - "ax2.text(\n", - " 0.85,\n", - " 0.88,\n", - " \"1,1\",\n", - " transform=ax2.transAxes,\n", - " bbox=dict(facecolor=\"white\", edgecolor=\"black\", boxstyle=\"round\", pad=0.5),\n", - ")\n", - "ax2.set_xscale(\"log\")\n", - "ax2.set_yscale(\"log\")\n", - "ax2.set_xlabel(rf\"$\\theta$ [{sep_units}]\")\n", - "ax2.set_xlim([0, 200])\n", - "_ = ax2.set_ylabel(r\"$\\xi_+(\\theta)$\")\n", - "ax2.legend(loc=\"lower left\")\n", - "# plt.savefig('../plots/xi_plus_%s.pdf' %cat_dict[cat]['label'],bbox_inches='tight')\n", - "plt.show()\n", - "\n", - "ax3 = plt.subplot(111)\n", - "for idx, cat in enumerate(cat_options):\n", - " ax3.errorbar(\n", - " cat_ggs[idx].meanr,\n", - " cat_ggs[idx].xim,\n", - " yerr=np.sqrt(cat_ggs[idx].varxim),\n", - " label=r\"$\\xi_-$ %s\" % (cat_dict[cat][\"label\"]),\n", - " ls=\"dotted\",\n", - " color=cat_dict[cat][\"colour\"],\n", - " )\n", - " ax3.axvspan(0, 20, color=\"gray\", alpha=0.3)\n", - " # ax3.axvspan(100,200,color='gray', alpha=0.3)\n", - "\n", - "ax3.text(\n", - " 0.85,\n", - " 0.88,\n", - " \"1,1\",\n", - " transform=ax3.transAxes,\n", - " bbox=dict(facecolor=\"white\", edgecolor=\"black\", boxstyle=\"round\", pad=0.5),\n", - ")\n", - "ax3.set_xscale(\"log\")\n", - "ax3.set_yscale(\"log\")\n", - "ax3.set_xlabel(rf\"$\\theta$ [{sep_units}]\")\n", - "ax3.set_xlim([0, 200])\n", - "ax3.legend(loc=\"lower left\")\n", - "_ = ax3.set_ylabel(r\"$\\xi_-(\\theta)$\")\n", - "# plt.savefig('../plots/xi_minus_%s.pdf' %cat_dict[cat]['label'],bbox_inches='tight')\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "id": "13", - "metadata": { - "tags": [] - }, - "source": [ - "## Comparison with theory PyCCL" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "14", - "metadata": {}, - "outputs": [], - "source": [ - "nz = np.loadtxt(\n", - " \"/feynman/work/dap/lcs/lg268561/UNIONS/Catalogues/v1.0/nz/dndz_SP_v1.0_A.txt\",\n", - " usecols=1,\n", - ")\n", - "bins = np.loadtxt(\n", - " \"/feynman/work/dap/lcs/lg268561/UNIONS/Catalogues/v1.0/nz/dndz_SP_v1.0_A.txt\",\n", - " usecols=0,\n", - ")\n", - "\n", - "\n", - "def theory_cls(Omega_c, Omega_b, h, n_s, sigma_8):\n", - " # Set cosmology\n", - " cosmo = ccl.Cosmology(Omega_c, Omega_b, h, n_s, sigma_8)\n", - "\n", - " ell = np.arange(2, 2000)\n", - " theta_deg = np.logspace(\n", - " np.log10(theta_min / 60), np.log10(theta_max / 60), num=20\n", - " ) # Theta is in degrees\n", - " # CALCULATION OF THEORY XI_PM\n", - " xi_plus_lf = []\n", - " xi_minus_lf = []\n", - "\n", - " for i in range(len(nz)):\n", - " bias_ia = 0 * np.ones_like(bins[i][:-1])\n", - " lens_ia = ccl.WeakLensingTracer(\n", - " cosmo,\n", - " dndz=(np.array(bins[i][:-1]), np.array(nz[i])),\n", - " ia_bias=(np.array(bins[i][:-1]), bias_ia),\n", - " )\n", - " cl = ccl.angular_cl(cosmo, lens_ia, lens_ia, ell)\n", - "\n", - " xi_plus_lf.append(\n", - " list(\n", - " ccl.correlation(cosmo, ell, cl, theta_deg, type=\"GG+\", method=\"FFTLog\")\n", - " )\n", - " )\n", - " xi_minus_lf.append(\n", - " list(\n", - " ccl.correlation(cosmo, ell, cl, theta_deg, type=\"GG-\", method=\"FFTLog\")\n", - " )\n", - " )\n", - "\n", - " style = [\":\", \"--\", \"-.\"]\n", - " plt.errorbar(\n", - " gg.meanr,\n", - " gg.xip,\n", - " yerr=np.sqrt(gg.varxip),\n", - " ls=\"\",\n", - " label=r\"$\\xi_+$ TreeCorr (LF)\",\n", - " capsize=5,\n", - " marker=\"o\",\n", - " color=\"b\",\n", - " )\n", - " plt.errorbar(\n", - " gg.meanr,\n", - " gg.xim,\n", - " yerr=np.sqrt(gg.varxim),\n", - " ls=\"\",\n", - " label=r\"$\\xi_-$ TreeCorr (LF)\",\n", - " capsize=5,\n", - " marker=\"o\",\n", - " color=\"g\",\n", - " )\n", - "\n", - " for i in range(len(blinds)):\n", - " plt.plot(\n", - " theta_deg * 60,\n", - " xi_plus_lf[i],\n", - " color=\"b\",\n", - " ls=style[i],\n", - " label=r\"$\\xi_+$ PyCCL (LF) blind %s\" % blinds[i],\n", - " )\n", - " plt.plot(\n", - " theta_deg * 60,\n", - " xi_minus_lf[i],\n", - " color=\"g\",\n", - " ls=style[i],\n", - " label=r\"$\\xi_-$ PyCCL (LF) blind %s\" % blinds[i],\n", - " )\n", - "\n", - " plt.xscale(\"log\")\n", - " # plt.yscale('log')\n", - " plt.legend(fontsize=20)\n", - " plt.ticklabel_format(axis=\"y\", style=\"sci\", scilimits=(0, 0))\n", - " plt.xlim([1, 200])\n", - " plt.ylim([0, 10e-5])\n", - " plt.ylabel(r\"$\\xi_\\pm(\\theta)$\")\n", - " plt.xlabel(r\"$\\theta$ [arcmin]\")\n", - " # plt.savefig('plots/pyccl_comparison_lensfit.pdf')\n", - "\n", - "\n", - "interact(\n", - " theory_cls,\n", - " Omega_c=widgets.FloatSlider(\n", - " value=0.26, min=0.01, max=0.5, step=0.01, description=r\"$\\Omega_c$\"\n", - " ),\n", - " Omega_b=widgets.FloatSlider(\n", - " value=0.04, min=0.001, max=0.07, step=0.001, description=r\"$\\Omega_b$\"\n", - " ),\n", - " h=widgets.FloatSlider(value=0.7, min=0.3, max=0.9, step=0.01, description=r\"$h$\"),\n", - " n_s=widgets.FloatSlider(\n", - " value=0.96, min=0.6, max=1.1, step=0.01, description=r\"$n_s$\"\n", - " ),\n", - " sigma_8=widgets.FloatSlider(\n", - " value=0.8, min=0.3, max=1.2, step=0.01, description=r\"$\\sigma_8$\"\n", - " ),\n", - ")" - ] - }, - { - "cell_type": "markdown", - "id": "15", - "metadata": { - "tags": [] - }, - "source": [ - "## Plot varxipm's\n", - "Error bars are computed by treecorr, either through the 'shot' or 'jackknife' method." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "16", - "metadata": {}, - "outputs": [], - "source": [ - "for idx, cat in enumerate(cat_options):\n", - " blind = \"A\"\n", - " label = \"SP_v1.4\"\n", - "\n", - " cc = \"/n23data1/n06data/lgoh/scratch/CFIS-UNIONS/CFIS-UNIONS_dev/cosmo_inference/data/{}/covs/cov_{}\".format(\n", - " label + \"_{}\".format(blind), label\n", - " )\n", - "\n", - " cc_var = np.diag(np.loadtxt(cc + \".txt\"))\n", - " cc_varxip = cc_var[:20]\n", - " cc_varxim = cc_var[20:]\n", - "\n", - " cc_var = np.diag(np.loadtxt(cc + \"_g.txt\"))\n", - " cc_varxip_g = cc_var[:20]\n", - " cc_varxim_g = cc_var[20:]\n", - "\n", - " plt.loglog(\n", - " cat_ggs[idx].meanr,\n", - " cat_ggs[idx].varxip,\n", - " \"-k\",\n", - " label=r\"$\\sigma(\\xi_+)$ TreeCorr jackknife %s\" % cat_dict[cat][\"label\"],\n", - " )\n", - " plt.loglog(\n", - " cat_ggs[idx].meanr,\n", - " cc_varxip,\n", - " ls=\"--\",\n", - " c=\"%s\" % cat_dict[cat][\"colour\"],\n", - " label=r\"$\\sigma(\\xi_+)$ CosmoCov %s\" % cat_dict[cat][\"label\"],\n", - " )\n", - " plt.loglog(\n", - " cat_ggs[idx].meanr,\n", - " cc_varxip_g,\n", - " ls=\":\",\n", - " c=\"%s\" % cat_dict[cat][\"colour\"],\n", - " label=r\"$\\sigma(\\xi_+)$ CosmoCov Gaussian %s\" % cat_dict[cat][\"label\"],\n", - " )\n", - " plt.grid()\n", - " plt.xlim([cat_ggs[idx].meanr[0], cat_ggs[idx].meanr[-1]])\n", - " plt.legend(fontsize=15)\n", - " plt.xlabel(rf\"$\\theta$ [{sep_units}]\")\n", - " plt.ylabel(r\"$\\sigma(\\xi_+)$\")\n", - " plt.show()\n", - " # plt.savefig()\n", - "\n", - " plt.loglog(\n", - " cat_ggs[idx].meanr,\n", - " cat_ggs[idx].varxim,\n", - " \"-k\",\n", - " label=r\"$\\sigma(\\xi_-)$ TreeCorr jackknife %s\" % cat_dict[cat][\"label\"],\n", - " )\n", - " plt.loglog(\n", - " cat_ggs[idx].meanr,\n", - " cc_varxim,\n", - " ls=\"--\",\n", - " c=\"%s\" % cat_dict[cat][\"colour\"],\n", - " label=r\"$\\sigma(\\xi_-)$ CosmoCov (SP) %s\" % cat_dict[cat][\"label\"],\n", - " )\n", - " plt.loglog(\n", - " cat_ggs[idx].meanr,\n", - " cc_varxim_g,\n", - " ls=\":\",\n", - " c=\"%s\" % cat_dict[cat][\"colour\"],\n", - " label=r\"$\\sigma(\\xi_-)$ CosmoCov (SP) Gaussian %s\" % cat_dict[cat][\"label\"],\n", - " )\n", - " plt.grid()\n", - " plt.xlim([cat_ggs[idx].meanr[0], cat_ggs[idx].meanr[-1]])\n", - " plt.legend(fontsize=15)\n", - " plt.xlabel(rf\"$\\theta$ [{sep_units}]\")\n", - " plt.ylabel(r\"$\\sigma(\\xi_-)$\")\n", - " plt.show()\n", - " # plt.savefig()" - ] - }, - { - "cell_type": "markdown", - "id": "17", - "metadata": { - "jp-MarkdownHeadingCollapsed": true, - "tags": [] - }, - "source": [ - "## Run systematic tests" - ] - }, - { - "cell_type": "markdown", - "id": "18", - "metadata": { - "jp-MarkdownHeadingCollapsed": true, - "tags": [] - }, - "source": [ - "### C_sys" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "19", - "metadata": {}, - "outputs": [], - "source": [ - "# CALCULATE XI_SYS FOR SHAPEPIPE\n", - "\n", - "sep_units = \"arcmin\"\n", - "theta_min = 1\n", - "theta_max = 200\n", - "\n", - "TreeCorrConfig = {\n", - " \"ra_units\": \"degrees\",\n", - " \"dec_units\": \"degrees\",\n", - " \"max_sep\": str(theta_max),\n", - " \"min_sep\": str(theta_min),\n", - " \"sep_units\": sep_units,\n", - " \"nbins\": 20,\n", - " \"var_method\": \"jackknife\",\n", - "}\n", - "\n", - "with fits.open(cat_dict[11][\"dir\"]) as data:\n", - " df_psf = pd.DataFrame(data[1].data)\n", - "\n", - "cat_psf = treecorr.Catalog(\n", - " ra=df_psf[\"RA\"],\n", - " dec=df_psf[\"DEC\"],\n", - " g1=df_psf[\"HSM_G1_PSF\"],\n", - " g2=df_psf[\"HSM_G2_PSF\"],\n", - " ra_units=\"degrees\",\n", - " dec_units=\"degrees\",\n", - " npatch=50,\n", - ")\n", - "\n", - "gg_psf = treecorr.GGCorrelation(TreeCorrConfig)\n", - "gg_psf.process(cat_psf)\n", - "\n", - "ggs_psf_star = []\n", - "for idx, cat in enumerate(cat_options):\n", - " cat_gal = treecorr.Catalog(\n", - " ra=dfs[idx][\"ra\"],\n", - " dec=dfs[idx][\"dec\"],\n", - " g1=dfs[idx][\"e1\"] - cat_dict[cat][\"e1_bias\"],\n", - " g2=dfs[idx][\"e2\"] - cat_dict[cat][\"e2_bias\"],\n", - " w=dfs[idx][\"w\"],\n", - " ra_units=\"degrees\",\n", - " dec_units=\"degrees\",\n", - " npatch=50,\n", - " )\n", - " gg_psf_star = treecorr.GGCorrelation(TreeCorrConfig)\n", - " gg_psf_star.process(cat_gal, cat_psf)\n", - " ggs_psf_star.append(gg_psf_star)\n", - "\n", - " print(\"done for cat %s\" % cat)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "20", - "metadata": {}, - "outputs": [], - "source": [ - "for idx, cat in enumerate(cat_options):\n", - " C_sys_xip = gg_psf.xip\n", - " C_sys_xim = gg_psf.xim\n", - "\n", - " # delta_C_sys_xip = C_sys_xip*np.sqrt((2*np.sqrt(ggs_psf_star[idx].varxip)/ggs_psf_star[idx].xip)**2+(np.sqrt(gg_psf.varxip)/gg_psf.xip)**2)\n", - " # delta_C_sys_xim = C_sys_xim*np.sqrt((2*np.sqrt(ggs_psf_star[idx].varxim)/ggs_psf_star[idx].xim)**2+(np.sqrt(gg_psf.varxim)/gg_psf.xim)**2)\n", - "\n", - " plt.errorbar(\n", - " ggs_psf_star[idx].meanr,\n", - " C_sys_xip,\n", - " yerr=0,\n", - " label=r\"$(\\xi^{sys}_+)$ Catalogue %s\" % cat_dict[cat][\"label\"],\n", - " ls=cat_dict[cat][\"ls\"],\n", - " color=cat_dict[cat][\"colour\"],\n", - " )\n", - " plt.legend()\n", - " plt.xlabel(r\"$\\theta[arcmin]$\")\n", - " plt.ylabel(r\"$\\xi^{sys}_\\pm$\")\n", - " # plt.ylim([-2e-8,2e-8])\n", - " plt.xscale(\"log\")\n", - " plt.ticklabel_format(style=\"sci\", axis=\"y\", scilimits=(0, 0))\n", - " plt.grid(True)\n", - "\n", - " # plt.errorbar(ggs_psf_star[idx].meanr, C_sys_xim, yerr=delta_C_sys_xim, label=r'$(\\xi^{sys}_-)$ Catalogue %s'%cat_dict[cat]['label'],color='g')\n", - " # plt.legend()\n", - " # plt.xlabel(r'$\\theta[arcmin]$')\n", - " # plt.ylabel(r'$\\xi^{sys}_\\pm$')\n", - " # plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0))\n", - " # # plt.ylim([-2e-8,2e-8])\n", - " # plt.xscale('log')\n", - " # plt.grid(True)" - ] - }, - { - "cell_type": "markdown", - "id": "21", - "metadata": { - "jp-MarkdownHeadingCollapsed": true, - "tags": [] - }, - "source": [ - "### M_ap" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "22", - "metadata": {}, - "outputs": [], - "source": [ - "for idx, cat in enumerate(cat_options):\n", - " R = cat_ggs[idx].rnom\n", - "\n", - " (Map_lf, mapsq_im_lf, Mx_lf, mxsq_im_lf, varMapsq_lf) = cat_ggs[idx].calculateMapSq(\n", - " R=R, m2_uform=\"Schneider\"\n", - " )\n", - " (Map_sp, mapsq_im_sp, Mx_sp, mxsq_im_sp, varMapsq_sp) = cat_ggs[idx].calculateMapSq(\n", - " R=R, m2_uform=\"Schneider\"\n", - " )\n", - "\n", - " plt.errorbar(\n", - " R,\n", - " Map_lf,\n", - " yerr=np.sqrt(varMapsq_lf),\n", - " label=r\"$$ {}\".format(cat_dict[cat][\"label\"]),\n", - " ls=\":\",\n", - " color=\"b\",\n", - " )\n", - " plt.errorbar(\n", - " R,\n", - " Mx_lf,\n", - " yerr=np.sqrt(varMapsq_lf),\n", - " label=r\"$$ {}\".format(cat_dict[cat][\"label\"]),\n", - " ls=\":\",\n", - " color=\"r\",\n", - " )\n", - " plt.axhline(y=0, xmin=0, xmax=200, color=\"k\")\n", - " plt.xlabel(r\"$\\theta[arcmin]$\")\n", - " plt.ylabel(r\"$$\")\n", - " plt.xscale(\"log\")\n", - " plt.ylim([-2e-5, 1e-5])\n", - " # plt.xlim([1,200])\n", - " plt.grid(True)\n", - " plt.legend()\n", - "\n", - " plt.errorbar(\n", - " R,\n", - " Map_sp,\n", - " yerr=np.sqrt(varMapsq_sp),\n", - " label=r\"$$ {}\".format(cat_dict[cat][\"label\"]),\n", - " ls=\":\",\n", - " color=\"b\",\n", - " )\n", - " plt.errorbar(\n", - " R,\n", - " Mx_sp,\n", - " yerr=np.sqrt(varMapsq_sp),\n", - " label=r\"$$ {}\".format(cat_dict[cat][\"label\"]),\n", - " ls=\":\",\n", - " color=\"r\",\n", - " )\n", - " plt.axhline(y=0, xmin=0, xmax=200, color=\"k\")\n", - " plt.xscale(\"log\")\n", - " plt.xlabel(r\"$\\theta[arcmin]$\")\n", - " plt.ylabel(r\"$$\")\n", - " plt.ticklabel_format(style=\"sci\", axis=\"y\", scilimits=(0, 0))\n", - " plt.ylim([-2e-5, 1e-5])\n", - " plt.grid(True)\n", - " plt.legend()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "23", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "24", - "metadata": {}, - "source": [ - "## Plot Covariance Matrix" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "25", - "metadata": {}, - "outputs": [], - "source": [ - "from numpy import linalg as LA\n", - "\n", - "%matplotlib inline\n", - "\n", - "\n", - "def get_cov(filename):\n", - "\n", - " data = np.loadtxt(filename)\n", - " ndata = int(np.max(data[:, 0])) + 1\n", - "\n", - " print(\"Dimension of cov: %dx%d\" % (ndata, ndata))\n", - "\n", - " # ndata_min = int(np.min(data[:,0]))\n", - " cov_g = np.zeros((ndata, ndata))\n", - " cov_ng = np.zeros((ndata, ndata))\n", - " for i in range(0, data.shape[0]):\n", - " cov_g[int(data[i, 0]), int(data[i, 1])] = data[i, 8]\n", - " cov_g[int(data[i, 1]), int(data[i, 0])] = data[i, 8]\n", - " cov_ng[int(data[i, 0]), int(data[i, 1])] = data[i, 9]\n", - " cov_ng[int(data[i, 1]), int(data[i, 0])] = data[i, 9]\n", - "\n", - " return cov_g, cov_ng, ndata\n", - "\n", - "\n", - "covfile = \"/feynman/work/dap/lcs/lg268561/UNIONS/CFIS-UNIONS/CFIS-UNIONS_dev/cosmo_inference/data/SP_cut_Fabian/covs/out_cov_ssss_+-_cov_Ntheta20_Ntomo1_3\"\n", - "\n", - "c_g, c_ng, ndata = get_cov(covfile)\n", - "cov = c_ng + c_g\n", - "cov_g = c_g\n", - "\n", - "b = np.sort(LA.eigvals(cov))\n", - "print(\"min+max eigenvalues cov: %e, %e\" % (np.min(b), np.max(b)))\n", - "if np.min(b) <= 0.0:\n", - " print(\"non-positive eigenvalue encountered! Covariance Invalid!\")\n", - " exit()\n", - "\n", - "print(\"Covariance is postive definite!\")\n", - "\n", - "pp_var = []\n", - "for i in range(ndata):\n", - " pp_var.append(cov[i][i])\n", - "\n", - "\n", - "cmap = \"seismic\"\n", - "\n", - "pp_norm = np.zeros((ndata, ndata))\n", - "for i in range(ndata):\n", - " for j in range(ndata):\n", - " pp_norm[i][j] = cov[i][j] / np.sqrt(cov[i][i] * cov[j][j])\n", - "\n", - "print(\"Plotting correlation matrix ...\")\n", - "\n", - "# plot_path = covfile+'_plot.pdf'\n", - "\n", - "fig = plt.figure()\n", - "ax = fig.add_subplot(1, 1, 1)\n", - "ax.xaxis.tick_top()\n", - "ax.xaxis.set_ticks(np.arange(0, 41, 1))\n", - "ax.yaxis.set_ticks(np.arange(0, 41, 1))\n", - "\n", - "\n", - "plt.axvline(x=19.5, color=\"black\", linewidth=1.5)\n", - "plt.axhline(y=19.5, color=\"black\", linewidth=1.5)\n", - "\n", - "\n", - "im3 = ax.imshow(pp_norm, cmap=cmap, vmin=-1, vmax=1)\n", - "ax.get_xaxis().set_ticklabels([])\n", - "ax.get_yaxis().set_ticklabels([])\n", - "cbar = fig.colorbar(im3, orientation=\"vertical\", shrink=0.6, ticks=[-1, 0, 1])\n", - "cbar.ax.tick_params(labelsize=15)\n", - "cbar.ax.set_yticklabels([r\"$-1$\", r\"$0$\", r\"$1$\"])\n", - "\n", - "ax.text(8, -2, r\"$\\xi_+^{ij}(\\theta)$\", fontsize=22)\n", - "ax.text(30, -2, r\"$\\xi_-^{ij}(\\theta)$\", fontsize=22)\n", - "ax.text(-6, 10, r\"$\\xi_+^{ij}(\\theta)$\", fontsize=22)\n", - "ax.text(-6, 30, r\"$\\xi_-^{ij}(\\theta)$\", fontsize=22)\n", - "# ax.set_title('Blind A',fontsize=15)\n", - "\n", - "plt.savefig(\"../plots/unions_covmat.pdf\", bbox_inches=\"tight\")\n", - "\n", - "\n", - "plt.show()\n", - "# print(\"Plot saved as %s\"%(plot_path))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "26", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "my_env", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.13" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/cosmo_inference/notebooks/cfis_mcmc.ipynb b/cosmo_inference/notebooks/cfis_mcmc.ipynb deleted file mode 100644 index 124eaf99..00000000 --- a/cosmo_inference/notebooks/cfis_mcmc.ipynb +++ /dev/null @@ -1,1546 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "id": "0", - "metadata": {}, - "outputs": [], - "source": [ - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "from getdist import plots\n", - "\n", - "# import uncertainties\n", - "\n", - "plt.rc(\"mathtext\", fontset=\"stix\")\n", - "plt.rc(\"font\", family=\"sans-serif\")\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "g.settings.axes_fontsize = 30\n", - "g.settings.axes_labelsize = 30\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 40\n", - "\n", - "\n", - "# SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE\n", - "root_dir = \"/n09data/guerrini/output_chains/\"\n", - "\n", - "\"\"\" lower_bound = ['3.0', '3.0', '3.0', '3.0', '3.0', '10.0', '10.0']\n", - "upper_bound = ['200.0', '150.0', '100.0', '80.0', '60.0', '150.0', '60.0']\n", - "roots = [\n", - " f'SP_v1.4.5_leak_corr_sc_{lc}_{hc}_10.0_200.0' for lc, hc in zip(lower_bound, upper_bound)\n", - " ] \"\"\"\n", - "\n", - "roots = [\n", - " \"SP_v1.4.5_glass_mock_1\",\n", - " \"SP_v1.4.5_glass_mock_1_takahashi\",\n", - " \"SP_v1.4.5_glass_mock_1_HM_code\",\n", - "]\n", - "\n", - "roots = [\n", - " \"SP_v1.4.5_A\",\n", - " # \"SP_v1.4.5_A_no_IA\",\n", - " # \"SP_v1.4.5_A_no_dz\",\n", - " # \"SP_v1.4.5_A_no_m_bias\",\n", - " \"SP_v1.4.5_A_sc_3_150\",\n", - " \"SP_v1.4.5_A_sc_3_60\",\n", - " # \"SP_v1.4.5_A_sc_10_150\",\n", - " # \"SP_v1.4.5_A_sc_10_60\",\n", - " # \"SP_v1.4.5_A_sc_5_150\",\n", - " # \"SP_v1.4.5_A_sc_7_150\",\n", - " \"SP_v1.4.5_A_no_leakage\",\n", - " \"SP_v1.4.5_A_no_leakage_150\",\n", - " \"SP_v1.4.5_A_no_leakage_60\",\n", - "]\n", - "\n", - "\"\"\" roots = [\n", - " f\"SP_v1.4.5_glass_mock_{i}\" for i in range(1, 17)\n", - "] \"\"\"\n", - "\n", - "\"\"\" roots = [\n", - " \"SP_v1.4.5_glass_mock_A_IA_m5_5\",\n", - " \"SP_v1.4.5_glass_mock_A_IA_G_0.57_0.5\",\n", - "] \"\"\"\n", - "\n", - "\n", - "roots = [\n", - " f\"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_{int(i)}.0_80.0_10.0_80.0\"\n", - " for i in [3, 5, 7, 10, 11]\n", - "]\n", - "\n", - "roots = [\n", - " \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_10.0_80.0_10.0_80.0\",\n", - " \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_10.0_80.0_10.0_80.0_no_alpha_beta\",\n", - "]\n", - "\n", - "roots = [\n", - " \"SP_v1.4.5_leak_corr_A_minsep=1_maxsep=250_nbins=20_npatch=1_sc_10.0_80.0_10.0_80.0\",\n", - " \"SP_v1.4.5_leak_corr_cell\",\n", - "]\n", - "\n", - "print(roots)" - ] - }, - { - "cell_type": "markdown", - "id": "1", - "metadata": {}, - "source": [ - "## Retrieve the chains" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2", - "metadata": {}, - "outputs": [], - "source": [ - "# MAKE PARAMNAMES FILE\n", - "\n", - "for root in roots:\n", - " with open(root_dir + \"{}/samples_{}.txt\".format(\"/\" + root, root), \"r\") as file:\n", - " params = file.readline()[1:].split(\"\\t\")[:-4]\n", - " file.close()\n", - "\n", - " with open(\n", - " root_dir + \"{}/getdist_{}.paramnames\".format(\"/\" + root, root), \"w\"\n", - " ) as file:\n", - " for i in range(len(params)):\n", - " if len(params[i].split(\"--\")) > 1:\n", - " file.write(params[i].split(\"--\")[1] + \"\\n\")\n", - " else:\n", - " file.write(params[i].split(\"--\")[0] + \"\\n\")\n", - " file.close()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3", - "metadata": {}, - "outputs": [], - "source": [ - "# READ CHAIN\n", - "\n", - "chains = []\n", - "\n", - "for root in roots:\n", - " samples = np.loadtxt(root_dir + \"{}/samples_{}.txt\".format(root, root))\n", - " print(len(samples))\n", - " if \"nautilus\" in root:\n", - " samples = np.column_stack(\n", - " (np.exp(samples[:, -3]), samples[:, -1] - samples[:, -2], samples[:, 0:-3])\n", - " )\n", - " else:\n", - " samples = np.column_stack((samples[:, -1], samples[:, -3], samples[:, 0:-4]))\n", - " np.savetxt(root_dir + \"{}/getdist_{}.txt\".format(root, root), samples)\n", - "\n", - " chain = g.samples_for_root(\n", - " root_dir + \"{}/getdist_{}\".format(root, root),\n", - " cache=False,\n", - " settings={\"ignore_rows\": 0, \"smooth_scale_2D\": 0.5, \"smooth_scale_1D\": 0.5},\n", - " )\n", - "\n", - " chains.append(chain)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4", - "metadata": {}, - "outputs": [], - "source": [ - "name_list = [\n", - " \"OMEGA_M\",\n", - " \"ombh2\",\n", - " \"h0\",\n", - " \"n_s\",\n", - " \"SIGMA_8\",\n", - " \"s_8_input\",\n", - " \"logt_agn\",\n", - " \"a\",\n", - " \"m1\",\n", - " \"bias_1\",\n", - "] # ,'alpha','beta']\n", - "label_list = [\n", - " r\"\\Omega_m\",\n", - " r\"\\omega_b h^2\",\n", - " \"h_0\",\n", - " \"n_s\",\n", - " r\"\\sigma_8\",\n", - " \"S_8\",\n", - " \"log T_{AGN}\",\n", - " \"A_{IA}\",\n", - " \"m_1\",\n", - " r\"\\Delta z_1\",\n", - "] # , '\\\\alpha_{PSF}', '\\\\beta_{PSF}']\n", - "\n", - "for chain in chains:\n", - " param_names = chain.getParamNames()\n", - " for name, label in zip(name_list, label_list):\n", - " param_names.parWithName(name).label = label" - ] - }, - { - "cell_type": "markdown", - "id": "5", - "metadata": {}, - "source": [ - "## Plot the chain" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6", - "metadata": {}, - "outputs": [], - "source": [ - "%matplotlib inline\n", - "\n", - "\"\"\" legend_labels = [\n", - " rf'$\\theta \\\\in$ [{lc}-{hc}]' for lc, hc in zip(lower_bound, upper_bound)\n", - "] \"\"\"\n", - "\n", - "legend_labels = [rf\"GLASS mock {i}\" for i in range(1, 17)]\n", - "\n", - "legend_labels = [\"GLASS mock 1\", \"GLASS mock 1 takahashi\", \"GLASS mock 1 HM code\"]\n", - "\n", - "legend_labels = [\n", - " \"SP_v1.4.5 blind A\",\n", - " # \"SP_v1.4.5 blind A no IA\",\n", - " # r\"SP_v1.4.5 blind A no $\\Delta z$\",\n", - " # r\"SP_v1.4.5 blind A no $m_1$\",\n", - " r\"SP_v1.4.5 blind A, $\\theta \\in [3-150]$\",\n", - " r\"SP_v1.4.5 blind A, $\\theta \\in [3-60]$\",\n", - " # r\"SP_v1.4.5 blind A, $\\theta \\in [10-150]$\",\n", - " # r\"SP_v1.4.5 blind A, $\\theta \\in [10-60]$\",\n", - " # r\"SP_v1.4.5 blind A, $\\theta \\in [5-150]$\",\n", - " # r\"SP_v1.4.5 blind A, $\\theta \\in [7-150]$\",\n", - " r\"SP_v1.4.5 blind A no leakage\",\n", - " r\"SP_v1.4.5 blind A no leakage, $\\theta \\in [3-150]$\",\n", - " r\"SP_v1.4.5 blind A no leakage, $\\theta \\in [3-60]$\",\n", - "]\n", - "\n", - "legend_labels = [\n", - " r\"SP_v1.4.5 blind A no leakage, $\\theta \\in [3-80]$\",\n", - " r\"SP_v1.4.5 blind A no leakage, $\\theta \\in [5-180]$\",\n", - " r\"SP_v1.4.5 blind A no leakage, $\\theta \\in [7-180]$\",\n", - " r\"SP_v1.4.5 blind A no leakage, $\\theta \\in [10-80]$\",\n", - " r\"SP_v1.4.5 blind A no leakage, $\\theta \\in [11-80]$\",\n", - "]\n", - "\n", - "legend_labels = [\n", - " r\"SP_v1.4.5 blind A no leakage, $\\theta \\in [10-80]$\",\n", - " r\"SP_v1.4.5 blind A no leakage, $C_\\ell$\",\n", - "]\n", - "\n", - "contour_colors = [\n", - " \"cornflowerblue\",\n", - " \"salmon\",\n", - " \"darkorange\",\n", - " \"forestgreen\",\n", - " \"turquoise\",\n", - " \"darkviolet\",\n", - " \"crimson\",\n", - " \"gold\",\n", - " \"lightcoral\",\n", - " \"mediumseagreen\",\n", - " \"lightsteelblue\",\n", - " \"black\",\n", - " \"silver\",\n", - " \"peru\",\n", - " \"maroon\",\n", - " \"olive\",\n", - "]\n", - "\n", - "\"\"\" legend_labels = [\n", - " r\"GLASS mock 3\",\n", - " r\"GLASS mock 3 no PSF\",\n", - " r\"GLASS mock 3 no PSF baryons\",\n", - "] \"\"\"\n", - "\n", - "marker = {\n", - " \"OMEGA_LAMBDA\": 0.7013160542257656,\n", - " \"ombh2\": 0.024499999999999997,\n", - " \"omch2\": 0.12249999999999998,\n", - " \"h0\": 0.70,\n", - " \"n_s\": 0.96,\n", - " \"SIGMA_8\": 0.793897,\n", - " \"s_8_input\": 0.79563645,\n", - " \"m1\": 0.0,\n", - " \"bias_1\": 0.0,\n", - " #'alpha': -0.0005,\n", - " #'beta': 0.0631,\n", - " \"a\": 0.0,\n", - "}\n", - "\n", - "marker = {\n", - " \"bias_1\": -0.045,\n", - " \"m1\": 0.0,\n", - " \"a\": 0.5,\n", - " #'alpha': 0.0169,\n", - " #'beta': 1.0789\n", - "}\n", - "g.triangle_plot(\n", - " chains,\n", - " [\n", - " \"OMEGA_M\",\n", - " \"ombh2\",\n", - " \"h0\",\n", - " \"n_s\",\n", - " \"SIGMA_8\",\n", - " \"s_8_input\",\n", - " \"logt_agn\",\n", - " \"a\",\n", - " \"m1\",\n", - " \"bias_1\",\n", - " \"alpha\",\n", - " \"beta\",\n", - " ],\n", - " legend_labels=legend_labels,\n", - " legend_loc=\"upper right\",\n", - " # param_limits={'bias_1':[-0.8,0.5]},\n", - " contour_colors=contour_colors,\n", - " line_args=[{\"color\": contour_colors[i], \"ls\": \"solid\"} for i in range(16)],\n", - " # title_limit=1,\n", - " filled=True,\n", - " markers=marker,\n", - ")\n", - "\n", - "g.export(\"contour_plot_unions_cell.png\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7", - "metadata": {}, - "outputs": [], - "source": [ - "\"\"\" legend_labels = [\n", - " rf'$\\theta \\\\in$ [{lc}-{hc}]' for lc, hc in zip(lower_bound, upper_bound)\n", - "] \"\"\"\n", - "g.triangle_plot(\n", - " chains,\n", - " [\"OMEGA_M\", \"s_8_input\", \"SIGMA_8\", \"a\"],\n", - " legend_labels=legend_labels,\n", - " legend_loc=\"upper right\",\n", - " # param_limits={'bias_1':[-0.8,0.5]},\n", - " contour_colors=contour_colors,\n", - " line_args=[{\"color\": contour_colors[i], \"ls\": \"solid\"} for i in range(16)],\n", - " title_limit=1,\n", - " filled=True,\n", - " markers=marker,\n", - ")\n", - "\n", - "g.export(\"contour_plot_s8_unions_cell.png\")" - ] - }, - { - "cell_type": "markdown", - "id": "8", - "metadata": { - "jp-MarkdownHeadingCollapsed": true, - "tags": [] - }, - "source": [ - "### Output bestfit and sigma values" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9", - "metadata": {}, - "outputs": [], - "source": [ - "#########BESTFIT AND SIGMA VALS##########\n", - "params = [\n", - " \"OMEGA_M\",\n", - " \"omega_b\",\n", - " \"h0\",\n", - " \"n_s\",\n", - " \"a_s\",\n", - " \"SIGMA_8\",\n", - " \"S_8\",\n", - " \"logt_agn\",\n", - " \"a\",\n", - " \"m1\",\n", - " \"bias_1\",\n", - " \"alpha\",\n", - " \"beta\",\n", - " \"omch2\",\n", - " \"ombh2\",\n", - "]\n", - "latex_params = [\n", - " r\"$\\Omega_{\\rm m,0}$\",\n", - " r\"$\\Omega_{\\rm b,0}$\",\n", - " r\"$h$\",\n", - " r\"$n_{\\rm s}$\",\n", - " r\"$A_{\\rm s}$\",\n", - " r\"$\\sigma_8$\",\n", - " r\"$S_8$\",\n", - " r\"$\\log_{10}{T_{\\rm AGN}}$\",\n", - " r\"$\\mathcal{A}_rm IA}$\",\n", - " r\"$m_1$\",\n", - " r\"$\\Delta z$\",\n", - " r\"$\\alpha$\",\n", - " r\"$\\beta$\",\n", - " r\"$\\Omega_{\\rm c,0}$\",\n", - " r\"$\\Omega_{\\rm b,0}$\",\n", - "]\n", - "\n", - "for chain in chains:\n", - " margestats = chain.getMargeStats()\n", - " likestats = chain.getLikeStats()\n", - " p = chain.getParams()\n", - "\n", - " for no in range(len(latex_params)):\n", - " if hasattr(p, params[no]):\n", - " param_stats = margestats.parWithName(params[no])\n", - " a = np.array(\n", - " [\n", - " param_stats.mean,\n", - " param_stats.mean - param_stats.limits[0].lower,\n", - " param_stats.limits[0].upper - param_stats.mean,\n", - " ]\n", - " )\n", - " if \"%.2g\" % a[1] == \"%.2g\" % a[2]:\n", - " latex_params[no] += r\"&$%.3g\\pm%.2g$\" % (a[0], a[1])\n", - " else:\n", - " latex_params[no] += \"&$%.3g_{-%.2g}^{+%.2g}$\" % (a[0], a[1], a[2])\n", - " else:\n", - " latex_params[no] += \"&$-$\"\n", - "\n", - "\n", - "for param in latex_params:\n", - " param += r\"\\\\\"\n", - " print(param)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "10", - "metadata": {}, - "outputs": [], - "source": [ - "chain = chains[0]\n", - "\n", - "margestats = chain.getMargeStats()\n", - "likestats = chain.getLikeStats()\n", - "p = chain.getParams()\n", - "\n", - "for no in range(len(latex_params)):\n", - " if hasattr(p, params[no]):\n", - " param_stats = margestats.parWithName(params[no])\n", - " a = np.array([param_stats.mean])\n", - " print(params[no], a[0])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "11", - "metadata": {}, - "outputs": [], - "source": [ - "#########BESTFIT AND SIGMA VALS##########\n", - "params = [\n", - " \"OMEGA_M\",\n", - " \"omega_b\",\n", - " \"h0\",\n", - " \"n_s\",\n", - " \"a_s\",\n", - " \"SIGMA_8\",\n", - " \"S_8\",\n", - " \"logt_agn\",\n", - " \"a\",\n", - " \"m1\",\n", - " \"bias_1\",\n", - " \"alpha\",\n", - " \"beta\",\n", - " \"omch2\",\n", - " \"ombh2\",\n", - "]\n", - "latex_params = [\n", - " r\"$\\Omega_{\\rm m,0}$\",\n", - " r\"$\\Omega_{\\rm b,0}$\",\n", - " r\"$h$\",\n", - " r\"$n_{\\rm s}$\",\n", - " r\"$A_{\\rm s}$\",\n", - " r\"$\\sigma_8$\",\n", - " r\"$S_8$\",\n", - " r\"$\\log_{10}{T_{\\rm AGN}}$\",\n", - " r\"$\\mathcal{A}_rm IA}$\",\n", - " r\"$m_1$\",\n", - " r\"$\\Delta z$\",\n", - " r\"$\\alpha$\",\n", - " r\"$\\beta$\",\n", - " r\"$\\Omega_{\\rm c,0}$\",\n", - " r\"$\\Omega_{\\rm b,0}$\",\n", - "]\n", - "\n", - "values = {param: [] for param in params}\n", - "for i, chain in enumerate(chains):\n", - " margestats = chain.getMargeStats()\n", - " likestats = chain.getLikeStats()\n", - " p = chain.getParams()\n", - "\n", - " print(legend_labels[i])\n", - "\n", - " for param in params:\n", - " if hasattr(p, param):\n", - " param_stats = margestats.parWithName(param)\n", - " a = np.array(\n", - " [\n", - " param_stats.mean,\n", - " param_stats.mean - param_stats.limits[0].lower,\n", - " param_stats.limits[0].upper - param_stats.mean,\n", - " ]\n", - " )\n", - " print(f\"{param}: {a[0]:.3g}_-{a[1]:.2g}^+{a[1]:.2g}\")\n", - " values[param].append(a[0])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "12", - "metadata": {}, - "outputs": [], - "source": [ - "bestfit_ix = np.argmax(chains[0].loglikes)\n", - "maxlike = chains[0].loglikes[bestfit_ix]\n", - "print(maxlike)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "13", - "metadata": {}, - "outputs": [], - "source": [ - "chains[0].loglikes" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "14", - "metadata": {}, - "outputs": [], - "source": [ - "print(chains[0].likeStats)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "15", - "metadata": {}, - "outputs": [], - "source": [ - "plt.figure(figsize=(15, 5))\n", - "\n", - "plt.subplot(131)\n", - "\n", - "plt.hist(values[\"OMEGA_M\"], bins=10, color=\"cornflowerblue\", alpha=0.5)\n", - "plt.axvline(0.301316, color=\"black\", linestyle=\"--\", label=\"True value\")\n", - "plt.xlabel(r\"$\\Omega_{\\rm m,0}$\")\n", - "plt.ylabel(\"Counts\")\n", - "plt.legend()\n", - "\n", - "plt.subplot(132)\n", - "\n", - "plt.hist(values[\"SIGMA_8\"], bins=10, color=\"cornflowerblue\", alpha=0.5)\n", - "plt.axvline(0.793897, color=\"black\", linestyle=\"--\", label=\"True value\")\n", - "plt.xlabel(r\"$\\sigma_8$\")\n", - "plt.ylabel(\"Counts\")\n", - "plt.legend()\n", - "\n", - "plt.subplot(133)\n", - "\n", - "plt.hist(values[\"S_8\"], bins=10, color=\"cornflowerblue\", alpha=0.5)\n", - "plt.axvline(0.79563645, color=\"black\", linestyle=\"--\", label=\"True value\")\n", - "plt.xlabel(r\"$S_8$\")\n", - "plt.ylabel(\"Counts\")\n", - "plt.legend()\n", - "plt.tight_layout()\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "16", - "metadata": {}, - "outputs": [], - "source": [ - "np.sum(np.abs(np.array(values[\"S_8\"]) - 0.79563645) < 0.03) / len(values[\"S_8\"])" - ] - }, - { - "cell_type": "markdown", - "id": "17", - "metadata": {}, - "source": [ - "## Looking at best fit" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "18", - "metadata": {}, - "outputs": [], - "source": [ - "from astropy.io import fits\n", - "\n", - "version = \"SP_v1.4.5_glass_mock_1\"\n", - "\n", - "data = fits.open(\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{version}/cosmosis_{version}.fits\"\n", - ")\n", - "xi_plus = data[\"XI_PLUS\"].data\n", - "xi_minus = data[\"XI_MINUS\"].data\n", - "cov_mat = data[\"COVMAT\"].data" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "19", - "metadata": {}, - "outputs": [], - "source": [ - "plt.figure(figsize=(15, 15))\n", - "\n", - "plt.subplot(211)\n", - "\n", - "plt.errorbar(\n", - " xi_plus[\"ANG\"],\n", - " xi_plus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[:20],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - ")\n", - "\n", - "plt.ylabel(r\"$\\xi_{+}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(3.0, color=\"grey\", linestyle=\"--\", label=\"3 arcmin\")\n", - "plt.axvline(100.0, color=\"grey\", linestyle=\"--\", label=\"100 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.subplot(212)\n", - "\n", - "plt.errorbar(\n", - " xi_minus[\"ANG\"],\n", - " xi_minus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[20:40],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - ")\n", - "\n", - "plt.xlabel(r\"$\\theta$ [arcmin]\")\n", - "plt.ylabel(r\"$\\xi_{-}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(10.0, color=\"grey\", linestyle=\"--\", label=\"10 arcmin\")\n", - "plt.axvline(200.0, color=\"grey\", linestyle=\"--\", label=\"200 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.savefig(\"xi_data.png\")\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "20", - "metadata": {}, - "outputs": [], - "source": [ - "import pyccl as ccl\n", - "\n", - "# Get theory correlation function from CCL\n", - "# Define the cosmology\n", - "theta_arcmin = np.logspace(np.log10(0.1), np.log10(250), 1000)\n", - "h = 0.7\n", - "Oc = 0.25\n", - "Ob = 0.05\n", - "sigma8 = 0.793897\n", - "n_s = 0.96\n", - "cosmo = ccl.Cosmology(\n", - " h=h,\n", - " Omega_c=Oc,\n", - " Omega_b=Ob,\n", - " sigma8=sigma8,\n", - " n_s=n_s,\n", - " transfer_function=\"boltzmann_camb\",\n", - ")\n", - "\n", - "# Define the redshift distribution\n", - "z, dndz = np.loadtxt(\n", - " \"/home/guerrini/sp_validation/cosmo_inference/cosmocov_config/dndz_test.txt\",\n", - " unpack=True,\n", - ")\n", - "\n", - "tracer = ccl.WeakLensingTracer(cosmo, dndz=(z, dndz), ia_bias=None)\n", - "\n", - "# COmpute the angular power spectrum C_ell\n", - "ell = np.logspace(0, np.log10(10000), 2000)\n", - "cl_gg = ccl.angular_cl(cosmo, tracer, tracer, ell)\n", - "\n", - "# Compute the 2PCF\n", - "theta_deg = theta_arcmin / 60\n", - "# xi+ fit\n", - "xi_p_theta_true = ccl.correlation(\n", - " cosmo, ell=ell, C_ell=cl_gg, theta=theta_deg, type=\"GG+\"\n", - ")\n", - "# xi- fit\n", - "xi_m_theta_true = ccl.correlation(\n", - " cosmo, ell=ell, C_ell=cl_gg, theta=theta_deg, type=\"GG-\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "21", - "metadata": {}, - "outputs": [], - "source": [ - "# Get theory correlation function from CCL\n", - "# Define the cosmology\n", - "theta_arcmin = np.logspace(np.log10(0.1), np.log10(250), 1000)\n", - "h = 0.6982064176424748\n", - "Oc = 0.21522128974860827 / h**2\n", - "print(\"Omega_c:\", Oc)\n", - "Ob = 0.024410205304489712 / h**2\n", - "print(\"Omega_b:\", Ob)\n", - "sigma8 = 0.5330533925822226\n", - "print(\"S8:\", sigma8 * np.sqrt((Oc + Ob) / 0.3))\n", - "n_s = 0.9867762122563981\n", - "a_ia = 0.0\n", - "cosmo = ccl.Cosmology(\n", - " h=h,\n", - " Omega_c=Oc,\n", - " Omega_b=Ob,\n", - " sigma8=sigma8,\n", - " n_s=n_s,\n", - " transfer_function=\"boltzmann_camb\",\n", - ")\n", - "\n", - "# Define the redshift distribution\n", - "z, dndz = np.loadtxt(\n", - " \"/home/guerrini/sp_validation/cosmo_inference/cosmocov_config/dndz_test.txt\",\n", - " unpack=True,\n", - ")\n", - "\n", - "tracer = ccl.WeakLensingTracer(\n", - " cosmo, dndz=(z, dndz), ia_bias=(z, np.ones_like(z) * a_ia)\n", - ")\n", - "\n", - "# COmpute the angular power spectrum C_ell\n", - "ell = np.logspace(0, np.log10(10000), 2000)\n", - "cl_gg = ccl.angular_cl(cosmo, tracer, tracer, ell)\n", - "\n", - "# Compute the 2PCF\n", - "theta_deg = theta_arcmin / 60\n", - "# xi+ fit\n", - "xi_p_theta_fit = ccl.correlation(\n", - " cosmo, ell=ell, C_ell=cl_gg, theta=theta_deg, type=\"GG+\"\n", - ")\n", - "# xi- fit\n", - "xi_m_theta_fit = ccl.correlation(\n", - " cosmo, ell=ell, C_ell=cl_gg, theta=theta_deg, type=\"GG-\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "22", - "metadata": {}, - "outputs": [], - "source": [ - "# Get theory correlation function from CCL\n", - "# Define the cosmology\n", - "theta_arcmin = np.logspace(np.log10(0.1), np.log10(250), 1000)\n", - "h = 0.6982064176424748\n", - "Oc = 0.21522128974860827 / h**2\n", - "print(\"Omega_c:\", Oc)\n", - "Ob = 0.024410205304489712 / h**2\n", - "print(\"Omega_b:\", Ob)\n", - "sigma8 = 0.5330533925822226\n", - "print(\"S8:\", sigma8 * np.sqrt((Oc + Ob) / 0.3))\n", - "n_s = 0.9867762122563981\n", - "a_ia = -0.4225120529551343\n", - "cosmo = ccl.Cosmology(\n", - " h=h,\n", - " Omega_c=Oc,\n", - " Omega_b=Ob,\n", - " sigma8=sigma8,\n", - " n_s=n_s,\n", - " transfer_function=\"boltzmann_camb\",\n", - ")\n", - "\n", - "# Define the redshift distribution\n", - "z, dndz = np.loadtxt(\n", - " \"/home/guerrini/sp_validation/cosmo_inference/cosmocov_config/dndz_test.txt\",\n", - " unpack=True,\n", - ")\n", - "\n", - "tracer = ccl.WeakLensingTracer(\n", - " cosmo, dndz=(z, dndz), ia_bias=(z, np.ones_like(z) * a_ia)\n", - ")\n", - "\n", - "# COmpute the angular power spectrum C_ell\n", - "ell = np.logspace(0, np.log10(10000), 2000)\n", - "cl_gg = ccl.angular_cl(cosmo, tracer, tracer, ell)\n", - "\n", - "# Compute the 2PCF\n", - "theta_deg = theta_arcmin / 60\n", - "# xi+ fit\n", - "xi_p_theta_fit_IA = ccl.correlation(\n", - " cosmo, ell=ell, C_ell=cl_gg, theta=theta_deg, type=\"GG+\"\n", - ")\n", - "# xi- fit\n", - "xi_m_theta_fit_IA = ccl.correlation(\n", - " cosmo, ell=ell, C_ell=cl_gg, theta=theta_deg, type=\"GG-\"\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "23", - "metadata": {}, - "outputs": [], - "source": [ - "plt.figure(figsize=(15, 15))\n", - "\n", - "plt.subplot(211)\n", - "\n", - "plt.errorbar(\n", - " xi_plus[\"ANG\"],\n", - " xi_plus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[:20],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - ")\n", - "plt.plot(theta_arcmin, xi_p_theta_fit, label=\"SP_v1.4.5 fit\", color=\"red\")\n", - "plt.plot(theta_arcmin, xi_p_theta_true, label=\"SP_v1.4.5 true\", color=\"blue\")\n", - "plt.plot(theta_arcmin, xi_p_theta_fit_IA, label=\"SP_v1.4.5 fit IA\", color=\"green\")\n", - "\n", - "plt.ylabel(r\"$\\xi_{+}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(3.0, color=\"grey\", linestyle=\"--\", label=\"3 arcmin\")\n", - "plt.axvline(100.0, color=\"grey\", linestyle=\"--\", label=\"100 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.subplot(212)\n", - "\n", - "plt.errorbar(\n", - " xi_minus[\"ANG\"],\n", - " xi_minus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[20:40],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - ")\n", - "plt.plot(theta_arcmin, xi_m_theta_fit, label=\"SP_v1.4.5 fit\", color=\"red\")\n", - "plt.plot(theta_arcmin, xi_m_theta_true, label=\"SP_v1.4.5 true\", color=\"blue\")\n", - "plt.plot(theta_arcmin, xi_m_theta_fit_IA, label=\"SP_v1.4.5 fit IA\", color=\"green\")\n", - "\n", - "plt.xlabel(r\"$\\theta$ [arcmin]\")\n", - "plt.ylabel(r\"$\\xi_{-}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(10.0, color=\"grey\", linestyle=\"--\", label=\"10 arcmin\")\n", - "plt.axvline(200.0, color=\"grey\", linestyle=\"--\", label=\"200 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "24", - "metadata": {}, - "outputs": [], - "source": [ - "# Add best-fit model\n", - "root_dir = \"/n09data/guerrini/output_chains/output_result/glass_mock_1/\"\n", - "xi_plus_bf_no_psf = np.loadtxt(root_dir + \"best_fit/shear_xi_plus/bin_1_1.txt\")\n", - "xi_minus_bf_no_psf = np.loadtxt(root_dir + \"best_fit/shear_xi_minus/bin_1_1.txt\")\n", - "xi_sys_p = np.loadtxt(root_dir + \"best_fit/xi_sys/shear_xi_plus.txt\")\n", - "xi_sys_m = np.loadtxt(root_dir + \"best_fit/xi_sys/shear_xi_minus.txt\")\n", - "theta_xi_sys = np.loadtxt(root_dir + \"best_fit/xi_sys/theta.txt\")\n", - "theta_xi_sys = theta_xi_sys * 180 * 60 / np.pi\n", - "angle = np.loadtxt(root_dir + \"best_fit/shear_xi_plus/theta.txt\")\n", - "angle = angle * 180 * 60 / np.pi\n", - "\n", - "mask = (angle < 250) & (angle > 0.1)\n", - "\n", - "from scipy.interpolate import interp1d\n", - "\n", - "xi_sys_p_interp = interp1d(\n", - " theta_xi_sys, xi_sys_p, kind=\"linear\", fill_value=\"extrapolate\"\n", - ")\n", - "xi_sys_m_interp = interp1d(\n", - " theta_xi_sys, xi_sys_m, kind=\"linear\", fill_value=\"extrapolate\"\n", - ")\n", - "xi_plus_bf = xi_plus_bf_no_psf[mask] + xi_sys_p_interp(angle[mask])\n", - "xi_minus_bf = xi_minus_bf_no_psf[mask] + xi_sys_m_interp(angle[mask])\n", - "\n", - "xi_plus_bf_no_baryons = np.loadtxt(\n", - " root_dir + \"best_fit_no_feedback/shear_xi_plus/bin_1_1.txt\"\n", - ")\n", - "xi_minus_bf_no_baryons = np.loadtxt(\n", - " root_dir + \"best_fit_no_feedback/shear_xi_minus/bin_1_1.txt\"\n", - ")\n", - "\n", - "xi_plus_bf_no_IA = np.loadtxt(root_dir + \"best_fit_no_IA/shear_xi_plus/bin_1_1.txt\")\n", - "xi_minus_bf_no_IA = np.loadtxt(root_dir + \"best_fit_no_IA/shear_xi_minus/bin_1_1.txt\")\n", - "\n", - "xi_plus_truth_cosmosis = np.loadtxt(root_dir + \"/truth/shear_xi_plus/bin_1_1.txt\")\n", - "xi_minus_truth_cosmosis = np.loadtxt(root_dir + \"/truth/shear_xi_minus/bin_1_1.txt\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "25", - "metadata": {}, - "outputs": [], - "source": [ - "plt.figure(figsize=(15, 15))\n", - "\n", - "plt.subplot(211)\n", - "\n", - "plt.errorbar(\n", - " xi_plus[\"ANG\"],\n", - " xi_plus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[:20],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - ")\n", - "plt.plot(theta_arcmin, xi_p_theta_true, label=\"SP_v1.4.5 true\", color=\"blue\")\n", - "plt.plot(angle[mask], xi_plus_bf, label=\"SP_v1.4.5 COSMOSIS\", color=\"orange\")\n", - "plt.plot(\n", - " angle[mask],\n", - " xi_plus_bf_no_psf[mask],\n", - " label=\"SP_v1.4.5 COSMOSIS no PSF\",\n", - " color=\"green\",\n", - ")\n", - "plt.plot(\n", - " angle[mask],\n", - " xi_plus_bf_no_baryons[mask],\n", - " label=\"SP_v1.4.5 COSMOSIS no baryons\",\n", - " color=\"red\",\n", - ")\n", - "plt.plot(\n", - " angle[mask],\n", - " xi_plus_bf_no_IA[mask],\n", - " label=\"SP_v1.4.5 COSMOSIS no IA\",\n", - " color=\"purple\",\n", - ")\n", - "plt.plot(\n", - " angle[mask],\n", - " xi_plus_truth_cosmosis[mask],\n", - " label=\"SP_v1.4.5 COSMOSIS truth\",\n", - " color=\"black\",\n", - " linestyle=\"--\",\n", - ")\n", - "\n", - "plt.ylabel(r\"$\\xi_{+}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(3.0, color=\"grey\", linestyle=\"--\", label=\"3 arcmin\")\n", - "plt.axvline(150.0, color=\"grey\", linestyle=\"--\", label=\"150 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.subplot(212)\n", - "\n", - "plt.errorbar(\n", - " xi_minus[\"ANG\"],\n", - " xi_minus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[20:40],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - " markersize=2,\n", - ")\n", - "plt.plot(theta_arcmin, xi_m_theta_true, label=\"SP_v1.4.5 true\", color=\"blue\")\n", - "plt.plot(angle[mask], xi_minus_bf, label=\"SP_v1.4.5 COSMOSIS\", color=\"orange\")\n", - "plt.plot(\n", - " angle[mask],\n", - " xi_minus_bf_no_psf[mask],\n", - " label=\"SP_v1.4.5 COSMOSIS no PSF\",\n", - " color=\"green\",\n", - ")\n", - "plt.plot(\n", - " angle[mask],\n", - " xi_minus_bf_no_baryons[mask],\n", - " label=\"SP_v1.4.5 COSMOSIS no baryons\",\n", - " color=\"red\",\n", - ")\n", - "plt.plot(\n", - " angle[mask],\n", - " xi_minus_bf_no_IA[mask],\n", - " label=\"SP_v1.4.5 COSMOSIS no IA\",\n", - " color=\"purple\",\n", - ")\n", - "plt.plot(\n", - " angle[mask],\n", - " xi_minus_truth_cosmosis[mask],\n", - " label=\"SP_v1.4.5 COSMOSIS truth\",\n", - " color=\"black\",\n", - " linestyle=\"--\",\n", - ")\n", - "\n", - "plt.xlabel(r\"$\\theta$ [arcmin]\")\n", - "plt.ylabel(r\"$\\xi_{-}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(10.0, color=\"grey\", linestyle=\"--\", label=\"10 arcmin\")\n", - "plt.axvline(200.0, color=\"grey\", linestyle=\"--\", label=\"200 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "26", - "metadata": {}, - "outputs": [], - "source": [ - "import treecorr\n", - "\n", - "theta_min = 0.1\n", - "theta_max = 250.0\n", - "nbins = 20\n", - "var_method = \"jackknife\"\n", - "\n", - "treecorr_config = {\n", - " \"ra_units\": \"degrees\",\n", - " \"dec_units\": \"degrees\",\n", - " \"min_sep\": theta_min,\n", - " \"max_sep\": theta_max,\n", - " \"sep_units\": \"arcmin\",\n", - " \"nbins\": nbins,\n", - " \"var_method\": var_method,\n", - "}\n", - "\n", - "gg = treecorr.GGCorrelation(treecorr_config)\n", - "\n", - "# Load the measurement\n", - "cat = fits.getdata(\n", - " \"/n09data/guerrini/glass_mock/results/unions_glass_sim_00001_4096.fits\"\n", - ")\n", - "\n", - "e1 = cat[\"e1\"]\n", - "e2 = cat[\"e2\"]\n", - "ra = cat[\"ra\"]\n", - "dec = cat[\"dec\"]\n", - "\n", - "# Create the catalog\n", - "cat = treecorr.Catalog(\n", - " ra=ra, dec=dec, ra_units=\"degrees\", dec_units=\"degrees\", g1=e1, g2=e2, npatch=200\n", - ")\n", - "\n", - "# Process the catalog\n", - "gg.process(cat)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "27", - "metadata": {}, - "outputs": [], - "source": [ - "cov = treecorr.estimate_multi_cov([gg], method=\"jackknife\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "28", - "metadata": {}, - "outputs": [], - "source": [ - "data_vector_sim = []\n", - "\n", - "for ver in [f\"SP_v1.4.5_glass_mock_{i}\" for i in range(1, 17)]:\n", - " data = fits.open(\n", - " f\"/home/guerrini/sp_validation/cosmo_inference/data/{ver}/cosmosis_{ver}.fits\"\n", - " )\n", - " xi_plus = data[\"XI_PLUS\"].data\n", - " xi_minus = data[\"XI_MINUS\"].data\n", - " data_vector_sim.append(np.concatenate((xi_plus[\"VALUE\"], xi_minus[\"VALUE\"])))\n", - "\n", - "data_vector_sim = np.array(data_vector_sim)\n", - "\n", - "data_vector_sim.shape" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "29", - "metadata": {}, - "outputs": [], - "source": [ - "cov_sim = np.cov(data_vector_sim.T)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "30", - "metadata": {}, - "outputs": [], - "source": [ - "ver_sacha = \"SP_v1.4.5\"\n", - "\n", - "cov_th_sacha = np.loadtxt(\n", - " \"/home/guerrini/sp_validation/cosmo_inference/data/{}/covs/cov_{}.txt\".format(\n", - " ver_sacha, ver_sacha\n", - " )\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "31", - "metadata": {}, - "outputs": [], - "source": [ - "plt.figure()\n", - "\n", - "plt.plot(xi_plus[\"ANG\"], np.diag(cov)[:20])\n", - "plt.plot(xi_plus[\"ANG\"], np.diag(cov_sim)[:20], label=\"SP_v1.4.5 data\", color=\"red\")\n", - "plt.plot(\n", - " xi_plus[\"ANG\"], np.diag(cov_th_sacha)[:20], label=\"SP_v1.4.5 data\", color=\"green\"\n", - ")\n", - "plt.plot(xi_plus[\"ANG\"], np.diag(cov_mat)[:20], label=\"SP_v1.4.5 data\", color=\"black\")\n", - "\n", - "plt.ylabel(\"Diagonal of the covariance\")\n", - "plt.xlabel(r\"$\\theta$ [arcmin]\")\n", - "\n", - "plt.yscale(\"log\")\n", - "plt.xscale(\"log\")\n", - "plt.savefig(\"check_cov.png\")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "32", - "metadata": {}, - "outputs": [], - "source": [ - "gg.varxip" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "33", - "metadata": {}, - "outputs": [], - "source": [ - "np.sqrt(gg.varxip)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "34", - "metadata": {}, - "outputs": [], - "source": [ - "np.sqrt(np.diag(cov_mat)[0:20])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "35", - "metadata": {}, - "outputs": [], - "source": [ - "plt.figure(figsize=(15, 15))\n", - "\n", - "plt.subplot(211)\n", - "\n", - "plt.errorbar(\n", - " xi_plus[\"ANG\"],\n", - " xi_plus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[:20],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - ")\n", - "plt.plot(angle[mask], xi_plus_bf[mask], label=\"Best-fit model\", color=\"red\")\n", - "\n", - "plt.ylabel(r\"$\\xi_{+}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(3.0, color=\"grey\", linestyle=\"--\", label=\"3 arcmin\")\n", - "plt.axvline(100.0, color=\"grey\", linestyle=\"--\", label=\"100 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.subplot(212)\n", - "\n", - "plt.errorbar(\n", - " xi_minus[\"ANG\"],\n", - " xi_minus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[20:40],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - ")\n", - "plt.plot(angle[mask], xi_minus_bf[mask], label=\"Best-fit model\", color=\"red\")\n", - "\n", - "plt.xlabel(r\"$\\theta$ [arcmin]\")\n", - "plt.ylabel(r\"$\\xi_{-}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(10.0, color=\"grey\", linestyle=\"--\", label=\"10 arcmin\")\n", - "plt.axvline(200.0, color=\"grey\", linestyle=\"--\", label=\"200 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.savefig(\"xi_data_bf.png\")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "36", - "metadata": {}, - "outputs": [], - "source": [ - "# Add PSF systematic\n", - "xi_sys_plus = np.loadtxt(root_dir + \"/xi_sys/shear_xi_plus.txt\")\n", - "xi_sys_minus = np.loadtxt(root_dir + \"/xi_sys/shear_xi_minus.txt\")\n", - "theta_sys = np.loadtxt(root_dir + \"/xi_sys/theta.txt\")\n", - "theta_sys = theta_sys * 180 * 60 / np.pi" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "37", - "metadata": {}, - "outputs": [], - "source": [ - "plt.figure(figsize=(15, 15))\n", - "\n", - "plt.subplot(211)\n", - "\n", - "plt.errorbar(\n", - " xi_plus[\"ANG\"],\n", - " xi_plus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[:20],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - ")\n", - "plt.plot(angle[mask], xi_plus_bf[mask], label=\"Best-fit model wo SYS\", color=\"red\")\n", - "plt.plot(theta_sys, xi_sys_plus, label=r\"$\\xi_{\\rm sys}$\", color=\"green\")\n", - "\n", - "plt.ylabel(r\"$\\xi_{+}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(3.0, color=\"grey\", linestyle=\"--\", label=\"3 arcmin\")\n", - "plt.axvline(100.0, color=\"grey\", linestyle=\"--\", label=\"100 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.subplot(212)\n", - "\n", - "plt.errorbar(\n", - " xi_minus[\"ANG\"],\n", - " xi_minus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[20:40],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - ")\n", - "plt.plot(angle[mask], xi_minus_bf[mask], label=\"Best-fit model wo SYS\", color=\"red\")\n", - "plt.plot(theta_sys, xi_sys_minus, label=r\"$\\xi_{\\rm sys}$\", color=\"green\")\n", - "\n", - "plt.xlabel(r\"$\\theta$ [arcmin]\")\n", - "plt.ylabel(r\"$\\xi_{-}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(10.0, color=\"grey\", linestyle=\"--\", label=\"10 arcmin\")\n", - "plt.axvline(200.0, color=\"grey\", linestyle=\"--\", label=\"200 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.savefig(\"xi_data_bf_sys.png\")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "38", - "metadata": {}, - "outputs": [], - "source": [ - "shear_cl = np.loadtxt(root_dir + \"/shear_cl/bin_1_1.txt\")\n", - "shear_cl_gg = np.loadtxt(root_dir + \"/shear_cl_gg/bin_1_1.txt\")\n", - "shear_cl_gi = np.loadtxt(root_dir + \"/shear_cl_gi/bin_1_1.txt\")\n", - "shear_cl_ii = np.loadtxt(root_dir + \"/shear_cl_ii/bin_1_1.txt\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "39", - "metadata": {}, - "outputs": [], - "source": [ - "A = 3.355083374185272\n", - "np.isclose(shear_cl, shear_cl_gg + 2 * shear_cl_gi + shear_cl_ii)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "40", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "41", - "metadata": {}, - "outputs": [], - "source": [ - "# Add the lensing part without intrinsic alignment\n", - "root_dir = \"/n09data/guerrini/output_chains/test_pipeline/\"\n", - "xi_plus_wo_ia = np.loadtxt(root_dir + \"/shear_xi_plus_wo_IA/bin_1_1.txt\")\n", - "xi_minus_wo_ia = np.loadtxt(root_dir + \"/shear_xi_minus_wo_IA/bin_1_1.txt\")\n", - "angle = np.loadtxt(root_dir + \"/shear_xi_plus_wo_IA/theta.txt\")\n", - "angle = angle * 180 * 60 / np.pi\n", - "\n", - "mask = (angle < 250) & (angle > 0.1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "42", - "metadata": {}, - "outputs": [], - "source": [ - "plt.figure(figsize=(15, 15))\n", - "\n", - "plt.subplot(211)\n", - "\n", - "plt.errorbar(\n", - " xi_plus[\"ANG\"],\n", - " xi_plus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[:20],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - ")\n", - "plt.plot(angle[mask], xi_plus_bf[mask], label=\"Best-fit model wo SYS\", color=\"red\")\n", - "plt.plot(theta_sys, xi_sys_plus, label=r\"$\\xi_{\\rm sys}$\", color=\"green\")\n", - "plt.plot(\n", - " angle[mask], xi_plus_wo_ia[mask], label=\"Best-fit model wo IA and SYS\", color=\"blue\"\n", - ")\n", - "\n", - "plt.ylabel(r\"$\\xi_{+}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(3.0, color=\"grey\", linestyle=\"--\", label=\"3 arcmin\")\n", - "plt.axvline(100.0, color=\"grey\", linestyle=\"--\", label=\"100 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.subplot(212)\n", - "\n", - "plt.errorbar(\n", - " xi_minus[\"ANG\"],\n", - " xi_minus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[20:40],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - ")\n", - "plt.plot(angle[mask], xi_minus_bf[mask], label=\"Best-fit model wo SYS\", color=\"red\")\n", - "plt.plot(theta_sys, xi_sys_minus, label=r\"$\\xi_{\\rm sys}$\", color=\"green\")\n", - "plt.plot(\n", - " angle[mask],\n", - " xi_minus_wo_ia[mask],\n", - " label=\"Best-fit model wo IA and SYS\",\n", - " color=\"blue\",\n", - ")\n", - "\n", - "plt.xlabel(r\"$\\theta$ [arcmin]\")\n", - "plt.ylabel(r\"$\\xi_{-}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(10.0, color=\"grey\", linestyle=\"--\", label=\"10 arcmin\")\n", - "plt.axvline(200.0, color=\"grey\", linestyle=\"--\", label=\"200 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.savefig(\"xi_data_bf_sys_ia.png\")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "43", - "metadata": {}, - "outputs": [], - "source": [ - "# Add the lensing part without intrinsic alignment\n", - "root_dir = \"/n09data/guerrini/output_chains/test_pipeline/\"\n", - "xi_plus_reas = np.loadtxt(root_dir + \"/shear_xi_plus/bin_1_1.txt\")\n", - "xi_minus_reas = np.loadtxt(root_dir + \"/shear_xi_minus/bin_1_1.txt\")\n", - "angle_reas = np.loadtxt(root_dir + \"/shear_xi_plus/theta.txt\")\n", - "angle_reas = angle_reas * 180 * 60 / np.pi\n", - "\n", - "mask = (angle < 250) & (angle > 0.1)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "44", - "metadata": {}, - "outputs": [], - "source": [ - "plt.figure(figsize=(15, 15))\n", - "\n", - "plt.subplot(211)\n", - "\n", - "plt.errorbar(\n", - " xi_plus[\"ANG\"],\n", - " xi_plus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[:20],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - ")\n", - "plt.plot(angle[mask], xi_plus_bf[mask], label=\"Best-fit model wo SYS\", color=\"red\")\n", - "plt.plot(theta_sys, xi_sys_plus, label=r\"$\\xi_{\\rm sys}$\", color=\"green\")\n", - "plt.plot(\n", - " angle[mask], xi_plus_wo_ia[mask], label=\"Best-fit model wo IA and SYS\", color=\"blue\"\n", - ")\n", - "plt.plot(\n", - " angle_reas[mask],\n", - " xi_plus_reas[mask],\n", - " label=\"Lower IA\",\n", - " color=\"orange\",\n", - " linestyle=\"--\",\n", - ")\n", - "\n", - "plt.ylabel(r\"$\\xi_{+}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(3.0, color=\"grey\", linestyle=\"--\", label=\"3 arcmin\")\n", - "plt.axvline(100.0, color=\"grey\", linestyle=\"--\", label=\"100 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.subplot(212)\n", - "\n", - "plt.errorbar(\n", - " xi_minus[\"ANG\"],\n", - " xi_minus[\"VALUE\"],\n", - " yerr=np.sqrt(np.diag(cov_mat))[20:40],\n", - " fmt=\"o\",\n", - " label=\"SP_v1.4.5 data\",\n", - " color=\"black\",\n", - ")\n", - "plt.plot(angle[mask], xi_minus_bf[mask], label=\"Best-fit model wo SYS\", color=\"red\")\n", - "plt.plot(theta_sys, xi_sys_minus, label=r\"$\\xi_{\\rm sys}$\", color=\"green\")\n", - "plt.plot(\n", - " angle[mask],\n", - " xi_minus_wo_ia[mask],\n", - " label=\"Best-fit model wo IA and SYS\",\n", - " color=\"blue\",\n", - ")\n", - "plt.plot(\n", - " angle_reas[mask],\n", - " xi_minus_reas[mask],\n", - " label=\"Lower IA\",\n", - " color=\"orange\",\n", - " linestyle=\"--\",\n", - ")\n", - "\n", - "plt.xlabel(r\"$\\theta$ [arcmin]\")\n", - "plt.ylabel(r\"$\\xi_{-}$\")\n", - "plt.xscale(\"log\")\n", - "plt.yscale(\"log\")\n", - "plt.axvline(10.0, color=\"grey\", linestyle=\"--\", label=\"10 arcmin\")\n", - "plt.axvline(200.0, color=\"grey\", linestyle=\"--\", label=\"200 arcmin\")\n", - "plt.legend()\n", - "\n", - "plt.savefig(\"xi_data_bf_sys_ia_reas.png\")\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "45", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "base", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.0" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/cosmo_inference/notebooks/get_prior_psf_leakage.ipynb b/cosmo_inference/notebooks/get_prior_psf_leakage.ipynb deleted file mode 100644 index 1dae9a36..00000000 --- a/cosmo_inference/notebooks/get_prior_psf_leakage.ipynb +++ /dev/null @@ -1,269 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "id": "0", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "\n", - "if not os.path.exists(\"./Plots\"):\n", - " os.makedirs(\"./Plots\")\n", - "\n", - "# Trick to plot with tex\n", - "os.environ[\"LD_LIBRARY_PATH\"] = \"\"\n", - "os.environ[\"CONDA_PREFIX\"] = \"/home/guerrini/.conda/envs/sp_validation_3.11\"\n", - "\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "import seaborn as sns\n", - "from astropy.io import fits\n", - "from getdist import MCSamples, plots\n", - "from shear_psf_leakage.rho_tau_stat import PSFErrorFit, RhoStat, TauStat\n", - "\n", - "# Use paper style and seaborn with husl palette\n", - "plt.style.use(\"/home/guerrini/matplotlib_config/paper.mplstyle\")\n", - "# Set default palette - will be updated per plot as needed\n", - "sns.set_palette(\"husl\")\n", - "%matplotlib inline\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "g.settings.axes_fontsize = 30\n", - "g.settings.axes_labelsize = 30\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 25" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1", - "metadata": {}, - "outputs": [], - "source": [ - "data_path = \"/home/guerrini/sp_validation/cosmo_inference/data/\"\n", - "\n", - "path_cosmo_val = \"/home/guerrini/sp_validation/cosmo_val/output/\"\n", - "\n", - "roots_cosmo_val = [\"SP_v1.4.6\", \"SP_v1.4.6_leak_corr\"]\n", - "\n", - "roots = [\"SP_v1.4.6_no_leak_corr_A_masked\", \"SP_v1.4.6_leak_corr_A_masked\"]\n", - "\n", - "labels = [\"SP_v1.4.6_A\", \"SP_v1.4.6_A leakage corrected\"]" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2", - "metadata": {}, - "outputs": [], - "source": [ - "data_vectors = []\n", - "\n", - "for root in roots:\n", - " data_vectors.append(fits.open(data_path + root + f\"/cosmosis_{root}.fits\"))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3", - "metadata": {}, - "outputs": [], - "source": [ - "def cov_to_corr(cov):\n", - " \"\"\"Convert a covariance matrix to a correlation matrix.\"\"\"\n", - " d = np.sqrt(np.diag(cov))\n", - " corr = cov / np.outer(d, d)\n", - " corr[cov == 0] = 0\n", - " return corr" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "4", - "metadata": {}, - "outputs": [], - "source": [ - "# Print the covariance matrix for each root\n", - "for i, root in enumerate(roots):\n", - " print(f\"Covariance matrix for {labels[i]}:\")\n", - " cov = data_vectors[i][\"COVMAT\"].data\n", - "\n", - " n_bins = cov.shape[0] // 4\n", - "\n", - " fig, ax = plt.subplots(figsize=(10, 8))\n", - "\n", - " im = ax.imshow(cov_to_corr(cov), vmin=-1, vmax=1, cmap=\"seismic\")\n", - " ax.set_aspect(\"equal\")\n", - " ax.set_yticks(np.array([10, 30, 50, 70]))\n", - " ax.set_yticklabels(\n", - " [\n", - " r\"$\\xi_+(\\vartheta)$\",\n", - " r\"$\\xi_-(\\vartheta)$\",\n", - " r\"$\\tau_0(\\vartheta)$\",\n", - " r\"$\\tau_2(\\vartheta)$\",\n", - " ]\n", - " )\n", - " ax.set_xticks(np.array([10, 30, 50, 70]))\n", - " ax.set_xticklabels(\n", - " [\n", - " r\"$\\xi_+(\\vartheta)$\",\n", - " r\"$\\xi_-(\\vartheta)$\",\n", - " r\"$\\tau_0(\\vartheta)$\",\n", - " r\"$\\tau_2(\\vartheta)$\",\n", - " ],\n", - " rotation=45,\n", - " )\n", - " fig.colorbar(im, ax=ax)\n", - "\n", - " plt.savefig(f\"./Plots/cov_matrix_{root}.png\", bbox_inches=\"tight\", dpi=300)\n", - " plt.show()\n", - " print(\"\\n\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5", - "metadata": {}, - "outputs": [], - "source": [ - "# Create dummy rho and tau stat handler.\n", - "\n", - "# Inference of the xi_sys parameters\n", - "sep_units = \"arcmin\"\n", - "coord_units = \"degrees\"\n", - "theta_min = 1.0\n", - "theta_max = 250\n", - "nbins = 20\n", - "\n", - "\n", - "TreeCorrConfig_xi = {\n", - " \"ra_units\": coord_units,\n", - " \"dec_units\": coord_units,\n", - " \"min_sep\": theta_min,\n", - " \"max_sep\": theta_max,\n", - " \"sep_units\": sep_units,\n", - " \"nbins\": nbins,\n", - " \"var_method\": \"jackknife\",\n", - "}\n", - "\n", - "rho_stats_handler = RhoStat(output=\".\", treecorr_config=TreeCorrConfig_xi, verbose=True)\n", - "\n", - "tau_stats_handler = TauStat(\n", - " catalogs=rho_stats_handler.catalogs,\n", - " output=\".\",\n", - " treecorr_config=TreeCorrConfig_xi,\n", - " verbose=True,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6", - "metadata": {}, - "outputs": [], - "source": [ - "# Create a PSFErrorFit instance\n", - "psf_fitter = PSFErrorFit(\n", - " rho_stats_handler,\n", - " tau_stats_handler,\n", - " path_cosmo_val + \"rho_tau_stats/\",\n", - " use_eta=False,\n", - ")\n", - "\n", - "\n", - "def load_matrix_and_cut(root, root_cosmo_val, type=\"rho\"):\n", - " if type == \"rho\":\n", - " cov = np.load(f\"{root}/cov_rho_{root_cosmo_val}.npy\")\n", - " nbins = cov.shape[0] // 6\n", - " cov = cov[: nbins * 3, : nbins * 3]\n", - " np.save(f\"{root}/cov_rho_{root_cosmo_val}_cut.npy\", cov)\n", - " elif type == \"tau\":\n", - " cov = np.load(f\"{root}/cov_tau_{root_cosmo_val}_th.npy\")\n", - " nbins = cov.shape[0] // 3\n", - " cov = cov[: nbins * 2, : nbins * 2]\n", - " np.save(f\"{root}/cov_tau_{root_cosmo_val}_th_cut.npy\", cov)\n", - " else:\n", - " raise ValueError(\"type must be 'rho' or 'tau'\")\n", - "\n", - "\n", - "g = plots.get_subplot_plotter(width_inch=30)\n", - "\n", - "g.settings.axes_fontsize = 30\n", - "g.settings.axes_labelsize = 30\n", - "g.settings.alpha_filled_add = 0.7\n", - "g.settings.legend_fontsize = 40\n", - "\n", - "chains = []\n", - "\n", - "# Load rho-, tau-statistics, and cov_tau from the data_vector\n", - "for i, root_cosmo_val in enumerate(roots_cosmo_val):\n", - " print(\"Sampling PSF parameters for \", labels[i])\n", - " path_rho = f\"rho_stats_{root_cosmo_val}.fits\"\n", - " path_tau = f\"tau_stats_{root_cosmo_val}.fits\"\n", - " path_cov_rho = f\"cov_rho_{root_cosmo_val}.npy\"\n", - " path_cov_tau = f\"cov_tau_{root_cosmo_val}_th.npy\"\n", - "\n", - " load_matrix_and_cut(path_cosmo_val + \"/rho_tau_stats/\", root_cosmo_val, type=\"rho\")\n", - " load_matrix_and_cut(path_cosmo_val + \"/rho_tau_stats/\", root_cosmo_val, type=\"tau\")\n", - " path_cov_rho = f\"cov_rho_{root_cosmo_val}_cut.npy\"\n", - " path_cov_tau = f\"cov_tau_{root_cosmo_val}_th_cut.npy\"\n", - "\n", - " psf_fitter.load_rho_stat(path_rho)\n", - " psf_fitter.load_tau_stat(path_tau)\n", - " psf_fitter.load_covariance(path_cov_rho, cov_type=\"rho\")\n", - " psf_fitter.load_covariance(path_cov_tau, cov_type=\"tau\")\n", - " samples_lq, _, _ = psf_fitter.get_least_squares_params_samples(\n", - " npatch=None, apply_debias=False\n", - " )\n", - "\n", - " samples_gd = MCSamples(\n", - " samples=samples_lq, names=[r\"\\alpha\", r\"\\beta\"], labels=[r\"\\alpha\", r\"\\beta\"]\n", - " )\n", - "\n", - " chains.append(samples_gd)\n", - "\n", - "g.triangle_plot(chains, filled=True, legend_labels=labels, legend_loc=\"upper right\")\n", - "\n", - "plt.savefig(\"./Plots/psf_leakage_params.png\", bbox_inches=\"tight\", dpi=300)\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "sp_validation_3.11", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.0" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/cosmo_inference/pipeline.sh b/cosmo_inference/pipeline.sh deleted file mode 100755 index f853d511..00000000 --- a/cosmo_inference/pipeline.sh +++ /dev/null @@ -1,131 +0,0 @@ -#!/bin/bash - -# Transform long options to short ones -for arg in "$@"; do - shift - case "$arg" in - '--help') set -- "$@" '-h' ;; - '--pcf') set -- "$@" '-p' ;; - '--covmat') set -- "$@" '-c' ;; - '--inference') set -- "$@" '-i' ;; - '--mcmc_process') set -- "$@" '-m' ;; - *) set -- "$@" "$arg" ;; - esac -done - -# Parse short options -OPTIND=1 -while getopts "hpcim" opt -do - case "$opt" in - 'h') - echo "Please input a flag: --help, --pcf, --covmat, --inference or --mcmc_process "; - exit 0 - ;; - 'p') - echo "Running cosmo_val.py to calculate 2 point correlation functions"; - python cosmo_val/cosmo_val.py - ;; - 'c') - read -p 'COVARIANCE FILE: ' covmat_file; - read -p 'OUTPUT STUB (without extension): ' output_stub; - echo "Processing covariance matrix"; - python scripts/cosmocov_process.py $covmat_file $output_stub - ;; - 'i') - read -p 'XI ROOT: ' xi_root; - read -p 'TAU ROOT: ' tau_root; - read -p 'COSMOSIS ROOT: ' cosmosis_root; - read -p 'COSMO_VAL OUTPUT FOLDER: ' output_folder; - read -p 'NZ FILE:' nz_file; - read -p 'OUTPUT MCMC CHAIN FOLDER: ' data; - read -p 'USE PSEUDO_CELL? (y/n): ' pseudo_cell; - - if [ "${pseudo_cell}" == "y" ]; then - echo "Using pseudo cell" - - out_file="data/${root}/cosmosis_${root}_cell.fits" - - # Create the folder if it does not exist - if [ ! -d "data/$root" ]; then - mkdir -p "data/$root" - echo "Directory 'data/$root' created." - else - echo "Directory 'data/$root' already exists." - fi - - python scripts/cosmosis_fitting.py $root $output_folder $nz_file $pseudo_cell $out_file - else - - read -p 'USE RHO/TAU_STATS? (y/n): ' rhotau_stats; - echo $rhotau_stats - read -p 'COV_XI MAT TXT FILE:' covmat; - - out_file="data/${root}/cosmosis_${root}.fits"; - - # Create the folder if it does not exist - if [ ! -d "data/$root" ]; then - mkdir -p "data/$root" - echo "Directory 'data/$root' created." - else - echo "Directory 'data/$root' already exists." - fi - - #LG: add check if xi_plus/xi_minus fits file exists - python scripts/cosmosis_fitting.py $root $output_folder $nz_file $pseudo_cell $out_file $covmat $rhotau_stats; - - fi - - if [ "${pseudo_cell}" == "y" ]; then - output_ini_file="cosmosis_config/cosmosis_pipeline_${root}_cell.ini" - cp cosmosis_config/cosmosis_pipeline_A_ia_cell.ini $output_ini_file - else - output_ini_file="cosmosis_config/cosmosis_pipeline_${root}.ini" - if [ "${rhotau_stats}" == "y" ]; then - cp cosmosis_config/cosmosis_pipeline_A_psf.ini $output_ini_file; - else - cp cosmosis_config/cosmosis_pipeline_A_ia.ini $output_ini_file; - fi - fi - - sed -i "/^\[DEFAULT\]/a\SCRATCH = ${data}" $output_ini_file; - sed -i "/^\[DEFAULT\]/a\FITS_FILE = ${out_file}" $output_ini_file; - if [ "${pseudo_cell}" == "y" ]; then - sed -i "/^\[output\]/a\filename = %(SCRATCH)s/${root}_cell/samples_${root}_cell.txt" $output_ini_file; - sed -i "/^\[pipeline\]/a\values = cosmosis_config/values_ia.ini" $output_ini_file; - sed -i "/^\[pipeline\]/a\priors = cosmosis_config/priors.ini" $output_ini_file; - sed -i "/^\[2pt_like]/a\file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py" $output_ini_file; - sed -i "/^\[2pt_like]/a\data_sets=CELL_EE" $output_ini_file; - sed -i "/^\[polychord\]/a\polychord_outfile_root = ${root}_cell" $output_ini_file; - sed -i "/^\[test\]/a\save_dir = %(SCRATCH)s/best_fit/${root}_cell" $output_ini_file; - else - sed -i "/^\[output\]/a\filename = %(SCRATCH)s/${root}/samples_${root}.txt" $output_ini_file; - if [ "${rhotau_stats}" == "y" ]; then - sed -i "/^\[pipeline\]/a\values = cosmosis_config/values_psf.ini" $output_ini_file; - sed -i "/^\[pipeline\]/a\priors = cosmosis_config/priors_psf.ini" $output_ini_file; - sed -i "/^\[2pt_like]/a\file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like_xi_sys.py" $output_ini_file; - sed -i "/^\[2pt_like]/a\data_sets=XI_PLUS XI_MINUS TAU_0_PLUS TAU_2_PLUS" $output_ini_file; - sed -i "/^\[2pt_like]/a\add_xi_sys=T" $output_ini_file; - else - sed -i "/^\[pipeline\]/a\values = cosmosis_config/values_ia.ini" $output_ini_file; - sed -i "/^\[pipeline\]/a\priors = cosmosis_config/priors.ini" $output_ini_file; - sed -i "/^\[2pt_like]/a\file = %(COSMOSIS_DIR)s/likelihood/2pt/2pt_like.py" $output_ini_file; - sed -i "/^\[2pt_like]/a\data_sets=XI_PLUS XI_MINUS" $output_ini_file; - fi - sed -i "/^\[polychord\]/a\polychord_outfile_root = ${root}" $output_ini_file; - sed -i "/^\[test\]/a\save_dir = %(SCRATCH)s/best_fit/${root}" $output_ini_file; - fi - echo "Prepared CosmoSIS configuration file in $output_ini_file"; - echo "You can now run the inference with the command: cosmosis $output_ini_file" - ;; - 'm') - # LG: also convert this into a script to directly output contour plots - echo "Run the cosmo_inference/notebooks/MCMC.ipynb notebook to analyse your chains" - ;; - '?') - print_usage >&2; - exit 1 - ;; - esac -done -shift $(expr $OPTIND - 1) # remove options from positional parameters \ No newline at end of file diff --git a/cosmo_inference/scripts/2pt_like_xi_sys.py b/cosmo_inference/scripts/2pt_like_xi_sys.py deleted file mode 100644 index 93f11bd3..00000000 --- a/cosmo_inference/scripts/2pt_like_xi_sys.py +++ /dev/null @@ -1,614 +0,0 @@ -import gaussian_covariance -import numpy as np -import twopoint -from astropy.io import fits -from cosmosis.datablock import SectionOptions, names -from cosmosis.gaussian_likelihood import GaussianLikelihood -from scipy.interpolate import interp1d -from spec_tools import TheorySpectrum -from twopoint_cosmosis import theory_names, type_table - -default_array = np.repeat(-1.0, 99) - - -# To copy in cosmosis-standard-library/likelihood -def is_default(x): - return len(x) == len(default_array) and (x == default_array).all() - - -def convert_nz_steradian(n): - return n * (41253.0 * 60.0 * 60.0) / (4 * np.pi) - - -class TwoPointLikelihood(GaussianLikelihood): - # This is a sub-class of the class GaussianLikelihood - # which can be found in the file ${COSMOSIS_SRC_DIR}/cosmosis/gaussian_likelihood.py - # That super-class implements the generic behaviour that all Gaussian likelihoods - # follow - the basic form of the likelihoods, inverting covariance matrices, saving - # results, etc. This sub-clas does the parts that are specific to this 2-pt - # likelihood - loading data from a file, getting the specific theory prediction - # to which to compare it, etc. - like_name = "2pt" - - def __init__(self, options): - # We may decide to use an analytic gaussian covariance - # in that case we won't load the covmat. - self.gaussian_covariance = options.get_bool("gaussian_covariance", False) - if self.gaussian_covariance: - self.constant_covariance = False - - self.moped = options.get_string("moped", default="") - - super(TwoPointLikelihood, self).__init__(options) - - self.raw_data_x, self.raw_data_y = self.build_data() - - if self.moped: - print( - "Using compressed data from MOPED algorithm: {} data points".format( - len(self.moped_data) - ) - ) - if self.sellentin: - raise ValueError( - "Sellentin mode is incompatible with Moped mode in 2pt like" - ) - - def build_data(self): - filename = self.options.get_string("data_file") - - # Suffixes to added on to two point data from e.g. different experiments - suffix_string = self.options.get_string("suffixes", default="") - if suffix_string == "": - # If there are no suffixes provided, then we create a list of a single empty suffix - suffixes = [""] - else: - suffixes_temp = suffix_string.split() - suffixes = [] - for suffix in suffixes_temp: - if suffix.lower() == "none": - suffixes.append("") - else: - suffixes.append("_" + suffix) - self.suffixes = suffixes - - if self.gaussian_covariance: - covmat_name = None - area = self.options.get_double("survey_area") # in square degrees - self.sky_area = area * (np.pi * np.pi) / (180 * 180) - - def get_arr(x): - if self.options.has_value(x): - a = self.options[x] - if not isinstance(a, np.ndarray): - a = [a] - else: - a = default_array - return a - - self.number_density_shear_bin = get_arr("number_density_shear_bin") - self.number_density_lss_bin = get_arr("number_density_lss_bin") - self.sigma_e_bin = get_arr("sigma_e_bin") - - else: - covmat_name = self.options.get_string("covmat_name", "COVMAT") - - # This is the main work - read data in from the file - self.two_point_data = twopoint.TwoPointFile.from_fits(filename, covmat_name) - - # Potentially cut out lines. For some reason one version of - # this file used zeros to mark masked values. - if self.options.get_bool("cut_zeros", default=False): - print("Removing 2-point values with value=0.0") - self.two_point_data.mask_bad(0.0) - - if self.options.get_bool("cut_cross", default=False): - print("Removing 2-point values from cross-bins") - self.two_point_data.mask_cross() - - # All the names of two-points measurements that were found in the data - # file - all_names = [spectrum.name for spectrum in self.two_point_data.spectra] - - # We may not want to use all the likelihoods in the file. - # We can set an option to only use some of them - data_sets = self.options.get_string("data_sets", default="all") - if data_sets != "all": - data_sets = data_sets.split() - self.two_point_data.choose_data_sets(data_sets) - - # The ones we actually used. - self.used_names = [spectrum.name for spectrum in self.two_point_data.spectra] - - # Check for scale cuts. In general, this is a minimum and maximum angle for - # each spectrum, for each redshift bin combination. Which is clearly a massive pain... - # but what can you do? - - scale_cuts = {} - for name in self.used_names: - s = self.two_point_data.get_spectrum(name) - for b1, b2 in s.bin_pairs: - option_name = "angle_range_{}_{}_{}".format(name, b1, b2) - if self.options.has_value(option_name): - r = self.options.get_double_array_1d(option_name) - scale_cuts[(name, b1, b2)] = r - - # Now check for completely cut bins - # example: - # cut_wtheta = 1,2 1,3 2,3 - bin_cuts = [] - for name in self.used_names: - s = self.two_point_data.get_spectrum(name) - option_name = "cut_{}".format(name) - if self.options.has_value(option_name): - cuts = self.options[option_name].split() - cuts = [eval(cut) for cut in cuts] - for b1, b2 in cuts: - bin_cuts.append((name, b1, b2)) - - if scale_cuts or bin_cuts: - self.two_point_data.mask_scales(scale_cuts, bin_cuts) - else: - print("No scale cuts mentioned in ini file.") - - # Info on which likelihoods we do and do not use - print("Found these data sets in the file:") - total_data_points = 0 - final_names = [spectrum.name for spectrum in self.two_point_data.spectra] - for name in all_names: - if name in final_names: - data_points = len(self.two_point_data.get_spectrum(name)) - else: - data_points = 0 - if name in self.used_names: - print( - " - {} {} data points after cuts {}".format( - name, data_points, " [using in likelihood]" - ) - ) - total_data_points += data_points - else: - print( - " - {} {} data points after cuts {}".format( - name, data_points, " [not using in likelihood]" - ) - ) - print("Total data points used = {}".format(total_data_points)) - - # Convert all units to radians. The units in cosmosis are all - # in radians, so this is the easiest way to compare them. - for spectrum in self.two_point_data.spectra: - if spectrum.is_real_space(): - spectrum.convert_angular_units("rad") - # if self.options.get_bool("print physical scale",False): - # section,_,_=theory_names(spectrum) - # chi_peak = - # for ang in spectrum.angle: - - # build up the data vector from all the separate vectors. - # Just concatenation - data_vector = np.concatenate( - [spectrum.value for spectrum in self.two_point_data.spectra] - ) - - # Make sure - if len(data_vector) == 0: - raise ValueError( - "No data was chosen to be used from 2-point data file {0}. It was either not selectedin data_sets or cut out".format( - filename - ) - ) - - if self.moped: - data_file = fits.open(filename) - self.moped_data = data_file["MOPED-DATA-{}".format(self.moped)].data[ - "moped" - ] - self.moped_transform = data_file[ - "MOPED-TRANSFORM-{}".format(self.moped) - ].data - data_file.close() - - return None, self.moped_data - - # The x data is not especially useful here, so return None. - # We will access the self.two_point_data directly later to - # determine ell/theta values - return None, data_vector - - def build_covariance(self): - - C = np.array(self.two_point_data.covmat) - r = self.options.get_int("covariance_realizations", default=-1) - self.sellentin = self.options.get_bool("sellentin", default=False) - - if self.moped: - return np.identity(len(self.moped_data)) - - if self.sellentin: - if not self.constant_covariance: - print() - print("You asked for the Sellentin-Heavens correction to be applied") - print("But also asked for a non-constant (maybe Gaussian?) covariance") - print("matrix. I think that probably suggests you have made a mistake") - print("somewhere unless you have thought about this quite carefully.") - print() - if r < 0: - print() - print("ERROR: You asked for the Sellentin-Heavens corrections") - print( - "by setting sellentin=T, but you did not set covariance_realizations" - ) - print("If you want covariance_realizations=infinity you can use 0") - print( - "(unlikely, but it's also possible you were super-perverse and set it negative?)" - ) - print() - raise ValueError( - "Please set covariance_realizations for 2pt like. See message above." - ) - elif r == 0: - print() - print("NOTE: You asked for the Sellentin-Heavens corrections") - print("but set covariance_realizations=0. I am assuming you want") - print( - "the limit of an infinite number of realizations, so we will just go back" - ) - print("to the original Gaussian model") - print() - self.sellentin = False - else: - # use proper correction - self.covariance_realizations = r - print() - print( - "You set sellentin=T so I will apply the Sellentin-Heavens correction" - ) - print("for a covariance matrix estimated from Monte-Carlo simulations") - print("(you told us it was {} simulations in the ini file)".format(r)) - print( - "This analytic marginalization converts the Gaussian distribution" - ) - print("to a multivariate student's t distribution instead.") - print() - - elif r > 0: - # Just regular increase in covariance size, no Sellentin change. - p = C.shape[0] - # This x is the inverse of the alpha used in the old code - # because that applied to the weight matrix not the covariance - x = (r - 1.0) / (r - p - 2.0) - C = C * x - print() - print( - "You set covariance_realizations={} in the 2pt likelihood parameter file".format( - r - ) - ) - print( - "So I will apply the Anderson-Hartlap correction to the covariance matrix" - ) - print("The covariance matrix is nxn = {}x{}".format(p, p)) - print( - "So the correction scales the covariance matrix by (r - 1) / (r - n - 2) = {}".format( - x - ) - ) - print() - return C - - def extract_theory_points(self, block): - theory = [] - # We may want to save these splines for the covariance matrix later - self.theory_splines = {} - - # We have a collection of data vectors, one for each spectrum - # that we include. We concatenate them all into one long vector, - # so we do the same for our theory data so that they match - - # We will also save angles and bin indices for plotting convenience, - # although these are not actually used in the likelihood - angle = [] - bin1 = [] - bin2 = [] - - # Get appropriate suffixes - # If only a single suffix is provided, assume this applies to all data sets - if len(self.suffixes) == 1: - suffixes = np.tile(self.suffixes[0], len(self.two_point_data.spectra)) - elif len(self.suffixes) > 1 and len(self.suffixes) == len( - self.two_point_data.spectra - ): - suffixes = self.suffixes - else: - raise ValueError( - "The number of suffixes supplied does not match the number of two point spectra." - ) - - # Now we actually loop through our data sets - for ii, spectrum in enumerate(self.two_point_data.spectra): - theory_vector, angle_vector, bin1_vector, bin2_vector = ( - self.extract_spectrum_prediction(block, spectrum, suffixes[ii]) - ) - theory.append(theory_vector) - angle.append(angle_vector) - bin1.append(bin1_vector) - bin2.append(bin2_vector) - # dataset_name.append(np.repeat(spectrum.name, len(bin1_vector))) - - # We also collect the ell or theta values. - # The gaussian likelihood code itself is not expecting these, - # so we just save them here for convenience. - angle = np.concatenate(angle) - bin1 = np.concatenate(bin1) - bin2 = np.concatenate(bin2) - # dataset_name = np.concatenate(dataset_name) - block[names.data_vector, self.like_name + "_angle"] = angle - block[names.data_vector, self.like_name + "_bin1"] = bin1 - block[names.data_vector, self.like_name + "_bin2"] = bin2 - # block[names.data_vector, self.like_name+"_name"] = dataset_name - - # the thing it does want is the theory vector, for comparison with - # the data vector - theory = np.concatenate(theory) - - if self.moped: - return np.dot(self.moped_transform, theory) - - return theory - - def do_likelihood(self, block): - # Run the - super(TwoPointLikelihood, self).do_likelihood(block) - - if self.sellentin: - # The Sellentin-Heavens correction from arxiv 1511.05969 - # accounts for a finite number of Monte-Carlo realizations - # being used to estimate the covariance matrix. - - # Note that this invalidates the saved simulation used for - # the ABC sampler. I can't think of a better way of doing this - # than overwriting the whole things with NaNs - that will at - # least make clear there is a problem somewhere and not - # yield misleading results. - block[names.data_vector, self.like_name + "_simulation"] = ( - np.nan * block[names.data_vector, self.like_name + "_simulation"] - ) - - # It changes the Likelihood from Gaussian to a multivariate - # student's t distribution. Here we will have to do a little - # hack and overwrite the stuff that the original Gaussian - # method did above - N = self.covariance_realizations - chi2 = block[names.data_vector, self.like_name + "_CHI2"] - - # We might be using a cosmologically varying - # covariance matrix, though I'm not sure what that would mean. - # There is a warning about this above. - if self.constant_covariance: - log_det = 0.0 - else: - log_det = block[names.data_vector, self.like_name + "_LOG_DET"] - - like = -0.5 * log_det - 0.5 * N * np.log(1 + chi2 / (N - 1.0)) - - # overwrite the log-likelihood - block[names.likelihoods, self.like_name + "_LIKE"] = like - - # Should suffix be made into a keyword? - def extract_spectrum_prediction(self, block, spectrum, suffix): - - # We may need theory predictions for multiple different - # types of spectra: e.g. shear-shear, pos-pos, shear-pos. - # So first we find out from the spectrum where in the data - # block we expect to find these - mapping spectrum types - # to block names - section, x_name, y_name = theory_names(spectrum) - - # To handle multiple different data sets we allow a suffix - # to be applied to the section names, so that we can look up - # e.g. "shear_cl_des" instead of just "shear_cl". - section += suffix - - # Initialize TheorySpectrum class from block - bin_pairs = spectrum.get_bin_pairs() - theory_spec = TheorySpectrum.from_block(block, section, bin_pairs=bin_pairs) - - # If the theory spectrum has been bin-averaged then we expect the - # data to be so also. We check this by ensuring that angle_min is specified - # Based on this, we also generate the angle argument passed to the spectrum - # differently. The bin-averaged version expects a tuple angle_min and angle_max, - # whereas the interpolated version just wants a single angle. - if theory_spec.is_bin_averaged: - if spectrum.angle_min is None: - raise ValueError( - "Your theory pipeline produced angle-binnned values, but your data it not binned." - ) - angles = list(zip(spectrum.angle_min, spectrum.angle_max)) - else: - angles = spectrum.angle - - # We store the nominal mid-points for plotting later on, etc. - angle_mids = spectrum.angle - - # This is a bit of a hack, but later on if we are making a covariance - # we need all the splines, so pull them out here. - bin_splines = {} - - # We build up these vectors from all the data points. - # Only the theory vector is needed for the likelihood - the others - # are for convenience, debugging, etc. - theory_vector = [] - angle_vector = [] - bin1_vector = [] - bin2_vector = [] - - for b1, b2, angle, angle_mid in zip( - spectrum.bin1, spectrum.bin2, angles, angle_mids - ): - # The extra object will either be a spline (for interpolated spectra) - # or theta mid-point values (for bin-averaged ones, e.g. for plotting) - theory, extra = theory_spec.get_spectrum_value(b1, b2, angle) - - # We can only record the splines for non-bin-averaged values - if not theory_spec.is_bin_averaged: - bin_splines[y_name.format(b1, b2)] = extra - - # Build up the vector - we make this into an array later - theory_vector.append(theory) - angle_vector.append(angle_mid) - bin1_vector.append(b1) - bin2_vector.append(b2) - - self.theory_splines[section] = bin_splines - - # Return the whole collection as an array - theory_vector = np.array(theory_vector) - - # For convenience we also save the angle vector (ell or theta) - # and bin indices - angle_vector = np.array(angle_vector) - bin1_vector = np.array(bin1_vector, dtype=int) - bin2_vector = np.array(bin2_vector, dtype=int) - - return theory_vector, angle_vector, bin1_vector, bin2_vector - - def extract_covariance(self, block): - assert self.gaussian_covariance, ( - "Set constant_covariance=F but somehow not with Gaussian covariance. Internal error - please open an issue on the cosmosis site." - ) - - C = [] - # s and t index the spectra that we have. e.g. s or t=1 might be the full set of - # shear-shear measuremnts - for s, AB in enumerate(self.two_point_data.spectra[:]): - M = [] - for t, CD in enumerate(self.two_point_data.spectra[:]): - print( - "Looking at covariance between {} and {} (s={}, t={})".format( - AB.name, CD.name, s, t - ) - ) - # We only calculate the upper triangular. - # Get the lower triangular here. We have to - # transpose it compared to the upper one. - if s > t: - MI = C[t][s].T - else: - MI = gaussian_covariance.compute_gaussian_covariance( - self.sky_area, self._lookup_theory_cl, block, AB, CD - ) - M.append(MI) - C.append(M) - - # C is now a list of lists of 2D arrays. - # Now turn C into a big 2D array by stacking - # the arrays - C = np.vstack([np.hstack(CI) for CI in C]) - - return C - - def _lookup_theory_cl(self, block, A, B, i, j, ell): - """ - This is a helper function for the compute_gaussian_covariance code. - It looks up the theory value of C^{ij}_{AB}(ell) in the - """ - # We have already saved splines into the theory space earlier - # when constructing the theory vector. - # So now we just need to look those up again, using the same - # code we use in the twopoint library. - section, ell_name, value_name = type_table[A, B] - assert ell_name == "ell", ( - "Gaussian covariances are currently only written for C_ell, not other 2pt functions" - ) - d = self.theory_splines[section] - - # We save the splines with these names when we extract the theory vector - name_ij = value_name.format(i, j) - name_ji = value_name.format(j, i) - - # Hopefully we already have the theory spline extracted - if name_ij in d: - spline = d[name_ij] - # For symmetric spectra (not just auto-correlations, but any thing like C_EE or C_NN where - # we cross-correlate something with itself) we can use ji for ij as it is the same. This is - # not true for cross spectra - elif name_ji in d and (A == B): - spline = d[name_ji] - else: - # It's possible too that we need something for the covariance that we didn't need for the - # data vector - for example to got the covariance between C^EE and C^NN we need C^NE even - # if we don't have any actual measurements of NE. In that case we have to g - angle_theory = block[section, ell_name] - if block.has_value(section, name_ij): - theory = block[section, name_ij] - # The same symmetry argument as above applies - elif block.has_value(section, name_ji) and A == B: - theory = block[section, name_ji] - else: - raise ValueError( - "Could not find theory prediction {} in section {}".format( - value_name.format(i, j), section - ) - ) - - spline = interp1d(angle_theory, theory) - # Finally cache this so we don't have to do this again. - d[name_ij] = spline - - obs_cl = spline(ell) - - # For shear-shear the noise component is sigma^2 / number_density_bin - # and for position-position it is just 1/number_density_bin - if ( - (A == B) - and (A == twopoint.Types.galaxy_shear_emode_fourier.name) - and (i == j) - ): - if ( - i > len(self.number_density_shear_bin) - or i > len(self.sigma_e_bin) - or is_default(self.sigma_e_bin) - or is_default(self.number_density_shear_bin) - ): - raise ValueError("Not enough number density bins for shear specified") - noise = self.sigma_e_bin[i - 1] ** 2 / convert_nz_steradian( - self.number_density_shear_bin[i - 1] - ) - obs_cl += noise - if (A == B) and (A == twopoint.Types.galaxy_position_fourier.name) and (i == j): - if i > len(self.number_density_lss_bin) or is_default( - self.number_density_lss_bin - ): - raise ValueError("Not enough number density bins for lss specified") - noise = 1.0 / convert_nz_steradian(self.number_density_lss_bin[i - 1]) - obs_cl += noise - - return obs_cl - - def update_xi_w_sys(self, block): - self.data_y = self.raw_data_y + block["xi_sys", "xi_sys_vec"] - - @classmethod - def build_module(cls): - - def setup(options): - options = SectionOptions(options) - likelihoodCalculator = cls(options) - return likelihoodCalculator - - def execute(block, config): - likelihoodCalculator = config - likelihoodCalculator.update_xi_w_sys(block) - # print(likelihoodCalculator.data_y) - likelihoodCalculator.do_likelihood(block) - return 0 - - def cleanup(config): - likelihoodCalculator = config - likelihoodCalculator.cleanup() - - return setup, execute, cleanup - - -setup, execute, cleanup = TwoPointLikelihood.build_module() diff --git a/cosmo_inference/scripts/chain_postprocessing.py b/cosmo_inference/scripts/chain_postprocessing.py deleted file mode 100644 index 83cddf4b..00000000 --- a/cosmo_inference/scripts/chain_postprocessing.py +++ /dev/null @@ -1,799 +0,0 @@ -""" -Scripts to postprocess the CosmoSIS chains -Author: Sacha Guerrini -""" - -import configparser -import os -import subprocess - -import matplotlib.pyplot as plt -import numpy as np -from astropy.io import fits -from getdist import plots - -# Mapping for CosmoSIS ini files section -section_map = { - "omch2": "cosmological_parameters", - "ombh2": "cosmological_parameters", - "h0": "cosmological_parameters", - "n_s": "cosmological_parameters", - "s_8_input": "cosmological_parameters", - "logt_agn": "halo_model_parameters", - "a": "intrinsic_alignment_parameters", - "m1": "shear_calibration_parameters", - "bias_1": "nofz_shifts", - "alpha": "psf_leakage_parameters", - "beta": "psf_leakage_parameters", -} - - -# Utils functions -def compute_average(chain, param_name): - """ - Compute the average of a parameter from a CosmoSIS chain - """ - margestats = chain.getMargeStats() - param_stats = margestats.parWithName(param_name) - return param_stats.mean - - -def compute_map_1D(chain, param_name, num_bins=1000): - """ - Compute the MAP value of a parameter from a CosmoSIS chain using 1D KDE - """ - param_names_getdist = chain.getParamNames() - par = param_names_getdist.parWithName(param_name) - kde = chain.get1DDensity(par, num_bins=num_bins) - kde_map = kde.x[np.argmax(kde.P)] - return kde_map - - -def compute_map_2D(chain, param_name_x, param_name_y, num_bins=1000): - """ - Compute the MAP value of two parameters from a CosmoSIS chain using 2D KDE - """ - param_names_getdist = chain.getParamNames() - par_x = param_names_getdist.parWithName(param_name_x) - par_y = param_names_getdist.parWithName(param_name_y) - kde = chain.get2DDensity(par_x, par_y, fine_bins_2D=num_bins) - kde_map_index = np.unravel_index(np.argmax(kde.P), kde.P.shape) - return kde.x[kde_map_index[1]], kde.y[kde_map_index[0]] - - -def compute_limits(chain, param_name): - """ - Compute the 68% and 95% confidence limits of a parameter from a CosmoSIS chain. - """ - margestats = chain.getMargeStats() - param_stats = margestats.parWithName(param_name) - return ( - param_stats.limits[0].upper, - param_stats.limits[0].lower, - param_stats.limits[1].upper, - param_stats.limits[1].lower, - ) - - -def load_samples_and_write_paramnames( - path_samples, path_paramnames, chain_type="polychord" -): - """ - Load the samples from a CosmoSIS chain and write the parameter names to a file - """ - with open(path_samples, "r") as file: - if chain_type == "nautilus": - params = file.readline()[1:].split("\t")[:-3] - else: - params = file.readline()[1:].split("\t")[:-4] - file.close() - - with open(path_paramnames, "w") as file: - for i in range(len(params)): - if len(params[i].split("--")) > 1: - param_name = params[i].split("--")[1] - if "Legacy" in path_paramnames and param_name not in [ - "OMEGA_M", - "SIGMA_8", - ]: - continue - file.write(param_name + "\n") - else: - param_name = params[i].split("--")[0] - if "Legacy" in path_paramnames and param_name not in [ - "OMEGA_M", - "SIGMA_8", - ]: - continue - file.write(param_name + "\n") - file.close() - return 0 - - -def write_samples_getdist_format(path_samples, path_gd, chain_type="polychord"): - """ - Load the samples from a CosmoSIS chain and write them in GetDist format - """ - samples = np.loadtxt(path_samples) - if chain_type == "nautilus": - if "Legacy" in path_gd: - samples = np.column_stack( - ( - np.exp(samples[:, -3]), - samples[:, -2] - samples[:, -1], - samples[:, 21], - samples[:, 23], - ) - ) - else: - samples = np.column_stack( - ( - np.exp(samples[:, -3]), - samples[:, -2] - samples[:, -1], - samples[:, 0:-3], - ) - ) - mask = np.isfinite(samples[:, 1]) - samples = samples[mask] - else: - samples = np.column_stack((samples[:, -1], samples[:, -2], samples[:, 0:-4])) - np.savetxt(path_gd, samples) - return 0 - - -def load_chain(path_gd, smoothing_scale=0.3): - g = plots.get_single_plotter() - chain = g.samples_for_root( - path_gd, - cache=False, - settings={ - "ignore_rows": 0, - "smooth_scale_1D": smoothing_scale, - "smooth_scale_2D": smoothing_scale, - }, - ) - return chain - - -def extract_best_fit_params(chain, best_fit_method="weighted_mean"): - best_fit_params = {} - chain.getMargeStats() - likestats = chain.getLikeStats() - for i, par in enumerate(likestats.names): - if best_fit_method == "weighted_mean": - best_fit = compute_average(chain, par.name) - elif best_fit_method == "1Dkde": - best_fit = compute_map_1D(chain, par.name) - elif best_fit_method == "2Dkde": - # If the parameter is S8 or Omega_m, use the 2D KDE - if par.name == "S_8" or par.name == "s_8_input" or par.name == "OMEGA_M": - s8_map_2D, omega_m_map_2D = compute_map_2D(chain, "S_8", "OMEGA_M") - best_fit = ( - s8_map_2D - if par.name == "S_8" or par.name == "s_8_input" - else omega_m_map_2D - ) - else: - best_fit = compute_map_1D(chain, par.name) - else: - raise ValueError( - "Invalid best fit method. Choose one of: '2Dkde', '1Dkde', 'weighted_mean'" - ) - best_fit_params.update({par.name: best_fit}) - return best_fit_params - - -def compute_best_fit( - path_ini_files, best_fit, root, is_harmonic, blind=None, ini_file_root=None -): - # Check if the values empty ini file exists - if not os.path.exists(path_ini_files + "/values_empty.ini"): - content = """[cosmological_parameters] - - tau = 0.0544 - w = -1.0 - mnu = 0.06 - omega_k = 0.0 - wa = 0.0 - - [halo_model_parameters] - - [intrinsic_alignment_parameters] - - [shear_calibration_parameters] - - [nofz_shifts] - - [psf_leakage_parameters] - """ - - with open(path_ini_files + "/values_empty.ini", "w") as f: - f.write(content) - f.close() - - print("File created successfully") - - # Load cosmosis in the library path - env = os.environ.copy() - env["LD_LIBRARY_PATH"] = ( - "/home/guerrini/.conda/envs/sp_validation/lib/python3.9/site-packages/cosmosis/datablock:" - + env.get("LD_LIBRARY_PATH", "") - ) - - config = configparser.ConfigParser() - config.optionxform = str # Preserve case sensitivity of option names - config.read(path_ini_files + "/values_empty.ini") - for param, value in best_fit.items(): - section = section_map.get(param) - if section is None: - continue - if section not in config: - config.add_section(section) - config[section][param] = str(value) - - with open(path_ini_files + "/values_empty.ini", "w") as configfile: - config.write(configfile) - - # Modify the ini file to run in test mode at the best fit - config = configparser.ConfigParser() - config.optionxform = str # Preserve case sensitivity of option names - if ini_file_root is None: - # If the ini file root is not provided, we construct it based on the root and blind parameters - if blind is not None: - subdir = ( - f"harmonic_space_fiducial_{blind}" if is_harmonic else "" - ) # TODO: add real space subdir if needed - else: - subdir = "" - ini_file_root = os.path.join( - path_ini_files, subdir, f"cosmosis_pipeline_{root}_cell.ini" - ) - config.read(ini_file_root) - - sampler = config["runtime"]["sampler"] - config["runtime"]["sampler"] = "test" - values = config["pipeline"]["values"] - config["pipeline"]["values"] = path_ini_files + "/values_empty.ini" - - with open(ini_file_root, "w") as configfile: - config.write(configfile) - - # Run cosmosis - os.chdir("/home/guerrini/sp_validation/cosmo_inference") - result = subprocess.run( - ["cosmosis", ini_file_root], env=env, capture_output=True, text=True - ) - print(f"STDOUT:\n{result.stdout}") - print(f"STDERR:\n{result.stderr}") - - # Modify the ini file to the previous one - config["pipeline"]["values"] = values - config["runtime"]["sampler"] = sampler - - with open(ini_file_root, "w") as configfile: - config.write(configfile) - - -def compute_best_fit_xi_from_cell(output_folder, root, best_fit_params, theta_rad): - - ell = np.loadtxt(output_folder + "{}/best_fit/shear_cl/ell.txt".format(root)) - shear_cl = np.loadtxt( - output_folder + "{}/best_fit/shear_cl/bin_1_1.txt".format(root) - ) - - import pyccl as ccl - - cosmo = ccl.Cosmology( - Omega_c=best_fit_params["omch2"] / (best_fit_params["h0"] / 100) ** 2, - Omega_b=best_fit_params["ombh2"] / (best_fit_params["h0"] / 100) ** 2, - h=best_fit_params["h0"] / 100, - n_s=best_fit_params["n_s"], - sigma8=best_fit_params["SIGMA_8"], - baryonic_effects=None, - extra_parameters={ - "camb": { - "halofit_version": "mead2020_feedback", - "HMCode_logT_AGN": best_fit_params["logt_agn"], - } - }, - ) - - theta_deg = np.rad2deg(theta_rad) - xi_p = ccl.correlation(cosmo, ell=ell, C_ell=shear_cl, theta=theta_deg, type="GG+") - xi_m = ccl.correlation(cosmo, ell=ell, C_ell=shear_cl, theta=theta_deg, type="GG-") - - os.makedirs( - output_folder + "{}/best_fit/shear_xi_minus".format(root), exist_ok=True - ) - os.makedirs(output_folder + "{}/best_fit/shear_xi_plus".format(root), exist_ok=True) - - np.savetxt( - output_folder + "{}/best_fit/shear_xi_plus/bin_1_1.txt".format(root), xi_p - ) - np.savetxt( - output_folder + "{}/best_fit/shear_xi_minus/bin_1_1.txt".format(root), xi_m - ) - np.savetxt( - output_folder + "{}/best_fit/shear_xi_plus/theta.txt".format(root), theta_rad - ) - np.savetxt( - output_folder + "{}/best_fit/shear_xi_minus/theta.txt".format(root), theta_rad - ) - - print( - f"Best fit xi+ and xi- from Cl's computed and saved in {output_folder + '{}/best_fit/shear_xi_plus'.format(root)} and {output_folder + '{}/best_fit/shear_xi_minus'.format(root)}" - ) - - -def adjust_paramname_chain(chain, current_name, target_name, label): - """ - Adjusts the parameter name and label in a GetDist chain. - """ - param_names = chain.getParamNames() - par = param_names.parWithName(current_name) - - par.label = label - par.name = target_name - - chain.setParamNames(param_names) - - -def derive_parameter_S8(chain): - """ - Derives the S_8 parameter from Omega_m and Sigma_8 in a GetDist chain. - S_8 = Sigma_8 * (Omega_m / 0.3) ** 0.5 - """ - omega_m = chain.getParams().OMEGA_M - sigma_8 = chain.getParams().SIGMA_8 - - s_8 = sigma_8 * (omega_m / 0.3) ** 0.5 - - chain.addDerived(s_8, name="S_8", label=r"S_8") - - return chain - - -def derive_parameter_Om(chain): - """ - Derives the Omega_m parameter from omch2 and h0 in a GetDist chain. - """ - omch2 = chain.getParams().omch2 - h0 = chain.getParams().h0 - - omega_m = omch2 / (h0 / 100) ** 2 - - chain.addDerived(omega_m, name="OMEGA_M", label=r"\Omega_{\rm m}") - - return chain - - -def get_sigma_tension(mean1, low1, high1, mean2, low2, high2): - sigma1 = 0.5 * (high1 + low1) - sigma2 = 0.5 * (high2 + low2) - delta_mean = np.abs(mean1 - mean2) - sigma_tension = delta_mean / np.sqrt(sigma1**2 + sigma2**2) - sign = 1 if mean1 > mean2 else -1 - return sigma_tension * sign - - -def read_config(path_ini_files, root, thisfile=None): - config = configparser.ConfigParser() - config.optionxform = str - if thisfile is not None: - read_path = thisfile - else: - read_path = os.path.join(path_ini_files, f"{root}.ini") - config.read(read_path) - return config - - -def update_properties_w_roots( - properties, root, path_ini_files, path_to_this_ini=None, with_configuration=False -): - config = read_config(path_ini_files, root, thisfile=path_to_this_ini) - - try: - lower_bound_cell_ee, upper_bound_cell_ee = map( - float, config["2pt_like"]["angle_range_CELL_EE_1_1"].split() - ) - properties[root].update( - { - "lower_bound_cell_ee": lower_bound_cell_ee, - "upper_bound_cell_ee": upper_bound_cell_ee, - } - ) - except KeyError: - properties[root] = {"lower_bound_cell_ee": 0.0, "upper_bound_cell_ee": 2048} - - if with_configuration: - # Also save the scale cuts in theta for xi - add_xi_sys = config["2pt_like"]["add_xi_sys"] - add_xi_sys = add_xi_sys == "T" - lower_bound_xi_plus, upper_bound_xi_plus = map( - float, config["2pt_like"]["angle_range_XI_PLUS_1_1"].split() - ) - lower_bound_xi_minus, upper_bound_xi_minus = map( - float, config["2pt_like"]["angle_range_XI_MINUS_1_1"].split() - ) - - properties[root].update( - { - "add_xi_sys": add_xi_sys, - "lower_bound_xi_plus": lower_bound_xi_plus, - "upper_bound_xi_plus": upper_bound_xi_plus, - "lower_bound_xi_minus": lower_bound_xi_minus, - "upper_bound_xi_minus": upper_bound_xi_minus, - } - ) - return properties - - -def plot_best_fit( - data_points, - root_to_plot, - output_folder, - line_args, - savefile, - ell_min=10.0, - ell_max=2048.0, - multiply_ell=True, - loc_legend="best", - bbox_to_anchor=None, - label_data="Fiducial data", - labels=None, - properties=None, - paths_to_bestfit=None, -): - data = fits.open( - f"/home/guerrini/sp_validation/cosmo_inference/data/{data_points}/cosmosis_{data_points}.fits" - ) - cell_ee = data["CELL_EE"].data - cov_mat = data["COVMAT"].data - - if labels is None: - labels = root_to_plot - - fig, ax = plt.subplots(1, 1, figsize=(8, 5)) - - ell, cell = cell_ee["ANG"], cell_ee["VALUE"] - ax.errorbar( - ell, - ell * cell, - yerr=ell * np.sqrt(np.diag(cov_mat)), - fmt="o", - label=label_data, - color="black", - capsize=2, - ) - - for idx, (label, root) in enumerate(zip(labels, root_to_plot)): - # Read the results - if paths_to_bestfit is None: - ell = np.loadtxt( - output_folder - + "{}/best_fit/shear_cl/ell.txt".format( - root, - ) - ) - shear_cl = np.loadtxt( - output_folder - + "{}/best_fit/shear_cl/bin_1_1.txt".format( - root, - ) - ) - else: - ell = np.loadtxt(paths_to_bestfit[idx] + "best_fit/shear_cl/ell.txt") - shear_cl = np.loadtxt( - paths_to_bestfit[idx] + "best_fit/shear_cl/bin_1_1.txt" - ) - - mask = (ell > ell_min) & (ell < ell_max) - - ax.plot( - ell[mask], - ell[mask] * shear_cl[mask] if multiply_ell else shear_cl[mask], - label=label, - **line_args[idx], - ) - - # Plot the scale cuts for different k_max - ax.axvline(x=1800, color="black", linestyle="--", alpha=0.5) - ax.axvline(x=2048, color="black", linestyle="--", alpha=1.0) - ax.axvline(x=500, color="black", linestyle="--", alpha=0.3) - - ymin = ax.get_ylim()[0] - ymax = ax.get_ylim()[1] - # Shadowing cut scaled - ax.fill_betweenx( - y=[ymin, ymax], - x1=0, - x2=300, - color="gray", - alpha=0.2, - label=r"$B$-mode informed scale cut", - ) - ax.fill_betweenx(y=[ymin, ymax], x1=1600, x2=2048, color="gray", alpha=0.2) - - ax.set_ylim(ymin, ymax) - - # Add labels directly under the tick - ax.text( - 1740, - 0.90, - r"$k_\mathrm{max} = 3 h$ Mpc$^{-1}$", - transform=ax.get_xaxis_transform(), - ha="center", - va="top", - fontsize=14, - rotation=90, - ) - - ax.text( - 1978, - 0.90, - r"$k_\mathrm{max} = 5 h$ Mpc$^{-1}$", - transform=ax.get_xaxis_transform(), - ha="center", - va="top", - fontsize=14, - rotation=90, - ) - - ax.text( - 470, - 0.90, - r"$k_\mathrm{max} = 1 h$ Mpc$^{-1}$", - transform=ax.get_xaxis_transform(), - ha="center", - va="top", - fontsize=14, - rotation=90, - ) - - ell, cell = cell_ee["ANG"], cell_ee["VALUE"] - ax.set_ylabel(r"$\ell C_\ell \times 10^{-7}$", fontsize=20) - ax.set_xlabel(r"Multipole $\ell$", fontsize=20) - ax.set_xlim(ell.min() - 10, ell.max() + 100) - ax.set_xscale("squareroot") - ax.set_xticks(np.array([100, 400, 900, 1600])) - ax.minorticks_on() - ax.tick_params(axis="x", which="minor", length=2, width=0.8) - minor_ticks = [i * 10 for i in range(1, 10)] + [i * 100 for i in range(1, 21)] - ax.xaxis.set_ticks(minor_ticks, minor=True) - ax.tick_params(axis="both", which="major", labelsize=14) - ax.tick_params(axis="both", which="minor", labelsize=10) - ax.yaxis.get_offset_text().set_visible(False) - - plt.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor, fontsize=11) - - if savefile is not None: - plt.savefig(savefile, bbox_inches="tight") - - plt.show() - - -def plot_best_fit_config( - data, - root_to_plot, - output_folder, - line_args, - savefile, - theta_min=1.0, - theta_max=250.0, - multiply_theta=True, - loc_legend="best", - bbox_to_anchor_xip=None, - bbox_to_anchor_xim=None, - label_data="Fiducial data", - labels=None, - properties=None, - paths_to_bestfit=None, -): - - data = fits.open(data) - - xi_p_data = data["XI_PLUS"].data - xi_m_data = data["XI_MINUS"].data - cov_mat = data["COVMAT"].data - - # Plot hyperparameter - loc_legend = "lower center" - - fig, [ax, ax2] = plt.subplots(2, 1, figsize=(8, 9)) - - theta, xi_p, xi_m = xi_p_data["ANG"], xi_p_data["VALUE"], xi_m_data["VALUE"] - ax.errorbar( - theta, - theta * xi_p, - yerr=theta * np.sqrt(np.diag(cov_mat[: len(theta), : len(theta)])), - fmt="o", - label=r"UNIONS $\xi_+$ data", - color="black", - capsize=2, - ) - ax2.errorbar( - theta, - theta * xi_m, - yerr=theta - * np.sqrt( - np.diag(cov_mat[len(theta) : 2 * len(theta), len(theta) : 2 * len(theta)]) - ), - fmt="o", - label=r"UNIONS $\xi_-$ data", - color="black", - capsize=2, - ) - - for idx, (label, root) in enumerate(zip(labels, root_to_plot)): - # Read the results - if paths_to_bestfit is None: - theta = ( - ( - np.loadtxt( - output_folder - + "{}/best_fit/shear_xi_plus/theta.txt".format(root) - ) - ) - * 180 - / np.pi - * 60 - ) - xi_plus = np.loadtxt( - output_folder + "{}/best_fit/shear_xi_plus/bin_1_1.txt".format(root) - ) - xi_minus = np.loadtxt( - output_folder + "{}/best_fit/shear_xi_minus/bin_1_1.txt".format(root) - ) - if r"$C_\ell$" not in label: - xi_sys_plus = np.loadtxt( - output_folder + "{}/best_fit/xi_sys/shear_xi_plus.txt".format(root) - ) - xi_sys_minus = np.loadtxt( - output_folder + "{}/best_fit/xi_sys/shear_xi_minus.txt".format(root) - ) - theta_xi_sys = ( - np.loadtxt( - output_folder + "{}/best_fit/xi_sys/theta.txt".format(root) - ) - * 180 - / np.pi - * 60 - ) - xi_plus += np.interp(theta, theta_xi_sys, xi_sys_plus) - xi_minus += np.interp(theta, theta_xi_sys, xi_sys_minus) - else: - theta = ( - (np.loadtxt(paths_to_bestfit[idx] + "best_fit/shear_xi_plus/theta.txt")) - * 180 - / np.pi - * 60 - ) - xi_plus = np.loadtxt( - paths_to_bestfit[idx] + "best_fit/shear_xi_plus/bin_1_1.txt" - ) - xi_minus = np.loadtxt( - paths_to_bestfit[idx] + "best_fit/shear_xi_minus/bin_1_1.txt" - ) - if r"$C_\ell$" not in label: - xi_sys_plus = np.loadtxt( - output_folder + "{}/best_fit/xi_sys/shear_xi_plus.txt".format(root) - ) - xi_sys_minus = np.loadtxt( - output_folder + "{}/best_fit/xi_sys/shear_xi_minus.txt".format(root) - ) - theta_xi_sys = ( - np.loadtxt( - output_folder + "{}/best_fit/xi_sys/theta.txt".format(root) - ) - * 180 - / np.pi - * 60 - ) - xi_plus += np.interp(theta, theta_xi_sys, xi_sys_plus) - xi_minus += np.interp(theta, theta_xi_sys, xi_sys_minus) - - mask = (theta > theta_min) & (theta < theta_max) - theta = theta[mask] - ax.plot( - theta, - theta * xi_plus[mask] if multiply_theta else xi_plus[mask], - label=label, - **line_args[idx], - ) - ax2.plot( - theta, - theta * xi_minus[mask] if multiply_theta else xi_minus[mask], - label=label, - **line_args[idx], - ) - - # XI PLUS PLOT SETTINGS - - # Plot the scale cuts for different k_max - ax.axvline(x=3.2, color="black", linestyle="--", alpha=0.7) - - ymin = ax.get_ylim()[0] - ymax = ax.get_ylim()[1] - # Shadowing cut scaled - ax.fill_betweenx( - y=[ymin, ymax], - x1=0, - x2=12, - color="gray", - alpha=0.2, - label=r"$B$-mode informed scale cut", - ) - ax.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color="gray", alpha=0.2) - - ax.set_ylim(ymin, ymax) - - # Add labels directly under the tick - ax.text( - 2.9, - 1.23e-4, - r"$k_\mathrm{max} = 1 h$ Mpc$^{-1}$", - ha="center", - va="top", - fontsize=14, - rotation=90, - ) - - # ax.set_ylabel('$\theta \xi_+$', fontsize=16) - # ax.set_xlabel('$\theta$', fontsize=16) - ax.set_xlim([theta.min() - 0.1, theta.max() + 20]) - ax.set_xscale("log") - ax.set_xticks(np.array([1, 10, 100])) - ax.tick_params(axis="x", which="minor", length=2, width=0.8) - ax.tick_params(axis="both", which="major", labelsize=14) - ax.tick_params(axis="both", which="minor", labelsize=10) - ax.yaxis.get_offset_text().set_fontsize(14) - ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) - ax.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xip, fontsize=12) - - # XI_MINUS PLOT SETTINGS - - # Plot the scale cuts for different k_max - ax2.axvline(x=24, color="black", linestyle="--", alpha=0.7) - - ymin = ax2.get_ylim()[0] - ymax = ax2.get_ylim()[1] - # Shadowing cut scaled - ax2.fill_betweenx( - y=[ymin, ymax], - x1=0, - x2=12, - color="gray", - alpha=0.2, - label=r"$B$-mode informed scale cut", - ) - ax2.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color="gray", alpha=0.2) - - ax2.set_ylim(ymin, ymax) - - # Add labels directly under the tick - ax2.text( - 21.8, - 1.15e-4, - r"$k_\mathrm{max} = 1 h$ Mpc$^{-1}$", - ha="center", - va="top", - fontsize=14, - rotation=90, - ) - - ax2.set_ylabel(r"$\theta \xi_-$", fontsize=16) - ax2.set_xlabel(r"$\theta$", fontsize=16) - ax2.set_xlim([theta.min() - 0.1, theta.max() + 20]) - ax2.set_xscale("log") - ax2.set_xticks(np.array([1, 10, 100])) - ax2.tick_params(axis="x", which="minor", length=2, width=0.8) - ax2.tick_params(axis="both", which="major", labelsize=14) - ax2.tick_params(axis="both", which="minor", labelsize=10) - ax2.yaxis.get_offset_text().set_fontsize(14) - ax2.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) - ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=12) - - if savefile is not None: - plt.savefig(savefile, bbox_inches="tight") - - plt.show() diff --git a/cosmo_inference/scripts/cosmocov_process.py b/cosmo_inference/scripts/cosmocov_process.py deleted file mode 100644 index c2c00996..00000000 --- a/cosmo_inference/scripts/cosmocov_process.py +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env python - -import sys - -import matplotlib.pyplot as plt -import numpy as np - - -def get_cov(filename): - - data = np.loadtxt(filename) - ndata = int(np.max(data[:, 0])) + 1 - - print("Dimension of cov: %dx%d" % (ndata, ndata)) - - cov_g = np.zeros((ndata, ndata)) - cov_ng = np.zeros((ndata, ndata)) - for i in range(0, data.shape[0]): - cov_g[int(data[i, 0]), int(data[i, 1])] = data[i, 8] - cov_g[int(data[i, 1]), int(data[i, 0])] = data[i, 8] - cov_ng[int(data[i, 0]), int(data[i, 1])] = data[i, 9] - cov_ng[int(data[i, 1]), int(data[i, 0])] = data[i, 9] - - return cov_g, cov_ng, ndata - - -if __name__ == "__main__": - if len(sys.argv) != 3: - print("Usage: python cosmocov_process.py ") - sys.exit(1) - - covfile = sys.argv[1] - output_base = sys.argv[2] - - c_g, c_ng, ndata = get_cov(covfile) - - cov = c_ng + c_g - cov_g = c_g - - b = np.sort(np.linalg.eigvals(cov)) - print("min+max eigenvalues cov: %e, %e" % (np.min(b), np.max(b))) - if np.min(b) <= 0.0: - print("non-positive eigenvalue encountered! Covariance Invalid!") - exit() - - print("Covariance is positive definite!") - - np.savetxt(str(output_base) + ".txt", cov) - print("covmat saved as %s" % (str(output_base) + ".txt")) - - np.savetxt(str(output_base) + "_g.txt", cov_g) - print("Gaussian covmat saved as %s" % (str(output_base) + "_g.txt")) - - cmap = "seismic" - - pp_norm = np.zeros((ndata, ndata)) - for i in range(ndata): - for j in range(ndata): - pp_norm[i][j] = cov[i][j] / np.sqrt(cov[i][i] * cov[j][j]) - - print("Plotting correlation matrix ...") - - plot_path = str(output_base) + "_plot.pdf" - fig = plt.figure() - ax = fig.add_subplot(1, 1, 1) - extent = (0, ndata, ndata, 0) - im3 = ax.imshow(pp_norm, cmap=cmap, vmin=-1, vmax=1, extent=extent) - - plt.axvline(x=int(ndata / 2), color="black", linewidth=1.0) - plt.axhline(y=int(ndata / 2), color="black", linewidth=1.0) - - fig.colorbar(im3, orientation="vertical") - - ax.text(int(ndata / 4), ndata + 5, r"$\xi_+^{ij}(\theta)$", fontsize=12) - ax.text(3 * int(ndata / 4), ndata + 5, r"$\xi_-^{ij}(\theta)$", fontsize=12) - ax.text(-9, int(ndata / 4), r"$\xi_+^{ij}(\theta)$", fontsize=12) - ax.text(-9, 3 * int(ndata / 4), r"$\xi_-^{ij}(\theta)$", fontsize=12) - - plt.savefig(plot_path, dpi=2000) - plt.close() - print("Plot saved as %s" % (plot_path)) diff --git a/cosmo_inference/scripts/cosmosis_fitting.py b/cosmo_inference/scripts/cosmosis_fitting.py index 6cfe8be8..57e0b725 100644 --- a/cosmo_inference/scripts/cosmosis_fitting.py +++ b/cosmo_inference/scripts/cosmosis_fitting.py @@ -399,8 +399,8 @@ def _generate_ini_file( modifications.append((r"^\[output\]", output_section)) pipeline_section = ( - f"[pipeline]\nvalues = cosmosis_config/{values_file}\npriors = " - f"cosmosis_config/{priors_file}" + f"[pipeline]\nvalues = cosmosis_config/templates/{values_file}\npriors = " + f"cosmosis_config/templates/{priors_file}" ) modifications.append((r"^\[pipeline\]", pipeline_section)) @@ -617,7 +617,7 @@ def parse_args(): parser.add_argument( "--template-dir", type=str, - default=str(cosmo_inference_root / "cosmosis_config"), + default=str(cosmo_inference_root / "cosmosis_config" / "templates" ), help=( "Directory containing CosmoSIS template INI files (defaults to the " "cosmosis_config folder next to this script)." @@ -636,7 +636,7 @@ def parse_args(): template_dir_path = Path(args.template_dir).expanduser().resolve() output_basename_path = Path(output_basename) data_dir_root = output_root_path / "data" / output_basename_path - config_dir_root = output_root_path / "cosmosis_config" + config_dir_root = output_root_path / "cosmosis_config" / "output" data_dir_root.mkdir(parents=True, exist_ok=True) config_dir_root.mkdir(parents=True, exist_ok=True) out_file_path = data_dir_root / f"cosmosis_{args.cosmosis_root}.fits" diff --git a/cosmo_inference/scripts/masking.py b/cosmo_inference/scripts/masking.py deleted file mode 100644 index ba2f3c4c..00000000 --- a/cosmo_inference/scripts/masking.py +++ /dev/null @@ -1,319 +0,0 @@ -import argparse -import os -from multiprocessing import Pool, cpu_count -from pathlib import Path - -import h5py -import healpy as hp -import numpy as np -import yaml - -# ------------------------- -# Spatially-structured cuts: these define the survey footprint. -# All other cuts (FLAGS, mag, SNR, shape measurement, PSF ellipticity, -# relative size) are per-galaxy quality cuts that should NOT affect -# the footprint definition. -SPATIAL_CUTS = { - "overlap", - "IMAFLAGS_ISO", - "N_EPOCH", - "4_Stars", - "8_Manual", - "64_r", - "1024_Maximask", - "npoint3", - "1_Faint_star_halos", - "2_Bright_star_halos", -} - -# ------------------------- -# Masking logic - - -def apply_condition(array, kind, value): - """ - Apply a logical condition to a NumPy array and return a boolean mask, based - on the "kind" key in the mask config YAML file. - """ - if kind == "equal": - return array == value - elif kind == "not_equal": - return array != value - elif kind == "greater_equal": - return array >= value - elif kind == "greater": - return array > value - elif kind == "less_equal": - return array <= value - elif kind == "less": - return array < value - elif kind == "range": - return (array >= value[0]) & (array <= value[1]) - else: - raise ValueError(f"Unknown kind: {kind}") - - -def apply_masks(data, data_ext, mask_config, footprint_only=False): - """ - Construct a boolean mask selecting galaxies that satisfy all - masking criteria defined in the YAML configuration file. - - Parameters - ---------- - data : numpy.ndarray or structured array - Slice of the HDF5 "data" group containing per-object - measurements (e.g. FLAGS, mag, NGMIX quantities). - - data_ext : numpy.ndarray or structured array - Slice of the HDF5 "data_ext" group containing external or - post-processing flags (e.g. star masks, footprint flags). - - mask_config : dict - Dictionary parsed from the YAML mask configuration file. - Expected structure: - - mask_config["dat"] : list of cuts applied to `data` - - mask_config["dat_ext"] : list of cuts applied to `data_ext` - - mask_config["metacal"] : derived-quantity parameters - (e.g. relative size limits) - - footprint_only : bool, optional - If True, only apply spatially-structured cuts (those in - SPATIAL_CUTS). Skips per-galaxy quality cuts (FLAGS, mag, - SNR, shape measurement, PSF ellipticity, relative size). - Used to define a consistent footprint from the comprehensive - catalog. Default is False. - - Returns - ------- - numpy.ndarray (bool) - Boolean array of length equal to the input data slice. - True indicates the object passes all cuts (kept), - False indicates the object is masked (removed). - """ - - # Initialize mask - mask = np.ones(len(data), dtype=bool) - - # --- dat group --- - for cut in mask_config.get("dat", []): - col = cut["col_name"] - if footprint_only and col not in SPATIAL_CUTS: - continue - kind = cut["kind"] - value = cut["value"] - - mask &= apply_condition(data[col], kind, value) - - # --- dat_ext group --- - for cut in mask_config.get("dat_ext", []): - col = cut["col_name"] - if footprint_only and col not in SPATIAL_CUTS: - continue - kind = cut["kind"] - value = cut["value"] - - mask &= apply_condition(data_ext[col], kind, value) - - # --- metacal relative size (skip for footprint-only) --- - if not footprint_only: - rel_size = np.divide( - data["NGMIX_T_NOSHEAR"], - data["NGMIX_T_PSF_RECONV_NOSHEAR"], - out=np.zeros_like(data["NGMIX_T_NOSHEAR"]), - where=(data["NGMIX_T_PSF_RECONV_NOSHEAR"] > 0), - ) - - rel_min = mask_config["metacal"]["gal_rel_size_min"] - rel_max = mask_config["metacal"]["gal_rel_size_max"] - - mask &= (rel_size >= rel_min) & (rel_size <= rel_max) - - return mask - - -# ------------------------- -# Process one chunk -def process_chunk(args): - """ - Process a chunk of the HDF5 catalogue and return the unique - HEALPix pixels containing unmasked galaxies,to be executed in - parallel. It reads a slice of the catalogue, applies - the defined masking criteria, converts the sky positions - (RA, Dec) of retained galaxies into HEALPix pixel indices, - and returns the unique pixel indices for that chunk. - - Parameters - ---------- - args : tuple - Tuple containing: - - start : int - Starting row index of the chunk (inclusive). - - stop : int - Ending row index of the chunk (exclusive). - - filename : str - Path to the input HDF5 catalogue. - - nside : int - HEALPix NSIDE parameter defining map resolution. - - mask_config : dict - Parsed YAML mask configuration. - - Returns - ------- - numpy.ndarray - Array of unique HEALPix pixel indices (int) corresponding - to sky locations of galaxies that pass all mask cuts in - this chunk. - """ - - start, stop, filename, nside, mask_config, footprint_only = args - with h5py.File(filename, "r") as f: - data = f["data"][start:stop] - data_ext = f["data_ext"][start:stop] - - mask = apply_masks(data, data_ext, mask_config, footprint_only=footprint_only) - - ra = data["RA"][mask] - dec = data["Dec"][mask] - - theta = np.radians(90.0 - dec) # colatitude - phi = np.radians(ra) # longitude - - pix = hp.ang2pix(nside, theta, phi) - - return np.unique(pix) - - -# ------------------------- -# Build mask map in parallel -def build_mask_map_hdf5( - filename, mask_config, nside, chunk_size=1_000_000, footprint_only=False -): - """ - Build a binary HEALPix mask map from an HDF5 galaxy catalogue. - - The catalogue is processed in chunks to limit memory usage. - - Parameters - ---------- - filename : str - Path to the input HDF5 catalogue containing "data" and - "data_ext" groups - mask_config : dict - Dictionary parsed from the YAML mask configuration file - nside : int - HEALPix NSIDE parameter defining the resolution of the - output map. - chunk_size : int, optional - Number of catalogue rows to process per chunk. - Default is 1,000,000. - footprint_only : bool, optional - If True, only apply spatially-structured cuts. - - Returns - ------- - numpy.ndarray - One-dimensional HEALPix map (dtype uint8) of length - hp.nside2npix(nside), where: - - 1 indicates at least one unmasked galaxy falls - in that pixel, - - 0 indicates no retained galaxies. - """ - with h5py.File(filename, "r") as f: - nrows = f["data"].shape[0] - - chunks = [ - (i, min(i + chunk_size, nrows), filename, nside, mask_config, footprint_only) - for i in range(0, nrows, chunk_size) - ] - - mask_map = np.zeros(hp.nside2npix(nside), dtype=np.uint8) - - with Pool(cpu_count()) as pool: - for pix_indices in pool.imap_unordered(process_chunk, chunks): - mask_map[pix_indices] = 1 - - return mask_map - - -############################################################################################################ -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Build HEALPix mask from HDF5 catalog") - parser.add_argument("nside", type=int, help="HEALPix NSIDE parameter") - parser.add_argument("--config", required=True, help="Path to mask config YAML") - parser.add_argument( - "--output-prefix", - required=True, - help="Output file prefix (e.g. 'footprint' or 'footprint_starhalo')", - ) - parser.add_argument( - "--footprint-only", - action="store_true", - help="Only apply spatially-structured cuts (for footprint definition)", - ) - parser.add_argument( - "--output-dir", - default=None, - help="Output directory (default: data/mask/ relative to script)", - ) - args = parser.parse_args() - - nside = args.nside - curr_dir = Path(os.path.dirname(os.path.abspath(__file__))) - - if args.output_dir: - out_dir = Path(args.output_dir) - else: - out_dir = curr_dir.parent / "data" / "mask" - out_dir.mkdir(parents=True, exist_ok=True) - - with open(args.config, "r") as f: - mask_config = yaml.safe_load(f) - - filename = f"/n17data/UNIONS/WL/v1.4.x/v1.4.5/{mask_config['params']['input_path']}" - prefix = args.output_prefix - - if args.footprint_only: - print(f"Footprint-only mode: applying only spatial cuts {SPATIAL_CUTS}") - - # Build mask map from comprehensive catalogue - mask_map = build_mask_map_hdf5( - filename, - mask_config, - nside, - chunk_size=500_000, - footprint_only=args.footprint_only, - ) - - # Get survey area after masking - npix = hp.nside2npix(nside) - pix_area_sr = 4 * np.pi / npix - pix_area_deg2 = (180 / np.pi) ** 2 * pix_area_sr - n_obs = mask_map.sum() - f_sky_obs = n_obs / npix - area_obs_deg2 = n_obs * pix_area_deg2 - print(f"Kept area = {area_obs_deg2:.2f} deg^2\n") - - # Compute Cls of the mask map - cl_mask = hp.anafast(mask_map, lmax=3 * nside - 1) - ells = np.arange(len(cl_mask)) - - # Save mask map and Cls - map_path = out_dir / f"mask_map_{prefix}_nside_{nside}.fits" - cls_path = out_dir / f"mask_cls_{prefix}_nside_{nside}.npz" - hp.write_map(map_path, mask_map, overwrite=True) - np.savez(cls_path, ells=ells, cl_mask=cl_mask) - - print(f"Mask map saved to {map_path}") - print(f"Mask Cls saved to {cls_path}\n") - - # Compute normalising factor for the mask Cls - integral_w = np.sum((2 * ells + 1) / (4 * np.pi) * cl_mask) / (np.pi / 180) ** 2 - norm_factor = area_obs_deg2 / integral_w - norm_cls = cl_mask * norm_factor - - # Save normalised Cls to text file - norm_path = out_dir / f"mask_cls_{prefix}_nside_{nside}_norm.txt" - idx = np.arange(len(cl_mask)) - data_to_save = np.column_stack((idx, norm_cls)) - np.savetxt(norm_path, data_to_save, fmt=["%d", "%.10e"]) - print(f"Normalised mask Cls saved to {norm_path}") diff --git a/cosmo_inference/scripts/matching.py b/cosmo_inference/scripts/matching.py deleted file mode 100644 index a465e449..00000000 --- a/cosmo_inference/scripts/matching.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Wed Mar 1 17:37:27 2023 -@author: fh272693 -""" - -import astropy.units as u -from astropy.coordinates import SkyCoord, match_coordinates_sky -from astropy.io import fits - -Cat1 = fits.open( - "/feynman/work/dap/lcs/lg268561/UNIONS/Catalogues/unions_shapepipe_2022_v1.0.fits" -) -Cat2 = fits.open( - "/feynman/work/dap/lcs/lg268561/UNIONS/Catalogues/lensfit_goldshape_2022v1.fits" -) - -coord_units = u.degree -Cat1_coord = SkyCoord( - ra=Cat1[1].data["ra"] * coord_units, dec=Cat1[1].data["dec"] * coord_units -) -Cat2_coord = SkyCoord( - ra=Cat2[1].data["ra"] * coord_units, dec=Cat2[1].data["dec"] * coord_units -) -idx, d2d, d3d = match_coordinates_sky(Cat1_coord, Cat2_coord) -max_sep = 1.0 * u.arcsec -sep_constraint = d2d < max_sep - -# Important here is that the first catalogue of match_coordinates_sky has -# indices [sep_constraint] and the second[idx[sep_constraint]] -Cat1_matches = Cat1[1].data[sep_constraint] - -# np.save('/feynman/work/dap/lcs/lg268561/UNIONS/Catalogues/shapepipe_unmatches_ra.npy',Cat1[1].data['ra'][sep_constraint]) -# np.save('/feynman/work/dap/lcs/lg268561/UNIONS/Catalogues/shapepipe_unmatches_dec.npy',Cat1[1].data['dec'][sep_constraint]) -# np.save('/feynman/work/dap/lcs/lg268561/UNIONS/Catalogues/shapepipe_unmatches_e1.npy',Cat1[1].data['e1'][sep_constraint]) -# np.save('/feynman/work/dap/lcs/lg268561/UNIONS/Catalogues/shapepipe_unmatches_e2.npy',Cat1[1].data['e2'][sep_constraint]) -# np.save('/feynman/work/dap/lcs/lg268561/UNIONS/Catalogues/shapepipe_unmatches_w.npy',Cat1[1].data['w'][sep_constraint]) - -print("there are ", len(Cat1_matches), " matching galaxies in catalogue", Cat1) -# print('there are ',len(Cat2_matches),' matching galaxies in catalogue', Cat2) diff --git a/cosmo_inference/scripts/nz_writeout.py b/cosmo_inference/scripts/nz_writeout.py deleted file mode 100644 index 81994335..00000000 --- a/cosmo_inference/scripts/nz_writeout.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -# In[ ]: - -import sys - -import matplotlib.pylab as plt -import numpy as np -from astropy.io import fits - -nz_hdu = sys.argv[1] -root = sys.argv[2] -blind = sys.argv[3] - -hdu = fits.open(nz_hdu) -z = hdu[1].data["Z_%s" % blind] - -zmax = 5.0 - -(n, bins, _) = plt.hist(z, bins=200, range=(0, zmax), density=True, weights=None) - -print("zmin = ", min(z)) -print("zmax = ", max(z)) - -np.savetxt("data/" + root + "/nz_" + root + ".txt", np.column_stack((bins[:-1], n))) diff --git a/cosmo_inference/scripts/slurm.sh b/cosmo_inference/scripts/slurm.sh deleted file mode 100644 index 793aa7cf..00000000 --- a/cosmo_inference/scripts/slurm.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -#SBATCH --job-name=unions_V1.4 -#SBATCH --mail-user=lgoh@roe.ac.uk -#SBATCH --mail-type=END,FAIL -#SBATCH --partition=compl -#SBATCH --nodes=1 -#SBATCH --ntasks=1 -#SBATCH --cpus-per-task=48 -#SBATCH --time=4-00:00:00 -#SBATCH --output=/n23data1/n06data/lgoh/scratch/CFIS-UNIONS/chains/SP_v1.4_A/inference_A.log - -module load gcc -module load intelpython/3-2024.1.0 -module load openmpi -source cosmosis-configure -source activate my_env - -cosmosis --mpi /n23data1/n06data/lgoh/scratch/CFIS-UNIONS/CFIS-UNIONS_dev/cosmo_inference/cosmosis_config/cosmosis_pipeline_A_1.ini - -# -# Return exit code -exit 0 \ No newline at end of file diff --git a/cosmo_inference/scripts/treecorr_calc.py b/cosmo_inference/scripts/treecorr_calc.py deleted file mode 100644 index 38eb855e..00000000 --- a/cosmo_inference/scripts/treecorr_calc.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - - -import os -import sys - -import numpy as np -import treecorr -from astropy.io import fits - -script_dir = os.path.dirname(os.path.abspath(sys.argv[0])) - -cat_name = sys.argv[1] -root = sys.argv[2] - -hdu = fits.open(cat_name) -data = hdu[1].data - -# Create TreeCorr catalogue -n_thread = 8 -treecorr.set_omp_threads(n_thread) - -sep_units = "arcmin" -nbins = 20 - -TreeCorrConfig = { - "ra_units": "degrees", - "dec_units": "degrees", - "max_sep": "200", - "min_sep": "1", - "sep_units": sep_units, - "nbins": nbins, - "var_method": "jackknife", -} - - -cat_gal = treecorr.Catalog( - ra=data["RA"], - dec=data["Dec"], - g1=data["e1_noleakage"], # for v1.4.1 - g2=data["e2_noleakage"], # for v1.4.1 - w=data["w"], - ra_units="degrees", - dec_units="degrees", - npatch=50, -) - -gg = treecorr.GGCorrelation(TreeCorrConfig) - -print("Running TreeCorr...") -gg.process(cat_gal) - - -lst = np.arange(1, nbins + 1) - -# create fits HDU with xi_p and xi_m data -col1 = fits.Column(name="BIN1", format="K", array=np.ones(len(lst))) -col2 = fits.Column(name="BIN2", format="K", array=np.ones(len(lst))) -col3 = fits.Column(name="ANGBIN", format="K", array=lst) -col4 = fits.Column(name="VALUE", format="D", array=gg.xip) -col5 = fits.Column(name="ANG", format="D", unit="arcmin", array=gg.meanr) -coldefs = fits.ColDefs([col1, col2, col3, col4, col5]) -xiplus_hdu = fits.BinTableHDU.from_columns(coldefs, name="XI_PLUS") - - -col4 = fits.Column(name="VALUE", format="D", array=gg.xim) -coldefs = fits.ColDefs([col1, col2, col3, col4, col5]) -ximinus_hdu = fits.BinTableHDU.from_columns(coldefs, name="XI_MINUS") - -# append xi_p/xi_m header info -xip_dict = { - "2PTDATA": "T", - "QUANT1": "G+R", - "QUANT2": "G+R", - "KERNEL_1": "NZ_SOURCE", - "KERNEL_2": "NZ_SOURCE", - "WINDOWS": "SAMPLE", -} -for key in xip_dict: - xiplus_hdu.header[key] = xip_dict[key] - - -xim_dict = { - "2PTDATA": "T", - "QUANT1": "G-R", - "QUANT2": "G-R", - "KERNEL_1": "NZ_SOURCE", - "KERNEL_2": "NZ_SOURCE", - "WINDOWS": "SAMPLE", -} - -for key in xim_dict: - ximinus_hdu.header[key] = xim_dict[key] - -ximinus_hdu.writeto( - "%s/../data/" % script_dir + root + "/ximinus_" + root + ".fits", overwrite=True -) -xiplus_hdu.writeto( - "%s/../data/" % script_dir + root + "/xiplus_" + root + ".fits", overwrite=True -) - -print( - "Correlation functions written to {}".format( - "%s/../data/" % script_dir + root + "/xiplus_minus_" + root + ".fits" - ) -) diff --git a/cosmo_inference/scripts/xi_sys_psf.py b/cosmo_inference/scripts/xi_sys_psf.py deleted file mode 100644 index 631b9464..00000000 --- a/cosmo_inference/scripts/xi_sys_psf.py +++ /dev/null @@ -1,53 +0,0 @@ -import numpy as np -from astropy.io import fits -from cosmosis.datablock import option_section - - -# This file should be added to your cosmosis_standard_library following the path shear/xi_sys/xi_sys_psf.py -def setup(options): - filename = options.get_string(option_section, "data_file") - data = fits.open(filename) - rho_stats_name = options.get_string(option_section, "rho_stats_name") - samples_path = options.get_string(option_section, "samples") - - samples = np.load(samples_path) - mean = np.mean(samples, axis=0) - cov = np.cov(samples.T) - - rho_stats = data[rho_stats_name].data - - return mean, cov, rho_stats - - -def execute(block, config): - - mean, cov, rho_stats = config - - alpha, beta, eta = np.random.multivariate_normal(mean, cov) - block["xi_sys", "alpha"], block["xi_sys", "beta"], block["xi_sys", "eta"] = ( - alpha, - beta, - eta, - ) - - xi_sys_p = ( - alpha**2 * rho_stats["rho_0_p"] - + beta**2 * rho_stats["rho_1_p"] - + eta**2 * rho_stats["rho_3_p"] - + 2 * alpha * beta * rho_stats["rho_2_p"] - + 2 * beta * eta * rho_stats["rho_4_p"] - + 2 * alpha * eta * rho_stats["rho_5_p"] - ) - - xi_sys_m = ( - alpha**2 * rho_stats["rho_0_m"] - + beta**2 * rho_stats["rho_1_m"] - + eta**2 * rho_stats["rho_3_m"] - + 2 * alpha * beta * rho_stats["rho_2_m"] - + 2 * beta * eta * rho_stats["rho_4_m"] - + 2 * alpha * eta * rho_stats["rho_5_m"] - ) - - block["xi_sys", "xi_sys_vec"] = np.concatenate([xi_sys_p, xi_sys_m]) - - return 0 diff --git a/papers/realspace/S8_om_sigma8_whisker.py b/papers/realspace/S8_om_sigma8_whisker.py new file mode 100644 index 00000000..80dc49cd --- /dev/null +++ b/papers/realspace/S8_om_sigma8_whisker.py @@ -0,0 +1,559 @@ +# +# This notebook plots the whisker plot of $S_8$, $\Omega_m$ and $\sigma_8$ + + +import os +import sys + +# Trick to plot with tex +os.environ["LD_LIBRARY_PATH"] = "" +os.environ["CONDA_PREFIX"] = "/home/guerrini/.conda/envs/sp_validation_3.11" + +sys.path.append("/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/") + +import sys +import warnings + +import matplotlib.pyplot as plt +import numpy as np +import seaborn as sns +from getdist import plots + +sys.path.append("/home/guerrini/sp_validation/cosmo_inference/scripts") + +import chain_postprocessing as cp + +plt.style.use("/home/guerrini/matplotlib_config/paper.mplstyle") + +plt.rc("text", usetex=True) + +sns.set_palette("husl") + +g = plots.get_subplot_plotter(width_inch=30) +g.settings.axes_fontsize = 60 +g.settings.axes_labelsize = 60 +g.settings.alpha_filled_add = 0.7 +g.settings.legend_fontsize = 60 + + +# SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE +root_dir = "/n09data/guerrini/output_chains/" +root_external = f"{root_dir}/ext_data/" +blind = "B" + +roots = [ + f"SP_v1.4.6.3_{blind}_fiducial_config", + f"SP_v1.4.6.3_leak_corr_{blind}", + "Planck18", + "DES Y6", + "KiDS-Legacy_bandpowers", + "KiDS-Legacy_cosebis", + "KiDS-Legacy_xipm", + "HSC_Y3", + "HSC_Y3_cell", + f"SP_v1.4.6.3_{blind}_small_scales_config", + f"SP_v1.4.6.3_{blind}_flat_alpha_beta_config", + f"SP_v1.4.6.3_{blind}_no_xi_sys_config", + f"SP_v1.4.6.3_{blind}_no_leak_corr_config", + f"SP_v1.4.6.3_{blind}_flat_delta_z_config", + f"SP_v1.4.6.3_{blind}_no_delta_z_config", + f"SP_v1.4.6.3_{blind}_flat_ia_config", + f"SP_v1.4.6.3_{blind}_no_ia_config", + f"SP_v1.4.6.3_{blind}_no_m_bias_config", + f"SP_v1.4.6.3_{blind}_unmasked_covmat_config", + f"SP_v1.4.6.3_{blind}_halofit_config", + f"SP_v1.4.6.3_{blind}_no_baryons_config", + f"SP_v1.4.6.3_{blind}_nautilus_config", + f"SP_v1.4.6.3_{blind}_planck_config", + f"SP_v1.4.6.3_{blind}_planck_desi_config", +] + +legend_labels = [ + r"UNIONS-3500 $\xi_{\pm}(\theta)$ (This work)", + r"UNIONS-3500 $C_\ell$ (Guerrini et al. 2026)", + r"$\textit{Planck}$ 2018", + r"DES Y6 $\xi_{\pm}$, NLA", + r"KiDS-Legacy Bandpowers ($C_{\rm E}$)", + r"KiDS-Legacy COSEBIs ($E_n$)", + r"KiDS-Legacy $\xi_{\pm}(\theta)$", + r"HSC-Y3 $\xi_{\pm}(\theta)$", + r"HSC-Y3 $C_\ell$", + r"$\xi_+$ small scales, $\theta$=[5,83] arcmin", + r"Flat $\alpha_{\rm{PSF}}$ and $\beta_{\rm{PSF}}$ priors", + r"No $\xi^{\rm sys}_{\pm}$", + r"No leakage correction", + r"Flat $\Delta z$ priors", + r"No $\Delta z$", + r"Flat $A_{\rm IA}$ prior", + r"No $A_{\rm IA}$", + r"No $m$ bias", + r"Unmasked covmat", + r"$\texttt{Halofit}$", + r"$\texttt{HMCode}$ no baryons", + r"Nautilus sampler", + r"UNIONS-3500 + $\textit{Planck}$", + r"UNIONS-3500 + $\textit{Planck}$ + DESI BAO", +] + +categories = [ + "configuration", + "harmonic", + "external", + "external", + "external", + "external", + "external", + "external", + "external", + "configuration", + "configuration", + "configuration", + "configuration", + "configuration", + "configuration", + "configuration", + "configuration", + "configuration", + "configuration", + "configuration", + "configuration", + "configuration", + "configuration", + "configuration", +] +colours = [ + "darkorange", + "royalblue", + "violet", + "black", + "black", + "black", + "black", + "black", + "black", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", + "forestgreen", +] + + +chains = [] +for i, root in enumerate(roots): + category = categories[i] + if root == "DES Y6": + continue + if category != "external": + if category == "configuration": + path_samples = os.path.join(root_dir, f"{root}/samples_{root}.txt") + path_getdist = os.path.join(root_dir, f"{root}/getdist_{root}") + elif category == "harmonic": + path_samples = os.path.join( + root_dir, f"{root}/{root}/samples_{root}_cell.txt" + ) + path_getdist = os.path.join(root_dir, f"{root}/{root}/getdist_{root}") + elif category == "external_compute_sample": + path_samples = os.path.join(root_dir, f"ext_data/{root}/samples_{root}.txt") + path_getdist = os.path.join(root_dir, f"ext_data/{root}/getdist_{root}") + else: + raise ValueError(f"The category, {category}, of {root} is not correct") + if "nautilus" not in root: + cp.load_samples_and_write_paramnames( + path_samples, path_getdist + ".paramnames" + ) + cp.write_samples_getdist_format(path_samples, path_getdist + ".txt") + else: + cp.load_samples_and_write_paramnames( + path_samples, path_getdist + ".paramnames", chain_type="nautilus" + ) + cp.write_samples_getdist_format( + path_samples, path_getdist + ".txt", chain_type="nautilus" + ) + chains.append(cp.load_chain(path_getdist, smoothing_scale=0.5)) + else: + path_getdist = os.path.join(root_dir, f"ext_data/{root}/getdist_{root}") + chains.append(cp.load_chain(path_getdist)) + + +name_list = [ + "OMEGA_M", + "ombh2", + "h0", + "n_s", + "SIGMA_8", + "S_8", + "s_8_input", + "logt_agn", + "a", + "m1", + "bias_1", +] +label_list = [ + r"\Omega_{\rm m}", + r"\omega_b h^2", + r"h_0", + r"n_s", + r"\sigma_8", + r"S_8", + r"S_8", + r"\log T_{\rm AGN}", + r"A_{\rm IA}", + r"m_1", + r"\Delta z_1", +] + +for i, chain in enumerate(chains): + print(legend_labels[i]) + param_names = chain.getParamNames() + for name, label in zip(name_list, label_list): + try: + param_names.parWithName(name).label = label + except Exception: + warnings.warn(f"Parameter {name} not found in chain {roots[i]}.") + + +# Micro management of external chains + +# Account for the missing parameter conventions + +idx = roots.index("KiDS-Legacy_xipm") +cp.derive_parameter_S8(chains[idx]) + +idx = roots.index("KiDS-Legacy_bandpowers") +cp.derive_parameter_S8(chains[idx]) + +idx = roots.index("KiDS-Legacy_cosebis") +cp.derive_parameter_S8(chains[idx]) + +# OMEGA_M not in HSC_Y3_cell +idx = roots.index("HSC_Y3_cell") +cp.adjust_paramname_chain(chains[idx], "omega_m", "OMEGA_M", r"\Omega_{\rm m}") + + +param_values = np.array( + [ + "# Expt", + "Colour", + "S8_Mean", + "S8_low", + "S8_high", + "sigma_8_Mean", + "sigma_8_low", + "sigma_8_high", + "Omega_m_Mean", + "Omega_m_low", + "Omega_m_high", + ] +) +escaped = np.char.replace(legend_labels, "\\", "\\\\") + +for i, root in enumerate(roots): + chain = chains[i] + if root == "DES Y6": + param_values = np.vstack( + ( + param_values, + [ + escaped[i], + colours[i], + 0.798, + 0.015, + 0.014, + 0.763, + 0.057, + 0.050, + 0.332, + 0.040, + 0.035, + ], + ) + ) + else: + best_fit_params = cp.extract_best_fit_params(chain, best_fit_method="2Dkde") + margestats = chain.getMargeStats() + + s8_stats = margestats.parWithName("S_8") + sigma8_stats = margestats.parWithName("SIGMA_8") + omegam_stats = margestats.parWithName("OMEGA_M") + + param_values = np.vstack( + ( + param_values, + [ + escaped[i], + colours[i], + best_fit_params["S_8"], + best_fit_params["S_8"] - s8_stats.limits[0].lower, + s8_stats.limits[0].upper - best_fit_params["S_8"], + best_fit_params["SIGMA_8"], + best_fit_params["SIGMA_8"] - sigma8_stats.limits[0].lower, + sigma8_stats.limits[0].upper - best_fit_params["SIGMA_8"], + best_fit_params["OMEGA_M"], + best_fit_params["OMEGA_M"] - omegam_stats.limits[0].lower, + omegam_stats.limits[0].upper - best_fit_params["OMEGA_M"], + ], + ) + ) +print(param_values) +np.savetxt( + f"{root_dir}/param_values.txt", + param_values, + fmt=["%s" for i in range(11)], + delimiter=";", +) + + +# Load the value of the parameters +cosmo = np.loadtxt( + f"{root_dir}/param_values.txt", + dtype={ + "names": ( + "Expt", + "colour", + "s8_mean", + "s8_low", + "s8_high", + "sigma8_mean", + "sigma8_low", + "sigma8_high", + "omegam_mean", + "omegam_low", + "omegam_high", + ), + "formats": ( + "U250", + "U20", + "U20", + "U20", + "U20", + "U20", + "U20", + "U20", + "U20", + "U20", + "U20", + ), + }, + skiprows=1, + delimiter=";", +) +expt = np.char.replace(cosmo["Expt"], "\\\\", "\\") +colours = cosmo["colour"] +s8_mean = cosmo["s8_mean"].astype(np.float64) +s8_low = cosmo["s8_low"].astype(np.float64) +s8_high = cosmo["s8_high"].astype(np.float64) +sigma8_mean = cosmo["sigma8_mean"].astype(np.float64) +sigma8_low = cosmo["sigma8_low"].astype(np.float64) +sigma8_high = cosmo["sigma8_high"].astype(np.float64) +omegam_mean = cosmo["omegam_mean"].astype(np.float64) +omegam_low = cosmo["omegam_low"].astype(np.float64) +omegam_high = cosmo["omegam_high"].astype(np.float64) + + +from matplotlib.gridspec import GridSpec + +fig = plt.figure(figsize=(13, 8)) +gs = GridSpec(1, 3, width_ratios=[1, 0.5, 0.5]) +ax1 = fig.add_subplot(gs[0]) +ax2 = fig.add_subplot(gs[1], sharey=ax1) +ax3 = fig.add_subplot(gs[2], sharey=ax1) + +axs = [ax1, ax2, ax3] + +params = [ + (s8_mean, s8_low, s8_high, r"$S_8$"), + (sigma8_mean, sigma8_low, sigma8_high, r"$\sigma_8$"), + (omegam_mean, omegam_low, omegam_high, r"$\Omega_{\rm m}$"), +] +reference = r"UNIONS-3500 $\xi_{\pm}(\theta)$ (This work)" + +separation_after = [ + r"UNIONS-3500 $C_\ell$ (Guerrini et al. 2026)", + r"HSC-Y3 $C_\ell$", + r"$\xi_+$ small scales, $\theta$=[5,83] arcmin", + r"Unmasked covmat", + r"$\texttt{HMCode}$ no baryons", + r"Nautilus sampler", +] +list_section_index = [r"(ii)", r"(iii)", r"(iv)", r"(v)", r"(vi)", r"(vii)"] + +preliminary_watermark = False +blind_axes = False +row_spacing = 0.2 + +index_ref = np.where(expt == reference)[0][0] + +y = np.arange(len(expt)) +for ax, param in zip(axs, params): + means, lows, highs, label = param + for i, mean, low, high, color in zip(y, means, lows, highs, colours): + ax.errorbar( + mean, + 0.05 + i * row_spacing, + xerr=np.array([low, high])[:, None], + fmt="o", + color=color, + ecolor=color, + elinewidth=2, + capsize=3, + ) + ax.set_xlabel(label, fontsize=14) + + ax.grid(False) + ax.tick_params(axis="y", left=False, labelleft=False) + if label == r"$S_8$": + ax.axvspan( + s8_mean[index_ref] - s8_low[index_ref], + s8_mean[index_ref] + s8_high[index_ref], + color=colours[index_ref], + alpha=0.2, + ) + ax.set_xlim(0.6, 1.35) + if blind_axes: + ref_tick = np.mean(s8_mean[:4]) + ax.set_xticks([ref_tick + i * 0.1 for i in range(-5, 5)], labels=[]) + elif label == r"$\sigma_8$": + ax.axvspan( + sigma8_mean[index_ref] - sigma8_low[index_ref], + sigma8_mean[index_ref] + sigma8_high[index_ref], + color=colours[index_ref], + alpha=0.2, + ) + ax.set_xlim(0.5, 1.35) + if blind_axes: + ref_tick = np.mean(sigma8_mean[:4]) + ax.set_xticks([ref_tick + i * 0.2 for i in range(-2, 2)], labels=[]) + elif label == r"$\Omega_{\rm m}$": + ax.axvspan( + omegam_mean[index_ref] - omegam_low[index_ref], + omegam_mean[index_ref] + omegam_high[index_ref], + color=colours[index_ref], + alpha=0.2, + ) + ax.set_xlim(0.1, 0.5) + if blind_axes: + ref_tick = np.mean(omegam_mean[:4]) + ax.set_xticks([ref_tick + i * 0.1 for i in range(-2, 3)], labels=[]) + + +ax1.set_yticks(0.01 + y * row_spacing) +ax1.set_yticklabels([]) +for label, color in zip(expt, colours): + if "This work" in label: + label_bold = ( + r"$\bf{UNIONS}$-$\bf{3500}$ $\xi_{\pm}(\theta)$ $\bf{(This\ work)}$" + ) + ax1.text( + -0.6, + 0.05 + row_spacing * np.where(expt == label)[0][0], + label_bold, + fontsize=12, + ha="left", + va="center", + color=color, + ) + else: + ax1.text( + -0.6, + 0.05 + row_spacing * np.where(expt == label)[0][0], + label, + fontsize=12, + ha="left", + va="center", + color=color, + ) + if label != reference: + index = np.where(expt == label)[0][0] + s8_tension = cp.get_sigma_tension( + s8_mean[index], + s8_low[index], + s8_high[index], + s8_mean[index_ref], + s8_low[index_ref], + s8_high[index_ref], + ) + sign_str = "+" if s8_tension > 0 else "-" + ax1.text( + 1.32, + 0.05 + row_spacing * index, + rf"${sign_str}{np.abs(s8_tension):.2f}" + r"\, \sigma$", + fontsize=10, + ha="right", + va="center", + color=color, + ) +# Add separation lines +for i, sep in enumerate(separation_after): + print(sep) + index_sep = np.where(expt == sep)[0][0] + ax2.axhline( + row_spacing * (index_sep + 1) - 0.07, + color="black", + linestyle="dotted", + linewidth=1, + ) + ax3.axhline( + row_spacing * (index_sep + 1) - 0.07, + color="black", + linestyle="dotted", + linewidth=1, + ) + ax1.axhline( + row_spacing * (index_sep + 1) - 0.07, + xmin=-1.8, + color="black", + linestyle="dotted", + linewidth=1, + clip_on=False, + ) + ax1.text( + -0.61, + row_spacing * (index_sep + 1) + 0.05, + list_section_index[i], + fontsize=12, + fontweight="bold", + va="center", + ha="right", + ) + + +# --- Add section label (i)) --- +ax1.text(-0.61, 0.05, r"(i)", fontsize=12, fontweight="bold", va="center", ha="right") + +if preliminary_watermark: + plt.figtext( + 0.5, + 0.5, + "PRELIMINARY", + fontsize=50, + color="gray", + ha="center", + va="center", + alpha=0.3, + rotation=330, + ) + +plt.gca().invert_yaxis() + +plt.tight_layout() + +# plt.savefig("./plots/whisker_plot.png", dpi=300) +# #Save pdf +plt.savefig("../Plots/S8_whisker_plot.pdf", bbox_inches="tight") + + + + + + diff --git a/papers/realspace/best_fit_xipm.py b/papers/realspace/best_fit_xipm.py new file mode 100644 index 00000000..db7f5b56 --- /dev/null +++ b/papers/realspace/best_fit_xipm.py @@ -0,0 +1,513 @@ + + +import os +import sys + +sys.path.append("/home/guerrini/sp_validation/cosmo_inference/scripts") + +import chain_postprocessing as cp +import matplotlib.pyplot as plt +import matplotlib.scale as mscale +import numpy as np +import seaborn as sns +from astropy.io import fits +from getdist import plots + +plt.style.use("/home/guerrini/matplotlib_config/paper.mplstyle") + +from sp_validation.rho_tau import SquareRootScale + +mscale.register_scale(SquareRootScale) + +plt.rcParams["text.usetex"] = True + +sns.set_palette("husl") + +g = plots.get_subplot_plotter(width_inch=30) +g.settings.axes_fontsize = 40 +g.settings.axes_labelsize = 40 +g.settings.alpha_filled_add = 0.7 +g.settings.legend_fontsize = 50 + +# Directory where the chains are located +root_dir = "/n09data/guerrini/output_chains" + +# THE BLIND TO USE FOR THE PLOTS +blind = "B" +catalog_version = "SP_v1.4.6.3" +fiducial_root_cell = f"SP_v1.4.6.3_leak_corr_{blind}" +label_fiducial_cell = r"UNIONS $C_{\ell}$" +fiducial_root_xi_data = f"SP_v1.4.6.3_leak_corr_{blind}_masked" +fiducial_root_xi_chains = f"SP_v1.4.6.3_{blind}_fiducial_config" +label_fiducial_xi = r"UNIONS $\xi_{\pm}$" + +# Path to the ini files used +path_ini_files = "/home/guerrini/sp_validation/cosmo_inference/cosmosis_config" +path_datavectors = "/home/guerrini/sp_validation/cosmo_inference/data/" +path_output_chains = "/n09data/guerrini/output_chains/" + + +data_cell = fits.open( + os.path.join( + path_datavectors, f"{fiducial_root_cell}/cosmosis_{fiducial_root_cell}.fits" + ) +) + +data_xi = fits.open( + os.path.join( + path_datavectors, + f"SP_v1.4.6.3_config/SP_v1.4.6.3_{blind}/cosmosis_{fiducial_root_xi_data}.fits", + ) +) + +path_samples_fiducial_cell = os.path.join( + path_output_chains, + fiducial_root_cell, + fiducial_root_cell, + f"samples_{fiducial_root_cell}_cell.txt", +) +path_gd_fiducial_cell = os.path.join( + path_output_chains, + fiducial_root_cell, + fiducial_root_cell, + f"getdist_{fiducial_root_cell}_cell", +) +cp.load_samples_and_write_paramnames( + path_samples_fiducial_cell, path_gd_fiducial_cell + ".paramnames" +) +cp.write_samples_getdist_format( + path_samples_fiducial_cell, path_gd_fiducial_cell + ".txt", chain_type="polychord" +) + +chain_fiducial_cell = cp.load_chain(path_gd_fiducial_cell, smoothing_scale=0.5) + +best_fit_params_fiducial_cell = cp.extract_best_fit_params( + chain_fiducial_cell, best_fit_method="2Dkde" +) + +cp.compute_best_fit( + path_ini_files, + best_fit_params_fiducial_cell, + fiducial_root_cell, + is_harmonic=True, + blind=blind, +) +path_samples_fiducial_xi = os.path.join( + path_output_chains, + fiducial_root_xi_chains, + f"samples_{fiducial_root_xi_chains}.txt", +) + +path_gd_fiducial_xi = os.path.join( + path_output_chains, fiducial_root_xi_chains, f"getdist_{fiducial_root_xi_chains}" +) +cp.load_samples_and_write_paramnames( + path_samples_fiducial_xi, path_gd_fiducial_xi + ".paramnames" +) +cp.write_samples_getdist_format( + path_samples_fiducial_xi, path_gd_fiducial_xi + ".txt", chain_type="polychord" +) + +chain_fiducial_xi = cp.load_chain(path_gd_fiducial_xi, smoothing_scale=0.5) + +best_fit_params_fiducial_xi = cp.extract_best_fit_params( + chain_fiducial_xi, best_fit_method="2Dkde" +) + +ini_file_root = os.path.join( + path_ini_files, + f"config_space_v1.4.6.3_fiducial/pipeline/blind_{blind}/fiducial.ini", +) +cp.compute_best_fit( + path_ini_files, + best_fit_params_fiducial_xi, + fiducial_root_xi_chains, + is_harmonic=False, + blind=blind, + ini_file_root=ini_file_root, +) + +root_to_plot = [ + fiducial_root_xi_chains, + fiducial_root_cell, +] + +labels = [ + r"UNIONS $\xi_\pm(\theta)$", + r"UNIONS $C_\ell$", +] + +line_args = [ + {"color": "royalblue", "linestyle": "-"}, + {"color": "orange", "linestyle": "-"}, +] + +properties = {} + +properties = cp.update_properties_w_roots( + properties, fiducial_root_cell, path_ini_files, with_configuration=False +) +properties = cp.update_properties_w_roots( + properties, + fiducial_root_xi_chains, + path_ini_files, + with_configuration=True, + path_to_this_ini=ini_file_root, +) + + +root_to_plot = [fiducial_root_cell, fiducial_root_xi_chains] +labels = [r"Best fit $C_\ell$", r"Best fit $\xi_\pm(\theta)$"] +path_best_fit_xi_theta = os.path.join( + path_output_chains, fiducial_root_xi_chains, "best_fit/shear_xi_plus/theta.txt" +) + +theta_rad = np.loadtxt(path_best_fit_xi_theta) +theta_min = 1 +theta_max = 250 + +cp.compute_best_fit_xi_from_cell( + path_output_chains, fiducial_root_cell, best_fit_params_fiducial_cell, theta_rad +) + +data = fits.open( + os.path.join( + path_datavectors, + f"SP_v1.4.6.3_config/SP_v1.4.6.3_{blind}/cosmosis_{fiducial_root_xi_data}.fits", + ) +) +bbox_to_anchor_xip = (0.685, 0.09) +bbox_to_anchor_xim = (0.3, 0.65) +xi_p_data = data["XI_PLUS"].data +xi_m_data = data["XI_MINUS"].data +cov_mat = data["COVMAT"].data + +# Plot hyperparameter +loc_legend = "lower center" + +fig, [ax, ax2] = plt.subplots(1, 2, figsize=(20, 8)) + +theta, xi_p, xi_m = xi_p_data["ANG"], xi_p_data["VALUE"], xi_m_data["VALUE"] +ax.errorbar( + theta, + theta * xi_p, + yerr=theta * np.sqrt(np.diag(cov_mat[: len(theta), : len(theta)])), + fmt="o", + label=r"UNIONS $\xi_+$ data", + color="black", + capsize=2, +) +ax2.errorbar( + theta, + theta * xi_m, + yerr=theta + * np.sqrt( + np.diag(cov_mat[len(theta) : 2 * len(theta), len(theta) : 2 * len(theta)]) + ), + fmt="o", + label=r"UNIONS $\xi_-$ data", + color="black", + capsize=2, +) + +for idx, (label, root) in enumerate(zip(labels, root_to_plot)): + # Read the results + theta = ( + ( + np.loadtxt( + path_output_chains + "{}/best_fit/shear_xi_plus/theta.txt".format(root) + ) + ) + * 180 + / np.pi + * 60 + ) + xi_plus = np.loadtxt( + path_output_chains + "{}/best_fit/shear_xi_plus/bin_1_1.txt".format(root) + ) + xi_minus = np.loadtxt( + path_output_chains + "{}/best_fit/shear_xi_minus/bin_1_1.txt".format(root) + ) + if r"$C_\ell$" not in label: + xi_sys_plus = np.loadtxt( + path_output_chains + "{}/best_fit/xi_sys/shear_xi_plus.txt".format(root) + ) + xi_sys_minus = np.loadtxt( + path_output_chains + "{}/best_fit/xi_sys/shear_xi_minus.txt".format(root) + ) + theta_xi_sys = ( + np.loadtxt(path_output_chains + "{}/best_fit/xi_sys/theta.txt".format(root)) + * 180 + / np.pi + * 60 + ) + + xi_sys_plus = np.interp(theta, theta_xi_sys, xi_sys_plus) + xi_sys_minus = np.interp(theta, theta_xi_sys, xi_sys_minus) + xi_plus += xi_sys_plus + xi_minus += xi_sys_minus + + mask = (theta > theta_min) & (theta < theta_max) + theta = theta[mask] + ax.plot( + theta, + theta * xi_plus[mask], + label=r"Best fit $\xi_+(\theta)$", + **line_args[idx], + lw=2.5, + ) + ax.plot( + theta, + theta * xi_sys_plus[mask], + label=r"Best fit $\xi^{\rm sys}_{+}(\theta)$", + c="r", + ) + ax2.plot( + theta, + theta * xi_minus[mask], + label=r"Best fit $\xi_-(\theta)$", + **line_args[idx], + lw=2.5, + ) + ax2.plot( + theta, + theta * xi_sys_minus[mask], + label=r"Best fit $\xi^{\rm sys}_{-}(\theta)$", + c="r", + ) + + else: + mask = (theta > theta_min) & (theta < theta_max) + theta = theta[mask] + ax.plot(theta, theta * xi_plus[mask], label=label, **line_args[idx], lw=2.5) + ax2.plot(theta, theta * xi_minus[mask], label=label, **line_args[idx], lw=2.5) +# XI PLUS PLOT SETTINGS + +# Plot the scale cuts for different k_max +ax.axvline(x=5, color="gray", linestyle="--", alpha=0.7) +ax.axhline(y=0, color="black", linestyle="--", alpha=0.7) + +ymin = ax.get_ylim()[0] +ymax = ax.get_ylim()[1] +# Shadowing cut scaled +ax.fill_betweenx(y=[ymin, ymax], x1=0, x2=12, color="gray", alpha=0.2) +ax.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color="gray", alpha=0.2) + +ax.set_ylim(ymin, ymax) + +# Add labels directly under the tick +ax.text( + 4.5, + 0.47e-4, + r"$k_\mathrm{max} = 1 h$ Mpc$^{-1}$", + ha="center", + va="top", + fontsize=20, + rotation=90, +) + +ax.set_ylabel(r"$\theta \xi_\pm$", fontsize=26) +ax.set_xlabel(r"$\theta$ (arcmin)", fontsize=26) +ax.set_xlim([theta.min() - 0.1, theta.max() + 20]) +ax.set_title(r"$\xi_+(\theta)$", fontsize=26) +ax.set_xscale("log") +ax.set_xticks(np.array([1, 10, 100])) +ax.tick_params(axis="x", which="minor", length=2, width=0.8) +ax.tick_params(axis="both", which="major", labelsize=24) +ax.tick_params(axis="both", which="minor", labelsize=20) +ax.yaxis.get_offset_text().set_fontsize(24) +ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) +ax.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xip, fontsize=20) + +# XI_MINUS PLOT SETTINGS + +# Plot the scale cuts for different k_max +ax2.axvline(x=50, color="gray", linestyle="--", alpha=0.7) +ax2.axhline(y=0, color="black", linestyle="--", alpha=0.7) + +ymin = ax2.get_ylim()[0] +ymax = ax2.get_ylim()[1] +# Shadowing cut scaled +ax2.fill_betweenx(y=[ymin, ymax], x1=0, x2=12, color="gray", alpha=0.2) +ax2.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color="gray", alpha=0.2) + +ax2.set_ylim(ymin, ymax) + +# Add labels directly under the tick +ax2.text( + 45, + 1.15e-4, + r"$k_\mathrm{max} = 1 h$ Mpc$^{-1}$", + ha="center", + va="top", + fontsize=20, + rotation=90, +) + +# ax2.set_ylabel(r'$\theta \xi_-$', fontsize=16) +ax2.set_xlabel(r"$\theta$ (arcmin)", fontsize=26) +ax2.set_xlim([theta.min() - 0.1, theta.max() + 20]) +ax2.set_xscale("log") +ax2.set_title(r"$\xi_-(\theta)$", fontsize=26) +ax2.set_xticks(np.array([1, 10, 100])) +ax2.tick_params(axis="x", which="minor", length=2, width=0.8) +ax2.tick_params(axis="both", which="major", labelsize=24) +ax2.tick_params(axis="both", which="minor", labelsize=20) +ax2.yaxis.get_offset_text().set_fontsize(24) +ax2.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) +ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20) + +plt.savefig( + "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/best_fit_xipm_SP_v1.4.6.3_B.pdf", + bbox_inches="tight", +) + + + + +root_to_plot = [fiducial_root_xi_chains] +labels = [r"Best fit $\tau_{0,2}(\theta)$"] + +bbox_to_anchor_xip = (0.285, 0.7) +bbox_to_anchor_xim = (0.3, 0.65) +tau0_data = data["TAU_0_PLUS"].data +tau2_data = data["TAU_2_PLUS"].data +cov_mat = data["COVMAT"].data + +# Plot hyperparameter + +fig, [ax, ax2] = plt.subplots(1, 2, figsize=(20, 8)) + +theta, tau0, tau2 = tau0_data["ANG"], tau0_data["VALUE"], tau2_data["VALUE"] +ax.errorbar( + theta, + theta * tau0, + yerr=theta + * np.sqrt( + np.diag( + cov_mat[2 * len(theta) : 3 * len(theta), 2 * len(theta) : 3 * len(theta)] + ) + ), + fmt="o", + label=r"UNIONS $\tau_{0,+}$", + color="black", + capsize=2, +) +ax2.errorbar( + theta, + theta * tau2, + yerr=theta + * np.sqrt( + np.diag( + cov_mat[3 * len(theta) : 4 * len(theta), 3 * len(theta) : 4 * len(theta)] + ) + ), + fmt="o", + label=r"UNIONS $\tau_{2,+}$", + color="black", + capsize=2, +) + +for idx, (label, root) in enumerate(zip(labels, root_to_plot)): + # Read the results + theta = ( + ( + np.loadtxt( + path_output_chains + "{}/best_fit/tau_0_plus/theta.txt".format(root) + ) + ) + * 180 + / np.pi + * 60 + ) + tau0_plus = np.loadtxt( + path_output_chains + "{}/best_fit/tau_0_plus/bin_1_1.txt".format(root) + ) + tau2_plus = np.loadtxt( + path_output_chains + "{}/best_fit/tau_2_plus/bin_1_1.txt".format(root) + ) + + mask = (theta > theta_min) & (theta < theta_max) + theta = theta[mask] + ax.plot( + theta, + theta * tau0_plus[mask], + label=r"Best fit $\tau_{0,+}(\theta)$", + c="orange", + lw=2.5, + ) + ax2.plot( + theta, + theta * tau2_plus[mask], + label=r"Best fit $\tau_{2,+}(\theta)$", + c="orange", + lw=2.5, + ) + +# XI PLUS PLOT SETTINGS + +# Plot the scale cuts for different k_max +ax.axhline(y=0, color="black", linestyle="--", alpha=0.7) + +ymin = ax.get_ylim()[0] +ymax = ax.get_ylim()[1] + +ax.set_ylim(ymin, ymax) + +ax.set_ylabel(r"$\theta\tau_{0,2}$", fontsize=26) +ax.set_xlabel(r"$\theta$ (arcmin)", fontsize=26) +ax.set_xlim([theta.min() - 0.1, theta.max() + 20]) +ax.set_title(r"$\tau_{0,+}(\theta)$", fontsize=26) +ax.set_xscale("log") +ax.set_xticks(np.array([1, 10, 100])) +ax.tick_params(axis="x", which="minor", length=2, width=0.8) +ax.tick_params(axis="both", which="major", labelsize=24) +ax.tick_params(axis="both", which="minor", labelsize=20) +ax.yaxis.get_offset_text().set_fontsize(24) +ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) +ax.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xip, fontsize=20) + +# XI_MINUS PLOT SETTINGS + +# Plot the scale cuts for different k_max +ax2.axhline(y=0, color="black", linestyle="--", alpha=0.7) + +ymin = ax2.get_ylim()[0] +ymax = ax2.get_ylim()[1] +# Shadowing cut scaled +ax2.fill_betweenx( + y=[ymin, ymax], + x1=0, + x2=12, + color="gray", + alpha=0.2, + label=r"$B$-mode informed scale cut", +) +ax2.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color="gray", alpha=0.2) + +ax2.set_ylim(ymin, ymax) + +# ax2.set_ylabel(r'$\theta \xi_-$', fontsize=16) +ax2.set_xlabel(r"$\theta$ (arcmin)", fontsize=26) +ax2.set_xlim([theta.min() - 0.1, theta.max() + 20]) +ax2.set_xscale("log") +ax2.set_title(r"$\tau_{2,+}(\theta)$", fontsize=26) +ax2.set_xticks(np.array([1, 10, 100])) +ax2.tick_params(axis="x", which="minor", length=2, width=0.8) +ax2.tick_params(axis="both", which="major", labelsize=24) +ax2.tick_params(axis="both", which="minor", labelsize=20) +ax2.yaxis.get_offset_text().set_fontsize(24) +ax2.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) +ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20) + +plt.savefig( + "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/best_fit_tau_02_SP_v1.4.6.3_B.pdf", + bbox_inches="tight", +) + + + + + + + diff --git a/papers/realspace/contours.py b/papers/realspace/contours.py new file mode 100644 index 00000000..9d103211 --- /dev/null +++ b/papers/realspace/contours.py @@ -0,0 +1,761 @@ +# # 2D contour plots +# +# This notebook produces the plots for all the 2D contours in the results section. + + +import os.path + +import matplotlib.pyplot as plt +import numpy as np +import seaborn as sns +from astropy.io import fits +from getdist import plots + +plt.style.use("/home/guerrini/matplotlib_config/paper.mplstyle") + +plt.rcParams["text.usetex"] = True + +sns.set_palette("husl") +g = plots.get_subplot_plotter(width_inch=30) +g.settings.axes_fontsize = 70 +g.settings.axes_labelsize = 80 +g.settings.alpha_filled_add = 0.7 +g.settings.legend_fontsize = 70 + + +# SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE + +root_dir = "/n09data/guerrini/output_chains/" +path_datavectors = "/home/guerrini/sp_validation/cosmo_inference/data/" +path_output_chains = "/n09data/guerrini/output_chains/" + +data = fits.open( + os.path.join( + path_datavectors, + "SP_v1.4.6.3_config/SP_v1.4.6.3_B/cosmosis_SP_v1.4.6.3_leak_corr_B_masked.fits", + ) +) + +roots_fid = { + "SP_v1.4.6.3_leak_corr_B": r"UNIONS-3500 $C_\ell$", + "SP_v1.4.6.3_B_fiducial_config": r"UNIONS-3500 $\xi_\pm$ (This work) ", + "KiDS-Legacy_xipm": r"KiDS-Legacy $\xi_\pm$", + "HSC_Y3": r"HSC-Y3 $\xi_\pm$", + "Planck18": r"$\textit{Planck}$ 2018", +} + +roots_full = { + "SP_v1.4.6.3_B_fiducial_config": r"UNIONS-3500 $\xi_\pm$ (This work) ", +} + +roots_ia = { + "SP_v1.4.6.3_B_fiducial_config": r"Gaussian $A_{\rm{IA}}$ prior", + "SP_v1.4.6.3_B_flat_ia_config": r"Flat $A_{\rm{IA}}$ prior", + "SP_v1.4.6.3_B_no_ia_config": r"No IA", +} + +roots_ext = { + "SP_v1.4.6.3_B_fiducial_config": r"UNIONS-3500 $\xi_\pm$", + "SP_v1.4.6.3_B_planck_config": r"UNIONS-3500 $\xi_\pm$ + CMB", + "SP_v1.4.6.3_B_planck_desi_config": r"UNIONS-3500 $\xi_\pm$ + CMB + BAO", + "Planck18": r"$\textit{Planck}$ 2018", +} + +roots_dz = { + "SP_v1.4.6.3_B_fiducial_config": r"Gaussian $\Delta z$ prior", + "SP_v1.4.6.3_B_flat_delta_z_config": r"Flat $\Delta z$ prior", + "SP_v1.4.6.3_B_no_delta_z_config": r"No $\Delta z$ modelling", +} + +roots_psf = { + "SP_v1.4.6.3_B_flat_alpha_beta_config": r"Flat $\alpha$ and $\beta$ priors", + "SP_v1.4.6.3_B_fiducial_config": r"Gaussian $\alpha$ and $\beta$ priors", + "SP_v1.4.6.3_B_no_xi_sys_config": r"No $\xi^{\rm sys}$ included", + "SP_v1.4.6.3_B_no_leak_corr_config": r"No object-wise leakage correction", +} + +roots_scale = { + "SP_v1.4.6.3_B_fiducial_config": r"$\xi_+$: $\theta=[12,83]$", + "SP_v1.4.6.3_B_small_scales_config": r"$\xi_+$: $\theta=[5,83]$", +} + +roots_nonlin = { + "SP_v1.4.6.3_B_fiducial_config": r"Fiducial (\texttt{HMCode2020}, $\log(T_{\rm AGN})$)", + "SP_v1.4.6.3_B_no_baryons_config": r"\texttt{HMCode2020} no baryons", + "SP_v1.4.6.3_B_halofit_config": r"\texttt{Halofit}", +} +roots = roots_ext + + +# ## Retrieve the chains + + +# READ CHAIN + +chains = [] + +for i, root in enumerate(list(roots.keys())): + burnin = 0 + if "SP" not in root: + chain = g.samples_for_root( + root_dir + "ext_data/{}/getdist_{}".format(root, root), + cache=False, + settings={ + "ignore_rows": burnin, + # 'smooth_scale_2D':0.2, + # 'smooth_scale_1D':0.2 + }, + ) + p = chain.getParams() + if hasattr(p, "S_8") == False: + omega_m = chain.getParams().OMEGA_M + sigma_8 = chain.getParams().SIGMA_8 + + s_8 = sigma_8 * (omega_m / 0.3) ** 0.5 + + chain.addDerived(s_8, name="S_8", label=r"S_8") + + p = chain.paramNames.parWithName("S_8") + + elif "config" in root: + if os.path.isfile(root_dir + "{}/getdist_{}.txt".format(root, root)) == False: + samples = np.loadtxt(root_dir + "{}/samples_{}.txt".format(root, root)) + + if "nautilus" in root: + weights = np.exp(samples[:, -3]) + neglogL = samples[:, -2] - samples[:, -1] + + samples = np.column_stack((weights, neglogL, samples[:, 0:-3])) + elif "mh" in root: + samples = np.column_stack( + ( + np.ones_like(samples[:, -1]), + np.log(samples[:, -1]) - np.log(samples[:, -2]), + samples[:, 0:-2], + ) + ) + burnin = 0.3 + else: + samples = np.column_stack( + (samples[:, -1], samples[:, -3], samples[:, 0:-4]) + ) + + np.savetxt(root_dir + "{}/getdist_{}.txt".format(root, root), samples) + + chain = g.samples_for_root( + root_dir + "{}/getdist_{}".format(root, root), + cache=False, + settings={ + "ignore_rows": burnin, + # 'smooth_scale_2D':0.2, + # 'smooth_scale_1D':0.2 + }, + ) + else: + if ( + os.path.isfile( + root_dir + "{}/{}/getdist_{}_cell.txt".format(root, root, root) + ) + == False + ): + samples = np.loadtxt( + root_dir + "{}/{}/samples_{}_cell.txt".format(root, root, root) + ) + + if "nautilus" in root: + weights = np.exp(samples[:, -3]) + neglogL = samples[:, -2] - samples[:, -1] + + samples = np.column_stack((weights, neglogL, samples[:, 0:-3])) + elif "mh" in root: + samples = np.column_stack( + ( + np.ones_like(samples[:, -1]), + np.log(samples[:, -1]) - np.log(samples[:, -2]), + samples[:, 0:-2], + ) + ) + burnin = 0.3 + else: + samples = np.column_stack( + (samples[:, -1], samples[:, -3], samples[:, 0:-4]) + ) + + np.savetxt( + root_dir + "{}/{}/getdist_{}_cell.txt".format(root, root, root), samples + ) + + chain = g.samples_for_root( + root_dir + "{}/{}/getdist_{}_cell".format(root, root, root), + cache=False, + settings={ + "ignore_rows": burnin, + # 'smooth_scale_2D':0.2, + # 'smooth_scale_1D':0.2 + }, + ) + p = chain.getParams() + + chains.append(chain) + + +name_list = [ + "OMEGA_M", + "ombh2", + "h0", + "n_s", + "SIGMA_8", + "S_8", + "logt_agn", + "a", + "m1", + "bias_1", + "alpha", + "beta", + "omch2", +] +label_list = [ + r"\Omega_{\rm m}", + r"\omega_{\rm b}", + r"h", + r"n_{\rm s}", + r"\sigma_8", + r"S_8", + r"\log T_{\rm AGN}", + r"A_{\rm IA}", + r"m_1", + r"\Delta z", + r"\alpha_{\rm PSF}", + r"\beta_{\rm PSF}", + r"\omega_{\rm c}", +] + +for chain in chains: + param_names = chain.getParamNames() + p = chain.getParams() + for name, label in zip(name_list, label_list): + if hasattr(p, name): + param_names.parWithName(name).label = label + +legend_labels = list(roots.values()) + + +# ## Plot the chains + + +# ### FIDUCIAL PLOT + + + +colours = [ + "royalblue", + "orange", + "crimson", + "forestgreen", + "indigo", +] + +linestyle = ["solid", "solid", "solid", "solid", "solid"] + +line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)] + +# FIDUCIAL PLOT +g.triangle_plot( + chains, + ["SIGMA_8", "S_8", "OMEGA_M"], # + legend_labels=legend_labels, + line_args=line_args, + contour_colors=colours, + label_order=[1, 0, 2, 3, 4], + filled=[True, True, False, False, True], +) + +g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot.pdf") + + +# ### FULL PLOT + + + + +g.settings.axes_fontsize = 40 +g.settings.axes_labelsize = 50 + +colours = [ + "orange", +] + +linestyle = [ + "solid", +] + +line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)] + +# FIDUCIAL PLOT +g.triangle_plot( + chains, + [ + "OMEGA_M", + "ombh2", + "h0", + "n_s", + "SIGMA_8", + "S_8", + "logt_agn", + "a", + "m1", + "bias_1", + ], + legend_labels=legend_labels, + line_args=line_args, + contour_colors=colours, + filled=True, +) + +g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_full.pdf") + + +# ### IA PLOT + + +colours = [ + "orange", + "royalblue", + "forestgreen", +] + +linestyle = [ + "solid", + "solid", + "solid", +] + +line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)] + +g.triangle_plot( + chains, + ["S_8", "OMEGA_M", "a"], # + legend_labels=legend_labels, + line_args=line_args, + contour_args={"alpha": 0.6}, + contour_colors=colours, + filled=[True, False, True], +) + +g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_ia.pdf") + + +# ### PSF PLOT + + +colours = [ + "royalblue", + "orange", + "hotpink", + "slategray", +] + +linestyle = [ + "solid", + "solid", + "solid", + "solid", +] + +line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)] + +g.triangle_plot( + chains, + ["S_8", "OMEGA_M", "alpha", "beta"], # + legend_labels=legend_labels, + line_args=line_args, + contour_args=[{"alpha": 1}, {"alpha": 0.6}, {"alpha": 0.8}, {"alpha": 0.8}], + contour_colors=colours, + legend_loc="upper right", + label_order=[1, 0, 2, 3], + filled=[False, True, True, True], +) + +g.subplots[3, 2].scatter( + 0.005, 0.81, color="k", marker="X", s=400, label="Fiducial config best-fit" +) +g.subplots[3, 2].scatter( + 0.022, 0.798, color="k", marker="P", s=400, label="Fiducial config best-fit" +) + +g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_psf.pdf") + + +# ### DELTA Z PLOT + + +colours = [ + "orange", + "royalblue", + "indigo", +] + +linestyle = [ + "solid", + "solid", + "solid", +] + +line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)] +g.triangle_plot( + chains, + ["S_8", "OMEGA_M", "bias_1"], # + legend_labels=legend_labels, + line_args=line_args, + contour_args=[{"alpha": 1.0}, {"alpha": 0.9}, {"alpha": 0.5}], + contour_colors=colours, + filled=[True, False, True], +) + +g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_dz.pdf") + + +# ### EXTERNAL DATA + + +colours = [ + "orange", + "royalblue", + "crimson", + "forestgreen", +] + +linestyle = [ + "solid", + "solid", + "solid", + "solid", + "solid", +] + +line_args = [dict(color=col, ls=ls) for col, ls in zip(colours, linestyle)] + +g = plots.get_subplot_plotter(width_inch=10) +g.settings.axes_fontsize = 25 +g.settings.axes_labelsize = 25 +g.settings.legend_fontsize = 22 + +g.plot_2d( + chains, + ["S_8", "OMEGA_M", "SIGMA_8"], # + line_args=line_args, + contour_colors=colours, + legend_labels=legend_labels, + alphas=[0.7, 1.0, 1.0, 1.0], + filled=[True, True, True, False], +) + +g.add_y_bands(0.2975, 0.0086, alpha2=0, color="k", label="BAO") +g.add_legend(legend_labels, legend_loc="upper right") + +g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_ext.pdf") + + +# ### Small scales + + + + +colours = [ + "orange", + "dodgerblue", +] + +linestyle = [ + "solid", + "solid", +] + +line_args = [dict(color=col, ls=ls) for col, ls in zip(colours, linestyle)] + +g = plots.get_subplot_plotter(width_inch=9) +g.settings.axes_fontsize = 25 +g.settings.axes_labelsize = 25 +g.settings.alpha_filled_add = 0.7 +g.settings.legend_fontsize = 30 + +g.plot_2d( + chains, + ["S_8", "OMEGA_M"], # + line_args=line_args, + contour_args=[{"alpha": 0.7}, {"alpha": 1.0}], + contour_colors=colours, + filled=[True, True], +) +g.add_legend(legend_labels, legend_loc="upper right") + +g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_scales.pdf") + + +# ### BBN Prior + + + + +from getdist.gaussian_mixtures import Gaussian1D + +colours = [ + "orange", + "royalblue", +] + +linestyle = [ + "solid", + "solid", +] + +line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)] + +# BBN PRIOR +bbn_prior = Gaussian1D( + mean=0.02218, + sigma=0.00055, + name="ombh2", + labels=[r"\omega_{\rm b}"], + label="BBN prior", +) +bbn_chain = bbn_prior.MCSamples(3000, label="BBN prior") + +g.triangle_plot( + chains + [bbn_chain], + name_list, + legend_labels=legend_labels, + line_args=line_args, + contour_colors=colours, + filled=[True, False], +) + + +# ## Plot the best-fit $\xi_\pm$ + + +xi_p_data = data["XI_PLUS"].data +xi_m_data = data["XI_MINUS"].data +cov_mat = data["COVMAT"].data + +labels = roots_scale.values() + +bbox_to_anchor_xip = (0.685, 0.09) +bbox_to_anchor_xim = (0.3, 0.65) +theta_min = 1.0 +theta_max = 250.0 +loc_legend = "lower center" + + +colours = [ + "orange", + "dodgerblue", +] + +linestyle = [ + "solid", + "solid", +] + +line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)] + +labels = roots_scale.values() + +fig, ax = plt.subplots(1, 1, figsize=(11, 7)) + +theta, xi_p, xi_m = xi_p_data["ANG"], xi_p_data["VALUE"], xi_m_data["VALUE"] +ax.errorbar( + theta, + theta * xi_p, + yerr=theta * np.sqrt(np.diag(cov_mat[: len(theta), : len(theta)])), + fmt="o", + color="black", + capsize=2, +) + +for idx, (label, root) in enumerate(zip(labels, roots_scale)): + # Read the results + theta = ( + ( + np.loadtxt( + path_output_chains + "{}/best_fit/shear_xi_plus/theta.txt".format(root) + ) + ) + * 180 + / np.pi + * 60 + ) + xi_plus = np.loadtxt( + path_output_chains + "{}/best_fit/shear_xi_plus/bin_1_1.txt".format(root) + ) + xi_minus = np.loadtxt( + path_output_chains + "{}/best_fit/shear_xi_minus/bin_1_1.txt".format(root) + ) + xi_sys_plus = np.loadtxt( + path_output_chains + "{}/best_fit/xi_sys/shear_xi_plus.txt".format(root) + ) + xi_sys_minus = np.loadtxt( + path_output_chains + "{}/best_fit/xi_sys/shear_xi_minus.txt".format(root) + ) + theta_xi_sys = ( + np.loadtxt(path_output_chains + "{}/best_fit/xi_sys/theta.txt".format(root)) + * 180 + / np.pi + * 60 + ) + + xi_sys_plus = np.interp(theta, theta_xi_sys, xi_sys_plus) + xi_sys_minus = np.interp(theta, theta_xi_sys, xi_sys_minus) + xi_plus += xi_sys_plus + xi_minus += xi_sys_minus + + mask = (theta > theta_min) & (theta < theta_max) + theta = theta[mask] + ax.plot(theta, theta * xi_plus[mask], label=label, **line_args[idx]) + +ymin = ax.get_ylim()[0] +ymax = ax.get_ylim()[1] + +ax.fill_betweenx(y=[ymin, ymax], x1=0, x2=12, color="gray", alpha=0.2) +ax.fill_betweenx(y=[ymin, ymax], x1=0, x2=5, color="gray", alpha=0.7) +ax.fill_betweenx(y=[ymin, ymax], x1=83, x2=300, color="gray", alpha=0.2) + +ax.set_ylim(ymin, ymax) + +ax.set_ylabel(r"$\theta \xi_\pm$", fontsize=26) +ax.set_xlabel(r"$\theta$ (arcmin)", fontsize=26) +ax.set_xlim([theta.min() - 0.1, theta.max() + 20]) +ax.set_title(r"$\xi_+(\theta)$", fontsize=26) +ax.set_xscale("log") +ax.set_xticks(np.array([1, 10, 100])) +ax.tick_params(axis="x", which="minor", length=2, width=0.8) +ax.tick_params(axis="both", which="major", labelsize=24) +ax.tick_params(axis="both", which="minor", labelsize=20) +ax.yaxis.get_offset_text().set_fontsize(24) +ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) +ax.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xip, fontsize=20) + + +plt.savefig("/Plots/scale_cut_xipm_SP_v1.4.6.3_B.pdf", bbox_inches="tight") + + + + +labels = roots_nonlin.values() + +colours = ["orange", "hotpink", "teal"] + +linestyle = ["solid", "solid", "dashed"] + +line_args = [dict(color=col, ls=ls, lw=2) for col, ls in zip(colours, linestyle)] + +fig, [ax, ax2] = plt.subplots(2, 1, figsize=(11, 14)) + +theta, xi_p, xi_m = xi_p_data["ANG"], xi_p_data["VALUE"], xi_m_data["VALUE"] +ax.errorbar( + theta, + theta * xi_p, + yerr=theta * np.sqrt(np.diag(cov_mat[: len(theta), : len(theta)])), + fmt="o", + color="black", + capsize=2, +) +ax2.errorbar( + theta, + theta * xi_m, + yerr=theta + * np.sqrt( + np.diag(cov_mat[len(theta) : 2 * len(theta), len(theta) : 2 * len(theta)]) + ), + fmt="o", + color="black", + capsize=2, +) + +for idx, (label, root) in enumerate(zip(labels, roots_nonlin)): + # Read the results + theta = ( + ( + np.loadtxt( + path_output_chains + "{}/best_fit/shear_xi_plus/theta.txt".format(root) + ) + ) + * 180 + / np.pi + * 60 + ) + xi_plus = np.loadtxt( + path_output_chains + "{}/best_fit/shear_xi_plus/bin_1_1.txt".format(root) + ) + xi_minus = np.loadtxt( + path_output_chains + "{}/best_fit/shear_xi_minus/bin_1_1.txt".format(root) + ) + xi_sys_plus = np.loadtxt( + path_output_chains + "{}/best_fit/xi_sys/shear_xi_plus.txt".format(root) + ) + xi_sys_minus = np.loadtxt( + path_output_chains + "{}/best_fit/xi_sys/shear_xi_minus.txt".format(root) + ) + theta_xi_sys = ( + np.loadtxt(path_output_chains + "{}/best_fit/xi_sys/theta.txt".format(root)) + * 180 + / np.pi + * 60 + ) + + xi_sys_plus = np.interp(theta, theta_xi_sys, xi_sys_plus) + xi_sys_minus = np.interp(theta, theta_xi_sys, xi_sys_minus) + xi_plus += xi_sys_plus + xi_minus += xi_sys_minus + + mask = (theta > theta_min) & (theta < theta_max) + theta = theta[mask] + ax.plot(theta, theta * xi_plus[mask], label=label, **line_args[idx]) + ax2.plot(theta, theta * xi_minus[mask], label=label, **line_args[idx]) + +ymin = ax.get_ylim()[0] +ymax = ax.get_ylim()[1] +ax.fill_betweenx(y=[ymin, ymax], x1=0, x2=12, color="gray", alpha=0.2) +ax.fill_betweenx(y=[ymin, ymax], x1=83, x2=300, color="gray", alpha=0.2) + +ax.set_ylim(ymin, ymax) + +ax.set_ylabel(r"$\theta \xi_\pm$", fontsize=26) +ax.set_xlabel(r"$\theta$ (arcmin)", fontsize=26) +ax.set_xlim([theta.min() - 0.1, theta.max() + 20]) +ax.set_title(r"$\xi_+(\theta)$", fontsize=26) +ax.set_xscale("log") +ax.set_xticks(np.array([1, 10, 100])) +ax.tick_params(axis="x", which="minor", length=2, width=0.8) +ax.tick_params(axis="both", which="major", labelsize=24) +ax.tick_params(axis="both", which="minor", labelsize=20) +ax.yaxis.get_offset_text().set_fontsize(24) +ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) + + +ymin = ax2.get_ylim()[0] +ymax = ax2.get_ylim()[1] +ax2.fill_betweenx(y=[ymin, ymax], x1=0, x2=12, color="gray", alpha=0.2) +ax2.fill_betweenx(y=[ymin, ymax], x1=83, x2=3000, color="gray", alpha=0.2) + +ax2.set_ylim(ymin, ymax) +ax2.set_xlabel(r"$\theta$ (arcmin)", fontsize=26) +ax2.set_xlim([theta.min() - 0.1, theta.max()]) +ax2.set_xscale("log") +ax2.set_title(r"$\xi_-(\vartheta)$", fontsize=26) +ax2.set_xticks(np.array([1, 10, 100])) +ax2.tick_params(axis="x", which="minor", length=2, width=0.8) +ax2.tick_params(axis="both", which="major", labelsize=24) +ax2.tick_params(axis="both", which="minor", labelsize=20) +ax2.yaxis.get_offset_text().set_fontsize(24) +ax2.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) +ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20) + +plt.savefig("/Plots/nonlin_xipm_SP_v1.4.6.3_B.pdf", bbox_inches="tight") + + + + + + + diff --git a/papers/realspace/cov_masking.py b/papers/realspace/cov_masking.py new file mode 100644 index 00000000..669b7f25 --- /dev/null +++ b/papers/realspace/cov_masking.py @@ -0,0 +1,84 @@ +# # Covmat mask analysis +# +# This notebook creates the plots to look at the ratio of the covaraiance matrices when applying the mask or not + + +import os + +import healpy as hp +import matplotlib.pyplot as plt +import numpy as np +import seaborn as sns + +plt.style.use("/home/guerrini/matplotlib_config/paper.mplstyle") + +plt.rcParams["axes.labelsize"] = 18 +plt.rcParams["xtick.labelsize"] = 18 +plt.rcParams["ytick.labelsize"] = 18 + +plt.rcParams["text.usetex"] = True +sns.set_palette("husl") + +cat_dir = "/n17data/UNIONS/WL/v1.4.x/" +catalog_ver = "v1.4.6.3" +blind = "B" + +nside = 8192 +npix = hp.nside2npix(nside) + +data_dir = "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/data/" +curr_dir = os.getcwd() + + +# PLOT 2D MAP OF COVMAT masked vs unmasked RATIOS +nbins = 20 +ndata = nbins * 2 +full_ratio = np.zeros((ndata, ndata)) + +cov = np.loadtxt(data_dir + f"/covs/cov_SP_{catalog_ver}_{blind}.txt") +cov_masked = np.loadtxt(data_dir + f"/covs/cov_masked_SP_{catalog_ver}_{blind}.txt") + +for i in range(ndata): + for j in range(ndata): + full_ratio[i][j] = cov_masked[i][j] / cov[i][j] + +fig = plt.figure() +ax = fig.add_subplot(1, 1, 1) +extent = (0, ndata, ndata, 0) + +vmin, vmax = np.percentile(full_ratio, [1, 99]) + +im3 = ax.imshow(full_ratio, cmap="RdBu_r", vmin=vmin, vmax=vmax, extent=extent) + +cbar = fig.colorbar(im3, ax=ax, fraction=0.046, pad=0.04) + +ax.text(int(ndata / 4), ndata + 5, r"$\xi_+$", fontsize=15) +ax.text(3 * int(ndata / 4), ndata + 5, r"$\xi_-$", fontsize=15) +ax.text(-8, int(ndata / 4), r"$\xi_+$", fontsize=15, rotation=90) +ax.text(-8, 3 * int(ndata / 4), r"$\xi_-$", fontsize=15, rotation=90) +ax.set_xticks([0, 10, 20, 30, 40]) +ax.set_yticks([0, 10, 20, 30, 40]) +ax.set_yticklabels(["1'", "125'", "250'", "125'", "250'"]) +ax.set_xticklabels(["1'", "125'", "250'", "125'", "250'"]) +plt.axvline(x=int(ndata / 2), color="white", linewidth=1.0) +plt.axhline(y=int(ndata / 2), color="white", linewidth=1.0) + +plt.savefig( + f"./Plots/covmat_masked_unmasked_ratio_{catalog_ver}_{blind}.pdf", + bbox_inches="tight", +) + + +theta = np.linspace(1, 250, 20) +plt.axhline(y=1, color="k", ls="--") +plt.plot(theta, np.diag(cov_masked)[:20] / np.diag(cov)[:20], label=r"$\xi_+$") +plt.plot(theta, np.diag(cov_masked)[20:] / np.diag(cov)[20:], label=r"$\xi_-$") + +plt.xlabel(r"$\theta$ (arcmin)") +plt.ylabel("Cov masked / Cov unmasked") +plt.legend(fontsize=20) +plt.savefig( + f"./Plots/covmat_masked_unmasked_ratio_diag.pdf", bbox_inches="tight" +) + + diff --git a/papers/realspace/get_chi2.py b/papers/realspace/get_chi2.py new file mode 100644 index 00000000..24e67ca5 --- /dev/null +++ b/papers/realspace/get_chi2.py @@ -0,0 +1,574 @@ + +import configparser +import os +import re +import subprocess +import sys + +import matplotlib.pyplot as plt +import numpy as np +import scipy.stats as stats +from astropy.io import fits +from getdist import plots +from IPython.display import Markdown, display +from scipy.interpolate import interp1d + +sys.path.append("/home/guerrini/sp_validation/cosmo_inference/scripts") + +import chain_postprocessing + + + +plt.rc("mathtext", fontset="stix") +plt.rc("font", family="sans-serif") + +g = plots.get_subplot_plotter(width_inch=30) +g.settings.axes_fontsize = 30 +g.settings.axes_labelsize = 30 +g.settings.alpha_filled_add = 0.7 +g.settings.legend_fontsize = 40 + +# #SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE +root_dir = "/n09data/guerrini/output_chains/" +blind = "B" + +roots = [ + f"SP_v1.4.6.3_{blind}_fiducial_config", + f"SP_v1.4.6.3_{blind}_small_scales_config", + f"SP_v1.4.6.3_{blind}_flat_alpha_beta_config", + f"SP_v1.4.6.3_{blind}_no_xi_sys_config", + f"SP_v1.4.6.3_{blind}_no_leak_corr_config", + f"SP_v1.4.6.3_{blind}_flat_delta_z_config", + f"SP_v1.4.6.3_{blind}_no_delta_z_config", + f"SP_v1.4.6.3_{blind}_flat_ia_config", + f"SP_v1.4.6.3_{blind}_no_ia_config", + f"SP_v1.4.6.3_{blind}_no_m_bias_config", + f"SP_v1.4.6.3_{blind}_unmasked_covmat_config", + f"SP_v1.4.6.3_{blind}_halofit_config", + f"SP_v1.4.6.3_{blind}_no_baryons_config", + f"SP_v1.4.6.3_{blind}_nautilus_config", + f"SP_v1.4.6.3_{blind}_planck_config", + f"SP_v1.4.6.3_{blind}_planck_desi_config", +] + +catalog_versions = [ + f"SP_v1.4.6.3_config/SP_v1.4.6.3_{blind}", +] + +catalog_sub_versions = [ + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", + f"SP_v1.4.6.3_leak_corr_{blind}_masked", +] +output_folder = "/n09data/guerrini/output_chains/" + +path_ini_files = "/home/guerrini/sp_validation/cosmo_inference/cosmosis_config/" + + +ini_roots = [ + f"blind_{blind}/fiducial", + f"blind_{blind}/small_scales", + f"blind_{blind}/flat_alpha_beta", + f"blind_{blind}/no_xi_sys", + f"blind_{blind}/no_leak_corr", + f"blind_{blind}/flat_delta_z", + f"blind_{blind}/no_delta_z", + f"blind_{blind}/flat_ia", + f"blind_{blind}/no_ia", + f"blind_{blind}/no_m_bias", + f"blind_{blind}/unmasked_covmat", + f"blind_{blind}/halofit", + f"blind_{blind}/no_baryons", + f"blind_{blind}/nautilus", + f"blind_{blind}/planck", + f"blind_{blind}/planck_desi", +] + +properties = {} + +for i, root in enumerate(roots): + print(root) + config = configparser.ConfigParser() + config.optionxform = str # Preserve case sensitivity of option names + config.read( + path_ini_files + + "config_space_v1.4.6.3_fiducial/pipeline/" + + ini_roots[i] + + ".ini" + ) + add_xi_sys = config["2pt_like"]["add_xi_sys"] + lower_bound_xi_plus, upper_bound_xi_plus = map( + float, config["2pt_like"]["angle_range_XI_PLUS_1_1"].split() + ) + lower_bound_xi_minus, upper_bound_xi_minus = map( + float, config["2pt_like"]["angle_range_XI_MINUS_1_1"].split() + ) + + properties[root] = { + "add_xi_sys": add_xi_sys, + "lower_bound_xi_plus": lower_bound_xi_plus, + "upper_bound_xi_plus": upper_bound_xi_plus, + "lower_bound_xi_minus": lower_bound_xi_minus, + "upper_bound_xi_minus": upper_bound_xi_minus, + } + + +# ## Retrieve the chains + + +# READ CHAIN + +chains = [] + +for i, root in enumerate(roots): + burnin = 0 + + if os.path.isfile(root_dir + "{}/getdist_{}.txt".format(root, root)) == False: + samples = np.loadtxt(root_dir + "{}/samples_{}.txt".format(root, root)) + + if "nautilus" in root: + samples = np.column_stack( + ( + np.exp(samples[:, -3]), + samples[:, -1] - samples[:, -2], + samples[:, 0:-3], + ) + ) + elif "mh" in root: + samples = np.column_stack( + ( + np.ones_like(samples[:, -1]), + np.log(samples[:, -1]) - np.log(samples[:, -2]), + samples[:, 0:-2], + ) + ) + burnin = 0.3 + else: + samples = np.column_stack( + (samples[:, -1], samples[:, -3], samples[:, 0:-4]) + ) + + np.savetxt(root_dir + "{}/getdist_{}.txt".format(root, root), samples) + + chain = g.samples_for_root( + root_dir + "{}/getdist_{}".format(root, root), + cache=False, + settings={ + "ignore_rows": burnin, + "smooth_scale_2D": 0.5, + "smooth_scale_1D": 0.5, + }, + ) + p = chain.getParams() + + chains.append(chain) + + +param_list = [ + "OMEGA_M", + "ombh2", + "h0", + "n_s", + "SIGMA_8", + "s_8_input", + "logt_agn", + "a", + "m1", + "bias_1", + "alpha", + "beta", + "omch2", + "m", + "a_planck", +] +label_list = [ + r"\Omega_m", + r"\omega_b", + "h_0", + "n_s", + r"\sigma_8", + "S_8", + "log T_{AGN}", + "A_{IA}", + "m_1", + r"\Delta z_1", + "\\alpha_{PSF}", + "\\beta_{PSF}", + r"\omega_c", + "M", + "A_{\rm Planck}", +] + +for chain in chains: + param_names = chain.getParamNames() + for name, label in zip(param_list, label_list): + if param_names.parWithName(name) is not None: + param_names.parWithName(name).label = label + + +# ## Extract the best fit parameters + + +best_fit = {} + +for root, chain in zip(roots, chains): + print(root) + p = chain.getParams() + + best_fit[root] = chain_postprocessing.extract_best_fit_params( + chain, best_fit_method="2Dkde" + ) + + for param_name in best_fit[root].keys(): + high_68, low_68, high_95, low_95 = chain_postprocessing.compute_limits( + chain, param_name + ) + if param_name == "S_8": + print(f"{best_fit[root][param_name]}") + + +# ## Run `Cosmosis` in test mode to get the data vectors + + +if not os.path.exists(path_ini_files + "/values_empty.ini"): + content = """[cosmological_parameters] + +tau = 0.0544 +w = -1.0 +mnu = 0.06 +omega_k = 0.0 +wa = 0.0 + +[halo_model_parameters] + +[intrinsic_alignment_parameters] + +[shear_calibration_parameters] + +[nofz_shifts] + +[psf_leakage_parameters] +""" + + with open(path_ini_files + "/values_empty.ini", "w") as f: + f.write(content) + f.close() + + print("File created successfully") + + +section_map = { + "omch2": "cosmological_parameters", + "ombh2": "cosmological_parameters", + "h0": "cosmological_parameters", + "n_s": "cosmological_parameters", + "tau": "cosmological_parameters", + "s_8_input": "cosmological_parameters", + "logt_agn": "halo_model_parameters", + "a": "intrinsic_alignment_parameters", + "m1": "shear_calibration_parameters", + "bias_1": "nofz_shifts", + "alpha": "psf_leakage_parameters", + "beta": "psf_leakage_parameters", + "m": "supernova_params", + "a_planck": "planck", +} + +best_fit["SP_v1.4.6.3_B_no_ia_config"]["a"] = 0 + + +env = os.environ.copy() +env["LD_LIBRARY_PATH"] = ( + "/home/guerrini/.conda/envs/sp_validation/lib/python3.9/site-packages/cosmosis/datablock:" + + env.get("LD_LIBRARY_PATH", "") +) + +for i, root in enumerate(roots): + print(root) + config = configparser.ConfigParser() + config.optionxform = str # Preserve case sensitivity of option names + + for param, section in section_map.items(): + # Check if this parameter exists for the current root + if param in best_fit[root]: + value = best_fit[root][param] + + if section not in config: + config.add_section(section) + + config[section][param] = str(value) + + with open(path_ini_files + "/values_empty.ini", "w") as configfile: + config.write(configfile) + + # Modify the ini file to run in test mode at the best fit + config = configparser.ConfigParser() + config.optionxform = str # Preserve case sensitivity of option names + + ini_file = path_ini_files + "config_space_v1.4.6.3_fiducial/pipeline/{}.ini".format( + ini_roots[i] + ) + config.read(ini_file) + + sampler = config["runtime"]["sampler"] + config["runtime"]["sampler"] = "test" + values = config["pipeline"]["values"] + config["pipeline"]["values"] = path_ini_files + "/values_empty.ini" + config["DEFAULT"]["FITS_FILE"] = ( + f"/home/guerrini/sp_validation/cosmo_inference/data/{catalog_versions[0]}/cosmosis_{catalog_sub_versions[i]}.fits" + ) + config["test"]["save_dir"] = root_dir + "{}/best_fit".format(root) + + with open(ini_file, "w") as configfile: + config.write(configfile) + + # Run cosmosis + result = subprocess.run( + ["cosmosis", ini_file], env=env, capture_output=True, text=True + ) + print(f"STDOUT:\n{result.stdout}") + print(f"STDERR:\n{result.stderr}") + + # Modify the ini file to the previous one + config["pipeline"]["values"] = values + config["runtime"]["sampler"] = sampler + + with open(ini_file, "w") as configfile: + config.write(configfile) + + +# ## Compute the $\chi^2$ + + +metrics = {} + +for idx, root in enumerate(roots): + print(root) + match = re.search(r"corr_([A-Za-z])", root) + if match: + blind = match.group(1) + + add_xi_sys = properties[root]["add_xi_sys"] + print(f"add_xi_sys: {add_xi_sys}") + lower_bound_xi_plus = properties[root]["lower_bound_xi_plus"] + upper_bound_xi_plus = properties[root]["upper_bound_xi_plus"] + lower_bound_xi_minus = properties[root]["lower_bound_xi_minus"] + upper_bound_xi_minus = properties[root]["upper_bound_xi_minus"] + + # Read the results + theta = np.loadtxt( + output_folder + "{}/best_fit/shear_xi_plus/theta.txt".format(root) + ) + theta_arcmin = theta * 180 * 60 / np.pi + shear_xi_plus = np.loadtxt( + output_folder + "{}/best_fit/shear_xi_plus/bin_1_1.txt".format(root) + ) + shear_xi_minus = np.loadtxt( + output_folder + "{}/best_fit/shear_xi_minus/bin_1_1.txt".format(root) + ) + + if add_xi_sys == "T": + xi_sys_plus = np.loadtxt( + output_folder + "{}/best_fit/xi_sys/shear_xi_plus.txt".format(root) + ) + xi_sys_minus = np.loadtxt( + output_folder + "{}/best_fit/xi_sys/shear_xi_minus.txt".format(root) + ) + + theta_tau = np.loadtxt( + output_folder + "{}/best_fit/tau_0_plus/theta.txt".format(root) + ) + theta_tau_arcmin = theta_tau * 180 * 60 / np.pi + tau_0_model = np.loadtxt( + output_folder + "{}/best_fit/tau_0_plus/bin_1_1.txt".format(root) + ) + tau_2_model = np.loadtxt( + output_folder + "{}/best_fit/tau_2_plus/bin_1_1.txt".format(root) + ) + + data = fits.open( + f"/home/guerrini/sp_validation/cosmo_inference/data/{catalog_versions[0]}/cosmosis_{catalog_sub_versions[idx]}.fits" + ) + + tau_0_data = data["TAU_0_PLUS"].data["VALUE"] + tau_2_data = data["TAU_2_PLUS"].data["VALUE"] + + theta_data = data["XI_PLUS"].data["ANG"] + xi_plus_data = data["XI_PLUS"].data["VALUE"] + xi_minus_data = data["XI_MINUS"].data["VALUE"] + + # Load the covariance + cov = data["COVMAT"].data + cov_xi = cov[0 : 2 * len(xi_plus_data), 0 : 2 * len(xi_plus_data)] + cov_tau = cov[2 * len(xi_plus_data) :, 2 * len(xi_plus_data) :] + + # interpolate the model + interp_xi_plus = interp1d( + theta_arcmin, shear_xi_plus, kind="cubic", fill_value="extrapolate" + ) + interp_xi_minus = interp1d( + theta_arcmin, shear_xi_minus, kind="cubic", fill_value="extrapolate" + ) + + xi_plus_model = interp_xi_plus(theta_data) + if add_xi_sys: + xi_plus_model += xi_sys_plus + xi_minus_model = interp_xi_minus(theta_data) + if add_xi_sys: + xi_minus_model += xi_sys_minus + + # Concatenate the data vector + xi_data = np.concatenate((xi_plus_data, xi_minus_data)) + xi_model = np.concatenate((xi_plus_model, xi_minus_model)) + + tau_data = np.concatenate((tau_0_data, tau_2_data)) + tau_model = np.concatenate((tau_0_model, tau_2_model)) + + # Apply scale cuts + mask_xi_plus = (theta_data > lower_bound_xi_plus) & ( + theta_data < upper_bound_xi_plus + ) + mask_xi_minus = (theta_data > lower_bound_xi_minus) & ( + theta_data < upper_bound_xi_minus + ) + mask = np.concatenate((mask_xi_plus, mask_xi_minus)) + + xi_data = xi_data[mask] + xi_model = xi_model[mask] + cov_xi = cov_xi[mask][:, mask] + + cov_xi_plus = cov[0 : len(xi_plus_data), 0 : len(xi_plus_data)] + cov_xi_plus = cov_xi_plus[mask_xi_plus][:, mask_xi_plus] + cov_xi_minus = cov[ + len(xi_plus_data) : 2 * len(xi_minus_data), + len(xi_plus_data) : 2 * len(xi_minus_data), + ] + cov_xi_minus = cov_xi_minus[mask_xi_minus][:, mask_xi_minus] + + xi_plus_chi2 = np.dot( + (xi_plus_model[mask_xi_plus] - xi_plus_data[mask_xi_plus]), + np.dot( + np.linalg.inv(cov_xi_plus), + (xi_plus_model[mask_xi_plus] - xi_plus_data[mask_xi_plus]), + ), + ) + xi_minus_chi2 = np.dot( + (xi_minus_model[mask_xi_minus] - xi_minus_data[mask_xi_minus]), + np.dot( + np.linalg.inv(cov_xi_minus), + (xi_minus_model[mask_xi_minus] - xi_minus_data[mask_xi_minus]), + ), + ) + xi_chi2 = np.dot( + (xi_model - xi_data), np.dot(np.linalg.inv(cov_xi), (xi_model - xi_data)) + ) + tau_chi2 = np.dot( + (tau_model - tau_data), np.dot(np.linalg.inv(cov_tau), (tau_model - tau_data)) + ) + n_dof_xi_plus = np.sum(mask_xi_plus) + n_dof_xi_minus = np.sum(mask_xi_minus) + n_dof_tau = len(tau_0_data) + len(tau_2_data) + p_value_xi_plus = 1 - stats.chi2.cdf(xi_plus_chi2, n_dof_xi_plus) + p_value_xi_minus = 1 - stats.chi2.cdf(xi_minus_chi2, n_dof_xi_minus) + p_value_xi = 1 - stats.chi2.cdf(xi_chi2, n_dof_xi_plus + n_dof_xi_minus) + p_value_tau = 1 - stats.chi2.cdf(tau_chi2, n_dof_tau) + chi2_tot = xi_plus_chi2 + xi_minus_chi2 + tau_chi2 + n_dof_tot = n_dof_xi_plus + n_dof_xi_minus + n_dof_tau + p_value_tot = 1 - stats.chi2.cdf(chi2_tot, n_dof_tot) + + metrics[root] = { + "chi2_xi_plus": xi_plus_chi2, + "n_dof_xi_plus": n_dof_xi_plus, + "p_value_xi_plus": p_value_xi_plus, + "chi2_xi_minus": xi_minus_chi2, + "n_dof_xi_minus": n_dof_xi_minus, + "p_value_xi_minus": p_value_xi_minus, + "chi2_xi": xi_chi2, + "p_value_xi": p_value_xi, + "chi2_tau": tau_chi2, + "n_dof_tau": n_dof_tau, + "p_value_tau": p_value_tau, + "chi2_tot": chi2_tot, + "n_dof_tot": n_dof_tot, + "p_value_tot": p_value_tot, + } + print("Done!") + + +def get_latex_table(metrics): + latex_lines = [ + r"\begin{tabular}{lccc|ccc|ccc}", + r"\hline", + r"Root & $\chi^2_{\xi^+}$/dof & $p_{\xi^+}$ & $\chi^2_{\xi^-}$/dof & $p_{\xi^+}$ & $\chi^2_{\xi}$/dof & $p_{\xi}$ &" + r"$\chi^2_\tau$/dof & $p_\tau$ & $\chi^2_{\text{tot}}$/dof & $p_{\text{tot}}$ \\", + r"\hline", + ] + + for root, vals in metrics.items(): + escaped = root.replace("_", r"\_") + line = ( + f"{escaped} & " + f"{vals['chi2_xi_plus']:.2f}/{vals['n_dof_xi_plus']} & {vals['p_value_xi_plus']:.3g} & " + f"{vals['chi2_xi_minus']:.2f}/{vals['n_dof_xi_minus']} & {vals['p_value_xi_minus']:.3g} & " + f"{vals['chi2_xi']:.2f}/{vals['n_dof_xi_plus'] + vals['n_dof_xi_minus']} & {vals['p_value_xi']:.3g} &" + f"{vals['chi2_tau']:.2f}/{vals['n_dof_tau']} & {vals['p_value_tau']:.3g} & " + f"{vals['chi2_tot']:.2f}/{vals['n_dof_tot']} & {vals['p_value_tot']:.3g} \\\\" + ) + latex_lines.append(line) + + latex_lines.append(r"\hline") + latex_lines.append(r"\end{tabular}") + + # Print LaTeX table + print("\n".join(latex_lines)) + + +get_latex_table(metrics) + + +def display_markdown(metrics): + # Build Markdown table + header = ( + "| Root | $\\chi^2$ (ξ⁺) / dof | p-val (ξ⁺) |$\\chi^2$ (ξ-) / dof | p-val (ξ-) | $\\chi^2$ (ξ) / dof | p-val (ξ) | $\\chi^2$ (τ) / dof | p-val (τ) | $\\chi^2$ (tot) / dof | p-val (tot) |\n" + "|------|----------------|------------|----------------|------------|------------|---------------|------------|------------|------------------|--------------|\n" + ) + + rows = [] + for root, vals in metrics.items(): + row = f"| `{root}` " + row += f"| {vals['chi2_xi_plus']:.2f} / {vals['n_dof_xi_plus']} " + row += f"| {vals['p_value_xi_plus']:.5f} " + row += f"| {vals['chi2_xi_minus']:.2f} / {vals['n_dof_xi_minus']} " + row += f"| {vals['p_value_xi_minus']:.5f} " + row += f"| {vals['chi2_xi']:.2f} / {vals['n_dof_xi_minus'] + vals['n_dof_xi_plus']} " + row += f"| {vals['p_value_xi']:.5f} " + row += f"| {vals['chi2_tau']:.2f} / {vals['n_dof_tau']} " + row += f"| {vals['p_value_tau']:.5f} " + row += f"| {vals['chi2_tot']:.2f} / {vals['n_dof_tot']} " + row += f"| {vals['p_value_tot']:.5f} |" + rows.append(row) + + # Display in Jupyter + display(Markdown(header + "\n".join(rows))) + return header + "\n".join(rows) + + +markdown_source = display_markdown(metrics) + + + + + diff --git a/papers/realspace/get_chi2_glass_mock.py b/papers/realspace/get_chi2_glass_mock.py new file mode 100644 index 00000000..a08669cf --- /dev/null +++ b/papers/realspace/get_chi2_glass_mock.py @@ -0,0 +1,480 @@ + + +import configparser +import os +import subprocess +import sys + +import matplotlib.pyplot as plt +import numpy as np + +# Make the plot +import seaborn as sns +from astropy.io import fits +from getdist import plots +from scipy.interpolate import interp1d +from scipy.stats import chi2 + +sys.path.append("/home/guerrini/sp_validation/cosmo_inference/scripts") + +import chain_postprocessing + + +plt.style.use("/home/guerrini/matplotlib_config/paper.mplstyle") + +plt.rcParams["axes.labelsize"] = 18 +plt.rcParams["xtick.labelsize"] = 18 +plt.rcParams["ytick.labelsize"] = 18 + +plt.rcParams["text.usetex"] = True + +g = plots.get_subplot_plotter(width_inch=30) +g.settings.axes_fontsize = 30 +g.settings.axes_labelsize = 30 +g.settings.alpha_filled_add = 0.7 +g.settings.legend_fontsize = 40 + +# #SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE + +root_dir = "/n09data/guerrini/glass_mock_chains/" + +# Version of the glass mock chain run +chain_version = "v6" + +# Path to the glass mock data vectors +root_glass_dv = ( + f"/home/guerrini/sp_validation/cosmo_inference/data/glass_mocks/{chain_version}/" +) + +# Choose the best-fit method +best_fit_method = "2Dkde" + +# Create the list of mocks +max_sim = 350 +failed_simulations = [82, 83, 281, 282, 283, 284, 285, 286, 287] +roots = [f"glass_mock_{chain_version}_{str(i).zfill(5)}" for i in range(1, max_sim + 1)] +roots = [root for root in roots if int(root.split("_")[-1]) not in failed_simulations] + +catalog_versions = [ + "SP_v1.4.6.3_config/SP_v1.4.6.3_A", +] + +output_folder_chains = "/n23data1/n06data/lgoh/scratch/temp/" +path_ini_files = "/home/guerrini/sp_validation/cosmo_inference/cosmosis_config/" +output_fig_path = ( + "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/" +) + +ini_root = "blind_A/fiducial" + +lower_bound_xi = 12 +upper_bound_xi = 83 + +# ## Retrieve the chains + + +# READ CHAIN + +chains = [] +best_fit = {} + +for i, root in enumerate(roots): + burnin = 0 + + if os.path.isfile(f"{root_dir}/{root}/{root}/getdist_{root}.txt") == True: + chain = g.samples_for_root( + f"{root_dir}/{root}/{root}/getdist_{root}", + cache=False, + settings={ + "ignore_rows": burnin, + "smooth_scale_2D": 0.5, + "smooth_scale_1D": 0.5, + }, + ) + p = chain.getParams() + + best_fit[root] = chain_postprocessing.extract_best_fit_params( + chain, best_fit_method="2Dkde" + ) + + +param_list = [ + "OMEGA_M", + "ombh2", + "h0", + "n_s", + "SIGMA_8", + "s_8_input", + "logt_agn", + "a", + "m1", + "bias_1", + "alpha", + "beta", + "omch2", + "m", + "a_planck", +] +label_list = [ + r"\Omega_m", + r"\omega_b", + "h_0", + "n_s", + r"\sigma_8", + "S_8", + "log T_{AGN}", + "A_{IA}", + "m_1", + r"\Delta z_1", + "\\alpha_{PSF}", + "\\beta_{PSF}", + r"\omega_c", + "M", + "A_{\rm Planck}", +] + + +# ## Run `Cosmosis` in test mode to get the data vectors + + +if not os.path.exists(path_ini_files + "/values_empty.ini"): + content = """[cosmological_parameters] + +tau = 0.0544 +w = -1.0 +mnu = 0.06 +omega_k = 0.0 +wa = 0.0 + +[halo_model_parameters] + +[intrinsic_alignment_parameters] + +[shear_calibration_parameters] + +[nofz_shifts] + +[psf_leakage_parameters] +""" + + with open(path_ini_files + "/values_empty.ini", "w") as f: + f.write(content) + f.close() + + print("File created successfully") + + +section_map = { + "omch2": "cosmological_parameters", + "ombh2": "cosmological_parameters", + "h0": "cosmological_parameters", + "n_s": "cosmological_parameters", + "s_8_input": "cosmological_parameters", + "logt_agn": "halo_model_parameters", + "a": "intrinsic_alignment_parameters", + "m1": "shear_calibration_parameters", + "bias_1": "nofz_shifts", + "alpha": "psf_leakage_parameters", + "beta": "psf_leakage_parameters", +} + + +env = os.environ.copy() +env["LD_LIBRARY_PATH"] = ( + "/home/guerrini/.conda/envs/sp_validation/lib/python3.9/site-packages/cosmosis/datablock:" + + env.get("LD_LIBRARY_PATH", "") +) +for i, root in enumerate(roots): + print(root) + config = configparser.ConfigParser() + config.optionxform = str # Preserve case sensitivity of option names + + for param, section in section_map.items(): + # Check if this parameter exists for the current root + if param in best_fit[root]: + value = best_fit[root][param] + + if section not in config: + config.add_section(section) + + config[section][param] = str(value) + + with open(path_ini_files + "/values_empty.ini", "w") as configfile: + config.write(configfile) + + # Modify the ini file to run in test mode at the best fit + config = configparser.ConfigParser() + config.optionxform = str # Preserve case sensitivity of option names + + ini_file = ( + path_ini_files + f"config_space_v1.4.6.3_fiducial/pipeline/{ini_root}.ini" + ) + config.read(ini_file) + + sampler = config["runtime"]["sampler"] + config["runtime"]["sampler"] = "test" + values = config["pipeline"]["values"] + config["pipeline"]["values"] = path_ini_files + "/values_empty.ini" + config["DEFAULT"]["FITS_FILE"] = ( + f"{root_glass_dv}/glass_mock_{root[-5:]}/cosmosis_glass_mock_v6_{root[-5:]}.fits" + ) + config["test"]["save_dir"] = output_folder_chains + f"{root}/best_fit_config" + + with open(ini_file, "w") as configfile: + config.write(configfile) + + # Run cosmosis + result = subprocess.run( + ["cosmosis", ini_file], env=env, capture_output=True, text=True + ) + # print(f"STDOUT:\n{result.stdout}") + # print(f"STDERR:\n{result.stderr}") + + # Modify the ini file to the previous one + config["pipeline"]["values"] = values + config["runtime"]["sampler"] = sampler + + with open(ini_file, "w") as configfile: + config.write(configfile) + + +xi_plus_chi2s = np.array([]) +xi_minus_chi2s = np.array([]) +xi_chi2s = np.array([]) +tau_chi2s = np.array([]) +chi2_tots = np.array([]) + + +for idx, root in enumerate(roots): + print(root) + + data = fits.open( + f"{root_glass_dv}/glass_mock_{root[-5:]}/cosmosis_glass_mock_v6_{root[-5:]}.fits" + ) + + tau_0_data = data["TAU_0_PLUS"].data["VALUE"] + tau_2_data = data["TAU_2_PLUS"].data["VALUE"] + + theta_data = data["XI_PLUS"].data["ANG"] + xi_plus_data = data["XI_PLUS"].data["VALUE"] + xi_minus_data = data["XI_MINUS"].data["VALUE"] + xi_data = np.concatenate((xi_plus_data, xi_minus_data)) + + tau_data = np.concatenate((tau_0_data, tau_2_data)) + + # Apply scale cuts + mask_xi_plus = (theta_data > lower_bound_xi) & (theta_data < upper_bound_xi) + mask_xi_minus = (theta_data > lower_bound_xi) & (theta_data < upper_bound_xi) + mask = np.concatenate((mask_xi_plus, mask_xi_minus)) + # Load the covariance + cov = data["COVMAT"].data + cov_xi = cov[0 : 2 * len(xi_plus_data), 0 : 2 * len(xi_plus_data)] + cov_tau = cov[ + 2 * len(xi_plus_data) : 4 * len(xi_plus_data), + 2 * len(xi_plus_data) : 4 * len(xi_plus_data), + ] + xi_data = xi_data[mask] + cov_xi = cov_xi[mask][:, mask] + + cov_xi_plus = cov[0 : len(xi_plus_data), 0 : len(xi_plus_data)] + cov_xi_plus = cov_xi_plus[mask_xi_plus][:, mask_xi_plus] + cov_xi_minus = cov[ + len(xi_plus_data) : 2 * len(xi_minus_data), + len(xi_plus_data) : 2 * len(xi_minus_data), + ] + cov_xi_minus = cov_xi_minus[mask_xi_minus][:, mask_xi_minus] + + # Read the results + theta = np.loadtxt( + output_folder_chains + f"{root}/best_fit_config/shear_xi_plus/theta.txt" + ) + theta_arcmin = theta * 180 * 60 / np.pi + shear_xi_plus = np.loadtxt( + output_folder_chains + f"{root}/best_fit_config/shear_xi_plus/bin_1_1.txt" + ) + shear_xi_minus = np.loadtxt( + output_folder_chains + f"{root}/best_fit_config/shear_xi_minus/bin_1_1.txt" + ) + + xi_sys_plus = np.loadtxt( + output_folder_chains + f"{root}/best_fit_config/xi_sys/shear_xi_plus.txt" + ) + xi_sys_minus = np.loadtxt( + output_folder_chains + f"{root}/best_fit_config/xi_sys/shear_xi_minus.txt" + ) + + theta_tau = np.loadtxt( + output_folder_chains + f"{root}/best_fit_config/tau_0_plus/theta.txt" + ) + theta_tau_arcmin = theta_tau * 180 * 60 / np.pi + tau_0_model = np.loadtxt( + output_folder_chains + f"{root}/best_fit_config/tau_0_plus/bin_1_1.txt" + ) + tau_2_model = np.loadtxt( + output_folder_chains + f"{root}/best_fit_config/tau_2_plus/bin_1_1.txt" + ) + + # interpolate the model + interp_xi_plus = interp1d( + theta_arcmin, shear_xi_plus, kind="cubic", fill_value="extrapolate" + ) + interp_xi_minus = interp1d( + theta_arcmin, shear_xi_minus, kind="cubic", fill_value="extrapolate" + ) + + xi_plus_model = interp_xi_plus(theta_data) + xi_plus_model += xi_sys_plus + xi_minus_model = interp_xi_minus(theta_data) + xi_minus_model += xi_sys_minus + + xi_model = np.concatenate((xi_plus_model, xi_minus_model)) + tau_model = np.concatenate((tau_0_model, tau_2_model)) + xi_model = xi_model[mask] + + xi_plus_chi2 = np.dot( + (xi_plus_model[mask_xi_plus] - xi_plus_data[mask_xi_plus]), + np.dot( + np.linalg.inv(cov_xi_plus), + (xi_plus_model[mask_xi_plus] - xi_plus_data[mask_xi_plus]), + ), + ) + xi_minus_chi2 = np.dot( + (xi_minus_model[mask_xi_minus] - xi_minus_data[mask_xi_minus]), + np.dot( + np.linalg.inv(cov_xi_minus), + (xi_minus_model[mask_xi_minus] - xi_minus_data[mask_xi_minus]), + ), + ) + xi_chi2 = np.dot( + (xi_model - xi_data), np.dot(np.linalg.inv(cov_xi), (xi_model - xi_data)) + ) + tau_chi2 = np.dot( + (tau_model - tau_data), np.dot(np.linalg.inv(cov_tau), (tau_model - tau_data)) + ) + chi2_tot = xi_plus_chi2 + xi_minus_chi2 + tau_chi2 + + xi_plus_chi2s = np.append(xi_plus_chi2s, xi_plus_chi2) + xi_minus_chi2s = np.append(xi_minus_chi2s, xi_minus_chi2) + xi_chi2s = np.append(xi_chi2s, xi_chi2) + tau_chi2s = np.append(tau_chi2s, tau_chi2) + chi2_tots = np.append(chi2_tots, chi2_tot) + + +fig, [ax1, ax2] = plt.subplots(2, 1, figsize=(7, 10)) +chi2_fiducial = -2 * -37.560916821678894 +dof, loc, scale = chi2.fit(chi2_tots, floc=0) + +print(f"Best-fit dof: {dof:.3e}") +counts, bin_edges = np.histogram(chi2_tots, bins=25, density=True) + +sns.histplot( + chi2_tots, + ax=ax1, + kde=False, + bins=bin_edges, + stat="density", + label=r"$\chi^2$ for \texttt{GLASS} mocks best-fits", + color="green", + alpha=0.3, +) + +# Compute the p-value + +# 1. Get in which bin the chi2 of the fiducial falls +bin_index = np.digitize(chi2_fiducial, bin_edges) + +# 2. Compute the p-value as the integral of the tail of the histogram +p_value = np.sum(counts[bin_index:]) * np.diff(bin_edges)[0] + +print(f"P-value: {p_value}") + +ax1.axvline(chi2_fiducial, color="red", label=r"$\chi^2$ of the fiducial", lw=2) + +mantissa, exponent = np.frexp(p_value) +pte_string = rf"${{\rm PTE}} = {p_value:.4f}$" +print(f"mantissa: {mantissa}, exponent: {exponent}") +x_text = 78 +y_text = max(counts) * 0.95 +ax1.text( + x_text, + y_text, + pte_string, + fontsize=15, + bbox=dict(facecolor="wheat", alpha=0.8, edgecolor="black"), +) + +chi2_string = rf"${{\rm Eff. dof}}= {dof:.1f}$" +y_text = max(counts) * 0.85 +ax1.text( + x_text, + y_text, + chi2_string, + fontsize=15, + bbox=dict(facecolor="wheat", alpha=0.8, edgecolor="black"), +) + +ax1.set_xlabel(r"$\chi^2_{\rm tot}$") +ax1.set_ylabel("Density") + +chi2_fiducial = 9.5 +dof, loc, scale = chi2.fit(xi_chi2s, floc=0) + +print(f"Best-fit dof: {dof:.3e}") +counts, bin_edges = np.histogram(xi_chi2s, bins=25, density=True) + +sns.histplot( + xi_chi2s, + ax=ax2, + kde=False, + bins=bin_edges, + stat="density", + label=r"$\chi^2$ for \texttt{GLASS} mocks best-fits", + color="pink", + alpha=0.5, +) + +# Compute the p-value + +# 1. Get in which bin the chi2 of the fiducial falls +bin_index = np.digitize(chi2_fiducial, bin_edges) + +# 2. Compute the p-value as the integral of the tail of the histogram +p_value = np.sum(counts[bin_index:]) * np.diff(bin_edges)[0] + +print(f"P-value: {p_value}") + +ax2.axvline(chi2_fiducial, color="red", label=r"$\chi^2$ of the fiducial", lw=2) + +mantissa, exponent = np.frexp(p_value) +print(f"mantissa: {mantissa}, exponent: {exponent}") +pte_string = rf"${{\rm PTE}} = {p_value:.4f}$" +# rf"${{\rm PTE}} = {mantissa:.2f} \times 10^{{{exponent}}}$" if exponent != 0 else +x_text = 17.5 +y_text = max(counts) * 0.95 +ax2.text( + x_text, + y_text, + pte_string, + fontsize=15, + bbox=dict(facecolor="wheat", alpha=0.8, edgecolor="black"), +) + +chi2_string = rf"${{\rm Eff. dof}}= {dof:.1f}$" +y_text = max(counts) * 0.85 +ax2.text( + x_text, + y_text, + chi2_string, + fontsize=15, + bbox=dict(facecolor="wheat", alpha=0.8, edgecolor="black"), +) + +ax2.set_xlabel(r"$\chi^2 (\xi_\pm)$") +ax2.set_ylabel("Density") +fig.savefig(f"{output_fig_path}/chi2_glass_mocks_p_value_xi_tau.pdf") + + + + + + diff --git a/papers/realspace/get_prior_psf_leakage.py b/papers/realspace/get_prior_psf_leakage.py new file mode 100644 index 00000000..ae219baa --- /dev/null +++ b/papers/realspace/get_prior_psf_leakage.py @@ -0,0 +1,176 @@ + +# # Covariance matrix and PSF leakage +# +# This notebook plots the combined covariance matrix, and samples and plots the 2D marginalised posteriors of the PSF leakage parameters $\alpha$ and $\beta$. + + +import os + +if not os.path.exists("./Plots"): + os.makedirs("./Plots") + +import matplotlib.pyplot as plt +import numpy as np +import seaborn as sns +from astropy.io import fits +from getdist import MCSamples, plots +from shear_psf_leakage.rho_tau_stat import PSFErrorFit, RhoStat, TauStat + +# Use paper style and seaborn with husl palette +plt.style.use("/home/guerrini/matplotlib_config/paper.mplstyle") +# Set default palette - will be updated per plot as needed +sns.set_palette("husl") + +g = plots.get_subplot_plotter(width_inch=30) +g.settings.axes_fontsize = 30 +g.settings.axes_labelsize = 30 +g.settings.alpha_filled_add = 0.7 +g.settings.legend_fontsize = 25 + +ver = "v1.4.6.3" +blind = "B" + + +data_path = f"/home/guerrini/sp_validation/cosmo_inference/data/SP_{ver}_config/" + +path_cosmo_val = "/home/guerrini/sp_validation/cosmo_val/output/" + +roots = [f"SP_{ver}_{blind}", f"SP_{ver}_leak_corr_{blind}"] + +labels = [f"SP_{ver}_{blind}", f"SP_{ver}_leak_corr_{blind}"] + + +data_vectors = [] + +for root in roots: + data_vectors.append( + fits.open(data_path + f"SP_{ver}_{blind}/cosmosis_{root}_masked.fits") + ) + + +def cov_to_corr(cov): + """Convert a covariance matrix to a correlation matrix.""" + d = np.sqrt(np.diag(cov)) + corr = cov / np.outer(d, d) + corr[cov == 0] = 0 + return corr + + +# Print the covariance matrix for each root +for i, root in enumerate(roots): + print(f"Covariance matrix for {labels[i]}:") + cov = data_vectors[i]["COVMAT"].data + + n_bins = cov.shape[0] // 4 + + fig, ax = plt.subplots(figsize=(10, 8)) + + im = ax.imshow(cov_to_corr(cov), vmin=-1, vmax=1, cmap="seismic") + ax.set_aspect("equal") + ax.set_yticks(np.array([10, 30, 50, 70])) + ax.set_yticklabels( + [ + r"$\xi_+(\vartheta)$", + r"$\xi_-(\vartheta)$", + r"$\tau_0(\vartheta)$", + r"$\tau_2(\vartheta)$", + ] + ) + ax.set_xticks(np.array([10, 30, 50, 70])) + ax.set_xticklabels( + [ + r"$\xi_+(\vartheta)$", + r"$\xi_-(\vartheta)$", + r"$\tau_0(\vartheta)$", + r"$\tau_2(\vartheta)$", + ], + rotation=45, + ) + fig.colorbar(im, ax=ax) + + plt.savefig(f"./Plots/cov_matrix_{root}.png", bbox_inches="tight", dpi=300) + + + +# Create dummy rho and tau stat handler. + +# Inference of the xi_sys parameters +sep_units = "arcmin" +coord_units = "degrees" +theta_min = 1.0 +theta_max = 250 +nbins = 20 + + +TreeCorrConfig_xi = { + "ra_units": coord_units, + "dec_units": coord_units, + "min_sep": theta_min, + "max_sep": theta_max, + "sep_units": sep_units, + "nbins": nbins, + "var_method": "jackknife", +} + +rho_stats_handler = RhoStat(output=".", treecorr_config=TreeCorrConfig_xi, verbose=True) + +tau_stats_handler = TauStat( + catalogs=rho_stats_handler.catalogs, + output=".", + treecorr_config=TreeCorrConfig_xi, + verbose=True, +) + + +# Create a PSFErrorFit instance +psf_fitter = PSFErrorFit( + rho_stats_handler, + tau_stats_handler, + path_cosmo_val + "rho_tau_stats/", + use_eta=False, +) + +g = plots.get_subplot_plotter(width_inch=30) + +g.settings.axes_fontsize = 30 +g.settings.axes_labelsize = 30 +g.settings.alpha_filled_add = 0.7 +g.settings.legend_fontsize = 40 + +chains = [] + +# Load rho-, tau-statistics, and cov_tau from the data_vector +for i, root in enumerate(roots): + print("Sampling PSF parameters for ", labels[i]) + path_rho = f"rho_stats_{root}.fits" + path_tau = f"tau_stats_{root}.fits" + path_cov_rho = f"cov_rho_{root}.npy" + path_cov_tau = f"cov_tau_{root}_th.npy" + psf_fitter.load_rho_stat(path_rho) + psf_fitter.load_tau_stat(path_tau) + psf_fitter.load_covariance(path_cov_rho, cov_type="rho") + psf_fitter.load_covariance(path_cov_tau, cov_type="tau") + samples_lq, _, _ = psf_fitter.get_least_squares_params_samples( + npatch=None, apply_debias=False + ) + + samples_gd = MCSamples( + samples=samples_lq, names=[r"\alpha", r"\beta"], labels=[r"\alpha", r"\beta"] + ) + + chains.append(samples_gd) + +g.triangle_plot( + chains, + filled=True, + legend_labels=labels, + legend_loc="upper right", +) + +# plt.savefig(f"./Plots/psf_leakage_params.png", bbox_inches='tight', dpi=300) + + + + + + diff --git a/papers/realspace/glass_mock_hist.py b/papers/realspace/glass_mock_hist.py new file mode 100644 index 00000000..43bf9a33 --- /dev/null +++ b/papers/realspace/glass_mock_hist.py @@ -0,0 +1,481 @@ + +import IPython + +ipython = IPython.get_ipython() + +if ipython is not None: + ipython.run_line_magic("load_ext", "autoreload") + ipython.run_line_magic("autoreload", "2") + +import os + +import matplotlib.pyplot as plt +import numpy as np +import seaborn as sns +from getdist import plots +from tqdm import tqdm + +g = plots.get_subplot_plotter(width_inch=7) +g.settings.axes_fontsize = 15 +g.settings.axes_labelsize = 15 +g.settings.alpha_filled_add = 0.7 +g.settings.legend_fontsize = 15 + +if os.path.exists("/home/guerrini/matplotlib_config/paper.mplstyle"): + plt.style.use("/home/guerrini/matplotlib_config/paper.mplstyle") + +# Set default palette - will be updated per plot as needed +sns.set_palette("husl") + +if ipython is not None: + ipython.run_line_magic("matplotlib", "inline") + + +root_dir = "/n09data/guerrini/glass_mock_chains/" +chain_version = "v6" +num_sims = 350 + +roots = [f"glass_mock_{chain_version}_{i + 1:05d}" for i in range(num_sims)] + + +# +def load_samples_and_write_paramames(root_dir, root, chain_type="configuration"): + assert chain_type in ["configuration", "harmonic"], ( + "chain_type must be 'configuration' or 'harmonic'" + ) + + if chain_type == "configuration": + path_samples = root_dir + "{}/{}/samples_{}.txt".format("/" + root, root, root) + path_paramnames = root_dir + "{}/{}/getdist_{}.paramnames".format( + "/" + root, root, root + ) + else: + path_samples = root_dir + "{}/{}/samples_{}_cell.txt".format( + "/" + root, root, root + ) + path_paramnames = root_dir + "{}/{}/getdist_{}_cell.paramnames".format( + "/" + root, root, root + ) + + with open(path_samples, "r") as file: + params = file.readline()[1:].split("\t")[:-4] + file.close() + + with open(path_paramnames, "w") as file: + for i in range(len(params)): + if len(params[i].split("--")) > 1: + file.write(params[i].split("--")[1] + "\n") + else: + file.write(params[i].split("--")[0] + "\n") + file.close() + + +def write_samples_getdist_format(root_dir, root, chain_type="configuration"): + assert chain_type in ["configuration", "harmonic"], ( + "chain_type must be 'configuration' or 'harmonic'" + ) + + if chain_type == "configuration": + path_samples = root_dir + "{}/{}/samples_{}.txt".format("/" + root, root, root) + path_gd_samples = root_dir + "{}/{}/getdist_{}.txt".format( + "/" + root, root, root + ) + path_gd = root_dir + "{}/{}/getdist_{}".format(root, root, root) + else: + path_samples = root_dir + "{}/{}/samples_{}_cell.txt".format( + "/" + root, root, root + ) + path_gd_samples = root_dir + "{}/{}/getdist_{}_cell.txt".format( + "/" + root, root, root + ) + path_gd = root_dir + "{}/{}/getdist_{}_cell".format(root, root, root) + + samples = np.loadtxt( + path_samples, + ) + if "nautilus" in root: + samples = np.column_stack( + (np.exp(samples[:, -3]), samples[:, -1] - samples[:, -2], samples[:, 0:-3]) + ) + else: + samples = np.column_stack((samples[:, -1], samples[:, -2], samples[:, 0:-4])) + np.savetxt(path_gd_samples, samples) + + chain = g.samples_for_root( + path_gd, + cache=False, + settings={"ignore_rows": 0.0, "smooth_scale_2D": 0.5, "smooth_scale_1D": 0.5}, + ) + + return chain + + +def extract_param_chain(chain, param_names): + margestats = chain.getMargeStats() + likestats = chain.getLikeStats() + + param_values = {} + for param_name in param_names: + if param_name not in chain.getParamNames().list(): + raise ValueError(f"Parameter {param_name} not found in chain.") + + param_stats = margestats.parWithName(param_name) + param_values[param_name] = { + "mean": param_stats.mean, + "1sigma_minus": param_stats.mean - param_stats.limits[0].lower, + "1sigma_plus": param_stats.limits[0].upper - param_stats.mean, + "2sigma_minus": param_stats.mean - param_stats.limits[1].lower, + "2sigma_plus": param_stats.limits[1].upper - param_stats.mean, + } + + param_stats = likestats.parWithName(param_name) + param_names_getdist = chain.getParamNames() + par = param_names_getdist.parWithName(param_name) + kde = chain.get1DDensity(par, num_bins=1000) + kde_map = kde.x[np.argmax(kde.P)] + param_values[param_name].update( + { + "MAP": kde_map, + } + ) + + par = chain.getParamNames().parWithName("S_8") + par_om = chain.getParamNames().parWithName("OMEGA_M") + kde = chain.get2DDensity(par, par_om, fine_bins_2D=1000) + s8_kde_map = kde.x[np.unravel_index(np.argmax(kde.P), kde.P.shape)[1]] + om_kde_map = kde.y[np.unravel_index(np.argmax(kde.P), kde.P.shape)[0]] + param_values["S_8"].update( + { + "MAP_2D": s8_kde_map, + } + ) + param_values["OMEGA_M"].update( + { + "MAP_2D": om_kde_map, + } + ) + + return param_values + + +def concatenate_param_stats(name, param_values, verbose=False): + output = [name] + for key in param_values.keys(): + param_stat = param_values[key] + if verbose: + print( + f"{name} - {key}: {param_stat['mean']:.4f} +{param_stat['1sigma_plus']:.4f}/-{param_stat['1sigma_minus']:.4f} (1σ), +{param_stat['2sigma_plus']:.4f}/-{param_stat['2sigma_minus']:.4f} (2σ)" + ) + + param_list = [ + param_stat["mean"], + param_stat["1sigma_minus"], + param_stat["1sigma_plus"], + param_stat["2sigma_minus"], + param_stat["2sigma_plus"], + param_stat["MAP"], + ] + + if key == "S_8": + param_list.append(param_stat["MAP_2D"]) + + if key == "OMEGA_M": + param_list.append(param_stat["MAP_2D"]) + + output += param_list + + return output + + +def merge_param_stats(params_configuration, params_harmonic): + merged_params = {} + for key in params_configuration.keys(): + if key in params_harmonic: + merged_params[key] = { + "configuration": params_configuration[key], + "harmonic": params_harmonic[key], + } + return merged_params + + +def concatenate_merge_params(name, merged_params, verbose=False): + output = [name] + for key in merged_params.keys(): + param_config = merged_params[key]["configuration"] + param_harm = merged_params[key]["harmonic"] + + if verbose: + print( + f"{name} - {key} (Configuration): {param_config['mean']:.4f} +{param_config['1sigma_plus']:.4f}/-{param_config['1sigma_minus']:.4f} (1σ), +{param_config['2sigma_plus']:.4f}/-{param_config['2sigma_minus']:.4f} (2σ)" + ) + print( + f"{name} - {key} (Harmonic): {param_harm['mean']:.4f} +{param_harm['1sigma_plus']:.4f}/-{param_harm['1sigma_minus']:.4f} (1σ), +{param_harm['2sigma_plus']:.4f}/-{param_harm['2sigma_minus']:.4f} (2σ)" + ) + + param_list = [ + param_config["mean"], + param_config["1sigma_minus"], + param_config["1sigma_plus"], + param_config["2sigma_minus"], + param_config["2sigma_plus"], + param_config["MAP"], + param_harm["mean"], + param_harm["1sigma_minus"], + param_harm["1sigma_plus"], + param_harm["2sigma_minus"], + param_harm["2sigma_plus"], + param_harm["MAP"], + ] + + output += param_list + + return output + + +chain_harmonic = [] +chain_config = [] + +for i, root in enumerate(tqdm(roots)): + if os.path.isfile(f"{root_dir}/{root}/{root}/getdist_{root}.txt"): + # Load samples and write paramnames for harmonic space + load_samples_and_write_paramames(root_dir, root, chain_type="harmonic") + write_samples_getdist_format(root_dir, root, chain_type="harmonic") + chain_harm = g.samples_for_root( + root_dir + f"/{root}/{root}/getdist_{root}_cell", + cache=False, + settings={ + "ignore_rows": 0.0, + "smooth_scale_2D": 0.5, + "smooth_scale_1D": 0.5, + }, + ) + chain_harmonic.append(chain_harm) + + # Load samples and write paramnames for harmonic space + load_samples_and_write_paramames(root_dir, root, chain_type="configuration") + write_samples_getdist_format(root_dir, root, chain_type="configuration") + chain_conf = g.samples_for_root( + root_dir + f"/{root}/{root}/getdist_{root}", + cache=False, + settings={ + "ignore_rows": 0.0, + "smooth_scale_2D": 0.5, + "smooth_scale_1D": 0.5, + }, + ) + chain_config.append(chain_conf) +# +param_names = ["S_8", "OMEGA_M", "SIGMA_8", "a"] + +output_mocks_harm = np.array( + [ + "Name", + "S8_mean", + "S8_1sigma_minus", + "S8_1sigma_plus", + "S8_2sigma_minus", + "S8_2sigma_plus", + "S8_MAP", + "S8_MAP_2D", + "OMEGA_M_mean", + "OMEGA_M_1sigma_minus", + "OMEGA_M_1sigma_plus", + "OMEGA_M_2sigma_minus", + "OMEGA_M_2sigma_plus", + "OMEGA_M_MAP", + "OMEGA_M_MAP_2D", + "SIGMA_8_mean", + "SIGMA_8_1sigma_minus", + "SIGMA_8_1sigma_plus", + "SIGMA_8_2sigma_minus", + "SIGMA_8_2sigma_plus", + "SIGMA_8_MAP", + "a_mean", + "a_1sigma_minus", + "a_1sigma_plus", + "a_2sigma_minus", + "a_2sigma_plus", + "a_MAP", + ] +) + +output_mocks_config = np.array( + [ + "Name", + "S8_mean", + "S8_1sigma_minus", + "S8_1sigma_plus", + "S8_2sigma_minus", + "S8_2sigma_plus", + "S8_MAP", + "S8_MAP_2D", + "OMEGA_M_mean", + "OMEGA_M_1sigma_minus", + "OMEGA_M_1sigma_plus", + "OMEGA_M_2sigma_minus", + "OMEGA_M_2sigma_plus", + "OMEGA_M_MAP", + "OMEGA_M_MAP_2D", + "SIGMA_8_mean", + "SIGMA_8_1sigma_minus", + "SIGMA_8_1sigma_plus", + "SIGMA_8_2sigma_minus", + "SIGMA_8_2sigma_plus", + "SIGMA_8_MAP", + "a_mean", + "a_1sigma_minus", + "a_1sigma_plus", + "a_2sigma_minus", + "a_2sigma_plus", + "a_MAP", + ] +) + +for i, root in enumerate(tqdm(roots[:-1])): + param_values_harm = extract_param_chain(chain_harmonic[i], param_names) + + param_harm = concatenate_param_stats(root, param_values_harm, verbose=False) + + output_mocks_harm = np.vstack((output_mocks_harm, param_harm)) + + param_values_config = extract_param_chain(chain_config[i], param_names) + + param_config = concatenate_param_stats(root, param_values_config, verbose=False) + + output_mocks_config = np.vstack((output_mocks_config, param_config)) + +np.savetxt( + f"summary_parameter_constraints_harmonic_space_{chain_version}.txt", + output_mocks_harm, + fmt="%s", + delimiter=";", +) +np.savetxt( + f"summary_parameter_constraints_configuration_space_{chain_version}.txt", + output_mocks_config, + fmt="%s", + delimiter=";", +) +print( + f"Saved summary of parameter constraints for harmonic space in summary_parameter_constraints_harmonic_space_{chain_version}.txt" +) +print( + f"Saved summary of parameter constraints for configuration space in summary_parameter_constraints_configuration_space_{chain_version}.txt" +) + + +import pandas as pd + +output_df_harm = pd.read_csv( + f"summary_parameter_constraints_harmonic_space_{chain_version}.txt", + delimiter=";", + skiprows=1, + names=output_mocks_harm[0], +) + +output_df_config = pd.read_csv( + f"summary_parameter_constraints_configuration_space_{chain_version}.txt", + delimiter=";", + skiprows=1, + names=output_mocks_config[0], +) + + +# Define the true value of the parameters +from astropy.cosmology import Planck18 as planck + +Omega_m_fid = planck.Om0 +sigma_8_fid = 0.8102 +s8_fid = sigma_8_fid * (Omega_m_fid / 0.3) ** 0.5 +h = planck.h +Omega_b_fig = planck.Ob0 +n_s_fid = 0.9665 +print( + f"Fiducial values: Omega_m = {Omega_m_fid}, sigma_8 = {sigma_8_fid}, S_8 = {s8_fid}" +) + + +sns.histplot( + output_df_harm["S8_mean"] - output_df_config["S8_mean"], + kde=True, + bins=30, + label="Mean", +) +# sns.histplot( +# output_df_harm["S8_MAP"]-output_df_config["S8_MAP"], +# kde=True, +# bins=20, +# label="MAP", +# ) +sns.histplot( + output_df_harm["S8_MAP_2D"] - output_df_config["S8_MAP_2D"], + kde=True, + bins=30, + label="2D Mode", + alpha=0.5, +) +plt.axvline(0, color="black", linestyle="--") +plt.legend(fontsize=12) + +plt.xlabel(r"$\Delta S_8$") +plt.savefig( + "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/S8_comparison_harmonic_vs_configuration.pdf", + bbox_inches="tight", +) + + + +output_df_config["S8_MAP_2D"].shape +output_df_harm["S8_MAP_2D"].shape + + +# Create JointGrid +g = sns.JointGrid( + x=output_df_config["OMEGA_M_MAP_2D"], + y=output_df_config["S8_MAP_2D"], + height=7, + ratio=5, + space=0, +) + +# Main 2D histogram +sns.histplot( + x=output_df_config["OMEGA_M_MAP_2D"], + y=output_df_config["S8_MAP_2D"], + bins=25, + cmap="Greens", + cbar=False, + ax=g.ax_joint, +) + +# Marginal histograms +sns.histplot( + x=output_df_config["OMEGA_M_MAP_2D"], bins=25, color="#2ca25f", ax=g.ax_marg_x +) +sns.histplot(y=output_df_config["S8_MAP_2D"], bins=25, color="#2ca25f", ax=g.ax_marg_y) + +# Add dashed reference lines +g.ax_joint.axvline(Omega_m_fid, color="k", linestyle="--") +g.ax_joint.axhline(s8_fid, color="k", linestyle="--") + +# Labels +g.set_axis_labels( + r"$\Omega_m$ estimated from mocks (Configuration space)", + r"$S_8$ estimated from mocks (Configuration space)", +) + +# Optional styling tweaks +g.ax_joint.tick_params(labelsize=12) +plt.savefig( + "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/S8_vs_OmegaM_configuration_space_mocks.pdf", + bbox_inches="tight", +) + + + + + + + + + diff --git a/papers/realspace/nonlin_k_analysis.py b/papers/realspace/nonlin_k_analysis.py new file mode 100644 index 00000000..6d5febfe --- /dev/null +++ b/papers/realspace/nonlin_k_analysis.py @@ -0,0 +1,114 @@ +# # Nonlinear $k$ contributions +# +# This notebook plots the 2D heatmap of ratio of scale contributions to the $\xi_\pm$ 2PCF given angular scale $\theta$ and wavenumber $k$. + + +import os + +import matplotlib.pylab as plt +import numpy as np +import seaborn as sns + +plt.style.use("/home/guerrini/matplotlib_config/paper.mplstyle") + +plt.rcParams["text.usetex"] = True + +plt.rcParams.update( + { + "font.size": 20, + "axes.titlesize": 21, + "axes.labelsize": 20, + "xtick.labelsize": 20, + "ytick.labelsize": 20, + "legend.fontsize": 20, + "figure.titlesize": 21, + } +) +sns.set_palette("husl") + +blind = "B" +ver = "v1.4.6.3" + + +data_dir = "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/data/" +curr_dir = os.getcwd() + +# Read the 2D array from the text file + +file_headers = ["xip_%s_%s" % (ver, blind), "xim_%s_%s" % (ver, blind)] + +for f in file_headers: + xis = np.loadtxt(data_dir + f"theta_k_{f}.txt") + xis_reshaped = xis.reshape(-1, 201) + sorted_xis = xis_reshaped[np.argsort(xis_reshaped[:, 0])] + + np.savetxt(data_dir + f"theta_k_{f}_sorted.txt", sorted_xis) + + +fig, axs = plt.subplots(2, 1, figsize=(8, 10)) + +# --- k grid --- +h = 0.6766 +k_plot = np.logspace(-4, 2, 200) + +file_header = "%s_%s" % (ver, blind) + +xi_thetas = np.loadtxt(data_dir + f"theta_k_xip_{file_header}_sorted.txt") +thetas = xi_thetas[:, 0] +xis = xi_thetas[:, 1:] + +# normalise +xi_plot = xis / np.max(xis, axis=1, keepdims=True) + +T, K = np.meshgrid(thetas, k_plot) + +axs[0].contour(T, K, xi_plot.T, levels=[0.9], colors="red", linewidths=1.7) +pcm = axs[0].pcolormesh(T, K, xi_plot.T, shading="auto", cmap="viridis") +pcm.set_rasterized(True) + +axs[0].axvline(5, color="k", ls="dashed", lw=1.2) +axs[0].axvline(12, color="white", ls="dashed", lw=1.6) +axs[0].axhline(1, color="k", ls="dashed", lw=1.2) # converted to h/Mpc space if needed +axs[0].axhline(0.425, color="white", ls="dashed", lw=1.6) + +axs[0].set_yscale("log") +axs[0].set_xlabel(r"$\theta\ \mathrm{(arcmin)}$") +axs[0].set_ylabel(r"$k\ (h$ Mpc$^{-1})$") + +axs[0].set_title(r"$\xi_+$") + +xi_thetas = np.loadtxt(data_dir + f"theta_k_xim_{file_header}_sorted.txt") +thetas = xi_thetas[:, 0] +xis = xi_thetas[:, 1:] + +xi_plot = xis / np.max(xis, axis=1, keepdims=True) + +T, K = np.meshgrid(thetas, k_plot) + +axs[1].contour(T, K, xi_plot.T, levels=[0.9], colors="red", linewidths=1.7) +pcm = axs[1].pcolormesh(T, K, xi_plot.T, shading="nearest", cmap="viridis") +pcm.set_rasterized(True) + +axs[1].axvline(12, color="white", ls="dashed", lw=1.6) +axs[1].axhline(2.85, color="white", ls="dashed", lw=1.6) + + +axs[1].set_yscale("log") +axs[1].set_xlabel(r"$\theta\ \mathrm{(arcmin)}$") +axs[1].set_ylabel(r"$k\ (h$ Mpc$^{-1})$") +axs[1].set_title(r"$\xi_-$") + + +fig.tight_layout() + +cbar_ax = fig.add_axes([0.99, 0.15, 0.02, 0.7]) +cbar = fig.colorbar(pcm, cax=cbar_ax) + +fig.savefig( + curr_dir + f"/../Plots/theta_k_xip_xim_{ver}_{blind}.pdf", bbox_inches="tight" +) + + + + + diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_unblinding/unblinding_party_plots.py b/papers/realspace/unblinding_party_plots.py similarity index 100% rename from cosmo_inference/notebooks/2D_cosmic_shear_unblinding/unblinding_party_plots.py rename to papers/realspace/unblinding_party_plots.py diff --git a/workflow/rules/inference.smk b/workflow/rules/inference.smk index a93c0e71..d2847976 100644 --- a/workflow/rules/inference.smk +++ b/workflow/rules/inference.smk @@ -29,7 +29,7 @@ GLASS_MOCK_FITS_PATTERN = str( ) GLASS_MOCK_CONFIG_PATTERN = str( COSMO_INFERENCE_PROD - / f"cosmosis_config/cosmosis_pipeline_glass_mocks_{GLASS_MOCK_VERSION}_glass_mock_{{mock_id}}.ini" + / f"cosmosis_config/output/cosmosis_pipeline_glass_mocks_{GLASS_MOCK_VERSION}_glass_mock_{{mock_id}}.ini" ) # Fiducial harmonic-binning tag the pseudo-Cl producer (twopoint.smk) stamps @@ -78,7 +78,7 @@ rule inference_prep: ), config_file=str( COSMO_INFERENCE_PROD - / "cosmosis_config/cosmosis_pipeline_{version}_{blind}_minsep={min_sep}_maxsep={max_sep}_nbins={nbins}_npatch={npatch}.ini" + / "cosmosis_config/output/cosmosis_pipeline_{version}_{blind}_minsep={min_sep}_maxsep={max_sep}_nbins={nbins}_npatch={npatch}.ini" ) params: cosmosis_root="{version}_{blind}_minsep={min_sep}_maxsep={max_sep}_nbins={nbins}_npatch={npatch}", diff --git a/workflow/scripts/generate_cosmocov_ini.py b/workflow/scripts/generate_cosmocov_ini.py deleted file mode 100644 index 11e785cf..00000000 --- a/workflow/scripts/generate_cosmocov_ini.py +++ /dev/null @@ -1,149 +0,0 @@ -"""Generate a CosmoCov ``.ini`` for one (version, blind, grid, flavour, mask). - -CLI refactor of the former ``rule covariance_ini`` heredoc. Cosmology is read -from the frozen ``planck18.json`` snapshot (the cosmology_snapshot lc output — -source of truth is cs_util.cosmo.PLANCK18); survey (area, n_eff, -sigma_e) from the catalog config's per-version ``cov_th``; n(z) via the same -path convention as workflow/common.build_redshift_path; the footprint mask -power spectrum is passed explicitly (empty string for the unmasked variant). -The emitted ``.ini`` is byte-compatible with the paper's covariance_ini rule. - - python generate_cosmocov_ini.py \ - --version SP_v1.4.6.3_leak_corr --blind A \ - --planck18-json /planck18.json \ - --cat-config \ - --min-sep 0.5 --max-sep 300.0 --nbins 1000 --gaussian g \ - --mask-cls \ - --out-ini -""" - -import argparse -import json -import os -import re - -import yaml - - -def build_redshift_path(version, blind): - """Replicate workflow/common.build_redshift_path.""" - base_version = re.sub(r"_leak_corr$", "", version) - base_version = re.sub(r"_ecut\d+", "", base_version) - if "v1.4.11" in base_version: - base_version = "SP_v1.4.6" - version_dir = base_version.replace("SP_", "") - return ( - f"/n17data/sguerrini/UNIONS/WL/nz/{version_dir}/nz_{base_version}_{blind}.txt" - ) - - -INI_TEMPLATE = """\ -# -# Cosmological parameters -# -Omega_m : {Omega_m} -Omega_v : {Omega_v} -sigma_8 : {sigma_8} -n_spec : {n_s} -w0 : -1 -wa : 0 -omb : {Omega_b} -h0 : {h} - - -# Survey and galaxy parameters -# -# area in degrees -# n_gal,lens_n_gal in gals/arcmin^2 - -area : {area} -sourcephotoz : multihisto -lensphotoz : multihisto -source_tomobins : 1 -lens_tomobins : 1 -sigma_e : {sigma_e} -source_n_gal : {n_e} -lens_n_gal : {n_e} - - -shear_REDSHIFT_FILE : {nz} -clustering_REDSHIFT_FILE : {nz} -c_footprint_file : {mask} - - -# IA parameters -IA : 1 -A_ia : 0.0 -eta_ia : 0.0 - - -# Covariance parameters -# -# tmin,tmax in arcminutes -tmin : {min_sep} -tmax : {max_sep} -ntheta : {nbins} -ng : {ng} -cng : {ng} - - -outdir : ./ -filename : cov_tmp -ss : true -ls : false -ll : false -""" - - -def main(argv=None): - ap = argparse.ArgumentParser(description=__doc__.split("\n")[0]) - ap.add_argument("--version", required=True) - ap.add_argument("--blind", default="A") - ap.add_argument("--planck18-json", required=True) - ap.add_argument("--cat-config", required=True) - ap.add_argument("--min-sep", required=True, help="tmin arcmin (string, e.g. 0.5)") - ap.add_argument("--max-sep", required=True, help="tmax arcmin (string, e.g. 300.0)") - ap.add_argument("--nbins", required=True, help="ntheta (string, e.g. 1000)") - ap.add_argument("--gaussian", required=True, choices=["g", "ng"]) - ap.add_argument( - "--mask-cls", default="", help="footprint mask Cl path ('' = unmasked)" - ) - ap.add_argument("--out-ini", required=True) - a = ap.parse_args(argv) - - with open(a.planck18_json) as f: - cosmo = json.load(f) - with open(a.cat_config) as f: - cat_config = yaml.safe_load(f) - - base_version = a.version.replace("_leak_corr", "") - cov_th = cat_config[base_version]["cov_th"] - - ng_value = "1" if a.gaussian == "ng" else "0" - - ini = INI_TEMPLATE.format( - Omega_m=cosmo["Omega_m"], - Omega_v=cosmo["Omega_v"], - sigma_8=cosmo["sigma_8"], - n_s=cosmo["n_s"], - Omega_b=cosmo["Omega_b"], - h=cosmo["h"], - area=cov_th["A"], - sigma_e=cov_th["sigma_e"], - n_e=cov_th["n_e"], - nz=build_redshift_path(a.version, a.blind), - mask=a.mask_cls, - min_sep=a.min_sep, - max_sep=a.max_sep, - nbins=a.nbins, - ng=ng_value, - ) - - os.makedirs(os.path.dirname(os.path.abspath(a.out_ini)), exist_ok=True) - with open(a.out_ini, "w") as f: - f.write(ini) - print(f"Wrote {a.out_ini}") - - -if __name__ == "__main__": - main() diff --git a/workflow/scripts/run_cosmocov_chain.sh b/workflow/scripts/run_cosmocov_chain.sh deleted file mode 100644 index 80a80370..00000000 --- a/workflow/scripts/run_cosmocov_chain.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env bash -# CosmoCov covariance chain (lc-native, container:none recipe). -# -# Faithful port of covariance_ini -> covariance_cosmocov (x3 blocks) -> -# covariance_cat -> covariance_process. The CosmoCov C++ binary runs on the -# bare host (module load gcc/intelpython/openmpi, as in the original -# container:None rule); the .ini generation and cosmocov_process step run inside -# the sp_validation apptainer container. The 3 shear-shear blocks (++,--,+-) are -# independent and run in parallel. -# -# Usage: -# run_cosmocov_chain.sh --version SP_v1.4.6.3_leak_corr --blind A \ -# --min-sep 0.5 --max-sep 300.0 --nbins 1000 --gaussian g \ -# --planck18-json /planck18.json \ -# --cat-config --mask-cls \ -# --out -set -euo pipefail - -CONTAINER=/n17data/cdaley/containers/containers/ -WT=/n17data/cdaley/unions/code/sp_validation.worktrees/repro-paper-ii-astra -SRC=$WT/src -BIND=/home,/scratch,/automnt,/n17data,/n23data1,/n09data -COSMOCOV=/n23data1/n06data/lgoh/scratch/UNIONS/CosmoCov/covs/cov - -VERSION=""; BLIND="A"; MINSEP=""; MAXSEP=""; NBINS=""; GAUSSIAN="" -PLANCK18=""; CATCONFIG=""; MASKCLS=""; OUT="" -while [ $# -gt 0 ]; do - case "$1" in - --version) VERSION="$2"; shift 2;; - --blind) BLIND="$2"; shift 2;; - --min-sep) MINSEP="$2"; shift 2;; - --max-sep) MAXSEP="$2"; shift 2;; - --nbins) NBINS="$2"; shift 2;; - --gaussian) GAUSSIAN="$2"; shift 2;; - --planck18-json) PLANCK18="$2"; shift 2;; - --cat-config) CATCONFIG="$2"; shift 2;; - --mask-cls) MASKCLS="$2"; shift 2;; - --cosmocov) COSMOCOV="$2"; shift 2;; - --out) OUT="$2"; shift 2;; - *) echo "unknown arg: $1" >&2; exit 2;; - esac -done - -mkdir -p "$OUT" -# Absolutize OUT before any `cd` below: the CosmoCov binary writes its block -# files into cwd, so we cd into OUT (line ~61); every other OUT-relative path -# ($INI, block logs, covariance.txt, cosmocov_process output) must therefore be -# absolute or it re-resolves against the new cwd and double-nests. lc templates -# {output} as a project-relative path, so this makes the recipe robust to both -# relative (lc) and absolute (direct-run) --out. -OUT="$(cd "$OUT" && pwd)" -INI="$OUT/covariance.ini" - -echo "[cosmocov] generating .ini" -apptainer exec --bind "$BIND" --env PYTHONPATH="$SRC" "$CONTAINER" \ - /usr/local/bin/python "$WT/workflow/scripts/generate_cosmocov_ini.py" \ - --version "$VERSION" --blind "$BLIND" \ - --planck18-json "$PLANCK18" --cat-config "$CATCONFIG" \ - --min-sep "$MINSEP" --max-sep "$MAXSEP" --nbins "$NBINS" --gaussian "$GAUSSIAN" \ - --mask-cls "$MASKCLS" --out-ini "$INI" - -echo "[cosmocov] loading modules + running 3 blocks (parallel)" -source /etc/profile.d/modules.sh -module unload gcc 2>/dev/null || true; module load gcc -module unload intelpython 2>/dev/null || true; module load intelpython/3-2024.1.0 -module load openmpi - -cd "$OUT" -# BLOCK_PAIRS = [("++","1"), ("--","2"), ("+-","3")] — one CosmoCov invocation per block -for idx in 1 2 3; do - ( "$COSMOCOV" "$idx" "$INI" > "$OUT/cosmocov_block_${idx}.log" 2>&1 ) & -done -wait - -# Concatenate blocks in BLOCK_PAIRS order (++, --, +-) — as covariance_cat does -CAT="$OUT/covariance.txt" -: > "$CAT" -for pm_idx in "++:1" "--:2" "+-:3"; do - pm="${pm_idx%%:*}"; idx="${pm_idx##*:}" - blk="$OUT/cov_tmp_ssss_${pm}_cov_Ntheta${NBINS}_Ntomo1_${idx}" - [ -f "$blk" ] || { echo "MISSING block $blk (see cosmocov_block_${idx}.log)" >&2; exit 1; } - cat "$blk" >> "$CAT" -done -echo "[cosmocov] concatenated -> $CAT" - -echo "[cosmocov] processing (positive-definite check, G/G+NG extract, QA plot)" -apptainer exec --bind "$BIND" --env PYTHONPATH="$SRC" "$CONTAINER" \ - /usr/local/bin/python "$WT/cosmo_inference/scripts/cosmocov_process.py" \ - "$CAT" "$OUT/covariance_processed" -echo "[cosmocov] done -> $OUT/covariance_processed.txt (+_g.txt, +_plot.pdf)" From e64b48c1934a015207e9f4a6f7b2a575fea9e603 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 10:48:05 +0000 Subject: [PATCH 02/11] Fix ruff lint/format issues in papers/realspace files --- papers/realspace/S8_om_sigma8_whisker.py | 8 +---- papers/realspace/best_fit_xipm.py | 11 ------- papers/realspace/contours.py | 40 +++++++---------------- papers/realspace/cov_masking.py | 8 ++--- papers/realspace/get_chi2.py | 16 +++------ papers/realspace/get_chi2_glass_mock.py | 11 +------ papers/realspace/get_prior_psf_leakage.py | 10 +----- papers/realspace/glass_mock_hist.py | 15 ++------- papers/realspace/nonlin_k_analysis.py | 7 +--- 9 files changed, 24 insertions(+), 102 deletions(-) diff --git a/papers/realspace/S8_om_sigma8_whisker.py b/papers/realspace/S8_om_sigma8_whisker.py index 80dc49cd..6a483caa 100644 --- a/papers/realspace/S8_om_sigma8_whisker.py +++ b/papers/realspace/S8_om_sigma8_whisker.py @@ -1,4 +1,4 @@ -# +# # This notebook plots the whisker plot of $S_8$, $\Omega_m$ and $\sigma_8$ @@ -551,9 +551,3 @@ # plt.savefig("./plots/whisker_plot.png", dpi=300) # #Save pdf plt.savefig("../Plots/S8_whisker_plot.pdf", bbox_inches="tight") - - - - - - diff --git a/papers/realspace/best_fit_xipm.py b/papers/realspace/best_fit_xipm.py index db7f5b56..56316043 100644 --- a/papers/realspace/best_fit_xipm.py +++ b/papers/realspace/best_fit_xipm.py @@ -1,5 +1,3 @@ - - import os import sys @@ -363,8 +361,6 @@ ) - - root_to_plot = [fiducial_root_xi_chains] labels = [r"Best fit $\tau_{0,2}(\theta)$"] @@ -504,10 +500,3 @@ "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/best_fit_tau_02_SP_v1.4.6.3_B.pdf", bbox_inches="tight", ) - - - - - - - diff --git a/papers/realspace/contours.py b/papers/realspace/contours.py index 9d103211..c58f7c89 100644 --- a/papers/realspace/contours.py +++ b/papers/realspace/contours.py @@ -1,5 +1,5 @@ # # 2D contour plots -# +# # This notebook produces the plots for all the 2D contours in the results section. @@ -86,7 +86,7 @@ } roots = roots_ext - + # ## Retrieve the chains @@ -239,12 +239,11 @@ legend_labels = list(roots.values()) - + # ## Plot the chains - -# ### FIDUCIAL PLOT +# ### FIDUCIAL PLOT colours = [ @@ -272,10 +271,8 @@ g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot.pdf") - -# ### FULL PLOT - +# ### FULL PLOT g.settings.axes_fontsize = 40 @@ -314,7 +311,7 @@ g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_full.pdf") - + # ### IA PLOT @@ -344,7 +341,7 @@ g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_ia.pdf") - + # ### PSF PLOT @@ -385,7 +382,7 @@ g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_psf.pdf") - + # ### DELTA Z PLOT @@ -414,7 +411,7 @@ g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_dz.pdf") - + # ### EXTERNAL DATA @@ -455,10 +452,8 @@ g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_ext.pdf") - -# ### Small scales - +# ### Small scales colours = [ @@ -491,10 +486,8 @@ g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_scales.pdf") - -# ### BBN Prior - +# ### BBN Prior from getdist.gaussian_mixtures import Gaussian1D @@ -530,7 +523,7 @@ filled=[True, False], ) - + # ## Plot the best-fit $\xi_\pm$ @@ -639,8 +632,6 @@ plt.savefig("/Plots/scale_cut_xipm_SP_v1.4.6.3_B.pdf", bbox_inches="tight") - - labels = roots_nonlin.values() colours = ["orange", "hotpink", "teal"] @@ -752,10 +743,3 @@ ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20) plt.savefig("/Plots/nonlin_xipm_SP_v1.4.6.3_B.pdf", bbox_inches="tight") - - - - - - - diff --git a/papers/realspace/cov_masking.py b/papers/realspace/cov_masking.py index 669b7f25..1388d3c6 100644 --- a/papers/realspace/cov_masking.py +++ b/papers/realspace/cov_masking.py @@ -1,5 +1,5 @@ # # Covmat mask analysis -# +# # This notebook creates the plots to look at the ratio of the covaraiance matrices when applying the mask or not @@ -77,8 +77,4 @@ plt.xlabel(r"$\theta$ (arcmin)") plt.ylabel("Cov masked / Cov unmasked") plt.legend(fontsize=20) -plt.savefig( - f"./Plots/covmat_masked_unmasked_ratio_diag.pdf", bbox_inches="tight" -) - - +plt.savefig("./Plots/covmat_masked_unmasked_ratio_diag.pdf", bbox_inches="tight") diff --git a/papers/realspace/get_chi2.py b/papers/realspace/get_chi2.py index 24e67ca5..d77a8f03 100644 --- a/papers/realspace/get_chi2.py +++ b/papers/realspace/get_chi2.py @@ -1,4 +1,3 @@ - import configparser import os import re @@ -17,8 +16,6 @@ import chain_postprocessing - - plt.rc("mathtext", fontset="stix") plt.rc("font", family="sans-serif") @@ -125,7 +122,7 @@ "upper_bound_xi_minus": upper_bound_xi_minus, } - + # ## Retrieve the chains @@ -218,7 +215,7 @@ if param_names.parWithName(name) is not None: param_names.parWithName(name).label = label - + # ## Extract the best fit parameters @@ -239,7 +236,7 @@ if param_name == "S_8": print(f"{best_fit[root][param_name]}") - + # ## Run `Cosmosis` in test mode to get the data vectors @@ -349,7 +346,7 @@ with open(ini_file, "w") as configfile: config.write(configfile) - + # ## Compute the $\chi^2$ @@ -567,8 +564,3 @@ def display_markdown(metrics): markdown_source = display_markdown(metrics) - - - - - diff --git a/papers/realspace/get_chi2_glass_mock.py b/papers/realspace/get_chi2_glass_mock.py index a08669cf..7542fd8d 100644 --- a/papers/realspace/get_chi2_glass_mock.py +++ b/papers/realspace/get_chi2_glass_mock.py @@ -1,5 +1,3 @@ - - import configparser import os import subprocess @@ -19,7 +17,6 @@ import chain_postprocessing - plt.style.use("/home/guerrini/matplotlib_config/paper.mplstyle") plt.rcParams["axes.labelsize"] = 18 @@ -133,7 +130,7 @@ "A_{\rm Planck}", ] - + # ## Run `Cosmosis` in test mode to get the data vectors @@ -472,9 +469,3 @@ ax2.set_xlabel(r"$\chi^2 (\xi_\pm)$") ax2.set_ylabel("Density") fig.savefig(f"{output_fig_path}/chi2_glass_mocks_p_value_xi_tau.pdf") - - - - - - diff --git a/papers/realspace/get_prior_psf_leakage.py b/papers/realspace/get_prior_psf_leakage.py index ae219baa..c84d5611 100644 --- a/papers/realspace/get_prior_psf_leakage.py +++ b/papers/realspace/get_prior_psf_leakage.py @@ -1,6 +1,5 @@ - # # Covariance matrix and PSF leakage -# +# # This notebook plots the combined covariance matrix, and samples and plots the 2D marginalised posteriors of the PSF leakage parameters $\alpha$ and $\beta$. @@ -91,7 +90,6 @@ def cov_to_corr(cov): plt.savefig(f"./Plots/cov_matrix_{root}.png", bbox_inches="tight", dpi=300) - # Create dummy rho and tau stat handler. # Inference of the xi_sys parameters @@ -168,9 +166,3 @@ def cov_to_corr(cov): ) # plt.savefig(f"./Plots/psf_leakage_params.png", bbox_inches='tight', dpi=300) - - - - - - diff --git a/papers/realspace/glass_mock_hist.py b/papers/realspace/glass_mock_hist.py index 43bf9a33..113f3be9 100644 --- a/papers/realspace/glass_mock_hist.py +++ b/papers/realspace/glass_mock_hist.py @@ -1,4 +1,3 @@ - import IPython ipython = IPython.get_ipython() @@ -38,7 +37,7 @@ roots = [f"glass_mock_{chain_version}_{i + 1:05d}" for i in range(num_sims)] -# +# def load_samples_and_write_paramames(root_dir, root, chain_type="configuration"): assert chain_type in ["configuration", "harmonic"], ( "chain_type must be 'configuration' or 'harmonic'" @@ -264,7 +263,7 @@ def concatenate_merge_params(name, merged_params, verbose=False): }, ) chain_config.append(chain_conf) -# +# param_names = ["S_8", "OMEGA_M", "SIGMA_8", "a"] output_mocks_harm = np.array( @@ -424,7 +423,6 @@ def concatenate_merge_params(name, merged_params, verbose=False): ) - output_df_config["S8_MAP_2D"].shape output_df_harm["S8_MAP_2D"].shape @@ -470,12 +468,3 @@ def concatenate_merge_params(name, merged_params, verbose=False): "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/S8_vs_OmegaM_configuration_space_mocks.pdf", bbox_inches="tight", ) - - - - - - - - - diff --git a/papers/realspace/nonlin_k_analysis.py b/papers/realspace/nonlin_k_analysis.py index 6d5febfe..2ddef76e 100644 --- a/papers/realspace/nonlin_k_analysis.py +++ b/papers/realspace/nonlin_k_analysis.py @@ -1,5 +1,5 @@ # # Nonlinear $k$ contributions -# +# # This notebook plots the 2D heatmap of ratio of scale contributions to the $\xi_\pm$ 2PCF given angular scale $\theta$ and wavenumber $k$. @@ -107,8 +107,3 @@ fig.savefig( curr_dir + f"/../Plots/theta_k_xip_xim_{ver}_{blind}.pdf", bbox_inches="tight" ) - - - - - From 70b2800fe7a2b31547b5eae4700963965a21b9d3 Mon Sep 17 00:00:00 2001 From: LisaGoh Date: Wed, 8 Jul 2026 13:27:29 +0200 Subject: [PATCH 03/11] added back the chain_postprocessing.py script using cs_util functionalities --- .../scripts/chain_postprocessing.py | 796 ++++++++++++++++++ 1 file changed, 796 insertions(+) create mode 100644 cosmo_inference/scripts/chain_postprocessing.py diff --git a/cosmo_inference/scripts/chain_postprocessing.py b/cosmo_inference/scripts/chain_postprocessing.py new file mode 100644 index 00000000..53331943 --- /dev/null +++ b/cosmo_inference/scripts/chain_postprocessing.py @@ -0,0 +1,796 @@ +""" +Scripts to postprocess the CosmoSIS chains +Author: Sacha Guerrini +""" + +import configparser +import os +import subprocess + +import cs_util +import matplotlib.pyplot as plt +import numpy as np +from astropy.io import fits +from getdist import plots + +# Mapping for CosmoSIS ini files section +section_map = { + "omch2": "cosmological_parameters", + "ombh2": "cosmological_parameters", + "h0": "cosmological_parameters", + "n_s": "cosmological_parameters", + "s_8_input": "cosmological_parameters", + "logt_agn": "halo_model_parameters", + "a": "intrinsic_alignment_parameters", + "m1": "shear_calibration_parameters", + "bias_1": "nofz_shifts", + "alpha": "psf_leakage_parameters", + "beta": "psf_leakage_parameters", +} + + +# Utils functions +def compute_average(chain, param_name): + """ + Compute the average of a parameter from a CosmoSIS chain + """ + margestats = chain.getMargeStats() + param_stats = margestats.parWithName(param_name) + return param_stats.mean + + +def compute_map_1D(chain, param_name, num_bins=1000): + """ + Compute the MAP value of a parameter from a CosmoSIS chain using 1D KDE + """ + param_names_getdist = chain.getParamNames() + par = param_names_getdist.parWithName(param_name) + kde = chain.get1DDensity(par, num_bins=num_bins) + kde_map = kde.x[np.argmax(kde.P)] + return kde_map + + +def compute_map_2D(chain, param_name_x, param_name_y, num_bins=1000): + """ + Compute the MAP value of two parameters from a CosmoSIS chain using 2D KDE + """ + param_names_getdist = chain.getParamNames() + par_x = param_names_getdist.parWithName(param_name_x) + par_y = param_names_getdist.parWithName(param_name_y) + kde = chain.get2DDensity(par_x, par_y, fine_bins_2D=num_bins) + kde_map_index = np.unravel_index(np.argmax(kde.P), kde.P.shape) + return kde.x[kde_map_index[1]], kde.y[kde_map_index[0]] + + +def compute_limits(chain, param_name): + """ + Compute the 68% and 95% confidence limits of a parameter from a CosmoSIS chain. + """ + margestats = chain.getMargeStats() + param_stats = margestats.parWithName(param_name) + return ( + param_stats.limits[0].upper, + param_stats.limits[0].lower, + param_stats.limits[1].upper, + param_stats.limits[1].lower, + ) + + +def load_samples_and_write_paramnames( + path_samples, path_paramnames, chain_type="polychord" +): + """ + Load the samples from a CosmoSIS chain and write the parameter names to a file + """ + with open(path_samples, "r") as file: + if chain_type == "nautilus": + params = file.readline()[1:].split("\t")[:-3] + else: + params = file.readline()[1:].split("\t")[:-4] + file.close() + + with open(path_paramnames, "w") as file: + for i in range(len(params)): + if len(params[i].split("--")) > 1: + param_name = params[i].split("--")[1] + if "Legacy" in path_paramnames and param_name not in [ + "OMEGA_M", + "SIGMA_8", + ]: + continue + file.write(param_name + "\n") + else: + param_name = params[i].split("--")[0] + if "Legacy" in path_paramnames and param_name not in [ + "OMEGA_M", + "SIGMA_8", + ]: + continue + file.write(param_name + "\n") + file.close() + return 0 + + +def write_samples_getdist_format(path_samples, path_gd, chain_type="polychord"): + """ + Load the samples from a CosmoSIS chain and write them in GetDist format + """ + samples = np.loadtxt(path_samples) + if chain_type == "nautilus": + if "Legacy" in path_gd: + samples = np.column_stack( + ( + np.exp(samples[:, -3]), + samples[:, -2] - samples[:, -1], + samples[:, 21], + samples[:, 23], + ) + ) + else: + samples = np.column_stack( + ( + np.exp(samples[:, -3]), + samples[:, -2] - samples[:, -1], + samples[:, 0:-3], + ) + ) + mask = np.isfinite(samples[:, 1]) + samples = samples[mask] + else: + samples = np.column_stack((samples[:, -1], samples[:, -2], samples[:, 0:-4])) + np.savetxt(path_gd, samples) + return 0 + + +def load_chain(path_gd, smoothing_scale=0.3): + g = plots.get_single_plotter() + chain = g.samples_for_root( + path_gd, + cache=False, + settings={ + "ignore_rows": 0, + "smooth_scale_1D": smoothing_scale, + "smooth_scale_2D": smoothing_scale, + }, + ) + return chain + + +def extract_best_fit_params(chain, best_fit_method="weighted_mean"): + best_fit_params = {} + chain.getMargeStats() + likestats = chain.getLikeStats() + for i, par in enumerate(likestats.names): + if best_fit_method == "weighted_mean": + best_fit = compute_average(chain, par.name) + elif best_fit_method == "1Dkde": + best_fit = compute_map_1D(chain, par.name) + elif best_fit_method == "2Dkde": + # If the parameter is S8 or Omega_m, use the 2D KDE + if par.name == "S_8" or par.name == "s_8_input" or par.name == "OMEGA_M": + s8_map_2D, omega_m_map_2D = compute_map_2D(chain, "S_8", "OMEGA_M") + best_fit = ( + s8_map_2D + if par.name == "S_8" or par.name == "s_8_input" + else omega_m_map_2D + ) + else: + best_fit = compute_map_1D(chain, par.name) + else: + raise ValueError( + "Invalid best fit method. Choose one of: '2Dkde', '1Dkde', 'weighted_mean'" + ) + best_fit_params.update({par.name: best_fit}) + return best_fit_params + + +def compute_best_fit( + path_ini_files, best_fit, root, is_harmonic, blind=None, ini_file_root=None +): + # Check if the values empty ini file exists + if not os.path.exists(path_ini_files + "/values_empty.ini"): + content = """[cosmological_parameters] + + tau = 0.0544 + w = -1.0 + mnu = 0.06 + omega_k = 0.0 + wa = 0.0 + + [halo_model_parameters] + + [intrinsic_alignment_parameters] + + [shear_calibration_parameters] + + [nofz_shifts] + + [psf_leakage_parameters] + """ + + with open(path_ini_files + "/values_empty.ini", "w") as f: + f.write(content) + f.close() + + print("File created successfully") + + # Load cosmosis in the library path + env = os.environ.copy() + env["LD_LIBRARY_PATH"] = ( + "/home/guerrini/.conda/envs/sp_validation/lib/python3.9/site-packages/cosmosis/datablock:" + + env.get("LD_LIBRARY_PATH", "") + ) + + config = configparser.ConfigParser() + config.optionxform = str # Preserve case sensitivity of option names + config.read(path_ini_files + "/values_empty.ini") + for param, value in best_fit.items(): + section = section_map.get(param) + if section is None: + continue + if section not in config: + config.add_section(section) + config[section][param] = str(value) + + with open(path_ini_files + "/values_empty.ini", "w") as configfile: + config.write(configfile) + + # Modify the ini file to run in test mode at the best fit + config = configparser.ConfigParser() + config.optionxform = str # Preserve case sensitivity of option names + if ini_file_root is None: + # If the ini file root is not provided, we construct it based on the root and blind parameters + if blind is not None: + subdir = ( + f"harmonic_space_fiducial_{blind}" if is_harmonic else "" + ) # TODO: add real space subdir if needed + else: + subdir = "" + ini_file_root = os.path.join( + path_ini_files, subdir, f"cosmosis_pipeline_{root}_cell.ini" + ) + config.read(ini_file_root) + + sampler = config["runtime"]["sampler"] + config["runtime"]["sampler"] = "test" + values = config["pipeline"]["values"] + config["pipeline"]["values"] = path_ini_files + "/values_empty.ini" + + with open(ini_file_root, "w") as configfile: + config.write(configfile) + + # Run cosmosis + os.chdir("/home/guerrini/sp_validation/cosmo_inference") + result = subprocess.run( + ["cosmosis", ini_file_root], env=env, capture_output=True, text=True + ) + print(f"STDOUT:\n{result.stdout}") + print(f"STDERR:\n{result.stderr}") + + # Modify the ini file to the previous one + config["pipeline"]["values"] = values + config["runtime"]["sampler"] = sampler + + with open(ini_file_root, "w") as configfile: + config.write(configfile) + + +def compute_best_fit_xi_from_cell(output_folder, root, best_fit_params, theta_rad): + + ell = np.loadtxt(output_folder + "{}/best_fit/shear_cl/ell.txt".format(root)) + shear_cl = np.loadtxt( + output_folder + "{}/best_fit/shear_cl/bin_1_1.txt".format(root) + ) + + cosmo = cs_util.get_cosmo( + Omega_c=best_fit_params["omch2"] / (best_fit_params["h0"] / 100) ** 2, + Omega_b=best_fit_params["ombh2"] / (best_fit_params["h0"] / 100) ** 2, + h=best_fit_params["h0"] / 100, + n_s=best_fit_params["n_s"], + sigma8=best_fit_params["SIGMA_8"], + matter_power_spectrum="camb", + extra_parameters={ + "camb": { + "halofit_version": "mead2020_feedback", + "HMCode_logT_AGN": best_fit_params["logt_agn"], + } + }, + ) + + xi_p, xi_m = cs_util.c_ell_to_xi(cosmo, theta_rad, ell, shear_cl) + + os.makedirs( + output_folder + "{}/best_fit/shear_xi_minus".format(root), exist_ok=True + ) + os.makedirs(output_folder + "{}/best_fit/shear_xi_plus".format(root), exist_ok=True) + + np.savetxt( + output_folder + "{}/best_fit/shear_xi_plus/bin_1_1.txt".format(root), xi_p + ) + np.savetxt( + output_folder + "{}/best_fit/shear_xi_minus/bin_1_1.txt".format(root), xi_m + ) + np.savetxt( + output_folder + "{}/best_fit/shear_xi_plus/theta.txt".format(root), theta_rad + ) + np.savetxt( + output_folder + "{}/best_fit/shear_xi_minus/theta.txt".format(root), theta_rad + ) + + print( + f"Best fit xi+ and xi- from Cl's computed and saved in {output_folder + '{}/best_fit/shear_xi_plus'.format(root)} and {output_folder + '{}/best_fit/shear_xi_minus'.format(root)}" + ) + + +def adjust_paramname_chain(chain, current_name, target_name, label): + """ + Adjusts the parameter name and label in a GetDist chain. + """ + param_names = chain.getParamNames() + par = param_names.parWithName(current_name) + + par.label = label + par.name = target_name + + chain.setParamNames(param_names) + + +def derive_parameter_S8(chain): + """ + Derives the S_8 parameter from Omega_m and Sigma_8 in a GetDist chain. + S_8 = Sigma_8 * (Omega_m / 0.3) ** 0.5 + """ + omega_m = chain.getParams().OMEGA_M + sigma_8 = chain.getParams().SIGMA_8 + + s_8 = sigma_8 * (omega_m / 0.3) ** 0.5 + + chain.addDerived(s_8, name="S_8", label=r"S_8") + + return chain + + +def derive_parameter_Om(chain): + """ + Derives the Omega_m parameter from omch2 and h0 in a GetDist chain. + """ + omch2 = chain.getParams().omch2 + h0 = chain.getParams().h0 + + omega_m = omch2 / (h0 / 100) ** 2 + + chain.addDerived(omega_m, name="OMEGA_M", label=r"\Omega_{\rm m}") + + return chain + + +def get_sigma_tension(mean1, low1, high1, mean2, low2, high2): + sigma1 = 0.5 * (high1 + low1) + sigma2 = 0.5 * (high2 + low2) + delta_mean = np.abs(mean1 - mean2) + sigma_tension = delta_mean / np.sqrt(sigma1**2 + sigma2**2) + sign = 1 if mean1 > mean2 else -1 + return sigma_tension * sign + + +def read_config(path_ini_files, root, thisfile=None): + config = configparser.ConfigParser() + config.optionxform = str + if thisfile is not None: + read_path = thisfile + else: + read_path = os.path.join(path_ini_files, f"{root}.ini") + config.read(read_path) + return config + + +def update_properties_w_roots( + properties, root, path_ini_files, path_to_this_ini=None, with_configuration=False +): + config = read_config(path_ini_files, root, thisfile=path_to_this_ini) + + try: + lower_bound_cell_ee, upper_bound_cell_ee = map( + float, config["2pt_like"]["angle_range_CELL_EE_1_1"].split() + ) + properties[root].update( + { + "lower_bound_cell_ee": lower_bound_cell_ee, + "upper_bound_cell_ee": upper_bound_cell_ee, + } + ) + except KeyError: + properties[root] = {"lower_bound_cell_ee": 0.0, "upper_bound_cell_ee": 2048} + + if with_configuration: + # Also save the scale cuts in theta for xi + add_xi_sys = config["2pt_like"]["add_xi_sys"] + add_xi_sys = add_xi_sys == "T" + lower_bound_xi_plus, upper_bound_xi_plus = map( + float, config["2pt_like"]["angle_range_XI_PLUS_1_1"].split() + ) + lower_bound_xi_minus, upper_bound_xi_minus = map( + float, config["2pt_like"]["angle_range_XI_MINUS_1_1"].split() + ) + + properties[root].update( + { + "add_xi_sys": add_xi_sys, + "lower_bound_xi_plus": lower_bound_xi_plus, + "upper_bound_xi_plus": upper_bound_xi_plus, + "lower_bound_xi_minus": lower_bound_xi_minus, + "upper_bound_xi_minus": upper_bound_xi_minus, + } + ) + return properties + + +def plot_best_fit( + data_points, + root_to_plot, + output_folder, + line_args, + savefile, + ell_min=10.0, + ell_max=2048.0, + multiply_ell=True, + loc_legend="best", + bbox_to_anchor=None, + label_data="Fiducial data", + labels=None, + properties=None, + paths_to_bestfit=None, +): + data = fits.open( + f"/home/guerrini/sp_validation/cosmo_inference/data/{data_points}/cosmosis_{data_points}.fits" + ) + cell_ee = data["CELL_EE"].data + cov_mat = data["COVMAT"].data + + if labels is None: + labels = root_to_plot + + fig, ax = plt.subplots(1, 1, figsize=(8, 5)) + + ell, cell = cell_ee["ANG"], cell_ee["VALUE"] + ax.errorbar( + ell, + ell * cell, + yerr=ell * np.sqrt(np.diag(cov_mat)), + fmt="o", + label=label_data, + color="black", + capsize=2, + ) + + for idx, (label, root) in enumerate(zip(labels, root_to_plot)): + # Read the results + if paths_to_bestfit is None: + ell = np.loadtxt( + output_folder + + "{}/best_fit/shear_cl/ell.txt".format( + root, + ) + ) + shear_cl = np.loadtxt( + output_folder + + "{}/best_fit/shear_cl/bin_1_1.txt".format( + root, + ) + ) + else: + ell = np.loadtxt(paths_to_bestfit[idx] + "best_fit/shear_cl/ell.txt") + shear_cl = np.loadtxt( + paths_to_bestfit[idx] + "best_fit/shear_cl/bin_1_1.txt" + ) + + mask = (ell > ell_min) & (ell < ell_max) + + ax.plot( + ell[mask], + ell[mask] * shear_cl[mask] if multiply_ell else shear_cl[mask], + label=label, + **line_args[idx], + ) + + # Plot the scale cuts for different k_max + ax.axvline(x=1800, color="black", linestyle="--", alpha=0.5) + ax.axvline(x=2048, color="black", linestyle="--", alpha=1.0) + ax.axvline(x=500, color="black", linestyle="--", alpha=0.3) + + ymin = ax.get_ylim()[0] + ymax = ax.get_ylim()[1] + # Shadowing cut scaled + ax.fill_betweenx( + y=[ymin, ymax], + x1=0, + x2=300, + color="gray", + alpha=0.2, + label=r"$B$-mode informed scale cut", + ) + ax.fill_betweenx(y=[ymin, ymax], x1=1600, x2=2048, color="gray", alpha=0.2) + + ax.set_ylim(ymin, ymax) + + # Add labels directly under the tick + ax.text( + 1740, + 0.90, + r"$k_\mathrm{max} = 3 h$ Mpc$^{-1}$", + transform=ax.get_xaxis_transform(), + ha="center", + va="top", + fontsize=14, + rotation=90, + ) + + ax.text( + 1978, + 0.90, + r"$k_\mathrm{max} = 5 h$ Mpc$^{-1}$", + transform=ax.get_xaxis_transform(), + ha="center", + va="top", + fontsize=14, + rotation=90, + ) + + ax.text( + 470, + 0.90, + r"$k_\mathrm{max} = 1 h$ Mpc$^{-1}$", + transform=ax.get_xaxis_transform(), + ha="center", + va="top", + fontsize=14, + rotation=90, + ) + + ell, cell = cell_ee["ANG"], cell_ee["VALUE"] + ax.set_ylabel(r"$\ell C_\ell \times 10^{-7}$", fontsize=20) + ax.set_xlabel(r"Multipole $\ell$", fontsize=20) + ax.set_xlim(ell.min() - 10, ell.max() + 100) + ax.set_xscale("squareroot") + ax.set_xticks(np.array([100, 400, 900, 1600])) + ax.minorticks_on() + ax.tick_params(axis="x", which="minor", length=2, width=0.8) + minor_ticks = [i * 10 for i in range(1, 10)] + [i * 100 for i in range(1, 21)] + ax.xaxis.set_ticks(minor_ticks, minor=True) + ax.tick_params(axis="both", which="major", labelsize=14) + ax.tick_params(axis="both", which="minor", labelsize=10) + ax.yaxis.get_offset_text().set_visible(False) + + plt.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor, fontsize=11) + + if savefile is not None: + plt.savefig(savefile, bbox_inches="tight") + + plt.show() + + +def plot_best_fit_config( + data, + root_to_plot, + output_folder, + line_args, + savefile, + theta_min=1.0, + theta_max=250.0, + multiply_theta=True, + loc_legend="best", + bbox_to_anchor_xip=None, + bbox_to_anchor_xim=None, + label_data="Fiducial data", + labels=None, + properties=None, + paths_to_bestfit=None, +): + + data = fits.open(data) + + xi_p_data = data["XI_PLUS"].data + xi_m_data = data["XI_MINUS"].data + cov_mat = data["COVMAT"].data + + # Plot hyperparameter + loc_legend = "lower center" + + fig, [ax, ax2] = plt.subplots(2, 1, figsize=(8, 9)) + + theta, xi_p, xi_m = xi_p_data["ANG"], xi_p_data["VALUE"], xi_m_data["VALUE"] + ax.errorbar( + theta, + theta * xi_p, + yerr=theta * np.sqrt(np.diag(cov_mat[: len(theta), : len(theta)])), + fmt="o", + label=r"UNIONS $\xi_+$ data", + color="black", + capsize=2, + ) + ax2.errorbar( + theta, + theta * xi_m, + yerr=theta + * np.sqrt( + np.diag(cov_mat[len(theta) : 2 * len(theta), len(theta) : 2 * len(theta)]) + ), + fmt="o", + label=r"UNIONS $\xi_-$ data", + color="black", + capsize=2, + ) + + for idx, (label, root) in enumerate(zip(labels, root_to_plot)): + # Read the results + if paths_to_bestfit is None: + theta = ( + ( + np.loadtxt( + output_folder + + "{}/best_fit/shear_xi_plus/theta.txt".format(root) + ) + ) + * 180 + / np.pi + * 60 + ) + xi_plus = np.loadtxt( + output_folder + "{}/best_fit/shear_xi_plus/bin_1_1.txt".format(root) + ) + xi_minus = np.loadtxt( + output_folder + "{}/best_fit/shear_xi_minus/bin_1_1.txt".format(root) + ) + if r"$C_\ell$" not in label: + xi_sys_plus = np.loadtxt( + output_folder + "{}/best_fit/xi_sys/shear_xi_plus.txt".format(root) + ) + xi_sys_minus = np.loadtxt( + output_folder + "{}/best_fit/xi_sys/shear_xi_minus.txt".format(root) + ) + theta_xi_sys = ( + np.loadtxt( + output_folder + "{}/best_fit/xi_sys/theta.txt".format(root) + ) + * 180 + / np.pi + * 60 + ) + xi_plus += np.interp(theta, theta_xi_sys, xi_sys_plus) + xi_minus += np.interp(theta, theta_xi_sys, xi_sys_minus) + else: + theta = ( + (np.loadtxt(paths_to_bestfit[idx] + "best_fit/shear_xi_plus/theta.txt")) + * 180 + / np.pi + * 60 + ) + xi_plus = np.loadtxt( + paths_to_bestfit[idx] + "best_fit/shear_xi_plus/bin_1_1.txt" + ) + xi_minus = np.loadtxt( + paths_to_bestfit[idx] + "best_fit/shear_xi_minus/bin_1_1.txt" + ) + if r"$C_\ell$" not in label: + xi_sys_plus = np.loadtxt( + output_folder + "{}/best_fit/xi_sys/shear_xi_plus.txt".format(root) + ) + xi_sys_minus = np.loadtxt( + output_folder + "{}/best_fit/xi_sys/shear_xi_minus.txt".format(root) + ) + theta_xi_sys = ( + np.loadtxt( + output_folder + "{}/best_fit/xi_sys/theta.txt".format(root) + ) + * 180 + / np.pi + * 60 + ) + xi_plus += np.interp(theta, theta_xi_sys, xi_sys_plus) + xi_minus += np.interp(theta, theta_xi_sys, xi_sys_minus) + + mask = (theta > theta_min) & (theta < theta_max) + theta = theta[mask] + ax.plot( + theta, + theta * xi_plus[mask] if multiply_theta else xi_plus[mask], + label=label, + **line_args[idx], + ) + ax2.plot( + theta, + theta * xi_minus[mask] if multiply_theta else xi_minus[mask], + label=label, + **line_args[idx], + ) + + # XI PLUS PLOT SETTINGS + + # Plot the scale cuts for different k_max + ax.axvline(x=3.2, color="black", linestyle="--", alpha=0.7) + + ymin = ax.get_ylim()[0] + ymax = ax.get_ylim()[1] + # Shadowing cut scaled + ax.fill_betweenx( + y=[ymin, ymax], + x1=0, + x2=12, + color="gray", + alpha=0.2, + label=r"$B$-mode informed scale cut", + ) + ax.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color="gray", alpha=0.2) + + ax.set_ylim(ymin, ymax) + + # Add labels directly under the tick + ax.text( + 2.9, + 1.23e-4, + r"$k_\mathrm{max} = 1 h$ Mpc$^{-1}$", + ha="center", + va="top", + fontsize=14, + rotation=90, + ) + + # ax.set_ylabel('$\theta \xi_+$', fontsize=16) + # ax.set_xlabel('$\theta$', fontsize=16) + ax.set_xlim([theta.min() - 0.1, theta.max() + 20]) + ax.set_xscale("log") + ax.set_xticks(np.array([1, 10, 100])) + ax.tick_params(axis="x", which="minor", length=2, width=0.8) + ax.tick_params(axis="both", which="major", labelsize=14) + ax.tick_params(axis="both", which="minor", labelsize=10) + ax.yaxis.get_offset_text().set_fontsize(14) + ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) + ax.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xip, fontsize=12) + + # XI_MINUS PLOT SETTINGS + + # Plot the scale cuts for different k_max + ax2.axvline(x=24, color="black", linestyle="--", alpha=0.7) + + ymin = ax2.get_ylim()[0] + ymax = ax2.get_ylim()[1] + # Shadowing cut scaled + ax2.fill_betweenx( + y=[ymin, ymax], + x1=0, + x2=12, + color="gray", + alpha=0.2, + label=r"$B$-mode informed scale cut", + ) + ax2.fill_betweenx(y=[ymin, ymax], x1=83, x2=250, color="gray", alpha=0.2) + + ax2.set_ylim(ymin, ymax) + + # Add labels directly under the tick + ax2.text( + 21.8, + 1.15e-4, + r"$k_\mathrm{max} = 1 h$ Mpc$^{-1}$", + ha="center", + va="top", + fontsize=14, + rotation=90, + ) + + ax2.set_ylabel(r"$\theta \xi_-$", fontsize=16) + ax2.set_xlabel(r"$\theta$", fontsize=16) + ax2.set_xlim([theta.min() - 0.1, theta.max() + 20]) + ax2.set_xscale("log") + ax2.set_xticks(np.array([1, 10, 100])) + ax2.tick_params(axis="x", which="minor", length=2, width=0.8) + ax2.tick_params(axis="both", which="major", labelsize=14) + ax2.tick_params(axis="both", which="minor", labelsize=10) + ax2.yaxis.get_offset_text().set_fontsize(14) + ax2.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) + ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=12) + + if savefile is not None: + plt.savefig(savefile, bbox_inches="tight") + + plt.show() From 58cab3d1d11d2a6236634be3ab1696907b833cde Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 11:31:02 +0000 Subject: [PATCH 04/11] fix: resolve ruff lint issues in chain_postprocessing.py --- cosmo_inference/scripts/chain_postprocessing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cosmo_inference/scripts/chain_postprocessing.py b/cosmo_inference/scripts/chain_postprocessing.py index 53331943..bfffc658 100644 --- a/cosmo_inference/scripts/chain_postprocessing.py +++ b/cosmo_inference/scripts/chain_postprocessing.py @@ -7,7 +7,7 @@ import os import subprocess -import cs_util +import cs_util import matplotlib.pyplot as plt import numpy as np from astropy.io import fits @@ -281,7 +281,7 @@ def compute_best_fit_xi_from_cell(output_folder, root, best_fit_params, theta_ra shear_cl = np.loadtxt( output_folder + "{}/best_fit/shear_cl/bin_1_1.txt".format(root) ) - + cosmo = cs_util.get_cosmo( Omega_c=best_fit_params["omch2"] / (best_fit_params["h0"] / 100) ** 2, Omega_b=best_fit_params["ombh2"] / (best_fit_params["h0"] / 100) ** 2, @@ -298,7 +298,7 @@ def compute_best_fit_xi_from_cell(output_folder, root, best_fit_params, theta_ra ) xi_p, xi_m = cs_util.c_ell_to_xi(cosmo, theta_rad, ell, shear_cl) - + os.makedirs( output_folder + "{}/best_fit/shear_xi_minus".format(root), exist_ok=True ) From 7a8728f358a6a93119bce124ec2be002cba5e37f Mon Sep 17 00:00:00 2001 From: LisaGoh Date: Wed, 8 Jul 2026 15:23:09 +0200 Subject: [PATCH 05/11] bug in imports --- cosmo_inference/scripts/chain_postprocessing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cosmo_inference/scripts/chain_postprocessing.py b/cosmo_inference/scripts/chain_postprocessing.py index 53331943..e1dfb073 100644 --- a/cosmo_inference/scripts/chain_postprocessing.py +++ b/cosmo_inference/scripts/chain_postprocessing.py @@ -7,7 +7,7 @@ import os import subprocess -import cs_util +import cs_util.cosmo as cs_cosmo import matplotlib.pyplot as plt import numpy as np from astropy.io import fits @@ -282,7 +282,7 @@ def compute_best_fit_xi_from_cell(output_folder, root, best_fit_params, theta_ra output_folder + "{}/best_fit/shear_cl/bin_1_1.txt".format(root) ) - cosmo = cs_util.get_cosmo( + cosmo = cs_cosmo.get_cosmo( Omega_c=best_fit_params["omch2"] / (best_fit_params["h0"] / 100) ** 2, Omega_b=best_fit_params["ombh2"] / (best_fit_params["h0"] / 100) ** 2, h=best_fit_params["h0"] / 100, @@ -297,7 +297,7 @@ def compute_best_fit_xi_from_cell(output_folder, root, best_fit_params, theta_ra }, ) - xi_p, xi_m = cs_util.c_ell_to_xi(cosmo, theta_rad, ell, shear_cl) + xi_p, xi_m = cs_cosmo.c_ell_to_xi(cosmo, theta_rad, ell, shear_cl) os.makedirs( output_folder + "{}/best_fit/shear_xi_minus".format(root), exist_ok=True From 42e4150aeced2652912909e98ebcabbed87177f1 Mon Sep 17 00:00:00 2001 From: LisaGoh Date: Wed, 8 Jul 2026 15:26:34 +0200 Subject: [PATCH 06/11] ruff linter check --- cosmo_inference/scripts/chain_postprocessing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cosmo_inference/scripts/chain_postprocessing.py b/cosmo_inference/scripts/chain_postprocessing.py index e1dfb073..10a535e8 100644 --- a/cosmo_inference/scripts/chain_postprocessing.py +++ b/cosmo_inference/scripts/chain_postprocessing.py @@ -281,7 +281,7 @@ def compute_best_fit_xi_from_cell(output_folder, root, best_fit_params, theta_ra shear_cl = np.loadtxt( output_folder + "{}/best_fit/shear_cl/bin_1_1.txt".format(root) ) - + cosmo = cs_cosmo.get_cosmo( Omega_c=best_fit_params["omch2"] / (best_fit_params["h0"] / 100) ** 2, Omega_b=best_fit_params["ombh2"] / (best_fit_params["h0"] / 100) ** 2, @@ -298,7 +298,7 @@ def compute_best_fit_xi_from_cell(output_folder, root, best_fit_params, theta_ra ) xi_p, xi_m = cs_cosmo.c_ell_to_xi(cosmo, theta_rad, ell, shear_cl) - + os.makedirs( output_folder + "{}/best_fit/shear_xi_minus".format(root), exist_ok=True ) From 157beb02a38fb0b71d6ce1a59304d04446a91f98 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 8 Jul 2026 13:35:52 +0000 Subject: [PATCH 07/11] Fix Ruff formatting in cosmosis fitting script --- cosmo_inference/scripts/cosmosis_fitting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cosmo_inference/scripts/cosmosis_fitting.py b/cosmo_inference/scripts/cosmosis_fitting.py index 57e0b725..c35ef91c 100644 --- a/cosmo_inference/scripts/cosmosis_fitting.py +++ b/cosmo_inference/scripts/cosmosis_fitting.py @@ -617,7 +617,7 @@ def parse_args(): parser.add_argument( "--template-dir", type=str, - default=str(cosmo_inference_root / "cosmosis_config" / "templates" ), + default=str(cosmo_inference_root / "cosmosis_config" / "templates"), help=( "Directory containing CosmoSIS template INI files (defaults to the " "cosmosis_config folder next to this script)." From 97c7a351462231d20d64cd1ddc638109120e81b0 Mon Sep 17 00:00:00 2001 From: LisaGoh Date: Thu, 9 Jul 2026 13:08:25 +0200 Subject: [PATCH 08/11] changes after review --- .../scripts/chain_postprocessing.py | 17 +- cosmo_inference/scripts/cosmosis_fitting.py | 4 +- cosmo_inference/scripts/k_analysis.py | 278 ++++++++++++++++++ papers/realspace/S8_om_sigma8_whisker.py | 6 +- papers/realspace/best_fit_xipm.py | 11 +- papers/realspace/contours.py | 18 +- papers/realspace/cov_masking.py | 4 +- papers/realspace/get_chi2.py | 2 - papers/realspace/get_chi2_glass_mock.py | 7 +- papers/realspace/get_prior_psf_leakage.py | 8 +- papers/realspace/glass_mock_hist.py | 16 +- papers/realspace/nonlin_k_analysis.py | 5 +- 12 files changed, 311 insertions(+), 65 deletions(-) create mode 100644 cosmo_inference/scripts/k_analysis.py diff --git a/cosmo_inference/scripts/chain_postprocessing.py b/cosmo_inference/scripts/chain_postprocessing.py index 10a535e8..d1462902 100644 --- a/cosmo_inference/scripts/chain_postprocessing.py +++ b/cosmo_inference/scripts/chain_postprocessing.py @@ -283,13 +283,14 @@ def compute_best_fit_xi_from_cell(output_folder, root, best_fit_params, theta_ra ) cosmo = cs_cosmo.get_cosmo( - Omega_c=best_fit_params["omch2"] / (best_fit_params["h0"] / 100) ** 2, - Omega_b=best_fit_params["ombh2"] / (best_fit_params["h0"] / 100) ** 2, - h=best_fit_params["h0"] / 100, - n_s=best_fit_params["n_s"], - sigma8=best_fit_params["SIGMA_8"], - matter_power_spectrum="camb", - extra_parameters={ + camb_params={ + "H0": best_fit_params["h0"], + "ombh2": best_fit_params["ombh2"], + "omch2": best_fit_params["omch2"], + "ns": best_fit_params["n_s"], + "sigma8": best_fit_params["SIGMA_8"], + }, + extra_params={ "camb": { "halofit_version": "mead2020_feedback", "HMCode_logT_AGN": best_fit_params["logt_agn"], @@ -297,7 +298,7 @@ def compute_best_fit_xi_from_cell(output_folder, root, best_fit_params, theta_ra }, ) - xi_p, xi_m = cs_cosmo.c_ell_to_xi(cosmo, theta_rad, ell, shear_cl) + xi_p, xi_m = cs_cosmo.c_ell_to_xi(cosmo, np.rad2deg(theta_rad) * 60, ell, shear_cl) os.makedirs( output_folder + "{}/best_fit/shear_xi_minus".format(root), exist_ok=True diff --git a/cosmo_inference/scripts/cosmosis_fitting.py b/cosmo_inference/scripts/cosmosis_fitting.py index c35ef91c..7396ae35 100644 --- a/cosmo_inference/scripts/cosmosis_fitting.py +++ b/cosmo_inference/scripts/cosmosis_fitting.py @@ -3,8 +3,8 @@ """Prepare CosmoSIS inputs from UNIONS validation outputs. The script lives in ``cosmo_inference/scripts``. By default it reads templates -from ``cosmo_inference/cosmosis_config`` and writes data products beneath -``cosmo_inference/data`` and ``cosmo_inference/cosmosis_config``. Override +from ``cosmo_inference/cosmosis_config/templates`` and writes data products beneath +``cosmo_inference/data`` and ``cosmo_inference/cosmosis_config/output``. Override ``--template-dir`` or ``--output-root`` to use alternative locations. """ diff --git a/cosmo_inference/scripts/k_analysis.py b/cosmo_inference/scripts/k_analysis.py new file mode 100644 index 00000000..e2e58135 --- /dev/null +++ b/cosmo_inference/scripts/k_analysis.py @@ -0,0 +1,278 @@ +import sys +from multiprocessing import Pool + +import astropy.constants as const +import astropy.units as u +import camb +import numpy as np +import scipy.integrate as integrate +from cs_util.cosmo import PLANCK18 +from scipy import interpolate +from scipy.special import j0, jn + +###################################################################################################### + +###################################################################################################### + +def process_theta(theta, nz_file, output_root): + """Compute shear correlation functions for a single angular scale. + + For a given angular separation, this function computes the weak-lensing + correlation functions xi+ and xi- over a range of maximum wavenumbers + (kmax). The calculation includes nonlinear matter power spectra from + CAMB and optionally intrinsic-alignment contributions. Results are + appended to output text files. + + Parameters + ---------- + theta : float + Angular separation in arcminutes. + nz_file : str + Path to the source redshift distribution file. The file must contain + two columns giving redshift and n(z). + output_root : str + Prefix of the output files. Results are written to + ``{output_root}_xip.txt`` and ``{output_root}_xim.txt``. + + Returns + ------- + float + The input angular separation, returned for bookkeeping when running + in parallel. + """ + + def Hz(z): + """Return the Hubble expansion rate. + + Computes the Hubble parameter assuming a flat LCDM cosmology. + + Parameters + ---------- + z : float or ndarray + Redshift. + + Returns + ------- + float or ndarray + Hubble parameter in km s^-1 Mpc^-1. + """ + return H0 * np.sqrt(Omega_m*(1+z)**3 + (1-Omega_m)) + + def rz_interp(want_z): + """Create an interpolation between redshift and comoving distance. + + Computes the line-of-sight comoving distance by numerical integration + and returns an interpolation function in either direction. + + Parameters + ---------- + want_z : bool + If True, return an interpolator mapping comoving distance to + redshift. Otherwise return an interpolator mapping redshift to + comoving distance. + + Returns + ------- + scipy.interpolate.interp1d + Interpolation function relating redshift and comoving distance. + """ + hz_integrand = lambda zz: c/Hz(zz) + rz_ref = np.array([integrate.quad(hz_integrand, 0, z)[0] for z in zs]) + + if want_z == True: + return interpolate.interp1d(rz_ref, zs, bounds_error=False, fill_value="extrapolate") + else: + return interpolate.interp1d(zs, rz_ref, bounds_error=False, fill_value="extrapolate") + + + def W_gg(z, rz): + """Compute the lensing efficiency kernel. + + Evaluates the lensing kernel for the supplied source redshift + distribution. + + Parameters + ---------- + z : float + Lens redshift. + rz : callable + Function returning comoving distance as a function of redshift. + + Returns + ------- + float + Weak-lensing efficiency kernel evaluated at z. + """ + z_integrate = np.linspace(z, zmax, n) + r_zmin = rz(z) + nz_int = som_nz_interp(z_integrate) * (1 - r_zmin / rz(z_integrate)) + prefactor = 3 * H0**2 * Omega_m * (1+z) * r_zmin / (2 * c**2) + + return prefactor * integrate.simpson(nz_int, x=z_integrate) + + + def C_ell(ell, kmax, want_IA): + """Compute the angular power spectrum. + + Calculates the Limber-approximated cosmic shear power spectrum, + optionally including intrinsic-alignment (GI and II) contributions. + + Parameters + ---------- + ell : float + Angular multipole. + kmax : float + Maximum wavenumber used to truncate the Limber integral. + want_IA : bool + If True, include intrinsic-alignment contributions. + + Returns + ------- + float + Total cosmic shear angular power spectrum at the specified multipole. + """ + z_min = rz_interp_wantz((ell + 0.5) / kmax) + z_valid = zs[zs >= z_min] + + if len(z_valid) == 0: + return 0.0 + + rzs = rz_interp_noz(z_valid) + W_ggs = W_gg_interp(z_valid) + Pks = pkz_nl_interp((z_valid, (ell + 0.5) / rzs)) + Hzs = Hz(z_valid) + + gg_integrand = c * W_ggs**2 * Pks / (Hzs * rzs**2) + C_ell_gg = integrate.simpson(gg_integrand, x=z_valid) + + if want_IA == True: + + Dzs = pkz_lin_interp((z_valid, (ell + 0.5) / rzs)) / pkz_lin_interp((0, (ell + 0.5) / rzs)) + P_ia = -A_IA * c1 * Omega_m / Dzs + W_ias = Hzs * som_nz_interp(z_valid) / c + + gI_integrand = c * W_ggs * Pks * W_ias * P_ia / (Hzs * rzs**2) + II_integrand = c * Pks * W_ias**2 * P_ia**2 / (Hzs * rzs**2) + + C_ell_gI = integrate.simpson(gI_integrand, x=z_valid) + C_ell_II = integrate.simpson(II_integrand, x=z_valid) + + return C_ell_gg + C_ell_gI + C_ell_II + + return C_ell_gg + + def xi(theta_rad, kmax, want_IA): + """Compute the shear correlation functions. + + Evaluates the real-space shear correlation functions xi+ and xi- + by Hankel-transforming the convergence power spectrum. + + Parameters + ---------- + theta_rad : float + Angular separation in radians. + kmax : float + Maximum wavenumber used in the Limber integration. + want_IA : bool + If True, include intrinsic-alignment contributions. + + Returns + ------- + tuple of float + The pair (xi_plus, xi_minus). + """ + C_ell_vals = np.array([C_ell(ell, kmax, want_IA) for ell in ells]) + + xip_integrand = ells * C_ell_vals * j0(ells * theta_rad) + xim_integrand = ells * C_ell_vals * jn(4, ells * theta_rad) + + return integrate.simpson(xip_integrand, x=ells)/(2 * np.pi), integrate.simpson(xim_integrand, x=ells)/(2 * np.pi) + ########################################################################################### + + c = const.c.to('km/s') + H0 = PLANCK18['h'] * 100 + Omega_m = PLANCK18['Omega_m'] + + A_IA = 0.83 + c1 = 5e-14 * (u.Mpc**3.0) / u.solMass + + zmin = 1e-5 + zmax = 4 + n = 500 + zs = np.linspace(zmin,zmax,n) + ells = np.linspace(2,1e5,int(1e5-1)) + + kmaxs = np.logspace(-4,2,200) + theta_rad = theta * (np.pi / (180 * 60)) + + ombh2 = PLANCK18['Omega_b'] * PLANCK18['h']**2 + omch2 = (PLANCK18['Omega_m'] - PLANCK18['Omega_b']) * PLANCK18['h']**2 + pars = camb.set_params( + H0=H0, ombh2=ombh2, omch2=omch2, mnu=PLANCK18['m_nu'], As=PLANCK18['As'], ns=PLANCK18['n_s'], + halofit_version='mead2020_feedback', lmax=3000, WantTransfer=True) + + nz_z, som_nz = np.loadtxt(f'{nz_file}', unpack=True) + som_nz_interp = interpolate.interp1d(nz_z,som_nz, bounds_error=False, fill_value=None) + + pars.set_matter_power(redshifts = np.linspace(zmin,zmax, 150), kmax=200) + results = camb.get_results(pars) + results.calc_power_spectra(pars) + k_nonlin, z_nonlin, pk_nonlin = results.get_nonlinear_matter_power_spectrum(hubble_units=False, + k_hunit=False) + + pkz_nl_interp = interpolate.RegularGridInterpolator((z_nonlin, k_nonlin), pk_nonlin, + bounds_error=False, fill_value=None) + + k_lin, z_lin, pk_lin = results.get_linear_matter_power_spectrum(hubble_units=False, k_hunit=False) + + pkz_lin_interp = interpolate.RegularGridInterpolator((z_lin, k_lin), pk_lin, + bounds_error=False, fill_value=None) + + rz_interp_wantz = rz_interp(True) + rz_interp_noz = rz_interp(False) + W_gg_vals = np.array([W_gg(z, rz_interp_noz) for z in zs]) + W_gg_interp = interpolate.interp1d(zs, W_gg_vals, bounds_error=False, fill_value="extrapolate") + + ########################################################################################### + xis = np.array([xi(theta_rad, kmax, True) for kmax in kmaxs]) + xip = xis[:,0] + xim = xis[:,1] + + # Write results immediately to avoid thread conflicts + with open(f'{output_root}_xip.txt', "a") as f: + new_arr = np.concatenate(([theta], xip)) + np.savetxt(f, new_arr, fmt='%.8e') + + with open(f'{output_root}_xim.txt', "a") as f: + new_arr = np.concatenate(([theta], xim)) + np.savetxt(f, new_arr, fmt='%.8e') + + return theta + + ########################################################################################### + +if __name__ == "__main__": + """Run the shear-correlation calculation in parallel. + + The script expects three command-line arguments: + + 1. Block index specifying which subset of angular scales to process. + 2. Path to the source redshift distribution file. + 3. Output file prefix. + + The 50 angular scales between 1 and 20 arcmin are divided into + blocks of 10 values. Each block is processed in parallel using + multiprocessing, with one worker per angular scale. Each worker + computes xi+ and xi- over the predefined range of kmax values and + appends the results to the output files. + """ + i = int(sys.argv[1]) + nz_file = sys.argv[2] + output_root = sys.argv[3] + + thetas = np.linspace(1,20,50) + theta_block = thetas[i*10:(i+1)*10] + + # Run in parallel to speed up calculations for multiple angular scales + with Pool(processes=10) as pool: + pool.starmap(process_theta, [(theta, nz_file, output_root) for theta in theta_block]) diff --git a/papers/realspace/S8_om_sigma8_whisker.py b/papers/realspace/S8_om_sigma8_whisker.py index 6a483caa..9f0aecae 100644 --- a/papers/realspace/S8_om_sigma8_whisker.py +++ b/papers/realspace/S8_om_sigma8_whisker.py @@ -9,9 +9,6 @@ os.environ["LD_LIBRARY_PATH"] = "" os.environ["CONDA_PREFIX"] = "/home/guerrini/.conda/envs/sp_validation_3.11" -sys.path.append("/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/") - -import sys import warnings import matplotlib.pyplot as plt @@ -548,6 +545,5 @@ plt.tight_layout() -# plt.savefig("./plots/whisker_plot.png", dpi=300) # #Save pdf -plt.savefig("../Plots/S8_whisker_plot.pdf", bbox_inches="tight") +plt.savefig("./../../results/S8_whisker_plot.pdf", bbox_inches="tight") diff --git a/papers/realspace/best_fit_xipm.py b/papers/realspace/best_fit_xipm.py index 56316043..f0d02803 100644 --- a/papers/realspace/best_fit_xipm.py +++ b/papers/realspace/best_fit_xipm.py @@ -279,6 +279,7 @@ theta = theta[mask] ax.plot(theta, theta * xi_plus[mask], label=label, **line_args[idx], lw=2.5) ax2.plot(theta, theta * xi_minus[mask], label=label, **line_args[idx], lw=2.5) + # XI PLUS PLOT SETTINGS # Plot the scale cuts for different k_max @@ -355,10 +356,7 @@ ax2.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20) -plt.savefig( - "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/2D_cosmic_shear_configuration_plots/best_fit_xipm_SP_v1.4.6.3_B.pdf", - bbox_inches="tight", -) +plt.savefig("./../../results/best_fit_xipm_SP_v1.4.6.3_B.pdf",bbox_inches="tight") root_to_plot = [fiducial_root_xi_chains] @@ -496,7 +494,4 @@ ax2.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20) -plt.savefig( - "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/best_fit_tau_02_SP_v1.4.6.3_B.pdf", - bbox_inches="tight", -) +plt.savefig("./../../results/best_fit_tau_02_SP_v1.4.6.3_B.pdf",bbox_inches="tight") diff --git a/papers/realspace/contours.py b/papers/realspace/contours.py index c58f7c89..78b988f4 100644 --- a/papers/realspace/contours.py +++ b/papers/realspace/contours.py @@ -269,7 +269,7 @@ filled=[True, True, False, False, True], ) -g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot.pdf") +g.export("./../../results/SP_v1.4.6.3_B_fiducial_config_contour_plot.pdf") # ### FULL PLOT @@ -309,7 +309,7 @@ filled=True, ) -g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_full.pdf") +g.export("./../../results/SP_v1.4.6.3_B_fiducial_config_contour_plot_full.pdf") # ### IA PLOT @@ -339,7 +339,7 @@ filled=[True, False, True], ) -g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_ia.pdf") +g.export("./../../results/SP_v1.4.6.3_B_fiducial_config_contour_plot_ia.pdf") # ### PSF PLOT @@ -380,7 +380,7 @@ 0.022, 0.798, color="k", marker="P", s=400, label="Fiducial config best-fit" ) -g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_psf.pdf") +g.export("./../../results/SP_v1.4.6.3_B_fiducial_config_contour_plot_psf.pdf") # ### DELTA Z PLOT @@ -409,7 +409,7 @@ filled=[True, False, True], ) -g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_dz.pdf") +g.export("./../../results/SP_v1.4.6.3_B_fiducial_config_contour_plot_dz.pdf") # ### EXTERNAL DATA @@ -450,7 +450,7 @@ g.add_y_bands(0.2975, 0.0086, alpha2=0, color="k", label="BAO") g.add_legend(legend_labels, legend_loc="upper right") -g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_ext.pdf") +g.export("./../../results/SP_v1.4.6.3_B_fiducial_config_contour_plot_ext.pdf") # ### Small scales @@ -484,7 +484,7 @@ ) g.add_legend(legend_labels, legend_loc="upper right") -g.export("../Plots/SP_v1.4.6.3_B_fiducial_config_contour_plot_scales.pdf") +g.export("./../../results/SP_v1.4.6.3_B_fiducial_config_contour_plot_scales.pdf") # ### BBN Prior @@ -629,7 +629,7 @@ ax.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xip, fontsize=20) -plt.savefig("/Plots/scale_cut_xipm_SP_v1.4.6.3_B.pdf", bbox_inches="tight") +plt.savefig("./../../results/scale_cut_xipm_SP_v1.4.6.3_B.pdf", bbox_inches="tight") labels = roots_nonlin.values() @@ -742,4 +742,4 @@ ax2.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20) -plt.savefig("/Plots/nonlin_xipm_SP_v1.4.6.3_B.pdf", bbox_inches="tight") +plt.savefig("./../../results/nonlin_xipm_SP_v1.4.6.3_B.pdf", bbox_inches="tight") diff --git a/papers/realspace/cov_masking.py b/papers/realspace/cov_masking.py index 1388d3c6..77b075ea 100644 --- a/papers/realspace/cov_masking.py +++ b/papers/realspace/cov_masking.py @@ -64,7 +64,7 @@ plt.axhline(y=int(ndata / 2), color="white", linewidth=1.0) plt.savefig( - f"./Plots/covmat_masked_unmasked_ratio_{catalog_ver}_{blind}.pdf", + f"./../../results/covmat_masked_unmasked_ratio_{catalog_ver}_{blind}.pdf", bbox_inches="tight", ) @@ -77,4 +77,4 @@ plt.xlabel(r"$\theta$ (arcmin)") plt.ylabel("Cov masked / Cov unmasked") plt.legend(fontsize=20) -plt.savefig("./Plots/covmat_masked_unmasked_ratio_diag.pdf", bbox_inches="tight") +plt.savefig("./../../results/covmat_masked_unmasked_ratio_diag.pdf", bbox_inches="tight") diff --git a/papers/realspace/get_chi2.py b/papers/realspace/get_chi2.py index d77a8f03..c87a33da 100644 --- a/papers/realspace/get_chi2.py +++ b/papers/realspace/get_chi2.py @@ -9,7 +9,6 @@ import scipy.stats as stats from astropy.io import fits from getdist import plots -from IPython.display import Markdown, display from scipy.interpolate import interp1d sys.path.append("/home/guerrini/sp_validation/cosmo_inference/scripts") @@ -559,7 +558,6 @@ def display_markdown(metrics): rows.append(row) # Display in Jupyter - display(Markdown(header + "\n".join(rows))) return header + "\n".join(rows) diff --git a/papers/realspace/get_chi2_glass_mock.py b/papers/realspace/get_chi2_glass_mock.py index 7542fd8d..596da161 100644 --- a/papers/realspace/get_chi2_glass_mock.py +++ b/papers/realspace/get_chi2_glass_mock.py @@ -57,10 +57,7 @@ ] output_folder_chains = "/n23data1/n06data/lgoh/scratch/temp/" -path_ini_files = "/home/guerrini/sp_validation/cosmo_inference/cosmosis_config/" -output_fig_path = ( - "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/" -) +path_ini_files = "/home/xguerrini/sp_validation/cosmo_inference/cosmosis_config/" ini_root = "blind_A/fiducial" @@ -468,4 +465,4 @@ ax2.set_xlabel(r"$\chi^2 (\xi_\pm)$") ax2.set_ylabel("Density") -fig.savefig(f"{output_fig_path}/chi2_glass_mocks_p_value_xi_tau.pdf") +fig.savefig("./../../results/chi2_glass_mocks_p_value_xi_tau.pdf") diff --git a/papers/realspace/get_prior_psf_leakage.py b/papers/realspace/get_prior_psf_leakage.py index c84d5611..c08c76c5 100644 --- a/papers/realspace/get_prior_psf_leakage.py +++ b/papers/realspace/get_prior_psf_leakage.py @@ -3,10 +3,6 @@ # This notebook plots the combined covariance matrix, and samples and plots the 2D marginalised posteriors of the PSF leakage parameters $\alpha$ and $\beta$. -import os - -if not os.path.exists("./Plots"): - os.makedirs("./Plots") import matplotlib.pyplot as plt import numpy as np @@ -87,7 +83,7 @@ def cov_to_corr(cov): ) fig.colorbar(im, ax=ax) - plt.savefig(f"./Plots/cov_matrix_{root}.png", bbox_inches="tight", dpi=300) + plt.savefig(f"./../../results/cov_matrix_{root}.png", bbox_inches="tight", dpi=300) # Create dummy rho and tau stat handler. @@ -165,4 +161,4 @@ def cov_to_corr(cov): legend_loc="upper right", ) -# plt.savefig(f"./Plots/psf_leakage_params.png", bbox_inches='tight', dpi=300) +plt.savefig("./../../results/psf_leakage_params.png", bbox_inches='tight', dpi=300) diff --git a/papers/realspace/glass_mock_hist.py b/papers/realspace/glass_mock_hist.py index 113f3be9..97b34f1d 100644 --- a/papers/realspace/glass_mock_hist.py +++ b/papers/realspace/glass_mock_hist.py @@ -1,11 +1,3 @@ -import IPython - -ipython = IPython.get_ipython() - -if ipython is not None: - ipython.run_line_magic("load_ext", "autoreload") - ipython.run_line_magic("autoreload", "2") - import os import matplotlib.pyplot as plt @@ -26,10 +18,6 @@ # Set default palette - will be updated per plot as needed sns.set_palette("husl") -if ipython is not None: - ipython.run_line_magic("matplotlib", "inline") - - root_dir = "/n09data/guerrini/glass_mock_chains/" chain_version = "v6" num_sims = 350 @@ -418,7 +406,7 @@ def concatenate_merge_params(name, merged_params, verbose=False): plt.xlabel(r"$\Delta S_8$") plt.savefig( - "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/S8_comparison_harmonic_vs_configuration.pdf", + "./../../results/S8_comparison_harmonic_vs_configuration.pdf", bbox_inches="tight", ) @@ -465,6 +453,6 @@ def concatenate_merge_params(name, merged_params, verbose=False): # Optional styling tweaks g.ax_joint.tick_params(labelsize=12) plt.savefig( - "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/notebooks/Plots/S8_vs_OmegaM_configuration_space_mocks.pdf", + "./../../results/S8_vs_OmegaM_configuration_space_mocks.pdf", bbox_inches="tight", ) diff --git a/papers/realspace/nonlin_k_analysis.py b/papers/realspace/nonlin_k_analysis.py index 2ddef76e..bfda4e67 100644 --- a/papers/realspace/nonlin_k_analysis.py +++ b/papers/realspace/nonlin_k_analysis.py @@ -3,7 +3,6 @@ # This notebook plots the 2D heatmap of ratio of scale contributions to the $\xi_\pm$ 2PCF given angular scale $\theta$ and wavenumber $k$. -import os import matplotlib.pylab as plt import numpy as np @@ -31,7 +30,6 @@ data_dir = "/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/data/" -curr_dir = os.getcwd() # Read the 2D array from the text file @@ -104,6 +102,5 @@ cbar_ax = fig.add_axes([0.99, 0.15, 0.02, 0.7]) cbar = fig.colorbar(pcm, cax=cbar_ax) -fig.savefig( - curr_dir + f"/../Plots/theta_k_xip_xim_{ver}_{blind}.pdf", bbox_inches="tight" +fig.savefig("./../../results/theta_k_xip_xim_{ver}_{blind}.pdf", bbox_inches="tight" ) From ab1b57b0f63dc11c9911b6270f1bd9dcfa3cf4f0 Mon Sep 17 00:00:00 2001 From: Lisa Goh Date: Thu, 9 Jul 2026 15:35:52 +0100 Subject: [PATCH 09/11] Refactor hz_integrand to a named function --- cosmo_inference/scripts/k_analysis.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cosmo_inference/scripts/k_analysis.py b/cosmo_inference/scripts/k_analysis.py index e2e58135..b2396d79 100644 --- a/cosmo_inference/scripts/k_analysis.py +++ b/cosmo_inference/scripts/k_analysis.py @@ -76,7 +76,10 @@ def rz_interp(want_z): scipy.interpolate.interp1d Interpolation function relating redshift and comoving distance. """ - hz_integrand = lambda zz: c/Hz(zz) + + def hz_integrand(zz): + return c/Hz(zz) + rz_ref = np.array([integrate.quad(hz_integrand, 0, z)[0] for z in zs]) if want_z == True: From 5adb796cc104401bb628a86611c0f8774d2daa0d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 9 Jul 2026 14:38:46 +0000 Subject: [PATCH 10/11] Fix ruff W293: remove trailing whitespace from blank lines in k_analysis.py --- cosmo_inference/scripts/k_analysis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cosmo_inference/scripts/k_analysis.py b/cosmo_inference/scripts/k_analysis.py index b2396d79..eef59f8f 100644 --- a/cosmo_inference/scripts/k_analysis.py +++ b/cosmo_inference/scripts/k_analysis.py @@ -76,10 +76,10 @@ def rz_interp(want_z): scipy.interpolate.interp1d Interpolation function relating redshift and comoving distance. """ - + def hz_integrand(zz): return c/Hz(zz) - + rz_ref = np.array([integrate.quad(hz_integrand, 0, z)[0] for z in zs]) if want_z == True: From babae0c1ee64f99d8d41d192736ea26cd9148032 Mon Sep 17 00:00:00 2001 From: Cail Daley Date: Fri, 10 Jul 2026 08:43:42 +0200 Subject: [PATCH 11/11] ruff format pass over the 5 drifted files Formatter drift (quotes, operator spacing, blank lines) accumulated from per-line lint fixes; one `ruff format` pass settles it. Both `ruff check .` and `ruff format --check .` now clean. Co-Authored-By: Claude Fable 5 --- cosmo_inference/scripts/k_analysis.py | 115 +++++++++++++--------- papers/realspace/best_fit_xipm.py | 4 +- papers/realspace/cov_masking.py | 4 +- papers/realspace/get_prior_psf_leakage.py | 3 +- papers/realspace/nonlin_k_analysis.py | 4 +- 5 files changed, 78 insertions(+), 52 deletions(-) diff --git a/cosmo_inference/scripts/k_analysis.py b/cosmo_inference/scripts/k_analysis.py index eef59f8f..d3939c10 100644 --- a/cosmo_inference/scripts/k_analysis.py +++ b/cosmo_inference/scripts/k_analysis.py @@ -14,6 +14,7 @@ ###################################################################################################### + def process_theta(theta, nz_file, output_root): """Compute shear correlation functions for a single angular scale. @@ -56,7 +57,7 @@ def Hz(z): float or ndarray Hubble parameter in km s^-1 Mpc^-1. """ - return H0 * np.sqrt(Omega_m*(1+z)**3 + (1-Omega_m)) + return H0 * np.sqrt(Omega_m * (1 + z) ** 3 + (1 - Omega_m)) def rz_interp(want_z): """Create an interpolation between redshift and comoving distance. @@ -78,15 +79,18 @@ def rz_interp(want_z): """ def hz_integrand(zz): - return c/Hz(zz) + return c / Hz(zz) rz_ref = np.array([integrate.quad(hz_integrand, 0, z)[0] for z in zs]) if want_z == True: - return interpolate.interp1d(rz_ref, zs, bounds_error=False, fill_value="extrapolate") + return interpolate.interp1d( + rz_ref, zs, bounds_error=False, fill_value="extrapolate" + ) else: - return interpolate.interp1d(zs, rz_ref, bounds_error=False, fill_value="extrapolate") - + return interpolate.interp1d( + zs, rz_ref, bounds_error=False, fill_value="extrapolate" + ) def W_gg(z, rz): """Compute the lensing efficiency kernel. @@ -109,11 +113,10 @@ def W_gg(z, rz): z_integrate = np.linspace(z, zmax, n) r_zmin = rz(z) nz_int = som_nz_interp(z_integrate) * (1 - r_zmin / rz(z_integrate)) - prefactor = 3 * H0**2 * Omega_m * (1+z) * r_zmin / (2 * c**2) + prefactor = 3 * H0**2 * Omega_m * (1 + z) * r_zmin / (2 * c**2) return prefactor * integrate.simpson(nz_int, x=z_integrate) - def C_ell(ell, kmax, want_IA): """Compute the angular power spectrum. @@ -141,7 +144,7 @@ def C_ell(ell, kmax, want_IA): return 0.0 rzs = rz_interp_noz(z_valid) - W_ggs = W_gg_interp(z_valid) + W_ggs = W_gg_interp(z_valid) Pks = pkz_nl_interp((z_valid, (ell + 0.5) / rzs)) Hzs = Hz(z_valid) @@ -149,8 +152,9 @@ def C_ell(ell, kmax, want_IA): C_ell_gg = integrate.simpson(gg_integrand, x=z_valid) if want_IA == True: - - Dzs = pkz_lin_interp((z_valid, (ell + 0.5) / rzs)) / pkz_lin_interp((0, (ell + 0.5) / rzs)) + Dzs = pkz_lin_interp((z_valid, (ell + 0.5) / rzs)) / pkz_lin_interp( + (0, (ell + 0.5) / rzs) + ) P_ia = -A_IA * c1 * Omega_m / Dzs W_ias = Hzs * som_nz_interp(z_valid) / c @@ -189,12 +193,15 @@ def xi(theta_rad, kmax, want_IA): xip_integrand = ells * C_ell_vals * j0(ells * theta_rad) xim_integrand = ells * C_ell_vals * jn(4, ells * theta_rad) - return integrate.simpson(xip_integrand, x=ells)/(2 * np.pi), integrate.simpson(xim_integrand, x=ells)/(2 * np.pi) + return integrate.simpson(xip_integrand, x=ells) / ( + 2 * np.pi + ), integrate.simpson(xim_integrand, x=ells) / (2 * np.pi) + ########################################################################################### - c = const.c.to('km/s') - H0 = PLANCK18['h'] * 100 - Omega_m = PLANCK18['Omega_m'] + c = const.c.to("km/s") + H0 = PLANCK18["h"] * 100 + Omega_m = PLANCK18["Omega_m"] A_IA = 0.83 c1 = 5e-14 * (u.Mpc**3.0) / u.solMass @@ -202,57 +209,75 @@ def xi(theta_rad, kmax, want_IA): zmin = 1e-5 zmax = 4 n = 500 - zs = np.linspace(zmin,zmax,n) - ells = np.linspace(2,1e5,int(1e5-1)) + zs = np.linspace(zmin, zmax, n) + ells = np.linspace(2, 1e5, int(1e5 - 1)) - kmaxs = np.logspace(-4,2,200) + kmaxs = np.logspace(-4, 2, 200) theta_rad = theta * (np.pi / (180 * 60)) - ombh2 = PLANCK18['Omega_b'] * PLANCK18['h']**2 - omch2 = (PLANCK18['Omega_m'] - PLANCK18['Omega_b']) * PLANCK18['h']**2 + ombh2 = PLANCK18["Omega_b"] * PLANCK18["h"] ** 2 + omch2 = (PLANCK18["Omega_m"] - PLANCK18["Omega_b"]) * PLANCK18["h"] ** 2 pars = camb.set_params( - H0=H0, ombh2=ombh2, omch2=omch2, mnu=PLANCK18['m_nu'], As=PLANCK18['As'], ns=PLANCK18['n_s'], - halofit_version='mead2020_feedback', lmax=3000, WantTransfer=True) - - nz_z, som_nz = np.loadtxt(f'{nz_file}', unpack=True) - som_nz_interp = interpolate.interp1d(nz_z,som_nz, bounds_error=False, fill_value=None) - - pars.set_matter_power(redshifts = np.linspace(zmin,zmax, 150), kmax=200) + H0=H0, + ombh2=ombh2, + omch2=omch2, + mnu=PLANCK18["m_nu"], + As=PLANCK18["As"], + ns=PLANCK18["n_s"], + halofit_version="mead2020_feedback", + lmax=3000, + WantTransfer=True, + ) + + nz_z, som_nz = np.loadtxt(f"{nz_file}", unpack=True) + som_nz_interp = interpolate.interp1d( + nz_z, som_nz, bounds_error=False, fill_value=None + ) + + pars.set_matter_power(redshifts=np.linspace(zmin, zmax, 150), kmax=200) results = camb.get_results(pars) results.calc_power_spectra(pars) - k_nonlin, z_nonlin, pk_nonlin = results.get_nonlinear_matter_power_spectrum(hubble_units=False, - k_hunit=False) + k_nonlin, z_nonlin, pk_nonlin = results.get_nonlinear_matter_power_spectrum( + hubble_units=False, k_hunit=False + ) - pkz_nl_interp = interpolate.RegularGridInterpolator((z_nonlin, k_nonlin), pk_nonlin, - bounds_error=False, fill_value=None) + pkz_nl_interp = interpolate.RegularGridInterpolator( + (z_nonlin, k_nonlin), pk_nonlin, bounds_error=False, fill_value=None + ) - k_lin, z_lin, pk_lin = results.get_linear_matter_power_spectrum(hubble_units=False, k_hunit=False) + k_lin, z_lin, pk_lin = results.get_linear_matter_power_spectrum( + hubble_units=False, k_hunit=False + ) - pkz_lin_interp = interpolate.RegularGridInterpolator((z_lin, k_lin), pk_lin, - bounds_error=False, fill_value=None) + pkz_lin_interp = interpolate.RegularGridInterpolator( + (z_lin, k_lin), pk_lin, bounds_error=False, fill_value=None + ) rz_interp_wantz = rz_interp(True) rz_interp_noz = rz_interp(False) W_gg_vals = np.array([W_gg(z, rz_interp_noz) for z in zs]) - W_gg_interp = interpolate.interp1d(zs, W_gg_vals, bounds_error=False, fill_value="extrapolate") + W_gg_interp = interpolate.interp1d( + zs, W_gg_vals, bounds_error=False, fill_value="extrapolate" + ) ########################################################################################### xis = np.array([xi(theta_rad, kmax, True) for kmax in kmaxs]) - xip = xis[:,0] - xim = xis[:,1] + xip = xis[:, 0] + xim = xis[:, 1] # Write results immediately to avoid thread conflicts - with open(f'{output_root}_xip.txt', "a") as f: + with open(f"{output_root}_xip.txt", "a") as f: new_arr = np.concatenate(([theta], xip)) - np.savetxt(f, new_arr, fmt='%.8e') + np.savetxt(f, new_arr, fmt="%.8e") - with open(f'{output_root}_xim.txt', "a") as f: + with open(f"{output_root}_xim.txt", "a") as f: new_arr = np.concatenate(([theta], xim)) - np.savetxt(f, new_arr, fmt='%.8e') + np.savetxt(f, new_arr, fmt="%.8e") return theta - ########################################################################################### + +########################################################################################### if __name__ == "__main__": """Run the shear-correlation calculation in parallel. @@ -273,9 +298,11 @@ def xi(theta_rad, kmax, want_IA): nz_file = sys.argv[2] output_root = sys.argv[3] - thetas = np.linspace(1,20,50) - theta_block = thetas[i*10:(i+1)*10] + thetas = np.linspace(1, 20, 50) + theta_block = thetas[i * 10 : (i + 1) * 10] # Run in parallel to speed up calculations for multiple angular scales with Pool(processes=10) as pool: - pool.starmap(process_theta, [(theta, nz_file, output_root) for theta in theta_block]) + pool.starmap( + process_theta, [(theta, nz_file, output_root) for theta in theta_block] + ) diff --git a/papers/realspace/best_fit_xipm.py b/papers/realspace/best_fit_xipm.py index f0d02803..ebd66f27 100644 --- a/papers/realspace/best_fit_xipm.py +++ b/papers/realspace/best_fit_xipm.py @@ -356,7 +356,7 @@ ax2.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20) -plt.savefig("./../../results/best_fit_xipm_SP_v1.4.6.3_B.pdf",bbox_inches="tight") +plt.savefig("./../../results/best_fit_xipm_SP_v1.4.6.3_B.pdf", bbox_inches="tight") root_to_plot = [fiducial_root_xi_chains] @@ -494,4 +494,4 @@ ax2.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) ax2.legend(loc=loc_legend, bbox_to_anchor=bbox_to_anchor_xim, fontsize=20) -plt.savefig("./../../results/best_fit_tau_02_SP_v1.4.6.3_B.pdf",bbox_inches="tight") +plt.savefig("./../../results/best_fit_tau_02_SP_v1.4.6.3_B.pdf", bbox_inches="tight") diff --git a/papers/realspace/cov_masking.py b/papers/realspace/cov_masking.py index 77b075ea..210638cb 100644 --- a/papers/realspace/cov_masking.py +++ b/papers/realspace/cov_masking.py @@ -77,4 +77,6 @@ plt.xlabel(r"$\theta$ (arcmin)") plt.ylabel("Cov masked / Cov unmasked") plt.legend(fontsize=20) -plt.savefig("./../../results/covmat_masked_unmasked_ratio_diag.pdf", bbox_inches="tight") +plt.savefig( + "./../../results/covmat_masked_unmasked_ratio_diag.pdf", bbox_inches="tight" +) diff --git a/papers/realspace/get_prior_psf_leakage.py b/papers/realspace/get_prior_psf_leakage.py index c08c76c5..4d335085 100644 --- a/papers/realspace/get_prior_psf_leakage.py +++ b/papers/realspace/get_prior_psf_leakage.py @@ -3,7 +3,6 @@ # This notebook plots the combined covariance matrix, and samples and plots the 2D marginalised posteriors of the PSF leakage parameters $\alpha$ and $\beta$. - import matplotlib.pyplot as plt import numpy as np import seaborn as sns @@ -161,4 +160,4 @@ def cov_to_corr(cov): legend_loc="upper right", ) -plt.savefig("./../../results/psf_leakage_params.png", bbox_inches='tight', dpi=300) +plt.savefig("./../../results/psf_leakage_params.png", bbox_inches="tight", dpi=300) diff --git a/papers/realspace/nonlin_k_analysis.py b/papers/realspace/nonlin_k_analysis.py index bfda4e67..a44002a3 100644 --- a/papers/realspace/nonlin_k_analysis.py +++ b/papers/realspace/nonlin_k_analysis.py @@ -3,7 +3,6 @@ # This notebook plots the 2D heatmap of ratio of scale contributions to the $\xi_\pm$ 2PCF given angular scale $\theta$ and wavenumber $k$. - import matplotlib.pylab as plt import numpy as np import seaborn as sns @@ -102,5 +101,4 @@ cbar_ax = fig.add_axes([0.99, 0.15, 0.02, 0.7]) cbar = fig.colorbar(pcm, cax=cbar_ax) -fig.savefig("./../../results/theta_k_xip_xim_{ver}_{blind}.pdf", bbox_inches="tight" -) +fig.savefig("./../../results/theta_k_xip_xim_{ver}_{blind}.pdf", bbox_inches="tight")