Skip to content

Commit

Permalink
Add WFC3 notebook 'WFC3_UVIS_Pixel_Area_Map_Corrections_for_Subarrays…
Browse files Browse the repository at this point in the history
….ipynb' (spacetelescope#112)

* updated _toc.yml and _config.yml files

* WFC3_UVIS_Pixel_Area_Map_Corrections_for_Subarrays.ipynb: cleared notebook outputs.

* updating requirements.txt, some edits to notebook

* pep8 corrections and adding a section to the notebook to automatically downlaod necessary files from the WFC3 webpage

* PEP8 corrections

---------

Co-authored-by: annierose3 <[email protected]>
  • Loading branch information
dulude and annierose3 authored Dec 5, 2023
1 parent 3874f70 commit 32a780f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 67 deletions.
1 change: 0 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ exclude_patterns: [notebooks/DrizzlePac/align_mosaics/align_mosaics.ipynb,
notebooks/WFC3/ir_scattered_light_manual_corrections/Correcting_for_Scattered_Light_in_IR_Exposures_by_Manually_Subtracting_Bad_Reads.ipynb,
notebooks/WFC3/photometry_examples/phot_examples.ipynb,
notebooks/WFC3/tvb_flattenramp/TVB_flattenramp_notebook.ipynb,
notebooks/WFC3/uvis_pam_corrections/WFC3_UVIS_Pixel_Area_Map_Corrections_for_Subarrays.ipynb,
notebooks/WFC3/uvis_time_dependent_photometry/uvis_timedep_phot.ipynb,
notebooks/WFC3/zeropoints/zeropoints.ipynb]

2 changes: 1 addition & 1 deletion _toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ parts:
- file: notebooks/WFC3/persistence/wfc3_ir_persistence.ipynb
# - file: notebooks/WFC3/photometry_examples/phot_examples.ipynb
# - file: notebooks/WFC3/tvb_flattenramp/TVB_flattenramp_notebook.ipynb
# - file: notebooks/WFC3/uvis_pam_corrections/WFC3_UVIS_Pixel_Area_Map_Corrections_for_Subarrays.ipynb
- file: notebooks/WFC3/uvis_pam_corrections/WFC3_UVIS_Pixel_Area_Map_Corrections_for_Subarrays.ipynb
# - file: notebooks/WFC3/uvis_time_dependent_photometry/uvis_timedep_phot.ipynb
# - file: notebooks/WFC3/zeropoints/zeropoints.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"- *astroquery* for downloading data from MAST\n",
"- *matplotlib.pyplot* for plotting data\n",
"- *ginga* for finding min/max outlier pixels\n",
"- *shutil* for copying files from one directory to another"
"- *urlib* for downloading files from a webpage"
]
},
{
Expand All @@ -100,11 +100,10 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"import shutil\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import urllib.request\n",
"from astropy.io import fits\n",
"from astroquery.mast import Mast\n",
"from astroquery.mast import Observations\n",
"from ginga.util.zscale import zscale"
]
Expand Down Expand Up @@ -305,12 +304,12 @@
"source": [
"data_512 = hdu_512[1].data\n",
"\n",
"#We use zcale to find the min and max for plotting\n",
"# We use zcale to find the min and max for plotting\n",
"vmin_512, vmax_512 = zscale(data_512)\n",
"\n",
"im = plt.imshow(data_512, vmin=vmin_512, vmax=vmax_512, origin='lower')\n",
"clb = plt.colorbar(im)\n",
"_= clb.ax.set_title('Electrons')"
"_ = clb.ax.set_title('Electrons')"
]
},
{
Expand Down Expand Up @@ -369,7 +368,7 @@
"x1 = int(x0 + scihdr_512['NAXIS1'])\n",
"y1 = int(y0 + scihdr_512['NAXIS2'])\n",
"\n",
"print (f'(x0, y0, x1, y1) = ({x0}, {y0}, {x1}, {y1})')"
"print(f'(x0, y0, x1, y1) = ({x0}, {y0}, {x1}, {y1})')"
]
},
{
Expand All @@ -390,16 +389,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The UVIS CCD has two chips: UVIS1 and UVIS2.\n",
"\n",
"First, please go to the [WFC3 PAM website](https://www.stsci.edu/hst/instrumentation/wfc3/data-analysis/pixel-area-maps) and download the UVIS1 and UVIS2 PAMs under the \"Download Pixel Area Maps\" header. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, we will use `shutil.copy` to copy the PAMs from your Downloads directory to the present working directory. "
"The UVIS CCD has two chips: UVIS1 and UVIS2. We will download the UVIS1 and UVIS2 PAMs from the [WFC3 PAM website](https://www.stsci.edu/hst/instrumentation/wfc3/data-analysis/pixel-area-maps)."
]
},
{
Expand All @@ -408,35 +398,27 @@
"metadata": {},
"outputs": [],
"source": [
"#Please add the path to your local directory in place of \"pwd\" below\n",
"#Please add the path to your Downloads folder in place of \"downloads\" below\n",
"downloads = '/Users/yourHomeDirectory/Downloads/'\n",
"pwd = '/Users/yourHomeDirectory/PAM_notebook/'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Copy the content of source to destination\n",
"source_1 = downloads + 'UVIS1wfc3_map.fits'\n",
"source_2 = downloads + 'UVIS2wfc3_map.fits'\n",
"filenames = [\"UVIS1wfc3_map.fits\", \"UVIS2wfc3_map.fits\"]\n",
"\n",
"try:\n",
" for filename in filenames:\n",
" url = (\"https://www.stsci.edu/files/live/sites/www/files/home/hst/instrumentation/\" + \n",
" \"wfc3/data-analysis/pixel-area-maps/_documents/\")\n",
" url += filename\n",
"\n",
"dest_path1 = shutil.copy(source_1, pwd) \n",
"dest_path2 = shutil.copy(source_2, pwd) \n",
" with urllib.request.urlopen(url) as response:\n",
" with open(filename, \"wb\") as out_file:\n",
" out_file.write(response.read())\n",
"\n",
"# Print path of newly created file\n",
"print(\"Destination path for the UVIS1 PAM:\", dest_path1)\n",
"print(\"Destination path for the UVIS2 PAM:\", dest_path2)"
"except Exception as e:\n",
" print(f\"An error occured: {e}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we have our WFC3/UVIS PAM files in our working directory."
"Now, we should have our WFC3/UVIS PAM files in our working directory."
]
},
{
Expand All @@ -463,14 +445,14 @@
"outputs": [],
"source": [
"if scihdr_512['CCDCHIP'] == 1:\n",
" pam = fits.getdata('UVIS1wfc3_map.fits')\n",
" pamcorr_data_512 = data_512 * pam[y0:y1, x0:x1]\n",
" pam = fits.getdata('UVIS1wfc3_map.fits')\n",
" pamcorr_data_512 = data_512 * pam[y0:y1, x0:x1]\n",
"\n",
"elif scihdr_512['CCDCHIP'] == 2:\n",
" pam = fits.getdata('UVIS2wfc3_map.fits')\n",
" pamcorr_data_512 = data_512 * pam[y0:y1, x0:x1]\n",
" pam = fits.getdata('UVIS2wfc3_map.fits')\n",
" pamcorr_data_512 = data_512 * pam[y0:y1, x0:x1]\n",
"else:\n",
" raise Exception('Chip case not handled.')\n"
" raise Exception('Chip case not handled.')"
]
},
{
Expand All @@ -488,14 +470,13 @@
"source": [
"diff_data_512 = (pamcorr_data_512 - data_512)\n",
"\n",
"\n",
"#We use zcale to find the min and max for plotting\n",
"# We use zcale to find the min and max for plotting\n",
"vmin_diff_512, vmax_diff_512 = zscale(diff_data_512)\n",
"\n",
"im = plt.imshow(diff_data_512, vmin=vmin_diff_512, vmax=vmax_diff_512, origin='lower')\n",
"\n",
"clb = plt.colorbar(im)\n",
"_= clb.ax.set_title('Electrons')"
"_ = clb.ax.set_title('Electrons')"
]
},
{
Expand Down Expand Up @@ -536,14 +517,12 @@
" pamcorr_data : array\n",
" PAM-corrected data.\n",
" \"\"\"\n",
"\n",
" data = np.copy(data)\n",
" x0 = int(np.abs(scihdr['LTV1']))\n",
" y0 = int(np.abs(scihdr['LTV2']))\n",
" x1 = int(x0 + scihdr['NAXIS1'])\n",
" y1 = int(y0 + scihdr['NAXIS2'])\n",
" \n",
"\n",
" if scihdr['CCDCHIP'] == 1:\n",
" pam = fits.getdata(pamdir + 'UVIS1wfc3_map.fits')\n",
" pamcorr_data = data * pam[y0:y1, x0:x1]\n",
Expand Down Expand Up @@ -582,12 +561,12 @@
"metadata": {},
"outputs": [],
"source": [
"#We use zcale to find the min and max for plotting\n",
"# We use zcale to find the min and max for plotting\n",
"vmin_1024, vmax_1024 = zscale(data_1024)\n",
"\n",
"im = plt.imshow(data_1024, vmin=vmin_1024, vmax=vmax_1024, origin='lower')\n",
"clb = plt.colorbar(im)\n",
"_= clb.ax.set_title('Electrons')"
"_ = clb.ax.set_title('Electrons')"
]
},
{
Expand All @@ -607,13 +586,13 @@
"source": [
"diff_data_1024 = (pamcorr_data_1024-data_1024)\n",
"\n",
"#We use zcale to find the min and max for plotting\n",
"# We use zcale to find the min and max for plotting\n",
"vmin_diff_1024, vmax_diff_1024 = zscale(diff_data_1024)\n",
"\n",
"im = plt.imshow(diff_data_1024, vmin=vmin_diff_1024, vmax=vmax_diff_1024, origin='lower')\n",
"\n",
"clb = plt.colorbar(im)\n",
"_= clb.ax.set_title('Electrons')"
"_ = clb.ax.set_title('Electrons')"
]
},
{
Expand Down Expand Up @@ -641,12 +620,12 @@
"metadata": {},
"outputs": [],
"source": [
"#We use zcale to find the min and max for plotting\n",
"# We use zcale to find the min and max for plotting\n",
"vmin_2048, vmax_2048 = zscale(data_2048)\n",
"\n",
"im = plt.imshow(data_2048, vmin=vmin_2048, vmax=vmax_2048, origin='lower')\n",
"clb = plt.colorbar(im)\n",
"_= clb.ax.set_title('Electrons')"
"_ = clb.ax.set_title('Electrons')"
]
},
{
Expand All @@ -666,13 +645,13 @@
"source": [
"diff_data_2048 = (pamcorr_data_2048-data_2048)\n",
"\n",
"#We use zcale to find the min and max for plotting\n",
"# We use zcale to find the min and max for plotting\n",
"vmin_diff_2048, vmax_diff_2048 = zscale(diff_data_2048)\n",
"\n",
"im = plt.imshow(diff_data_2048, vmin=vmin_diff_2048, vmax=vmax_diff_2048, origin='lower')\n",
"\n",
"clb = plt.colorbar(im)\n",
"_= clb.ax.set_title('Electrons')"
"_ = clb.ax.set_title('Electrons')"
]
},
{
Expand Down Expand Up @@ -738,13 +717,6 @@
"[Top of Page](#top)\n",
"<img style=\"float: right;\" src=\"https://raw.githubusercontent.com/spacetelescope/notebooks/master/assets/stsci_pri_combo_mark_horizonal_white_bkgd.png\" alt=\"Space Telescope Logo\" width=\"200px\"/> "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -763,9 +735,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
"version": "3.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
2 changes: 1 addition & 1 deletion notebooks/WFC3/uvis_pam_corrections/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
astropy==5.2.1
astroquery==0.4.6
ginga==4.1.1
ginga==4.0.1
matplotlib==3.7.0
numpy==1.23.4

0 comments on commit 32a780f

Please sign in to comment.