{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Gemini GMOS Photometry reduction using DRAGONS Python API\n", "#### from https://gmosimg-drtutorial.readthedocs.io/en/v2.1.1/03_api_reduction.html\n", "#### don't forget to run `conda install nb_conda_kernels ipykernel` to run this notebook on the DRAGONS env" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Importing Python Libraries**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "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", "\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Downloading the data**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wget.download(\"http://archive.gemini.edu/file/N20170613S0180.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170613S0181.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170613S0182.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170613S0183.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170613S0184.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170614S0201.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170614S0202.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170614S0203.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170614S0204.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170614S0205.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170615S0534.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170615S0535.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170615S0536.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170615S0537.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170615S0538.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170702S0178.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170702S0179.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170702S0180.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170702S0181.fits\")\n", "wget.download(\"http://archive.gemini.edu/file/N20170702S0182.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 N*.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_my_data/gmosimg_tutorial_api/playground```" ] }, { "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/*.fits')\n", "all_files.sort()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**List of Biases**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "list_of_biases = dataselect.select_data(\n", " all_files,\n", " ['BIAS'],\n", " []\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**List of Flats**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "list_of_flats = dataselect.select_data(\n", " all_files,\n", " ['FLAT'],\n", " [],\n", " dataselect.expr_parser('filter_name==\"i\"')\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**List of Science Data**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "list_of_science = dataselect.select_data(\n", " all_files,\n", " [],\n", " ['CAL'],\n", " dataselect.expr_parser('(observation_class==\"science\" and filter_name==\"i\")')\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Make Master Bias**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "reduce_bias = Reduce()\n", "reduce_bias.files.extend(list_of_biases)\n", "reduce_bias.runr()\n", "\n", "caldb.add_cal(reduce_bias.output_filenames[0])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Make Master Flat**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "reduce_flats = Reduce()\n", "reduce_flats.files.extend(list_of_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_of_science)\n", "reduce_science.runr()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Display the Stacked Image**" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image_file = \"N20170614S0201_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": {}, "outputs": [], "source": [ "plt.figure(figsize = (10,10))\n", "plt.imshow(image_data,cmap='gray',norm=LogNorm(vmin=0.01, vmax=1000000))\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 }