{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Gemini GMOS Photometry reduction using DRAGONS Python API\n", "***\n", "## Public archival data from program GS2018A-Q-207 - NGC5018\n", "#### adapted from https://gmosimg-drtutorial.readthedocs.io/en/v2.1.1/03_api_reduction.html\n", "#### don't forget to `conda install -n dragons nb_conda_kernels ipykernel` to run this notebook on the DRAGONS env\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Importing Python Libraries** (you'll probably have to install the `wget` and `ipympl` libraries)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "from __future__ import print_function\n", "\n", "import glob\n", "import wget\n", "\n", "from gempy.adlibrary import dataselect\n", "from recipe_system import cal_service\n", "from recipe_system.reduction.coreReduce import Reduce\n", "from gempy.utils import logutils\n", "\n", "from astropy.io import fits\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import matplotlib.colors as colors\n", "import matplotlib.cbook as cbook\n", "from matplotlib.colors import LogNorm\n", "from matplotlib.colors import PowerNorm\n", "\n", "#%matplotlib widget\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Downloading the data**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Science data from GS2018A-Q-207\n", "wget.download(\"http://archive.gemini.edu/file/S20180419S0098.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180419S0099.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180419S0100.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180419S0101.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180419S0102.fits\")\n", "# Twilight flats \n", "wget.download(\"http://archive.gemini.edu/file/S20180419S0207.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180419S0208.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180419S0209.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180419S0210.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180419S0211.fits\")\n", "# Biases \n", "wget.download(\"http://archive.gemini.edu/file/S20180423S0050.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180423S0051.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180423S0052.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180423S0053.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/S20180423S0054.fits\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Create and move data to raw/ directory**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!mkdir raw/\n", "!mv S2018*.fits raw/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Setting up the DRAGONS logger**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "logutils.config(file_name='gmos_data_reduction.log')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Setting up the Calibration Service**\n", "\n", "First, check that you have already a `rsys.cfg` file inside the `~/.geminidr/`. It should contain:\n", "\n", "```[calibs]\n", "standalone = True\n", "database_dir = /path_to_this_folder/```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "caldb = cal_service.CalibrationService()\n", "caldb.config()\n", "caldb.init()\n", "\n", "cal_service.set_calservice()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Create a list of all the FITS files in the directory**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "all_files = glob.glob('raw/S2018*[0-9].fits')\n", "all_files.sort()\n", "#all_files" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**List of Biases, Flats, and Science frames**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "list_biases = dataselect.select_data(all_files,['BIAS'],[])\n", "list_flats = dataselect.select_data(all_files,['FLAT'],[],\n", " dataselect.expr_parser('filter_name==\"g\"'))\n", "list_science = dataselect.select_data(all_files,[],['CAL'],\n", " dataselect.expr_parser('(observation_class==\"science\" and filter_name==\"g\")'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Make master Bias/Flat and add to the calibration database**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "reduce_bias = Reduce()\n", "reduce_bias.files.extend(list_biases)\n", "reduce_bias.runr()\n", "\n", "caldb.add_cal(reduce_bias.output_filenames[0])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "reduce_flats = Reduce()\n", "reduce_flats.files.extend(list_flats)\n", "reduce_flats.runr()\n", "\n", "caldb.add_cal(reduce_flats.output_filenames[0])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Reduce Science Images**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "reduce_science = Reduce()\n", "reduce_science.files.extend(list_science)\n", "reduce_science.runr()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Display the Stacked Image**" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "image_file = \"S20180419S0098_stack.fits\"\n", "hdu_list = fits.open(image_file)\n", "hdu_list.info()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image_data = fits.getdata(image_file, ext=1)\n", "print(image_data.shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "plt.figure(figsize = (15,15))\n", "plt.imshow(image_data,cmap='gray',norm=LogNorm(vmin=3000, vmax=60000))\n", "plt.xlim(900,2500)\n", "plt.ylim(1600,600)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Optional: remove duplicate calibrations and remove raw data (uncomment lines before running)**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#!rm -rf *_bias.fits *_flat.fits\n", "#!rm -rf raw/" ] } ], "metadata": { "kernelspec": { "display_name": "Python [conda env:dragons] *", "language": "python", "name": "conda-env-dragons-py" }, "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.6.12" } }, "nbformat": 4, "nbformat_minor": 4 }