From b5f2e4889ed35ccaf59415e56bbfeea771071d52 Mon Sep 17 00:00:00 2001 From: LisaGoh Date: Fri, 4 Apr 2025 18:58:24 +0200 Subject: [PATCH 1/2] added notebooks to produce paper plots --- .../ psf_leakage.ipynb | 25 ++ .../S8_sigma8_Om_contour.ipynb | 266 ++++++++++++++++++ .../S8_whisker.ipynb | 115 ++++++++ .../corr_func.ipynb | 224 +++++++++++++++ .../supporting_plots.ipynb | 150 ++++++++++ 5 files changed, 780 insertions(+) create mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/ psf_leakage.ipynb create mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_sigma8_Om_contour.ipynb create mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_whisker.ipynb create mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/corr_func.ipynb create mode 100644 cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/supporting_plots.ipynb diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/ psf_leakage.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/ psf_leakage.ipynb new file mode 100644 index 0000000..a53f845 --- /dev/null +++ b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/ psf_leakage.ipynb @@ -0,0 +1,25 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## PSF Leakage Plots\n", + "\n", + "This notebook creates all the plots of the PSF leakage: the $\\rho$ and $\\tau$ statistics (from Guerrini et al. 2024) as well as the covariance matrix of the $\\alpha_{PSF}$ and $\\beta_{PSF}$ parameters." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_sigma8_Om_contour.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_sigma8_Om_contour.ipynb new file mode 100644 index 0000000..f36d0ac --- /dev/null +++ b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_sigma8_Om_contour.ipynb @@ -0,0 +1,266 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "510c4e0b", + "metadata": {}, + "source": [ + "## $S_8 - \\Omega_m$ and $\\sigma_8-\\Omega_m$ Contour Plot\n", + "\n", + "This notebook creates a 2D marginalised contour plot of the $S_8$ and $\\Omega_m$ parameters, comparing this work with fiducial results from DES Y3, HSC and KiDS-Legacy (no chains yet so maybe just KiDS-1000?). Also the same for a plot of $\\sigma_8-\\Omega_m$.\n", + "\n", + "This notebook also reds the chains and derives the posterior values of $S_8$, subsequently writing them intoa file to be read in and plotted as a whisker plot in S8_whisker.ipynb." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "5e65319a-63f3-47d7-90cd-7b7db06174e9", + "metadata": {}, + "outputs": [], + "source": [ + "from getdist import plots, loadMCSamples\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import uncertainties\n", + "import os\n", + "\n", + "plt.rcParams.update({\"text.usetex\": True})\n", + "\n", + "g = plots.get_subplot_plotter(width_inch=12)\n", + "g.settings.axes_fontsize=30\n", + "g.settings.axes_labelsize=40\n", + "g.settings.alpha_filled_add = 0.7\n", + "g.settings.legend_fontsize = 20\n", + "\n", + "%matplotlib inline\n", + "\n", + "#SPECIFY DATA DIRECTORY AND DESIRED CHAINS TO ANALYSE\n", + "root_dir='/n23data1/n06data/lgoh/scratch/UNIONS/chains/ext_data'\n", + "roots = [\n", + " 'DES_Y3',\n", + " 'HSC_Y3',\n", + " 'DES+KiDS',\n", + " 'KiDS-1000',\n", + " 'Planck18'\n", + " ]\n", + "\n", + "root_label = [\n", + " r'DES Y3 ($\\xi_\\pm$)',\n", + " r'HSC Y3 ($\\xi_\\pm$)',\n", + " r'DES+KiDS ($\\xi_\\pm$)',\n", + " r'KiDS-1000 ($\\xi_\\pm$)',\n", + " r'Planck18 TT+TE+EE+lowE'\n", + " ]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "ba84564b", + "metadata": {}, + "outputs": [], + "source": [ + "# Create the .paramnames file needed by getdist (take the parameter names from the first line of the output file)\n", + "for root in roots:\n", + " if os.path.isfile(f\"{root_dir}/{root}/getdist_{root}.paramnames\")==False:\n", + " \n", + " with open(f\"{root_dir}/{root}/{root}.txt\", \"r\") as file:\n", + " params = file.readline()[1:].split('\\t')[:-4]\n", + " file.close()\n", + " \n", + " with open(f\"{root_dir}/{root}/getdist_{root}.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", + " print(params)" + ] + }, + { + "cell_type": "markdown", + "id": "70549903-a160-4a3e-a202-bd5a9d6b45eb", + "metadata": {}, + "source": [ + "## Retrieve the chains" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "4795888c-ce6f-4fe2-bbd4-fe17b5e57f02", + "metadata": {}, + "outputs": [], + "source": [ + "#READ CHAIN\n", + "\n", + "chains=[]\n", + "\n", + "for root in roots:\n", + " if os.path.isfile(f\"{root_dir}/{root}/getdist_{root}.paramnames\")==False:\n", + " samples = np.loadtxt(f\"{root_dir}/{root}/{root}.txt\")\n", + " samples = np.column_stack((samples[:,-1],samples[:,-3],samples[:,0:-4]))\n", + " np.savetxt(f\"{root_dir}/{root}/getdist_{root}.txt\", samples)\n", + " \n", + " chain = g.samples_for_root(f\"{root_dir}/{root}/getdist_{root}\",\n", + " cache=False,\n", + " settings={'ignore_rows':0,\n", + " # 'smooth_scale_2D':0.7,\n", + " # 'smooth_scale_1D':0.7\n", + " })\n", + " p = chain.getParams()\n", + " chain.addDerived(p.omega_m, name='OMEGA_M', label=r'$\\Omega_m$')\n", + " chain.addDerived(p.SIGMA_8, name='sigma_8', label=r'$\\sigma_8$')\n", + " if hasattr(p,'S_8')==False:\n", + " chain.addDerived(p.SIGMA_8*(np.sqrt(p.omega_m/0.3)), name='S_8', label=r'S_8')\n", + "\n", + " chains.append(chain)" + ] + }, + { + "cell_type": "markdown", + "id": "09ff24ef-6e8c-4ddd-96de-eeaf63b6982d", + "metadata": {}, + "source": [ + "## Plot the chain" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9080b714-810e-4a9d-b59d-54299752e35f", + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "g.plot_2d(chains,\n", + " ['OMEGA_M','S_8'],\n", + " # contour_colors=['#0072B2', '#009E73', '#D55E00', '#CC79A7'],\n", + " filled=True)\n", + "g.add_legend(root_label, legend_loc='upper left')\n", + "# g.export('contour_plot_s8_om_fid.pdf')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d627a76", + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib inline\n", + "g.plot_2d(chains,\n", + " ['OMEGA_M','sigma_8'],\n", + " # contour_colors=['#0072B2', '#009E73', '#D55E00', '#CC79A7'],\n", + " filled=True)\n", + "g.add_legend(root_label, legend_loc='upper left')\n", + "# g.export('contour_plot_sigma8_om_fid.pdf')" + ] + }, + { + "cell_type": "markdown", + "id": "d386da94-c165-488f-8604-ec2109935e07", + "metadata": { + "jp-MarkdownHeadingCollapsed": true, + "tags": [] + }, + "source": [ + "### Output bestfit and sigma values of parameters" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1ab5f45e-9f92-422a-89ef-1453b0b1c153", + "metadata": {}, + "outputs": [], + "source": [ + "#########BESTFIT AND SIGMA VALS##########\n", + "params = ['OMEGA_M','S_8']\n", + "latex_params = [r'$\\Omega_{m}$',r'$S_8$']\n", + "\n", + "chains = chains[::-1]\n", + "for chain in chains:\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,param_stats.mean-param_stats.limits[0].lower, param_stats.limits[0].upper-param_stats.mean])\n", + " if '%.2g' %a[1] == '%.2g' %a[2]:\n", + " latex_params[no] += '&$%.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) \n" + ] + }, + { + "cell_type": "markdown", + "id": "bbf09de1", + "metadata": {}, + "source": [ + "### Save values of $S_8$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6cab7bbb-8ce2-4e8c-8a2d-721442d14a6f", + "metadata": {}, + "outputs": [], + "source": [ + "s8_values = np.array([\"Expt\", \"Mean\", \"S8_low\", \"S8_high\"])\n", + "for i, chain in enumerate(chains):\n", + "\n", + " margestats = chain.getMargeStats()\n", + " likestats = chain.getLikeStats()\n", + "\n", + " param_stats = margestats.parWithName('S_8')\n", + " \n", + " s8_values = np.vstack((s8_values,[root_label[i], param_stats.mean, param_stats.mean-param_stats.limits[0].lower, param_stats.limits[0].upper-param_stats.mean]))\n", + "print(s8_values)\n", + "np.savetxt(f\"{root_dir}/S8_means.txt\", s8_values, fmt=['%s','%s','%s','%s'], delimiter=',')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47e60452", + "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.21" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_whisker.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_whisker.ipynb new file mode 100644 index 0000000..559ed16 --- /dev/null +++ b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_whisker.ipynb @@ -0,0 +1,115 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## $S_8$ Whisker Plot\n", + "\n", + "This notebook creates a whisker plot of $S_8$ values for different test cases and external datasets." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib\n", + "from astropy.io import fits\n", + "import matplotlib.pyplot as plt\n", + "import uncertainties\n", + "import yaml\n", + "import os\n", + "import numpy as np\n", + "\n", + "plt.rcParams.update({\"text.usetex\": True})\n", + "plt.rcParams.update({'font.size': 25})\n", + "plt.rc('mathtext', fontset='stix')\n", + "plt.rc('font', family='serif')\n", + "\n", + "chains_dir = f\"/n23data1/n06data/lgoh/scratch/UNIONS/chains\"\n", + "num_test_cases = 1\n" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "# Read in text file with s8 values for the different test cases and external experiments \n", + "# (have had to run getdist to analyse the chains first)\n", + "\n", + "s8s = np.loadtxt(f\"{chains_dir}/S8_means.txt\",dtype={'names': ('Exp', 's8_mean', 's8_low', 's8_high'), 'formats': ('U40', 'U20', 'U20', 'U20')}, skiprows=1, delimiter=',')\n", + "expt = s8s['Exp']\n", + "s8s_mean = s8s['s8_mean'].astype(np.float64)\n", + "s8s_low = s8s['s8_low'].astype(np.float64)\n", + "s8s_high = s8s['s8_high'].astype(np.float64)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "fig, axs = plt.subplots(1, 1, sharey=True, figsize=[7,1.5*len(expt)])\n", + "axs.yaxis.set_visible(False)\n", + "# axs.invert_yaxis()\n", + "\n", + "y = np.arange(0,len(expt))\n", + "\n", + "for i in y:\n", + " if i > len(expt)-num_test_cases-1:\n", + " axs.errorbar(s8s_mean[i], i+1, xerr=np.vstack((s8s_low[i],s8s_high[i])), fmt='o', c = 'darkblue',lw = 2, capsize=5,capthick=2)\n", + " else:\n", + " axs.errorbar(s8s_mean[i], i+1, xerr=np.vstack((s8s_low[i],s8s_high[i])), fmt='o', c = 'darkgreen',lw = 2, capsize=5,capthick=2)\n", + " \n", + " if i == 0: # Plot the band for \"Planck\"\n", + " axs.axvspan(s8s_mean[i]-s8s_low[i], s8s_mean[i]+s8s_high[i], alpha=0.2, color='cyan')\n", + " if i == len(expt)-1: # Plot the band for \"this work\"\n", + " axs.axvspan(s8s_mean[i]-s8s_low[i], s8s_mean[i]+s8s_high[i], alpha=0.2, color='lightpink')\n", + " if i == len(expt)-num_test_cases-1: # Make a distinction between this work (and all its test cases) with external datasets\n", + " axs.axhline(i+1.5, ls='dashed',c='k')\n", + " \n", + " \n", + " \n", + " axs.set_xlabel(r'$S_8=\\sigma_8\\sqrt{\\Omega_{\\rm m}/0.3}$') \n", + " axs.text(0.62, i+1, rf\"{expt[i]}\")\n", + "\n", + "plt.ylim([0,i+2])\n", + "# plt.savefig('plots/s8_whisker.pdf',bbox_inches=\"tight\")" + ] + }, + { + "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.21" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/corr_func.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/corr_func.ipynb new file mode 100644 index 0000000..ea4933e --- /dev/null +++ b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/corr_func.ipynb @@ -0,0 +1,224 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Correlation Function Plots\n", + "\n", + "This notebook creates all the plots of the 2 point correlation functions (2PCFs) appearing in the paper: the fiducial $\\xi_\\pm$, the $\\xi_{E/B}$ as well as the $\\xi_{sys}$ correlation functions." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib\n", + "from astropy.io import fits\n", + "import matplotlib.pyplot as plt\n", + "import uncertainties\n", + "import yaml\n", + "import os\n", + "import numpy as np\n", + "\n", + "plt.rcParams.update({'font.size': 25,'figure.figsize':[12,7]})\n", + "plt.rcParams.update({\"text.usetex\": True})\n", + "plt.rc('mathtext', fontset='stix')\n", + "plt.rc('font', family='serif')\n", + "\n", + "# Define path to data files (NOTE: YOU MUST HAVE RAN THE cosmo_val.py PIPELINE!)\n", + "cosmoval_data_dir = \"/n23data1/n06data/lgoh/scratch/UNIONS/sp_validation/notebooks/cosmo_val/output\"\n", + "# inf_data_dir = \"/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/data/\"\n", + "ver = \"SP_v1.4.5\"\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Plot the 2PCFs $\\xi_\\pm$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Read in the text file of the 2PCFs\n", + "\n", + "xipm_fname = f\"{cosmoval_data_dir}/xi_pm_{ver}.txt\"\n", + "print(f\"Reading xi_plus's from {xipm_fname}\")\n", + "\n", + "xipm = np.loadtxt(xipm_fname)\n", + "theta = xipm[:,1]\n", + "xip = xipm[:,3]\n", + "xim = xipm[:,4]\n", + "varxip = xipm[:,7]\n", + "varxim = xipm[:,8]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Plot the xi_plus\n", + "ax1 = plt.subplot(111)\n", + "ax1.tick_params(axis='both', which='both', direction='in', length=6, width=1,\n", + " top=True, bottom=True, left=True, right=True)\n", + "ax1.yaxis.minorticks_on()\n", + "\n", + "# ax1.errorbar(theta, xip*1e4, yerr=varxip*1e4, \n", + "# fmt='o', markersize=6, capsize=2, capthick=1.5, ls = 'solid', lw=1.8,\n", + "# label=r'$\\xi_+$', \n", + "# color='royalblue')\n", + "ax1.plot(theta, xip*1e4, marker='o', markersize=4, ls = 'solid', lw=1.8, color=\"royalblue\")\n", + "ax1.fill_between(theta, (xip-varxip)*1e4, (xip+varxip)*1e4, color=\"powderblue\", alpha=0.7)\n", + "ax1.text(0.85 , 0.88, '1,1', transform=ax1.transAxes,\n", + " bbox=dict(facecolor='white', edgecolor='black', boxstyle='round', pad=0.5))\n", + "ax1.axvspan(0,10,color='gray', alpha=0.3)\n", + "ax1.axvspan(150,200,color='gray', alpha=0.3)\n", + "ax1.set_xscale('log')\n", + "ax1.set_xlabel(r'$\\theta$ [arcmin]')\n", + "ax1.set_ylabel(r'$\\xi_+\\times 10^4$')\n", + "# plt.savefig('plots/xi_plus_%s.pdf' %ver,bbox_inches='tight')\n", + "plt.show()\n", + "\n", + "# Plot the xi_minus\n", + "ax2 = plt.subplot(111)\n", + "ax2.tick_params(axis='both', which='both', direction='in', length=6, width=1,\n", + " top=True, bottom=True, left=True, right=True)\n", + "ax2.yaxis.minorticks_on()\n", + "\n", + "# ax2.errorbar(theta, xim*1e4, yerr=varxim*1e4, \n", + "# fmt='o', markersize=6, capsize=2, capthick=1.5, ls = 'solid', lw=1.8,\n", + "# label=r'$\\xi_-$',\n", + "# color='orangered')\n", + "ax2.plot(theta, xim*1e4, marker='o', markersize=4, ls = 'solid', lw=1.8, color=\"orangered\")\n", + "ax2.fill_between(theta, (xim-varxim)*1e4, (xim+varxim)*1e4, color=\"pink\", alpha=0.7)\n", + "ax2.text(0.85, 0.88, '1-1', transform=ax2.transAxes,\n", + " bbox=dict(facecolor='white', edgecolor='black', boxstyle='round', pad=0.5))\n", + "ax2.axvspan(0,10,color='gray', alpha=0.3)\n", + "ax2.axvspan(150,200,color='gray', alpha=0.3)\n", + "ax2.set_xscale('log')\n", + "ax2.set_xlabel(r'$\\theta$ [arcmin]')\n", + "ax2.set_ylabel(r'$\\xi_-\\times 10^4$')\n", + "# plt.savefig('plots/xi_minus_%s.pdf' %ver,bbox_inches='tight')\n", + "plt.show()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Plot the E/B modes $\\xi_{E/B}$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Plot the $\\xi_{sys}$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Read in the text file of the 2PCFs\n", + "\n", + "xisys_fname = f\"{cosmoval_data_dir}/leakage_{ver}/xi_sys.txt\"\n", + "print(f\"Reading xi_sys's from {xisys_fname}\")\n", + "\n", + "xisys = np.loadtxt(xisys_fname)\n", + "theta = xisys[:,0]\n", + "xip_sys = xisys[:,1]\n", + "xim_sys = xisys[:,2]\n", + "varxip_sys = xisys[:,3]\n", + "varxim_sys = xisys[:,4]\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# Plot the xi_+sys\n", + "ax1 = plt.subplot(111)\n", + "ax1.tick_params(axis='both', which='both', direction='in', length=6, width=1,\n", + " top=True, bottom=True, left=True, right=True)\n", + "ax1.yaxis.minorticks_on()\n", + "\n", + "ax1.errorbar(theta, xip_sys/xip, yerr=varxip_sys/xip, \n", + " fmt='o', markersize=4, capsize=2, capthick=1.5, ls = 'solid', lw=1.8,\n", + " label=r'$\\xi_{+,\\rm{sys}}$', \n", + " color='saddlebrown')\n", + "ax1.fill_between(theta, -varxip/xip,varxip/xip, color='palegreen', alpha=0.5)\n", + "ax1.axhline(0,ls='dashed',lw=1, color='grey')\n", + "ax1.text(0.07, 0.88, r'$\\xi_+$, 1-1', transform=ax1.transAxes,\n", + " bbox=dict(facecolor='white', edgecolor='black', boxstyle='round', pad=0.5))\n", + "ax1.set_xscale('log')\n", + "ax1.set_xlabel(r'$\\theta$ [arcmin]')\n", + "ax1.set_ylabel(r'$\\xi_{\\rm{sys}}/\\xi$')\n", + "# plt.savefig('plots/xip_sys_%s.pdf' %ver,bbox_inches='tight')\n", + "plt.show()\n", + "\n", + "# Plot the xi_- sys\n", + "ax2 = plt.subplot(111)\n", + "ax2.tick_params(axis='both', which='both', direction='in', length=6, width=1,\n", + " top=True, bottom=True, left=True, right=True)\n", + "ax2.yaxis.minorticks_on()\n", + "\n", + "ax2.errorbar(theta, xim_sys/xim, yerr=abs(varxim_sys/xim), \n", + " fmt='o', markersize=4, capsize=2, capthick=1.5, ls = 'solid', lw=1.8,\n", + " label=r'$\\xi_{-,\\rm{sys}}$', \n", + " color='teal')\n", + "ax2.fill_between(theta, -varxim/xim,varxim/xim, color='palegreen', alpha=0.5)\n", + "ax2.axhline(0,ls='dashed',lw=1, color='grey')\n", + "ax2.text(0.07, 0.88, r'$\\xi_-$, 1-1', transform=ax2.transAxes,\n", + " bbox=dict(facecolor='white', edgecolor='black', boxstyle='round', pad=0.5))\n", + "ax2.set_xscale('log')\n", + "ax2.set_xlabel(r'$\\theta$ [arcmin]')\n", + "ax2.set_ylabel(r'$\\xi_{\\rm{sys}}/\\xi$')\n", + "# plt.savefig('plots/xim_sys_%s.pdf' %ver,bbox_inches='tight')\n", + "plt.show()\n" + ] + }, + { + "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.21" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/supporting_plots.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/supporting_plots.ipynb new file mode 100644 index 0000000..aee68c6 --- /dev/null +++ b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/supporting_plots.ipynb @@ -0,0 +1,150 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## SUPPORTING PLOTS\n", + "\n", + "This notebook plots all other supporting plots in the paper: the covariance matrix, and the redshift distributions." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib\n", + "from astropy.io import fits\n", + "import matplotlib.pyplot as plt\n", + "import uncertainties\n", + "import yaml\n", + "import os\n", + "import numpy as np\n", + "\n", + "plt.rcParams.update({'font.size': 25,'figure.figsize':[12,7]})\n", + "plt.rcParams.update({\"text.usetex\": True})\n", + "plt.rc('mathtext', fontset='stix')\n", + "plt.rc('font', family='serif')\n", + "\n", + "# Define path to data files (NOTE: YOU MUST HAVE RAN THE INFERENCE PIPELINE!)\n", + "data_dir = \"/n17data/mkilbing/astro/data/\"\n", + "ver = \"SP_v1.4.5_A\"\n", + "nz_file = data_dir + \"CFIS/v1.0/nz/blind_nz_cfis_shapepipe_2022v1.fits\"\n", + "covmat_file = f\"/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/data/{ver}/covs/cov_{ver}.txt\"\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Plot the redshift distribution $n(z)$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "nz_hdu = fits.open(nz_file)\n", + "nz = nz_hdu[1].data\n", + "blind = 'A'\n", + "\n", + "z = nz_hdu[1].data['Z_%s'%blind]\n", + "bins=np.linspace(0,3,50)\n", + "\n", + "ax1 = plt.subplot(111)\n", + "ax1.tick_params(axis='both', which='both', direction='in', length=6, width=1,\n", + " top=True, bottom=True, left=True, right=True)\n", + "\n", + "y,edges = np.histogram(z, bins,density=True,weights=nz['som_w'])\n", + "centers = 0.5*(edges[1:]+ edges[:-1])\n", + "ax1.plot(centers,y,'-',lw = 2.5, alpha=0.7)\n", + "\n", + "ax1.set_xlabel(r'$z$')\n", + "ax1.set_ylabel(r'$n(z)$')\n", + "ax1.set_ylim([0,1.5])\n", + "# plt.savefig('plots/nz.pdf',bbox_inches='tight')\n", + "plt.show()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Plot the covariance matrix" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "cov = np.loadtxt(covmat_file)\n", + "ndata = len(cov[0])\n", + "cmap = 'seismic'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "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", + "fig = plt.figure()\n", + "ax = fig.add_subplot(1, 1, 1) \n", + "extent = (0, ndata, ndata, 0)\n", + "im3 = ax.imshow(pp_norm, cmap=cmap, vmin=-1, vmax=1, extent=extent)\n", + "\n", + "plt.axvline(x=int(ndata/2),color='black',linewidth=1.0)\n", + "plt.axhline(y=int(ndata/2),color='black',linewidth=1.0)\n", + "\n", + "fig.colorbar(im3, orientation='vertical')\n", + "\n", + "ax.text(int(ndata/4), ndata+5, r'$\\xi_+(\\theta)$')\n", + "ax.text(3*int(ndata/4), ndata+5, r'$\\xi_-(\\theta)$')\n", + "ax.text(-9, int(ndata/4), r'$\\xi_+(\\theta)$')\n", + "ax.text(-9, 3*int(ndata/4), r'$\\xi_-(\\theta)$')\n", + "\n", + "# plt.savefig(\"plots/covmat.pdf\", bbox_inches='tight')\n", + "plt.show()" + ] + }, + { + "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.21" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 5f8b88586f85c3f932b8d8bde42fc9883d08bb2c Mon Sep 17 00:00:00 2001 From: LisaGoh Date: Tue, 8 Apr 2025 17:38:25 +0200 Subject: [PATCH 2/2] added e/b plots, cleanup --- .../ psf_leakage.ipynb | 227 +++++++++++++++++- .../S8_sigma8_Om_contour.ipynb | 2 +- .../S8_whisker.ipynb | 4 +- .../corr_func.ipynb | 113 ++++++++- .../supporting_plots.ipynb | 5 + notebooks/cosmo_val/run_cosmo_val.py | 4 +- 6 files changed, 344 insertions(+), 11 deletions(-) diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/ psf_leakage.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/ psf_leakage.ipynb index a53f845..20f4a5a 100644 --- a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/ psf_leakage.ipynb +++ b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/ psf_leakage.ipynb @@ -6,18 +6,241 @@ "source": [ "## PSF Leakage Plots\n", "\n", - "This notebook creates all the plots of the PSF leakage: the $\\rho$ and $\\tau$ statistics (from Guerrini et al. 2024) as well as the covariance matrix of the $\\alpha_{PSF}$ and $\\beta_{PSF}$ parameters." + "This notebook creates all the plots of the PSF leakage: the scale-dependent $\\alpha$ parameter, $\\rho$ and $\\tau$ statistics (from Guerrini et al. 2024) as well as the covariance matrix of the $\\tau_0$ ad $\\tau_2$ data vectors." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib\n", + "from astropy.io import fits\n", + "import matplotlib.pyplot as plt\n", + "import uncertainties\n", + "import yaml\n", + "import os\n", + "import numpy as np\n", + "\n", + "plt.rcParams.update({'font.size': 25,'figure.figsize':[12,7]})\n", + "plt.rcParams.update({\"text.usetex\": True})\n", + "plt.rc('mathtext', fontset='stix')\n", + "plt.rc('font', family='serif')\n", + "\n", + "# Define path to data files (NOTE: YOU MUST HAVE RAN THE cosmo_val.py PIPELINE!)\n", + "cosmoval_data_dir = \"/n23data1/n06data/lgoh/scratch/UNIONS/sp_validation/notebooks/cosmo_val/output\"\n", + "ver = \"SP_v1.4.5\"\n" ] }, { "cell_type": "markdown", "metadata": {}, + "source": [ + "### Plot the $\\alpha(\\theta)$ leakage" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Read in the text file of the 2PCFs\n", + "\n", + "alpha_fname = f\"{cosmoval_data_dir}/leakage_{ver}/alpha_leakage.txt\"\n", + "print(f\"Reading xi_sys's from {alpha_fname}\")\n", + "\n", + "alphas = np.loadtxt(alpha_fname)\n", + "theta = alphas[:,0]\n", + "alpha = alphas[:,1]\n", + "var_alpha = alphas[:,2]\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# Plot the xi_+sys\n", + "ax1 = plt.subplot(111)\n", + "ax1.tick_params(axis='both', which='both', direction='in', length=6, width=1,\n", + " top=True, bottom=True, left=True, right=True)\n", + "ax1.yaxis.minorticks_on()\n", + "\n", + "ax1.errorbar(theta, alpha, yerr=var_alpha, \n", + " fmt='o', markersize=4, capsize=2, capthick=1.5, ls = 'solid', lw=1.8,\n", + " color='darkviolet')\n", + "ax1.axhline(0,ls='dashed',lw=1, color='grey')\n", + "ax1.text(0.85, 0.15, r'$1-1$', transform=ax1.transAxes,\n", + " bbox=dict(facecolor='white', edgecolor='black', boxstyle='round', pad=0.5))\n", + "ax1.set_xscale('log')\n", + "ax1.set_xlabel(r'$\\theta$ [arcmin]')\n", + "ax1.set_ylabel(r'$\\alpha(\\theta)$')\n", + "# plt.savefig('plots/alpha_sys_%s.pdf' %ver,bbox_inches='tight')\n", + "plt.show()\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Plot the $\\tau(\\theta)$ statistics" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tau_stats_fname = f\"{cosmoval_data_dir}/rho_tau_stats/tau_stats_{ver}.fits\"\n", + "print(f\"Reading tau stats from {tau_stats_fname}\")\n", + "tau_stats_hdu = fits.open(tau_stats_fname)\n", + "\n", + "theta = tau_stats_hdu[1].data['theta']\n", + "\n", + "tau_0_p = tau_stats_hdu[1].data['tau_0_p']\n", + "vartau_0_p = tau_stats_hdu[1].data['vartau_0_p']\n", + "\n", + "tau_2_p = tau_stats_hdu[1].data['tau_2_p']\n", + "vartau_2_p = tau_stats_hdu[1].data['vartau_2_p']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Plot the xi_plus\n", + "ax1 = plt.subplot(111)\n", + "ax1.tick_params(axis='both', which='both', direction='in', length=6, width=1,\n", + " top=True, bottom=True, left=True, right=True)\n", + "ax1.yaxis.minorticks_on()\n", + "\n", + "# ax1.errorbar(theta, tau_0_p*1e4, yerr=np.sqrt(vartau_0_p)*1e4, \n", + "# fmt='o', markersize=6, capsize=2, capthick=1.5, ls = 'solid', lw=1.8,\n", + "# color='royalblue')\n", + "ax1.plot(theta, tau_0_p*1e4, marker='o', markersize=4, ls = 'solid', lw=1.8, color=\"royalblue\")\n", + "ax1.fill_between(theta, (tau_0_p-np.sqrt(vartau_0_p))*1e4, (tau_0_p+np.sqrt(vartau_0_p))*1e4, color=\"powderblue\", alpha=0.7)\n", + "ax1.text(0.85 , 0.88, r'$1-1$', transform=ax1.transAxes,\n", + " bbox=dict(facecolor='white', edgecolor='black', boxstyle='round', pad=0.5))\n", + "ax1.axhline(0,ls='dashed',lw=1.5, color='grey')\n", + "# ax1.axvspan(0,10,color='gray', alpha=0.3)\n", + "# ax1.axvspan(150,200,color='gray', alpha=0.3)\n", + "ax1.set_xscale('log')\n", + "ax1.set_xlabel(r'$\\theta$ [arcmin]')\n", + "ax1.set_ylabel(r'$\\tau_{0,+}\\times 10^4$')\n", + "# plt.savefig('plots/tau0_%s.pdf' %ver,bbox_inches='tight')\n", + "plt.show()\n", + "\n", + "# Plot the xi_minus\n", + "ax2 = plt.subplot(111)\n", + "ax2.tick_params(axis='both', which='both', direction='in', length=6, width=1,\n", + " top=True, bottom=True, left=True, right=True)\n", + "ax2.yaxis.minorticks_on()\n", + "\n", + "# ax2.errorbar(theta, tau_2_p*1e4, yerr=np.sqrt(vartau_2_p)*1e4, \n", + "# fmt='o', markersize=6, capsize=2, capthick=1.5, ls = 'solid', lw=1.8,\n", + "# color='orangered')\n", + "ax2.plot(theta, tau_2_p*1e4, marker='o', markersize=4, ls = 'solid', lw=1.8, color=\"orangered\")\n", + "ax2.fill_between(theta, (tau_2_p-np.sqrt(vartau_2_p))*1e4, (tau_2_p+np.sqrt(vartau_2_p))*1e4, color=\"pink\", alpha=0.7)\n", + "ax2.text(0.85, 0.88, r'$1-1$', transform=ax2.transAxes,\n", + " bbox=dict(facecolor='white', edgecolor='black', boxstyle='round', pad=0.5))\n", + "ax2.axhline(0,ls='dashed',lw=1.5, color='grey')\n", + "# ax2.axvspan(0,10,color='gray', alpha=0.3)\n", + "# ax2.axvspan(150,200,color='gray', alpha=0.3)\n", + "ax2.set_xscale('log')\n", + "ax2.set_xlabel(r'$\\theta$ [arcmin]')\n", + "ax2.set_ylabel(r'$\\tau_{2,+}\\times 10^4$')\n", + "# plt.savefig('plots/tau2_%s.pdf' %ver,bbox_inches='tight')\n", + "plt.show()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Plot the $\\tau$ covariance matrix" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "tau_covmat_file = f\"{cosmoval_data_dir}/rho_tau_stats/cov_tau_{ver}_th.npy\"\n", + "print(f\"Reading tau covmat from {tau_covmat_file}\")\n", + "tau_cov = np.load(tau_covmat_file)\n", + "ndata = len(tau_cov[0])\n", + "tau_cov = tau_cov[:int(2*ndata/3),:int(2*ndata/3)]\n", + "cmap = 'coolwarm'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "ndata = len(tau_cov[0])\n", + "pp_norm = np.zeros((ndata,ndata))\n", + "for i in range(ndata):\n", + " for j in range(ndata):\n", + " pp_norm[i][j] = tau_cov[i][j]/ np.sqrt(tau_cov[i][i]*tau_cov[j][j])\n", + "\n", + "fig = plt.figure()\n", + "ax = fig.add_subplot(1, 1, 1) \n", + "extent = (0, ndata, ndata, 0)\n", + "im3 = ax.imshow(pp_norm, cmap=cmap, vmin=-1, vmax=1, extent=extent)\n", + "\n", + "plt.axvline(x=int(ndata/2),color='black',linewidth=1.0)\n", + "plt.axhline(y=int(ndata/2),color='black',linewidth=1.0)\n", + "\n", + "fig.colorbar(im3, orientation='vertical')\n", + "ticks = np.arange(0,ndata+10,10)\n", + "tick_labels = np.array([0,10,0,10,20])\n", + "ax.set_xticks(ticks,labels= tick_labels)\n", + "ax.set_yticks(ticks,labels= tick_labels)\n", + "ax.text(int(ndata/4), ndata+5, r'$\\tau_{0,+}(\\theta)$')\n", + "ax.text(3*int(ndata/4), ndata+5, r'$\\tau_{2,+}(\\theta)$')\n", + "ax.text(-11, int(ndata/4), r'$\\tau_{0,+}(\\theta)$')\n", + "ax.text(-11, 3*int(ndata/4), r'$\\tau_{2,+}(\\theta)$')\n", + "\n", + "# plt.savefig(\"plots/tau_covmat.pdf\", bbox_inches='tight')\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [] } ], "metadata": { + "kernelspec": { + "display_name": "sp-validation", + "language": "python", + "name": "python3" + }, "language_info": { - "name": "python" + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.21" } }, "nbformat": 4, diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_sigma8_Om_contour.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_sigma8_Om_contour.ipynb index f36d0ac..455e37c 100644 --- a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_sigma8_Om_contour.ipynb +++ b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_sigma8_Om_contour.ipynb @@ -220,7 +220,7 @@ "metadata": {}, "outputs": [], "source": [ - "s8_values = np.array([\"Expt\", \"Mean\", \"S8_low\", \"S8_high\"])\n", + "s8_values = np.array([\"# Expt\", \"Mean\", \"S8_low\", \"S8_high\"])\n", "for i, chain in enumerate(chains):\n", "\n", " margestats = chain.getMargeStats()\n", diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_whisker.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_whisker.ipynb index 559ed16..fada9ea 100644 --- a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_whisker.ipynb +++ b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/S8_whisker.ipynb @@ -41,7 +41,7 @@ "# Read in text file with s8 values for the different test cases and external experiments \n", "# (have had to run getdist to analyse the chains first)\n", "\n", - "s8s = np.loadtxt(f\"{chains_dir}/S8_means.txt\",dtype={'names': ('Exp', 's8_mean', 's8_low', 's8_high'), 'formats': ('U40', 'U20', 'U20', 'U20')}, skiprows=1, delimiter=',')\n", + "s8s = np.loadtxt(f\"{chains_dir}/S8_means.txt\",dtype={'names': ('Expt', 's8_mean', 's8_low', 's8_high'), 'formats': ('U40', 'U20', 'U20', 'U20')}, skiprows=1, delimiter=',')\n", "expt = s8s['Exp']\n", "s8s_mean = s8s['s8_mean'].astype(np.float64)\n", "s8s_low = s8s['s8_low'].astype(np.float64)\n", @@ -57,7 +57,6 @@ "\n", "fig, axs = plt.subplots(1, 1, sharey=True, figsize=[7,1.5*len(expt)])\n", "axs.yaxis.set_visible(False)\n", - "# axs.invert_yaxis()\n", "\n", "y = np.arange(0,len(expt))\n", "\n", @@ -75,7 +74,6 @@ " axs.axhline(i+1.5, ls='dashed',c='k')\n", " \n", " \n", - " \n", " axs.set_xlabel(r'$S_8=\\sigma_8\\sqrt{\\Omega_{\\rm m}/0.3}$') \n", " axs.text(0.62, i+1, rf\"{expt[i]}\")\n", "\n", diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/corr_func.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/corr_func.ipynb index ea4933e..8174ace 100644 --- a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/corr_func.ipynb +++ b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/corr_func.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -30,7 +30,6 @@ "\n", "# Define path to data files (NOTE: YOU MUST HAVE RAN THE cosmo_val.py PIPELINE!)\n", "cosmoval_data_dir = \"/n23data1/n06data/lgoh/scratch/UNIONS/sp_validation/notebooks/cosmo_val/output\"\n", - "# inf_data_dir = \"/n23data1/n06data/lgoh/scratch/UNIONS/cosmo_inference/data/\"\n", "ver = \"SP_v1.4.5\"\n" ] }, @@ -78,7 +77,7 @@ "# color='royalblue')\n", "ax1.plot(theta, xip*1e4, marker='o', markersize=4, ls = 'solid', lw=1.8, color=\"royalblue\")\n", "ax1.fill_between(theta, (xip-varxip)*1e4, (xip+varxip)*1e4, color=\"powderblue\", alpha=0.7)\n", - "ax1.text(0.85 , 0.88, '1,1', transform=ax1.transAxes,\n", + "ax1.text(0.85 , 0.88, '1-1', transform=ax1.transAxes,\n", " bbox=dict(facecolor='white', edgecolor='black', boxstyle='round', pad=0.5))\n", "ax1.axvspan(0,10,color='gray', alpha=0.3)\n", "ax1.axvspan(150,200,color='gray', alpha=0.3)\n", @@ -118,6 +117,114 @@ "### Plot the E/B modes $\\xi_{E/B}$" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Read in the text file of the 2PCFs\n", + "\n", + "xieb_fname = f\"{cosmoval_data_dir}/xi_eb_{ver}.txt\"\n", + "print(f\"Reading xi_e/b's from {xieb_fname}\")\n", + "\n", + "xieb = np.loadtxt(xieb_fname)\n", + "theta = xieb[:,0]\n", + "xie_p = xieb[:,1]\n", + "xie_m = xieb[:,2]\n", + "xib_p = xieb[:,3]\n", + "xib_m = xieb[:,4]\n", + "xiamb_p = xieb[:,5]\n", + "xiamb_m = xieb[:,6]\n", + "\n", + "xieb_cov_fname = f\"{cosmoval_data_dir}/xi_eb_{ver}_cov.txt\"\n", + "print(f\"Reading xi_e/b covmat from {xieb_cov_fname}\")\n", + "\n", + "xieb_cov = np.loadtxt(xieb_cov_fname)\n", + "ndata = len(theta)\n", + "varxi_e_p = np.diag(xieb_cov[:ndata,:ndata])\n", + "varxi_e_m = np.diag(xieb_cov[ndata:2*ndata,ndata:2*ndata])\n", + "varxi_b_p = np.diag(xieb_cov[2*ndata:3*ndata,2*ndata:3*ndata])\n", + "varxi_b_m = np.diag(xieb_cov[3*ndata:4*ndata,3*ndata:4*ndata])\n", + "varxi_amb_p = np.diag(xieb_cov[4*ndata:5*ndata,4*ndata:5*ndata])\n", + "varxi_amb_m = np.diag(xieb_cov[5*ndata:6*ndata,5*ndata:6*ndata])\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Plot the xi_plus\n", + "ax1 = plt.subplot(111)\n", + "ax1.tick_params(axis='both', which='both', direction='in', length=6, width=1,\n", + " top=True, bottom=True, left=True, right=True)\n", + "ax1.yaxis.minorticks_on()\n", + "\n", + "ax1.errorbar(theta, xie_p*1e4, yerr=np.sqrt(varxi_e_p)*1e4, \n", + " fmt='o', markersize=6, capsize=3, capthick=1.5, ls = 'solid', lw=1.8,\n", + " label=r'$\\xi_E$', \n", + " color='royalblue')\n", + "ax1.errorbar(theta, xib_p*1e4, yerr=np.sqrt(varxi_b_p)*1e4, \n", + " fmt='o', markersize=6, capsize=3, capthick=1.5, ls = 'dashed', lw=1.8,\n", + " label=r'$\\xi_B$', \n", + " color='chocolate')\n", + "ax1.errorbar(theta, xiamb_p*1e4, yerr=np.sqrt(varxi_amb_p)*1e4, \n", + " fmt='o', markersize=6, capsize=3, capthick=1.5, ls = 'dotted', lw=1.8,\n", + " label=r'$\\xi_{\\rm{amb}}$', \n", + " color='mediumvioletred')\n", + "ax1.text(0.9, 0.15, '1-1', transform=ax1.transAxes,\n", + " bbox=dict(facecolor='white', edgecolor='black', boxstyle='round', pad=0.5))\n", + "ax1.axvspan(0,10,color='grey', alpha=0.3)\n", + "ax1.axvspan(150,200,color='grey', alpha=0.3)\n", + "ax1.axhline(0,color='black',lw=1,ls='dashed')\n", + "ax1.set_xscale('log')\n", + "ax1.set_xlabel(r'$\\theta$ [arcmin]')\n", + "ax1.legend()\n", + "ax1.set_ylabel(r'$\\xi_+\\times 10^4$')\n", + "# plt.savefig('plots/xi_eb_plus_%s.pdf' %ver,bbox_inches='tight')\n", + "plt.show()\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Plot the xi_minus\n", + "ax1 = plt.subplot(111)\n", + "ax1.tick_params(axis='both', which='both', direction='in', length=6, width=1,\n", + " top=True, bottom=True, left=True, right=True)\n", + "ax1.yaxis.minorticks_on()\n", + "\n", + "ax1.errorbar(theta, xie_m*1e4, yerr=np.sqrt(varxi_e_m)*1e4, \n", + " fmt='o', markersize=6, capsize=3, capthick=1.5, ls = 'solid', lw=1.8,\n", + " label=r'$\\xi_E$', \n", + " color='royalblue')\n", + "ax1.errorbar(theta, xib_m*1e4, yerr=np.sqrt(varxi_b_m)*1e4, \n", + " fmt='o', markersize=6, capsize=3, capthick=1.5, ls = 'dashed', lw=1.8,\n", + " label=r'$\\xi_B$', \n", + " color='chocolate')\n", + "ax1.errorbar(theta, xiamb_m*1e4, yerr=np.sqrt(varxi_amb_m)*1e4, \n", + " fmt='o', markersize=6, capsize=3, capthick=1.5, ls = 'dotted', lw=1.8,\n", + " label=r'$\\xi_{\\rm{amb}}$', \n", + " color='mediumvioletred')\n", + "ax1.text(0.9, 0.15, '1-1', transform=ax1.transAxes,\n", + " bbox=dict(facecolor='white', edgecolor='black', boxstyle='round', pad=0.5))\n", + "ax1.axvspan(0,10,color='grey', alpha=0.3)\n", + "ax1.axvspan(150,200,color='grey', alpha=0.3)\n", + "ax1.axhline(0,color='black',lw=1,ls='dashed')\n", + "ax1.set_xscale('log')\n", + "ax1.set_xlabel(r'$\\theta$ [arcmin]')\n", + "ax1.legend()\n", + "ax1.set_ylabel(r'$\\xi_-\\times 10^4$')\n", + "# plt.savefig('plots/xi_eb_minus_%s.pdf' %ver,bbox_inches='tight')\n", + "plt.show()\n" + ] + }, { "cell_type": "markdown", "metadata": {}, diff --git a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/supporting_plots.ipynb b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/supporting_plots.ipynb index aee68c6..1de034f 100644 --- a/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/supporting_plots.ipynb +++ b/cosmo_inference/notebooks/2D_cosmic_shear_paper_plots/supporting_plots.ipynb @@ -108,6 +108,11 @@ "plt.axhline(y=int(ndata/2),color='black',linewidth=1.0)\n", "\n", "fig.colorbar(im3, orientation='vertical')\n", + "ticks = np.arange(0,ndata+10,10)\n", + "tick_labels = np.array([0,10,0,10,20])\n", + "ax.set_xticks(ticks,labels= tick_labels)\n", + "ax.set_yticks(ticks,labels= tick_labels)\n", + "\n", "\n", "ax.text(int(ndata/4), ndata+5, r'$\\xi_+(\\theta)$')\n", "ax.text(3*int(ndata/4), ndata+5, r'$\\xi_-(\\theta)$')\n", diff --git a/notebooks/cosmo_val/run_cosmo_val.py b/notebooks/cosmo_val/run_cosmo_val.py index 2e824b5..8caa13c 100644 --- a/notebooks/cosmo_val/run_cosmo_val.py +++ b/notebooks/cosmo_val/run_cosmo_val.py @@ -8,7 +8,7 @@ # %% cv = CosmologyValidation( - versions=["SP_v1.4.5_glass_mock"], + versions=["SP_v1.4.5"], data_base_dir="/n17data/mkilbing/astro/data/", npatch=100, ) @@ -30,7 +30,7 @@ cv.plot_scale_dependent_leakage() # %% -#cv.plot_objectwise_leakage() +cv.plot_objectwise_leakage() # %% cv.plot_ellipticity()