{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Day 3 - Get the Weak Lensing Signals" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this session, we will use the things described in the last two sessions and make a weak lensing measurement pipeline for ourselves. We will start with writing out the different steps required to get the pipeline ready. We then code up each of them as individual functions, which will be called in our main code.\n", "\n", "We are here studying the matter distribution around SDSS redmapper galaxy clusters - [arXiv:1303.3562](https://arxiv.org/abs/1303.3562) by the weak lensing technique using shape catalog data from HSC S16A data - [arXiv:1705.06745](https://arxiv.org/abs/1705.06745). We suggest readers to have a look at these references to have a better understanding of data provided to them. The readers can also compare their results with the same study done on these clusters using shape catalog from SDSS - [arXiv:1707.01907](https://arxiv.org/abs/1707.01907).\n", "\n", "**We highly suggest readers to make a separate notebook for this session as it will be useful for later use.** \n", "\n", "\n", "**In the codes below I have left some black spaces indicated using ??. Please fill up the ?? in the code below and make sure you are doing it with right equations and conversions.** " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Required Steps\n", "\n", "- Reading data from the catalog and appying the selection cuts.\n", "\n", "- Computing the tangential shear $e_{\\rm t}$ and inverse critical density $\\Sigma^{-1}_{\\rm crit}$. \n", "\n", "- $\\Delta \\Sigma (R)$ measurements using cKDTree and writing the output to a file.\n", "\n", "- Plotting the weak lensing signal.\n" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "#loading the required packages\n", "%matplotlib inline\n", "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from scipy.spatial import cKDTree\n", "from astropy.cosmology import FlatLambdaCDM\n", "import glob\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Reading data from the catalog and appying the selection cuts.\n", "\n", "We are going to use the selection cuts on lensing sample in the day-1 session. The below code can be use for other cuts too but for now lets stick to defaults as given below." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# selection cut on the lens sample\n", "def lens_select(zmin=0.1, zmax=0.33, lammin=55, lammax=100):\n", " #please check the file path properly \n", " data = pd.read_csv('/home/idies/workspace/Storage/divyar/IAGRG_2022/DataStore/redmapper.dat', delim_whitespace=1)\n", " #sample selection cut\n", " idx = (data['lambda']>lammin) & (data['lambda']<=lammax)\n", " idx = idx & (data['zred']>zmin) & (data['zred']<=zmax)\n", " ra = data['ra'].values[idx]\n", " dec = data['dec'].values[idx]\n", " zred = data['zred'].values[idx]\n", " #as we have no weights to apply we set them to unity\n", " wgt = ra*1.0/ra\n", " print('number of lenses=%d'%len(ra))\n", " return ra, dec, zred, wgt\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Similar we define a function for sources and collect the data from it.\n", "Please note that there are many columns in source file but for now we are only using some of them. \n", "Here we are only using \n", "\n", "- ra_gal, decgal : ra and dec for the sources\n", "- e1gal, e2gal: decribes the shapes of the sources\n", "- wgal, rms_egal: weights and Intrinsic shape dispersion per component\n", "- zphotgal: redshift of the sources\n", "\n", "For now we will neglect the data in other columns. As it is used for correcting the biases for our measurements and we will decribe how to use them at the end of this session. " ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def read_sources(ifil):\n", " # various columns in sources \n", " # ragal, decgal, e1gal, e2gal, wgal, rms_egal, mgal, c1gal, c2gal, R2gal, zphotgal\n", " data = pd.read_csv(ifil, delim_whitespace=1).values\n", " zphotgal = data[:,-1]\n", " # sanity checks on the sources data\n", " idx = (np.sum(np.isnan(data), axis=1)==0) & (zphotgal>0)\n", " datagal = np.zeros((np.sum(idx),7))\n", " datagal[:,:6] = data[idx,:6]\n", " datagal[:,6] = data[idx,-1]\n", " # collects only - ragal, decgal, e1gal, e2gal, wgal, rms_egal, zphotgal\n", " return datagal" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Computing the tangential shear $e_{\\rm t}$ and inverse critical density $\\Sigma^{-1}_{\\rm crit}$ " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we will follow the formalism described in Prof Surhud More's lectures. We will first code up function to compute tangential component of the ellipticity given the positions for the lenses ($\\alpha_l$, $\\delta_l$) and sources($\\alpha_s$, $\\delta_s$) along with the shape measurements ($e_1$,$e_2$) for the sources.\n", "\n", "We will first compute angle $\\theta$ between a given lens-source pair.\n", "$$\\cos \\theta = \\cos \\delta_l \\cos \\delta_s \\cos(\\alpha_l - \\alpha_s) + \\sin\\delta_l \\sin \\delta_s $$\n", "\n", "where $\\delta_{l,s}$ and $\\alpha_{l,s}$ are ra and dec for lens(l) and source(s). The tangential component of ellipticity $e_t$ is given as\n", "\n", "$$e_t = - e_1 \\cos 2\\phi - e_2 \\sin 2\\phi$$\n", "\n", "$$ \\sin \\phi = \\frac{-\\sin \\delta_l \\cos \\delta_s + \\cos \\delta_l \\sin \\delta_s \\cos(\\alpha_s - \\alpha_l)}{|\\sin\\theta|} $$\n", "\n", "$$\\cos \\phi = \\frac{\\cos\\delta_l \\sin(\\alpha_s - \\alpha_l)}{|\\sin\\theta|}$$\n", "\n", "\n", "For more info related to above equations refer to Lecture Notes for [Tangential-shear-computation](https://surhudm.github.io/Weaklensing_IAGRG/Weak_gravitational_lensing.html#Tangential-shear-computation)\n", "\n", "\n", "Coding up these equations requires trigonometric functions from numpy package. Please check them out - [sin]( https://numpy.org/doc/stable/reference/generated/numpy.sin.html), [cos](https://numpy.org/doc/stable/reference/generated/numpy.cos.html#numpy.cos)\n", "\n", "**Please note that these functions by default uses angles in radians and here we are working with catalog data with (ra,dec) in degrees. So, we need to do the needful conversion first** " ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "# lra, ldec - lenses position\n", "# sra, sdec - sources position\n", "# se1 and se2 - source ellipticities\n", "def get_et(lra, ldec, sra, sdec, se1, se2):\n", " # angle_in_radian = angle_in_degrees * np.pi/180\n", " lra = ??\n", " # fill up the blanks\n", " ldec = ??\n", " sra = ??\n", " sdec = ?? \n", " # c_theta = cos_theta, s_theta = sin_theta\n", " # use the equations above and complete the expressions\n", " c_theta = np.cos(??)*np.cos(sdec) * ?? + np.sin(ldec)*np.sin(??)\n", " s_theta = np.sqrt(1-c_theta**2)\n", "\n", " # phi to get the compute the tangential shear\n", " c_phi = ?? *1.0/s_theta\n", " s_phi = (-np.sin(ldec)*np.cos(sdec) + ?? )*1.0/s_theta\n", " # tangential shear\n", " e_t = - se1*(??) - se2*(??)\n", "\n", " return e_t\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "