Skip to content

Commit

Permalink
Set reusename to True in tweakreg
Browse files Browse the repository at this point in the history
  • Loading branch information
haticekaratay committed Sep 18, 2024
1 parent 08d99fe commit c6a34ad
Showing 1 changed file with 77 additions and 65 deletions.
142 changes: 77 additions & 65 deletions notebooks/DrizzlePac/align_multiple_visits/align_multiple_visits.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@
"props = [\"10737\"]\n",
"filts = [\"F606W\"]\n",
"\n",
"obsTable = Observations.query_criteria(obs_id=obs_ids, proposal_id=props, filters=filts)\n",
"obsTable = Observations.query_criteria(\n",
" obs_id=obs_ids, proposal_id=props, filters=filts)\n",
"products = Observations.get_product_list(obsTable)\n",
"\n",
"data_prod = [\"FLC\"] # ['FLC','FLT','DRC','DRZ']\n",
Expand All @@ -194,8 +195,7 @@
"source": [
"for flc in glob.glob(\"./mastDownload/HST/*/*flc.fits\"):\n",
" flc_name = os.path.basename(flc)\n",
" if not os.path.exists(flc_name):\n",
" os.rename(flc, flc_name)\n",
" os.rename(flc, flc_name)\n",
"if os.path.exists(\"mastDownload/\"):\n",
" shutil.rmtree(\"mastDownload/\")"
]
Expand Down Expand Up @@ -254,7 +254,7 @@
"]\n",
"ext_1_kws = [\"orientat\"]\n",
"\n",
"#grab keywords from data\n",
"# grab keywords from data\n",
"\n",
"for path in paths:\n",
" path_data = []\n",
Expand Down Expand Up @@ -313,7 +313,8 @@
"ext_0_kws = [\"DETECTOR\"]\n",
"ext_1_kws = [\"WCSNAME\", \"NMATCHES\", \"RMS_RA\", \"RMS_DEC\"]\n",
"\n",
"det_scale = {\"IR\": 0.1283, \"UVIS\": 0.0396, \"WFC\": 0.05} # plate scale (arcsec/pixel)\n",
"det_scale = {\"IR\": 0.1283, \"UVIS\": 0.0396,\n",
" \"WFC\": 0.05} # plate scale (arcsec/pixel)\n",
"\n",
"# create dictionary to store alignment keywords\n",
"format_dict = {}\n",
Expand Down Expand Up @@ -482,6 +483,7 @@
" ylimit=0.2,\n",
" fitgeometry=\"rscale\",\n",
" updatehdr=False,\n",
" reusename=True,\n",
")\n",
"\n",
"clear_output()"
Expand All @@ -497,7 +499,8 @@
"with open(\"shift_rscale.txt\", \"r\") as shift:\n",
" for line_number, line in enumerate(shift, start=1):\n",
" if \"nan\" in line:\n",
" raise ValueError(\"nan found in line {} in shift file\".format(line_number))"
" raise ValueError(\n",
" \"nan found in line {} in shift file\".format(line_number))"
]
},
{
Expand Down Expand Up @@ -550,11 +553,15 @@
"\n",
"# make a subdirectory for storing images\n",
"os.makedirs(\"images\", exist_ok=True)\n",
"shutil.copy(f\"residuals_{rootname_A}_flc.png\", f\"images/residuals_{rootname_A}_flc_rscale.png\")\n",
"shutil.copy(f\"residuals_{rootname_B}_flc.png\", f\"images/residuals_{rootname_B}_flc_rscale.png\")\n",
"shutil.copy(f\"residuals_{rootname_A}_flc.png\",\n",
" f\"images/residuals_{rootname_A}_flc_rscale.png\")\n",
"shutil.copy(f\"residuals_{rootname_B}_flc.png\",\n",
" f\"images/residuals_{rootname_B}_flc_rscale.png\")\n",
"\n",
"shutil.copy(f\"vector_{rootname_A}_flc.png\", f\"images/vector_{rootname_A}_flc_rscale.png\")\n",
"shutil.copy(f\"vector_{rootname_B}_flc.png\", f\"images/vector_{rootname_B}_flc_rscale.png\")"
"shutil.copy(f\"vector_{rootname_A}_flc.png\",\n",
" f\"images/vector_{rootname_A}_flc_rscale.png\")\n",
"shutil.copy(f\"vector_{rootname_B}_flc.png\",\n",
" f\"images/vector_{rootname_B}_flc_rscale.png\")"
]
},
{
Expand Down Expand Up @@ -644,6 +651,7 @@
" ylimit=0.2,\n",
" fitgeometry=\"general\",\n",
" updatehdr=False,\n",
" reusename=True\n",
")\n",
"clear_output()"
]
Expand Down Expand Up @@ -715,11 +723,15 @@
"outputs": [],
"source": [
"# Give the 'fit residual plots' a unique name for comparison with other tests.\n",
"shutil.copy(f\"residuals_{rootname_A}_flc.png\", f\"images/residuals_{rootname_A}_flc_general.png\")\n",
"shutil.copy(f\"residuals_{rootname_B}_flc.png\", f\"images/residuals_{rootname_B}_flc_general.png\")\n",
"shutil.copy(f\"residuals_{rootname_A}_flc.png\",\n",
" f\"images/residuals_{rootname_A}_flc_general.png\")\n",
"shutil.copy(f\"residuals_{rootname_B}_flc.png\",\n",
" f\"images/residuals_{rootname_B}_flc_general.png\")\n",
"\n",
"shutil.copy(f\"vector_{rootname_A}_flc.png\", f\"images/vector_{rootname_A}_flc_general.png\")\n",
"shutil.copy(f\"vector_{rootname_B}_flc.png\", f\"images/vector_{rootname_B}_flc_general.png\")"
"shutil.copy(f\"vector_{rootname_A}_flc.png\",\n",
" f\"images/vector_{rootname_A}_flc_general.png\")\n",
"shutil.copy(f\"vector_{rootname_B}_flc.png\",\n",
" f\"images/vector_{rootname_B}_flc_general.png\")"
]
},
{
Expand Down Expand Up @@ -804,41 +816,39 @@
"\n",
"plt.figure(figsize=(7, 7), dpi=140)\n",
"\n",
"with fits.open(rootname + \"_flc.fits\") as hdulist: \n",
" chip1_data = hdulist[\"SCI\", 2].data \n",
"with fits.open(rootname + \"_flc.fits\") as hdulist:\n",
" chip1_data = hdulist[\"SCI\", 2].data\n",
" chip2_data = hdulist[\"SCI\", 1].data\n",
"chip1_data = fits.open(rootname + \"_flc.fits\")[\"SCI\", 2].data\n",
"chip2_data = fits.open(rootname + \"_flc.fits\")[\"SCI\", 1].data\n",
"fullsci = np.concatenate([chip2_data, chip1_data])\n",
"zscale = ZScaleInterval()\n",
"z1, z2 = zscale.get_limits(fullsci)\n",
"plt.imshow(fullsci, cmap=\"Greys\", origin=\"lower\", vmin=z1, vmax=z2)\n",
"\n",
"match_tab = ascii.read(\n",
" rootname + \"_flc_catalog_fit.match\"\n",
") # load match file in astropy table\n",
"match_tab_chip1 = match_tab[\n",
" match_tab[\"col15\"] == 2\n",
"] # filter table for sources on chip 1 (on ext 4)\n",
"match_tab_chip2 = match_tab[\n",
" match_tab[\"col15\"] == 1\n",
"] # filter table for sources on chip 1 (on ext 4)\n",
"x_cord1, y_cord1 = match_tab_chip1[\"col11\"], match_tab_chip1[\"col12\"]\n",
"x_cord2, y_cord2 = match_tab_chip2[\"col11\"], match_tab_chip2[\"col12\"]\n",
"\n",
"plt.scatter(\n",
" x_cord1,\n",
" y_cord1 + 2051,\n",
" s=50,\n",
" edgecolor=\"r\",\n",
" facecolor=\"None\",\n",
" label=\"Matched Sources\",\n",
")\n",
"plt.scatter(x_cord2, y_cord2, s=50, edgecolor=\"r\", facecolor=\"None\")\n",
"plt.title(\n",
" f\"Matched sources W4 to W3: N = {len(match_tab)}\", fontsize=14\n",
")\n",
"plt.show()"
" fullsci = np.concatenate([chip2_data, chip1_data])\n",
" zscale = ZScaleInterval()\n",
" z1, z2 = zscale.get_limits(fullsci)\n",
" plt.imshow(fullsci, cmap=\"Greys\", origin=\"lower\", vmin=z1, vmax=z2)\n",
"\n",
" match_tab = ascii.read(\n",
" rootname + \"_flc_catalog_fit.match\"\n",
" ) # load match file in astropy table\n",
" match_tab_chip1 = match_tab[\n",
" match_tab[\"col15\"] == 2\n",
" ] # filter table for sources on chip 1 (on ext 4)\n",
" match_tab_chip2 = match_tab[\n",
" match_tab[\"col15\"] == 1\n",
" ] # filter table for sources on chip 1 (on ext 4)\n",
" x_cord1, y_cord1 = match_tab_chip1[\"col11\"], match_tab_chip1[\"col12\"]\n",
" x_cord2, y_cord2 = match_tab_chip2[\"col11\"], match_tab_chip2[\"col12\"]\n",
"\n",
" plt.scatter(\n",
" x_cord1,\n",
" y_cord1 + 2051,\n",
" s=50,\n",
" edgecolor=\"r\",\n",
" facecolor=\"None\",\n",
" label=\"Matched Sources\",\n",
" )\n",
" plt.scatter(x_cord2, y_cord2, s=50, edgecolor=\"r\", facecolor=\"None\")\n",
" plt.title(\n",
" f\"Matched sources W4 to W3: N = {len(match_tab)}\", fontsize=14\n",
" )\n",
" plt.show()"
]
},
{
Expand All @@ -865,8 +875,9 @@
" shiftfile=False,\n",
" ylimit=0.2,\n",
" fitgeometry=\"general\",\n",
" updatehdr=True, # update the header with the new solution\n",
") \n",
" updatehdr=True, # update the header with the new solution\n",
" reusename=True\n",
")\n",
"\n",
"clear_output()"
]
Expand Down Expand Up @@ -916,7 +927,8 @@
"# The following lines of code find and download the MDRIZTAB reference file.\n",
"mdz = fits.getval(input_flcs[0], 'MDRIZTAB', ext=0).split('$')[1]\n",
"print('Searching for the MDRIZTAB file:', mdz)\n",
"get_mdriztab = os.system('crds sync --hst --files ' + mdz + ' --output-dir '+os.environ['jref'])"
"get_mdriztab = os.system('crds sync --hst --files ' +\n",
" mdz + ' --output-dir '+os.environ['jref'])"
]
},
{
Expand Down Expand Up @@ -1050,13 +1062,13 @@
"source": [
"plt.figure(figsize=(8, 8))\n",
"\n",
"with fits.open(\"f606w_combined_drc.fits\") as hdulist: \n",
" drc_dat = hdulist[\"SCI\", 1].data # final drizzled image in SCI,1 extension\n",
" \n",
"z1, z2 = zscale.get_limits(drc_dat)\n",
"plt.imshow(drc_dat, origin=\"lower\", vmin=z1, vmax=z2, cmap=\"Greys\")\n",
"plt.title(\"F606W drizzled science image\", fontsize=20)\n",
"plt.show()"
"with fits.open(\"f606w_combined_drc.fits\") as hdulist:\n",
" drc_dat = hdulist[\"SCI\", 1].data # final drizzled image in SCI,1 extension\n",
"\n",
" z1, z2 = zscale.get_limits(drc_dat)\n",
" plt.imshow(drc_dat, origin=\"lower\", vmin=z1, vmax=z2, cmap=\"Greys\")\n",
" plt.title(\"F606W drizzled science image\", fontsize=20)\n",
" plt.show()"
]
},
{
Expand All @@ -1074,13 +1086,13 @@
"source": [
"plt.figure(figsize=(8, 8))\n",
"\n",
"with fits.open(\"f606w_combined_drc.fits\") as hdulist: \n",
" drc_dat = hdulist[\"WHT\", 1].data # final drizzled image in WHT,1 extension\n",
"with fits.open(\"f606w_combined_drc.fits\") as hdulist:\n",
" drc_dat = hdulist[\"WHT\", 1].data # final drizzled image in WHT,1 extension\n",
"\n",
"z1, z2 = zscale.get_limits(drc_dat)\n",
"plt.imshow(drc_dat, origin=\"lower\", vmin=z1, vmax=z2, cmap=\"Greys\")\n",
"plt.title(\"F606W drizzled weight image\", fontsize=20)\n",
"plt.show()"
" z1, z2 = zscale.get_limits(drc_dat)\n",
" plt.imshow(drc_dat, origin=\"lower\", vmin=z1, vmax=z2, cmap=\"Greys\")\n",
" plt.title(\"F606W drizzled weight image\", fontsize=20)\n",
" plt.show()"
]
},
{
Expand Down Expand Up @@ -1169,7 +1181,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down

0 comments on commit c6a34ad

Please sign in to comment.