From 8391bb1ab05bca8774a3753b08545bc267345fcc Mon Sep 17 00:00:00 2001 From: fjaviersanchez Date: Fri, 1 Mar 2024 10:42:12 -0800 Subject: [PATCH] updated and working --- tutorials/dm_butler_lensing_cuts.ipynb | 79 +++++++++++++++++++++----- 1 file changed, 66 insertions(+), 13 deletions(-) diff --git a/tutorials/dm_butler_lensing_cuts.ipynb b/tutorials/dm_butler_lensing_cuts.ipynb index 5fd9a812..e6b5c2fa 100644 --- a/tutorials/dm_butler_lensing_cuts.ipynb +++ b/tutorials/dm_butler_lensing_cuts.ipynb @@ -6,7 +6,7 @@ "source": [ "# Accessing the Coadd data using the Data Butler\n", "
Owner: **Jim Chiang** ([@jchiang87](https://github.com/LSSTDESC/DC2-analysis/issues/new?body=@jchiang87))\n", - "
Last Verified to Run: **2018-10-26** (by @yymao)\n", + "
Last Verified to Run: **2024-03-01** (by @fjaviersanchez)\n", "\n", "This notebook shows how to read in the coadd catalog data for an entire tract using the LSST Data Management (DM) data butler, and construct a Pandas dataframe with the columns needed to apply the weak lensing cuts used in recent analysis of data from Hyper Suprime Cam [Mandelbaum et al (2018)](https://arxiv.org/abs/1705.06745) using cuts given by [Francois in Slack](https://lsstc.slack.com/archives/C77DDKZHR/p1525197444000687).\n", "\n", @@ -24,7 +24,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "import numpy as np\n", @@ -49,7 +51,46 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "REPOS" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "tract = skymap[4851]\n", + "filter = 'i'\n", + "for patch in tract:\n", + " patchId = '%d,%d' % patch.getIndex()\n", + " dataId = dict(filter=filter_, tract=tract.getId(), patch=patchId)\n", + "\n", + " # Patches for which there is no data will raise a `NoResults` exception when requested\n", + " # from the butler. We catch those exceptions, note the missing data, and \n", + " # continue looping over the patches.\n", + " try:\n", + " forced = butler.get('deepCoadd_forced_src', dataId)\n", + " calib = butler.get('deepCoadd_calexp_photoCalib', dataId)\n", + " merged = butler.get('deepCoadd_ref', dataId)\n", + " except dp.NoResults as eobj:\n", + " print(eobj)\n", + " continue" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "def read_tract(butler, tract, filter_='i', num_patches=None):\n", @@ -108,8 +149,10 @@ " data[filter_ + '_modelfit_CModel_instFluxErr'] = forced['modelfit_CModel_instFluxErr']\n", "\n", " # The calib object applies the zero point to get calibrated magnitudes.\n", - " data[filter_ + '_mag_CModel'] = calib.getMagnitude(forced['modelfit_CModel_instFlux'])\n", - " data[filter_ + '_mag_err_CModel'] = calib.getMagnitude(forced['modelfit_CModel_instFluxErr'])\n", + " \n", + " _aux = calib.instFluxToMagnitude(forced, 'modelfit_CModel')\n", + " data[filter_ + '_mag_CModel'] = _aux[:, 0]\n", + " data[filter_ + '_mag_err_CModel'] = _aux[:, 1]\n", " data[filter_ + '_modelfit_CModel_SNR'] \\\n", " = forced['modelfit_CModel_instFlux']/forced['modelfit_CModel_instFluxErr']\n", " data['ext_shapeHSM_HsmShapeRegauss_abs_e'] \\\n", @@ -137,10 +180,12 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "butler = dp.Butler(REPOS['1.2i'])" + "butler = dp.Butler(REPOS['2.2i_dr6'])" ] }, { @@ -153,7 +198,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "skymap = butler.get('deepCoadd_skyMap')\n", @@ -176,7 +223,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "base_mask = ~(np.isnan(data['i_modelfit_CModel_instFlux'])\n", @@ -196,7 +245,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "mask = data['detect_isPrimary']\n", @@ -216,7 +267,7 @@ "mask &= data['ext_shapeHSM_HsmShapeRegauss_abs_e'] < 2\n", "mask &= data['ext_shapeHSM_HsmShapeRegauss_sigma'] <= 0.4\n", "mask &= data['i_mag_CModel'] < 24.5 # !!! Doesnt have exinction correction\n", - "mask &= data['base_Blendedness_abs_instFlux'] < 10**(-0.375)" + "mask &= data['base_Blendedness_abs'] < 10**(-0.375)" ] }, { @@ -229,7 +280,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "fig = plt.figure(figsize=(10, 10))\n", @@ -282,5 +335,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 }