Skip to content

Commit

Permalink
Merge pull request #25 from bhilbert4/imaging-mode-live
Browse files Browse the repository at this point in the history
Update live notebooks for imaging mode pipeline
  • Loading branch information
camipacifici authored May 17, 2021
2 parents 138001c + 3063366 commit bab5c5b
Show file tree
Hide file tree
Showing 6 changed files with 2,088 additions and 900 deletions.
57 changes: 46 additions & 11 deletions imaging_mode/imaging_mode_stage_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,9 @@
"metadata": {},
"outputs": [],
"source": [
"det1_reffile.tree"
"det1_reffile.tree\n",
"# or:\n",
"# det1_reffile.info(max_rows=None)"
]
},
{
Expand Down Expand Up @@ -1152,6 +1154,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Generate the rate file name from the uncal file name\n",
"rate_file = uncal_file.replace('uncal.fits', 'rate.fits')"
]
},
Expand All @@ -1170,6 +1173,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Use getdata to quickly read in the science data from the rate file\n",
"rate_data = fits.getdata(rate_file)"
]
},
Expand All @@ -1179,6 +1183,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Look at the rate image\n",
"show_image(rate_data, 0.5, 10)"
]
},
Expand All @@ -1197,6 +1202,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Generate the linear step file name from the uncal file name\n",
"linear_file = rate_file.replace('rate.fits', 'linearity.fits')"
]
},
Expand All @@ -1206,6 +1212,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Read in the science data from the linear file\n",
"lin_data = fits.getdata(linear_file)"
]
},
Expand Down Expand Up @@ -1357,19 +1364,13 @@
},
"outputs": [],
"source": [
"# Using the run() method\n",
"# Using the run() method. Instantiate and set parameters\n",
"dq_init_step = DQInitStep()\n",
"dq_init_step.output_dir = output_dir\n",
"dq_init_step.save_results = True\n",
"\n",
"# Note that the run() method can be called on EITHER:\n",
"# the datamodel instance output from the group_scale\n",
"# step.\n",
"dq_init = dq_init_step.run(uncal_file)\n",
"\n",
"# OR:\n",
"# the fits file containing the group_scale output\n",
"#dq_init = dq_init_step.run(group_scale_output_file)"
"# Call the run() method on the uncal file\n",
"dq_init = dq_init_step.run(uncal_file)"
]
},
{
Expand All @@ -1386,6 +1387,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Print the list of JWST bad pixel types\n",
"dqflags.pixel"
]
},
Expand All @@ -1409,6 +1411,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Generate the DQ step output file from the uncal file name\n",
"dq_init_output_file = os.path.join(output_dir, '{}dqinitstep.fits'.format(input_file_base))"
]
},
Expand All @@ -1418,6 +1421,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Print some basic information on the number of flagged pixels\n",
"idx_pixelDQ = np.where(dq_init.pixeldq.flatten() == 0.)[0]\n",
"num_flagged = dq_init.pixeldq.size - len(idx_pixelDQ)\n",
"print('Total pixels in PIXELDQ: {}'.format(dq_init.pixeldq.size))\n",
Expand Down Expand Up @@ -1493,6 +1497,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Find indexes of saturated pixels\n",
"saturated = np.where(saturation.groupdq & dqflags.pixel['SATURATED'] > 0)"
]
},
Expand Down Expand Up @@ -1584,9 +1589,12 @@
},
"outputs": [],
"source": [
"# Get the science and DQ values for the pixel.\n",
"groups = np.arange(saturation.data.shape[1])\n",
"full_ramp = saturation.data[0, :, y, x]\n",
"sat_dq = saturation.groupdq[0, :, y, x].astype(bool)\n",
"\n",
"# Make a copy of the science data and set all saturated groups to NaN\n",
"saturated_points = copy.deepcopy(saturation.data[0, :, y, x])\n",
"saturated_points[~sat_dq] = np.nan"
]
Expand All @@ -1597,6 +1605,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Plot the pixel's values up the ramp and denote the saturated groups\n",
"plot_ramps(groups, full_ramp, saturated_points, label1='Not Saturated',\n",
" label2='Saturated', title='Pixel ({}, {})'.format(x, y))"
]
Expand Down Expand Up @@ -1662,6 +1671,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Generate the name of the superbias step's output file from the uncal file name\n",
"superbias_output_file = os.path.join(output_dir, '{}superbiasstep.fits'.format(input_file_base))"
]
},
Expand All @@ -1671,6 +1681,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Print the superbias step's output file name\n",
"superbias_output_file"
]
},
Expand All @@ -1680,6 +1691,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Look at the shape of the data in the datamodel output from the step\n",
"superbias.data[0, 0, :, :].shape"
]
},
Expand All @@ -1689,6 +1701,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Look at the data before and after superbias subtraction\n",
"side_by_side(saturation.data[0, 0, :, :], superbias.data[0, 0, :, :], vmin=10000, vmax=18000,\n",
" title1='Before superbias subtraction', title2='After superbias subtraction')"
]
Expand Down Expand Up @@ -1763,6 +1776,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Use the spec attribute to print available parameters\n",
"print(RefPixStep.spec)"
]
},
Expand Down Expand Up @@ -2229,6 +2243,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Create an array of group numbers to plot against\n",
"group_nums = np.arange(10)"
]
},
Expand Down Expand Up @@ -2348,6 +2363,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Name of the file containing persistence-subtracted data\n",
"persist_output_file = os.path.join(output_dir, '{}persistencestep.fits'.format(input_file_base))"
]
},
Expand All @@ -2366,6 +2382,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Name of the file containing a map of the calculated persistence signal\n",
"persist_signal_file = os.path.join(output_dir, '{}output_pers.fits'.format(input_file_base))"
]
},
Expand All @@ -2375,6 +2392,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Read in the map of persistence signal\n",
"persist_signal = fits.getdata(persist_signal_file)"
]
},
Expand Down Expand Up @@ -2582,11 +2600,18 @@
"metadata": {},
"outputs": [],
"source": [
"# How many total jump flags were added? Note that some pixels\n",
"# will have more than one group flagged with a jump.\n",
"jump_flags = np.where(jump.groupdq & dqflags.pixel['JUMP_DET'] > 0)\n",
"print('{} jump flags detected.'.format(len(jump_flags[0])))\n",
"\n",
"# Create a 4-dimensional map of the jump flags\n",
"jump_map = (jump.groupdq & dqflags.pixel['JUMP_DET'] > 0)\n",
"\n",
"# Collapse down to a 2D map of the number of flagged jumps in each pixel\n",
"jump_map_2d = np.sum(jump_map[0, :, :, :], axis=0)\n",
"\n",
"# Determine how many pixels have jump flags\n",
"jump_map_indexes = np.where(jump_map_2d > 0)\n",
"impacted_pix = np.sum(jump_map_2d > 0)\n",
"total_pix = 2048 * 2048\n",
Expand All @@ -2607,6 +2632,7 @@
"metadata": {},
"outputs": [],
"source": [
"# The jump map is 4-dimensional, just like the science data\n",
"jump_map.shape"
]
},
Expand All @@ -2616,6 +2642,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Create an array of group numbers to plot against\n",
"group_indexes = np.arange(jump_map.shape[1]).astype(int)"
]
},
Expand Down Expand Up @@ -2871,6 +2898,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Generate the name of the optional output file\n",
"optional_file = os.path.join(output_dir, '{}fitopt.fits'.format(input_file_base))"
]
},
Expand All @@ -2880,6 +2908,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Open the file and examine the extensions\n",
"hdulist = fits.open(optional_file)\n",
"hdulist.info()"
]
Expand Down Expand Up @@ -2960,6 +2989,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Reconstruct the linear ramp for the single pixel we showed after the jump step\n",
"lin_data = intercepts[jumpy, jumpx] + (ramp_fit[0].data[jumpy, jumpx] * group_times)"
]
},
Expand All @@ -2969,6 +2999,8 @@
"metadata": {},
"outputs": [],
"source": [
"# Plot again the single pixel from the jump step, along with its\n",
"# reconstructed best-fit linear fit\n",
"plot_jump(jump.data[0, :, jumpy, jumpx], jump_grp, xpixel=jumpx,\n",
" ypixel=jumpy, slope=lin_data)"
]
Expand All @@ -2979,6 +3011,8 @@
"metadata": {},
"outputs": [],
"source": [
"# Plot the same as above, but for the collection of pixels\n",
"# we plotted after the jump step\n",
"plot_jumps(jump_data, jump_grps, jump_locs, slopes=lin_ramps)"
]
},
Expand Down Expand Up @@ -3085,6 +3119,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Print JWST bad pixel flag definitions\n",
"dqflags.pixel"
]
},
Expand Down Expand Up @@ -3342,7 +3377,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
"version": "3.8.6"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit bab5c5b

Please sign in to comment.