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

Add WFC3 notebook 'IR_IMA_Visualization_with_an_Example_of_Time_Variable_Background.ipynb' #106

Merged
merged 12 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ exclude_patterns: [notebooks/DrizzlePac/align_mosaics/align_mosaics.ipynb,
notebooks/WFC3/filter_transformations/filter_transformations.ipynb,
notebooks/WFC3/flux_conversion_tool/flux_conversion_tool.ipynb,
notebooks/WFC3/image_displayer_analyzer/wfc3_image_displayer_analyzer.ipynb,
notebooks/WFC3/ir_ima_visualization/IR_IMA_Visualization_with_an_Example_of_Time_Variable_Background.ipynb,
notebooks/WFC3/ir_scattered_light_calwf3_corrections/Correcting_for_Scattered_Light_in_IR_Exposures_Using_calwf3_to_Mask_Bad_Reads.ipynb,
notebooks/WFC3/ir_scattered_light_manual_corrections/Correcting_for_Scattered_Light_in_IR_Exposures_by_Manually_Subtracting_Bad_Reads.ipynb,
notebooks/WFC3/persistence/wfc3_ir_persistence.ipynb,
Expand Down
2 changes: 1 addition & 1 deletion _toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ parts:
# - file: notebooks/WFC3/filter_transformations/filter_transformations.ipynb
# - file: notebooks/WFC3/flux_conversion_tool/flux_conversion_tool.ipynb
# - file: notebooks/WFC3/image_displayer_analyzer/wfc3_image_displayer_analyzer.ipynb
# - file: notebooks/WFC3/ir_ima_visualization/IR_IMA_Visualization_with_an_Example_of_Time_Variable_Background.ipynb
- file: notebooks/WFC3/ir_ima_visualization/IR_IMA_Visualization_with_an_Example_of_Time_Variable_Background.ipynb
# - file: notebooks/WFC3/ir_scattered_light_calwf3_corrections/Correcting_for_Scattered_Light_in_IR_Exposures_Using_calwf3_to_Mask_Bad_Reads.ipynb
# - file: notebooks/WFC3/ir_scattered_light_manual_corrections/Correcting_for_Scattered_Light_in_IR_Exposures_by_Manually_Subtracting_Bad_Reads.ipynb
# - file: notebooks/WFC3/persistence/wfc3_ir_persistence.ipynb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
"- *matplotlib.pyplot* for plotting data\n",
haticekaratay marked this conversation as resolved.
Show resolved Hide resolved
haticekaratay marked this conversation as resolved.
Show resolved Hide resolved
haticekaratay marked this conversation as resolved.
Show resolved Hide resolved
haticekaratay marked this conversation as resolved.
Show resolved Hide resolved
"- *astropy.io fits* for accessing FITS files\n",
"- *astroquery* for downlaoding data from MAST\n",
"- *ginga* for scaling using zscale\n",
"\n",
"We import the following module:\n",
"- *ima_visualization_and_differencing* to take the difference between reads, plot the ramp, and to visualize the difference in images\n"
Expand All @@ -109,15 +108,10 @@
"outputs": [],
"source": [
"import os\n",
"\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"import matplotlib.patheffects as path_effects\n",
"\n",
"from astropy.io import fits\n",
"from astroquery.mast import Observations\n",
"from ginga.util.zscale import zscale\n",
"\n",
"import ima_visualization_and_differencing as diff\n",
"\n",
"%matplotlib inline"
Expand Down Expand Up @@ -162,9 +156,9 @@
"metadata": {},
"outputs": [],
"source": [
"EX_OBS = Observations.query_criteria(obs_id = 'ICQTBB020')\n",
"EX_OBS = Observations.query_criteria(obs_id='ICQTBB020')\n",
"EXOBS_Prods = Observations.get_product_list(EX_OBS)\n",
"yourProd = Observations.filter_products(EXOBS_Prods, obs_id = ['icqtbbbxq', 'icqtbbc0q'], extension = [\"_ima.fits\",\"_flt.fits\"])"
"yourProd = Observations.filter_products(EXOBS_Prods, obs_id=['icqtbbbxq', 'icqtbbc0q'], extension=[\"_ima.fits\", \"_flt.fits\"])"
]
},
{
Expand All @@ -182,7 +176,7 @@
"metadata": {},
"outputs": [],
"source": [
"Observations.download_products(yourProd, mrp_only = False, cache = False)"
"Observations.download_products(yourProd, mrp_only=False, cache=False)"
]
},
{
Expand Down Expand Up @@ -231,7 +225,7 @@
"flt_nominal = 'mastDownload/HST/icqtbbc0q/icqtbbc0q_flt.fits'\n",
"\n",
"image = fits.open(ima_scattered)\n",
"image.info()\n"
"image.info()"
]
},
{
Expand All @@ -258,10 +252,10 @@
"metadata": {},
"outputs": [],
"source": [
"sci16hdr = image['SCI',16].header\n",
"sci16hdr = image['SCI', 16].header\n",
"SAMPNUM_sci16 = sci16hdr['SAMPNUM']\n",
"SAMPTIME_sci16 = sci16hdr['SAMPTIME']\n",
"print(f'For sample number {SAMPNUM_sci16}, the exposure time is {SAMPTIME_sci16}s.')\n"
"print(f'For sample number {SAMPNUM_sci16}, the exposure time is {SAMPTIME_sci16}s.')"
]
},
{
Expand All @@ -270,7 +264,7 @@
"metadata": {},
"outputs": [],
"source": [
"sci1hdr = image['SCI',1].header\n",
"sci1hdr = image['SCI', 1].header\n",
"SAMPNUM_sci1 = sci1hdr['SAMPNUM']\n",
"SAMPTIME_sci1 = sci1hdr['SAMPTIME']\n",
"print(f'For sample number {SAMPNUM_sci1}, the exposure time is {SAMPTIME_sci1:.3f}s.')\n",
Expand Down Expand Up @@ -298,35 +292,37 @@
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(figsize = (30, 30))\n",
"fig = plt.figure(figsize=(30, 30))\n",
"fig\n",
"rows = 2\n",
"columns = 2\n",
"\n",
"files = [ima_scattered, flt_scattered, ima_nominal, flt_nominal] \n",
"# If only analyzing one image, please remove the second ima,flt pair from the list \n",
"\n",
"for i,file in enumerate(files):\n",
"for i, file in enumerate(files):\n",
" path, filename = os.path.split(file)\n",
" \n",
"\n",
" image = fits.open(file)\n",
"\n",
" ax = fig.add_subplot(rows, columns, i+1)\n",
" ax.set_title(filename, fontsize = 20)\n",
" \n",
" ax.set_title(filename, fontsize=20)\n",
"\n",
" subplot_titles = ['scattered', 'nominal']\n",
" #Please change the vmin and vmax values to fit your own data\n",
" # Please change the vmin and vmax values to fit your own data\n",
" if i == 0 or i == 1:\n",
" ax.set_title(f'{filename}, {subplot_titles[i//2]}', fontsize = 20)\n",
" im = ax.imshow(image[\"SCI\", 1].data, origin = 'lower',cmap = 'Greys_r', vmin = 0.25, vmax = 1.7)\n",
" ax.set_title(f'{filename}, {subplot_titles[i//2]}', fontsize=20)\n",
" im = ax.imshow(image[\"SCI\", 1].data, origin='lower', \n",
" cmap='Greys_r', vmin=0.25, vmax=1.7)\n",
" else:\n",
" ax.set_title(f'{filename}, {subplot_titles[i//2]}', fontsize = 20)\n",
" im = ax.imshow(image[\"SCI\", 1].data, origin = 'lower',cmap = 'Greys_r', vmin = 0.5, vmax = 1.2)\n",
" plt.colorbar(im, ax = ax)\n",
" ax.set_title(f'{filename}, {subplot_titles[i//2]}', fontsize=20)\n",
" im = ax.imshow(image[\"SCI\", 1].data, origin='lower', \n",
" cmap='Greys_r', vmin=0.5, vmax=1.2)\n",
" plt.colorbar(im, ax=ax)\n",
"\n",
"plt.subplots_adjust(bottom = 0.2, right = 0.5, top = 0.5)\n",
"plt.rc('xtick', labelsize = 10) \n",
"plt.rc('ytick', labelsize = 10) "
"plt.subplots_adjust(bottom=0.2, right=0.5, top=0.5)\n",
"plt.rc('xtick', labelsize=10) \n",
"plt.rc('ytick', labelsize=10) "
]
},
{
Expand Down Expand Up @@ -354,10 +350,10 @@
"outputs": [],
"source": [
"try:\n",
" diff.plot_ima_subplots(ima_filename = ima_scattered, vmin = 0, vmax = 2.2)\n",
" \n",
" diff.plot_ima_subplots(ima_filename=ima_scattered, vmin=0, vmax=2.2)\n",
"\n",
"except FileNotFoundError:\n",
" print(\"No file by this name found\")\n"
" print(\"No file by this name found\")"
]
},
{
Expand All @@ -376,7 +372,7 @@
"outputs": [],
"source": [
"try:\n",
" diff.plot_ima_subplots(ima_filename = ima_nominal, vmin = 0, vmax = 2)\n",
" diff.plot_ima_subplots(ima_filename=ima_nominal, vmin=0, vmax=2)\n",
"\n",
"except FileNotFoundError:\n",
" print(\"No file by this name found\")"
Expand All @@ -395,31 +391,31 @@
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(figsize = (10, 8))\n",
"fig = plt.figure(figsize=(10, 8))\n",
"\n",
"ima_files=[ima_scattered, ima_nominal] \n",
"#If only using one image, please remove the extraneous image from this list \n",
"ima_files = [ima_scattered, ima_nominal] \n",
"# If only using one image, please remove the extraneous image from this list \n",
"\n",
"marker_select = ['o','s']\n",
"color_select = ['black','C0']\n",
"marker_select = ['o', 's']\n",
"color_select = ['black', 'C0']\n",
"for i, ima in enumerate(ima_files):\n",
" path, filename = os.path.split(ima)\n",
" \n",
"\n",
" cube, integ_time = diff.read_wfc3(ima)\n",
" median_fullframe = np.nanmedian(cube, axis = (0,1))\n",
" median_fullframe = np.nanmedian(cube, axis=(0, 1))\n",
"\n",
" plt.rcParams.update({'font.size':15})\n",
" plt.rcParams.update({'font.size': 15})\n",
" plt.plot(integ_time[1:], median_fullframe[1:]*integ_time[1:],\n",
" marker = marker_select[i], markersize = 8, color = color_select[i], label = filename)\n",
" marker=marker_select[i], markersize=8, \n",
" color=color_select[i], label=filename)\n",
" plt.legend()\n",
"plt.grid()\n",
"plt.xlabel('Integ. Time (s)', fontsize = 15)\n",
"plt.ylabel('electrons', fontsize = 15)\n",
"plt.rc('xtick', labelsize = 15) \n",
"plt.rc('ytick', labelsize = 15) \n",
"plt.grid(visible = True)\n",
"_=plt.title(\"Comparison of Signal Accumulation Ramp in Nominal vs. Scattered Light Images\", fontsize=15)\n",
" "
"plt.xlabel('Integ. Time (s)', fontsize=15)\n",
"plt.ylabel('electrons', fontsize=15)\n",
"plt.rc('xtick', labelsize=15) \n",
"plt.rc('ytick', labelsize=15) \n",
"plt.grid(visible=True)\n",
"_ = plt.title(\"Comparison of Signal Accumulation Ramp in Nominal vs. Scattered Light Images\", fontsize=15)"
]
},
{
Expand All @@ -441,43 +437,49 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"fig = plt.figure(figsize = (50, 20))\n",
"fig = plt.figure(figsize=(50, 20))\n",
"fig\n",
"rows = 1\n",
"columns = 2\n",
"ima_files = [ima_scattered, ima_nominal] \n",
"#If only using one image, please remove the extraneous image from this list \n",
"# If only using one image, please remove the extraneous image from this list \n",
"\n",
"subplot_titles = ['scattered', 'nominal']\n",
"\n",
"lhs_region = {\"x0\": 50, \"x1\": 250, \"y0\": 100, \"y1\": 900}\n",
"rhs_region = {\"x0\": 700, \"x1\": 900, \"y0\": 100, \"y1\": 900}\n",
"for i, ima in enumerate(ima_files):\n",
"\n",
"lhs_region={\"x0\":50,\"x1\":250,\"y0\":100,\"y1\":900}\n",
"rhs_region={\"x0\":700,\"x1\":900,\"y0\":100,\"y1\":900}\n",
"for i,ima in enumerate(ima_files):\n",
" \n",
" path, filename = os.path.split(ima)\n",
" \n",
"\n",
" cube, integ_time = diff.read_wfc3(ima)\n",
"\n",
" median_fullframe, median_lhs, median_rhs = diff.get_median_fullframe_lhs_rhs(cube, \n",
" lhs_region=lhs_region, \n",
" rhs_region=rhs_region)\n",
" \n",
" median_fullframe, median_lhs, median_rhs = diff.get_median_fullframe_lhs_rhs(cube, lhs_region = lhs_region, rhs_region = rhs_region)\n",
" plt.rcParams.update({'font.size':40})\n",
" plt.rcParams.update({'font.size': 40})\n",
" ax = fig.add_subplot(rows, columns, i+1)\n",
" ax.plot(integ_time[1:], median_fullframe[1:]*integ_time[1:], 's', markersize = 25, label = 'Full Frame', color = 'black')\n",
" ax.plot(integ_time[1:], median_lhs[1:]*integ_time[1:], '<', markersize = 20, label = 'LHS', color = 'C1')\n",
" ax.plot(integ_time[1:], median_rhs[1:]*integ_time[1:], '>', markersize = 20, label = 'RHS', color= 'C2')\n",
" ax.set_ylim(0,1800)\n",
" ax.plot(integ_time[1:], median_fullframe[1:]*integ_time[1:], 's', \n",
" markersize=25, label='Full Frame', color='black')\n",
" \n",
" ax.plot(integ_time[1:], median_lhs[1:]*integ_time[1:], '<', \n",
" markersize=20, label='LHS', color='C1')\n",
" \n",
" ax.plot(integ_time[1:], median_rhs[1:]*integ_time[1:], '>', \n",
" markersize=20, label='RHS', color='C2')\n",
" \n",
" ax.set_ylim(0, 1800)\n",
" ax.grid()\n",
" ax.set_xlabel('Integ. Time (s)')\n",
" ax.set_ylabel('electrons')\n",
" ax.legend(loc = 0)\n",
" _=ax.set_title(f'{filename}, {subplot_titles[i]}', fontsize = 40)\n",
" ax.tick_params(axis = \"x\", labelsize = 30) \n",
" ax.tick_params(axis = \"y\", labelsize = 30) "
" ax.legend(loc=0)\n",
" _ = ax.set_title(f'{filename}, {subplot_titles[i]}', fontsize=40)\n",
" ax.tick_params(axis=\"x\", labelsize=30) \n",
" ax.tick_params(axis=\"y\", labelsize=30) "
]
},
{
Expand Down Expand Up @@ -514,10 +516,15 @@
"metadata": {},
"outputs": [],
"source": [
"##If only using one image, please remove the extraneous image from this list \n",
"lhs_region = {\"x0\":50,\"x1\":250,\"y0\":100,\"y1\":900}\n",
"rhs_region = {\"x0\":700,\"x1\":900,\"y0\":100,\"y1\":900}\n",
"diff.plot_ramp_subplots(ima_files = [ima_scattered, ima_nominal], difference_method = 'cumulative', exclude_sources = False, ylims = [-0.3,0.3], lhs_region = lhs_region, rhs_region = rhs_region)"
"# If only using one image, please remove the extraneous image from this list \n",
"lhs_region = {\"x0\": 50, \"x1\": 250, \"y0\": 100, \"y1\": 900}\n",
"rhs_region = {\"x0\": 700, \"x1\": 900, \"y0\": 100, \"y1\": 900}\n",
"diff.plot_ramp_subplots(ima_files=[ima_scattered, ima_nominal], \n",
" difference_method='cumulative', \n",
" exclude_sources=False, \n",
" ylims=[-0.3, 0.3], \n",
" lhs_region=lhs_region, \n",
" rhs_region=rhs_region)"
]
},
{
Expand All @@ -540,9 +547,12 @@
"outputs": [],
"source": [
"try:\n",
" lhs_region = {\"x0\":50,\"x1\":250,\"y0\":100,\"y1\":900}\n",
" rhs_region = {\"x0\":700,\"x1\":900,\"y0\":100,\"y1\":900}\n",
" diff.plot_ima_difference_subplots(ima_filename = ima_scattered, difference_method = 'cumulative', lhs_region = lhs_region, rhs_region = rhs_region)\n",
" lhs_region = {\"x0\": 50, \"x1\": 250, \"y0\": 100, \"y1\": 900}\n",
" rhs_region = {\"x0\": 700, \"x1\": 900, \"y0\": 100, \"y1\": 900}\n",
" diff.plot_ima_difference_subplots(ima_filename=ima_scattered, \n",
" difference_method='cumulative', \n",
" lhs_region=lhs_region, \n",
" rhs_region=rhs_region)\n",
" \n",
"except FileNotFoundError:\n",
" print(\"No file by this name found\")"
Expand Down Expand Up @@ -570,9 +580,12 @@
"outputs": [],
"source": [
"try:\n",
" lhs_region = {\"x0\":50,\"x1\":250,\"y0\":100,\"y1\":900}\n",
" rhs_region = {\"x0\":700,\"x1\":900,\"y0\":100,\"y1\":900}\n",
" diff.plot_ima_difference_subplots(ima_filename = ima_nominal, difference_method = 'cumulative', lhs_region = lhs_region, rhs_region = rhs_region)\n",
" lhs_region = {\"x0\": 50, \"x1\": 250, \"y0\": 100, \"y1\": 900}\n",
" rhs_region = {\"x0\": 700, \"x1\": 900, \"y0\": 100, \"y1\": 900}\n",
" diff.plot_ima_difference_subplots(ima_filename=ima_nominal, \n",
" difference_method='cumulative', \n",
" lhs_region=lhs_region, \n",
" rhs_region=rhs_region)\n",
"\n",
"except FileNotFoundError:\n",
" print(\"No file by this name found\")"
Expand Down Expand Up @@ -609,10 +622,15 @@
"metadata": {},
"outputs": [],
"source": [
"#If only using one image, please remove the extraneous image from this list \n",
"lhs_region = {\"x0\":50,\"x1\":250,\"y0\":100,\"y1\":900}\n",
"rhs_region = {\"x0\":700,\"x1\":900,\"y0\":100,\"y1\":900}\n",
"diff.plot_ramp_subplots(ima_files = [ima_scattered, ima_nominal], difference_method = 'instantaneous', exclude_sources = True, ylims = [0.5,2.5], lhs_region = lhs_region, rhs_region = rhs_region)"
"# If only using one image, please remove the extraneous image from this list \n",
"lhs_region = {\"x0\": 50, \"x1\": 250, \"y0\": 100, \"y1\": 900}\n",
"rhs_region = {\"x0\": 700, \"x1\": 900, \"y0\": 100, \"y1\": 900}\n",
"diff.plot_ramp_subplots(ima_files=[ima_scattered, ima_nominal], \n",
" difference_method='instantaneous', \n",
" exclude_sources=True, \n",
" ylims=[0.5, 2.5], \n",
" lhs_region=lhs_region, \n",
" rhs_region=rhs_region)"
]
},
{
Expand All @@ -636,9 +654,12 @@
"outputs": [],
"source": [
"try:\n",
" lhs_region = {\"x0\":50,\"x1\":250,\"y0\":100,\"y1\":900}\n",
" rhs_region = {\"x0\":700,\"x1\":900,\"y0\":100,\"y1\":900}\n",
" diff.plot_ima_difference_subplots(ima_filename = ima_scattered, difference_method = 'instantaneous', lhs_region = lhs_region, rhs_region = rhs_region)\n",
" lhs_region = {\"x0\": 50, \"x1\": 250, \"y0\": 100, \"y1\": 900}\n",
" rhs_region = {\"x0\": 700, \"x1\": 900, \"y0\": 100, \"y1\": 900}\n",
" diff.plot_ima_difference_subplots(ima_filename=ima_scattered, \n",
" difference_method='instantaneous', \n",
" lhs_region=lhs_region, \n",
" rhs_region=rhs_region)\n",
"\n",
"except FileNotFoundError:\n",
" print(\"No file by this name found\")"
Expand All @@ -664,7 +685,10 @@
"outputs": [],
"source": [
"try:\n",
" diff.plot_ima_difference_subplots(ima_filename = ima_nominal, difference_method = 'instantaneous', lhs_region = lhs_region, rhs_region = rhs_region)\n",
" diff.plot_ima_difference_subplots(ima_filename=ima_nominal, \n",
" difference_method='instantaneous', \n",
" lhs_region=lhs_region, \n",
" rhs_region=rhs_region)\n",
" \n",
"except FileNotFoundError:\n",
" print(\"No file by this name found\")"
Expand Down Expand Up @@ -770,9 +794,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
}
Loading
Loading