Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For commenting on 02-04-Combine-bias-images-to-make-master.ipynb (part of review-865a5c2) #216

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
261 changes: 261 additions & 0 deletions notebooks/02-04-Combine-bias-images-to-make-master.ipynb
@@ -0,0 +1,261 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Combine bias images to make master\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The final step is to combine the individual calibrated bias images into a single\n",
"combined image. That combined image will have less noise than the individual\n",
"images, minimizing the noise added to the remaining images when the bias is\n",
"subtracted.\n",
"\n",
"Regardless of which path you took through the calibration of the biases (with\n",
"overscan or without) there should be a folder named `reduced` that contains the\n",
"calibrated bias images. If there is not, please run the previous notebook before\n",
"continuing with this one."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"import os\n",
"\n",
"from astropy.nddata import CCDData\n",
"from astropy.stats import mad_std\n",
"\n",
"import ccdproc as ccdp\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"from convenience_functions import show_image"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Use custom style for larger fonts and figures\n",
"plt.style.use('guide.mplstyle')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Recommended settings for image combination\n",
"\n",
"As discussed in the [notebook about combining images](), the recommendation is\n",
"that you combine by averaging the individual images but sigma clip to remove\n",
"extreme values.\n",
"\n",
"[ccdproc]() provides two ways to combine:\n",
"\n",
"+ An object-oriented interface built around the `Combiner` object, described in\n",
"the [ccdproc documentation on image combination]().\n",
"+ A function called `combine`, which we will use here because the function\n",
"allows one to specify the maximum amount of memory that should be used during\n",
"combination. That feature can be essential depending on how many images you need\n",
"to combine, how big they are, and how much memory your computer has.\n",
"\n",
"*NOTE: If using a version of ccdproc lower than 2.0 set the memory limit a\n",
"factor of 2-3 lower than you want the maximum memory consumption to be.*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example 1: cryogenically-cooled camera"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The remainder of this section assumes the calibrated bias images are in the\n",
"folder `example1-reduced` which is created in the previous notebook."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"calibrated_path = Path('example1-reduced')\n",
"reduced_images = ccdp.ImageFileCollection(calibrated_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The code below:\n",
"\n",
"+ selects the calibrated bias images,\n",
"+ combines them using the `combine` function,\n",
"+ adds the keyword `COMBINED` to the header so that later calibration steps can\n",
"easily identify which bias to use, and\n",
"+ writes the file."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"calibrated_biases = reduced_images.files_filtered(imagetyp='bias', include_path=True)\n",
"\n",
"combined_bias = ccdp.combine(calibrated_biases,\n",
" method='average',\n",
" sigma_clip=True, sigma_clip_low_thresh=5, sigma_clip_high_thresh=5,\n",
" sigma_clip_func=np.ma.median, sigma_clip_dev_func=mad_std,\n",
" mem_limit=350e6\n",
" )\n",
"\n",
"combined_bias.meta['combined'] = True\n",
"\n",
"combined_bias.write(calibrated_path / 'combined_bias.fit')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Result for Example 1\n",
"\n",
"A single calibrated image and the combined image are shown below. There is\n",
"significant two-dimensional structure in the bias that cannot easily be removed\n",
"by subtracting only the overscan in the next image reduction steps. It takes\n",
"little time to acquire bias images and doing so will result in higher quality\n",
"science images."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 10))\n",
"\n",
"show_image(CCDData.read(calibrated_biases[0]).data, cmap='gray', ax=ax1, fig=fig, percl=90)\n",
"ax1.set_title('Single calibrated bias')\n",
"show_image(combined_bias.data, cmap='gray', ax=ax2, fig=fig, percl=90)\n",
"ax2.set_title('{} bias images combined'.format(len(calibrated_biases)))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example 2: Thermo-electrically cooled camera\n",
"\n",
"The process for combining the images is exactly the same as in example 1. The\n",
"only difference is the directory that contains the calibrated bias frames."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"calibrated_path = Path('example2-reduced')\n",
"reduced_images = ccdp.ImageFileCollection(calibrated_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The code below:\n",
"\n",
"+ selects the calibrated bias images,\n",
"+ combines them using the `combine` function,\n",
"+ adds the keyword `COMBINED` to the header so that later calibration steps can\n",
"easily identify which bias to use, and\n",
"+ writes the file."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"calibrated_biases = reduced_images.files_filtered(imagetyp='bias', include_path=True)\n",
"\n",
"combined_bias = ccdp.combine(calibrated_biases,\n",
" method='average',\n",
" sigma_clip=True, sigma_clip_low_thresh=5, sigma_clip_high_thresh=5,\n",
" sigma_clip_func=np.ma.median, signma_clip_dev_func=mad_std,\n",
" mem_limit=350e6\n",
" )\n",
"\n",
"combined_bias.meta['combined'] = True\n",
"\n",
"combined_bias.write(calibrated_path / 'combined_bias.fit')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Result for Example 2\n",
"\n",
"The difference between a single calibrated bias image and the combined bias\n",
"image is much clearer in this case."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 10))\n",
"\n",
"show_image(CCDData.read(calibrated_biases[0]).data, cmap='gray', ax=ax1, fig=fig)\n",
"ax1.set_title('Single calibrated bias')\n",
"show_image(combined_bias.data, cmap='gray', ax=ax2, fig=fig)\n",
"ax2.set_title('{} bias images combined'.format(len(calibrated_biases)))"
]
}
],
"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.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}