forked from spacetelescope/acs-notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request spacetelescope#15 from molaes-stsci/master
Update to ACS Notebooks
- Loading branch information
Showing
32 changed files
with
5,480 additions
and
3,802 deletions.
There are no files selected for viewing
326 changes: 326 additions & 0 deletions
326
acs_pixel_area_maps/.ipynb_checkpoints/acs_pixel_area_maps-checkpoint.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,326 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"<div class=\"alert alert-block alert-warning\">\n", | ||
"<b>REQUIREMENT:</b> Before proceeding, install or update your\n", | ||
"<b><a class=\"divlink\" href=\"https://astroconda.readthedocs.io\">AstroConda</a></b> distribution. The code cells below may not work properly with older versions of AstroConda.\n", | ||
"</div>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Obtaining Pixel Area Maps for ACS Data\n", | ||
"\n", | ||
"## Introduction\n", | ||
"\n", | ||
"***\n", | ||
"\n", | ||
"Users who do not use `astrodrizzle` to correct data for distortion will need to apply a pixel area map to their data to correct for the distorted pixel area projected onto the sky before performing photometry. More information about these topics can be found in the [ACS Data Handbook]() and on the [ACS website](http://www.stsci.edu/hst/acs).\n", | ||
"\n", | ||
"The distortion corrections applied by both AstroDrizzle and the PAMs include observation-specific corrections (e.g., velocity distortion). For the best results, users are advised to create a PAM for each observation individually.\n", | ||
"\n", | ||
"In the event a user wishes to perform photometry on data that have not been processed by AstroDrizzle, a correction must be applied to account for the different sizes of the pixels on the sky across the field of view. A pixel area map (PAM), which is an image where each pixel value describes that pixel's area on the sky relative to the native plate scale, is used for this correction. \n", | ||
"\n", | ||
"The optical design of ACS introduces larger geometric distortion than in other *HST* instruments. To transform a distorted FLT/FLC image so that it is suitable for photometry, users must multiply the image by the PAM and divide the result by the exposure time so that the image has units of electrons/second. \n", | ||
"\n", | ||
"After this transformation, the information on the [ACS Zeropoints](http://www.stsci.edu/hst/acs/analysis/zeropoints/) page can be used to convert flux measurements into physical units.\n", | ||
"\n", | ||
"### This tutorial will show you how to...\n", | ||
"\n", | ||
"#### 1. [Construct the Pixel Area Map](#_obtain)\n", | ||
"\n", | ||
"* Use `AstroDrizzle` with ASN files to combine images.\n", | ||
"\n", | ||
"#### 2. [Apply the Pixel Area Map](#_drkdrizzle)\n", | ||
"\n", | ||
"* Identify which dark images to use for your data.\n", | ||
"* Use `AstroDrizzle` to combine dark images." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Imports\n", | ||
"***\n", | ||
"\n", | ||
"Here we list the Python packages used in this notebook. Links to the documentation for each module is provided for convenience.\n", | ||
"\n", | ||
"| Package Name | module | docs | used for |\n", | ||
"|------------------|:-----------------|:-------------:|:------------|\n", | ||
"| `os` | `system` | <a class=\"divlink\" href=\"https://docs.python.org/2/library/os.html#os.system\">link</a>|command line input|\n", | ||
"| `os` | `environ` | <a class=\"divlink\" href=\"https://docs.python.org/2/library/os.html#os.environ\">link</a>| setting environments |\n", | ||
"|`shutil` | `rmtree` | <a class=\"divlink\" href=\"https://docs.python.org/2/library/shutil.html#shutil.rmtree\">link</a>| remove directory tree |\n", | ||
"|`astropy.io` | `fits` | <a class=\"divlink\" href=\"http://docs.astropy.org/en/stable/io/fits/\">link</a>| access and update fits files\n", | ||
"|`astroquery.mast` |`Observations` | <a class=\"divlink\" href=\"https://astroquery.readthedocs.io/en/latest/mast/mast.html\">link</a>| download data from MAST\n", | ||
"|`acs_pypack` |`notebook_tools` | N/A | convenience functions written for the purpose of this notebook\n", | ||
"|`matplotlib` |`pyplot` | <a class=\"divlink\" href=\"https://matplotlib.org/api/pyplot_api.html\">link</a>| plotting functions\n", | ||
"|`matplotlib` |`colors.LogNorm` | <a class=\"divlink\" href=\"https://matplotlib.org/api/_as_gen/matplotlib.colors.LogNorm.html#matplotlib.colors.LogNorm\">link</a>| data normalization used for contrast plotting\n", | ||
"|`stsci.skypac` |`pamutils`| <a class=\"divlink\" href=\"https://stsci-skypac.readthedocs.io/en/latest/pamutils.html\">link</a>| construct pixel area map" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from astroquery.mast import Observations\n", | ||
"\n", | ||
"import os\n", | ||
"import shutil\n", | ||
"from stsci.skypac import pamutils\n", | ||
"\n", | ||
"from astropy.io import fits\n", | ||
"import matplotlib.pyplot as plt" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Download the Data\n", | ||
"***\n", | ||
"\n", | ||
"Here we download all of the data required for this notebook. This is an important step! Some of the image processing steps require all relevant files to be in the working directory. We recommend working with a brand new directory for every new set of data.\n", | ||
"\n", | ||
"#### [GO Proposal 9438](https://stdatu.stsci.edu/proposal_search.php?mission=hst&id=9438): \"The Origin of the Intergalactic Globular Cluster Population in Abell 1185\"\n", | ||
"\n", | ||
"For this example, we will only retreive data associated with the Observation ID **J6ME13QHQ**. Using the python package `astroquery`, we can retreive files from the [MAST](http://archive.stsci.edu) archive." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"obs_table = Observations.query_criteria(proposal_id=9438, obs_id ='J6ME13QHQ')\n", | ||
"\n", | ||
"dl_table = Observations.download_products(obs_table['obsid'], \n", | ||
" mrp_only=False, \n", | ||
" productSubGroupDescription=['FLT'])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"We'll use the packages `os` and `shutil` to put all of these files in our working directory for convenience and do a little housekeeping." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for row in dl_table:\n", | ||
" oldfname = row['Local Path']\n", | ||
" newfname = os.path.basename(oldfname)\n", | ||
" os.rename(oldfname, newfname)\n", | ||
" \n", | ||
"shutil.rmtree('mastDownload')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## File Information\n", | ||
"***\n", | ||
"For more information, refer to Section <a class=\"divlink\" href=\"http://www.stsci.edu/hst/acs/documents/handbooks/currentDHB/acs_Ch23.html\">Section 2.2</a> of the ACS Data Handbook.\n", | ||
"\n", | ||
"#### FLT Files (WFC-Specific)\n", | ||
"\n", | ||
"| Ext | Name | Type | Contains |\n", | ||
"|:----------:|------------------|--------------|:---------------------------------------------------------|\n", | ||
"|<b>0</b> | PRIMARY | (PrimaryHDU) | Meta-data related to the entire file. |\n", | ||
"|<b>1</b> | SCI (Image) | (ImageHDU) | WFC2 raw image data. |\n", | ||
"|<b>2</b> | ERR (Error) | (ImageHDU) | WFC2 error array. |\n", | ||
"|<b>3</b> | DQ (Data Quality)| (ImageHDU) | WFC2 data quality array. |\n", | ||
"|<b>4</b> | SCI (Image) | (ImageHDU) | WFC1 raw image data. |\n", | ||
"|<b>5</b> | ERR (Error) | (ImageHDU) | WFC1 error array. |\n", | ||
"|<b>6</b> | DQ (Data Quality)| (ImageHDU) | WFC1 data quality array. |\n", | ||
"|<b>7-10</b> | D2IMARR | (ImageHDU) | Filter-independent CCD pixel-grid distortion corrections.|\n", | ||
"|<b>11-14</b>| WCSDVARR | (ImageHDU) | Filter-dependent non-polynomial distortion corrections. |\n", | ||
"|<b>15</b> | WCSCORR | (ImageHDU) | History of changes to the WCS solution. |" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"You can always use `.info()` on an HDUlist for an overview of the structure" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"with fits.open(flt_file) as hdulist:\n", | ||
" hdulist.info()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Setting our files to variable names for convenience" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"flt_file = 'j6me13qhq_flt.fits'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Construct Pixel Area Map\n", | ||
"***\n", | ||
"\n", | ||
"Function input for `pamutils.pam_from_file` is (input_file, extension, output_file). To create a PAM for the first science extension (WFC2) of this observation, we need to specify HDU Extension 1." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"pamutils.pam_from_file(flt_file, ext=1, output_pam='j6me13qhq_wfc2_pam.fits')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"For full-frame WFC observations, a second PAM for the WFC1 science array (extension 4) can be created as follows" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"pamutils.pam_from_file(flt_file, ext=4, output_pam='j6me13qhq_wfc1_pam.fits')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Apply the Pixel Area Map\n", | ||
"***\n", | ||
"\n", | ||
"Because the pixel area map is an array of flux corrections based on 2d image distortion, you can multiply it by your data element-by-element to produce the corrected image. Here, we present the results." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from astropy.visualization import (ZScaleInterval, LinearStretch,\n", | ||
" ImageNormalize)\n", | ||
"\n", | ||
"def ds9_imitate(ax,image):\n", | ||
" norm = ImageNormalize(image, \n", | ||
" interval=ZScaleInterval(),\n", | ||
" stretch=LinearStretch())\n", | ||
" \n", | ||
" ax.imshow(image, cmap='bone', norm=norm)\n", | ||
" return\n", | ||
"\n", | ||
"def triple_plot_pam(flt_file, pam_file, figtitle):\n", | ||
" fl_img = fits.getdata(flt_file, ext=1)\n", | ||
" pam_img = fits.getdata(pam_file)\n", | ||
"\n", | ||
" fig = plt.figure(figsize=(20,4))\n", | ||
" fig.suptitle(figtitle,fontsize=20)\n", | ||
" \n", | ||
" ax = fig.add_subplot(1, 3, 1)\n", | ||
" ds9_imitate(ax, fl_img)\n", | ||
" ax.set_title('Raw')\n", | ||
"\n", | ||
" ax2 = fig.add_subplot(1, 3, 2, yticks=[])\n", | ||
" ds9_imitate(ax2, pam_img)\n", | ||
" ax2.set_title('Pixel Area Map')\n", | ||
"\n", | ||
" pamd_img = fl_img*pam_img\n", | ||
"\n", | ||
" ax3 = fig.add_subplot(1, 3, 3, yticks=[])\n", | ||
" ds9_imitate(ax3, pamd_img)\n", | ||
" ax3.set_title('Raw x Pixel Area Map')\n", | ||
"\n", | ||
" plt.subplots_adjust(wspace=0.05)\n", | ||
" return" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"triple_plot_pam(flt_file, 'j6me13qhq_wfc2_pam.fits', 'WFC2 PAM Correction Results')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"triple_plot_pam(flt_file, 'j6me13qhq_wfc1_pam.fits', 'WFC1 PAM Correction Results')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### For more help:\n", | ||
"\n", | ||
"More details may be found on the [ACS website]() and in the [ACS Instrument]() and [Data Handbooks](). Geometric Distortion information can be found in [Section 5.6.4](http://www.stsci.edu/hst/acs/documents/handbooks/current/c05_imaging7.html#357374) of the ACS Instrument Handbook.\n", | ||
"\n", | ||
"Please visit the [HST Help Desk](http://hsthelp.stsci.edu). Through the help desk portal, you can explore the *HST* Knowledge Base and request additional help from experts." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.5.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.