Skip to content

Added notebooks to produce paper plots #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## PSF Leakage Plots\n",
"\n",
"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": {
"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
}
Loading