Skip to content

Commit

Permalink
Refactor the shell command exec
Browse files Browse the repository at this point in the history
  • Loading branch information
haticekaratay committed Sep 18, 2024
1 parent 5f5e5f1 commit db6d351
Showing 1 changed file with 26 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@
"props = [\"10737\"]\n",
"filts = [\"F606W\"]\n",
"\n",
"obsTable = Observations.query_criteria(\n",
" obs_id=obs_ids, proposal_id=props, filters=filts)\n",
"obsTable = Observations.query_criteria(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 Down Expand Up @@ -254,7 +253,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,8 +312,7 @@
"ext_0_kws = [\"DETECTOR\"]\n",
"ext_1_kws = [\"WCSNAME\", \"NMATCHES\", \"RMS_RA\", \"RMS_DEC\"]\n",
"\n",
"det_scale = {\"IR\": 0.1283, \"UVIS\": 0.0396,\n",
" \"WFC\": 0.05} # plate scale (arcsec/pixel)\n",
"det_scale = {\"IR\": 0.1283, \"UVIS\": 0.0396, \"WFC\": 0.05} # plate scale (arcsec/pixel)\n",
"\n",
"# create dictionary to store alignment keywords\n",
"format_dict = {}\n",
Expand Down Expand Up @@ -485,8 +483,7 @@
" updatehdr=False,\n",
" reusename=True,\n",
")\n",
"\n",
"clear_output()"
"#clear_output()"
]
},
{
Expand All @@ -499,8 +496,7 @@
"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(\n",
" \"nan found in line {} in shift file\".format(line_number))"
" raise ValueError(\"nan found in line {} in shift file\".format(line_number))"
]
},
{
Expand Down Expand Up @@ -553,15 +549,11 @@
"\n",
"# make a subdirectory for storing images\n",
"os.makedirs(\"images\", exist_ok=True)\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",
"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",
"\n",
"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\")"
"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\")"
]
},
{
Expand Down Expand Up @@ -723,15 +715,11 @@
"outputs": [],
"source": [
"# Give the 'fit residual plots' a unique name for comparison with other tests.\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",
"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",
"\n",
"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\")"
"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\")"
]
},
{
Expand Down Expand Up @@ -816,14 +804,14 @@
"\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",
" 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",
" \n",
" match_tab = ascii.read(\n",
" rootname + \"_flc_catalog_fit.match\"\n",
" ) # load match file in astropy table\n",
Expand All @@ -835,7 +823,7 @@
" ] # 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",
" \n",
" plt.scatter(\n",
" x_cord1,\n",
" y_cord1 + 2051,\n",
Expand Down Expand Up @@ -875,9 +863,9 @@
" shiftfile=False,\n",
" ylimit=0.2,\n",
" fitgeometry=\"general\",\n",
" updatehdr=True, # update the header with the new solution\n",
" updatehdr=True, # update the header with the new solution\n",
" reusename=True\n",
")\n",
") \n",
"\n",
"clear_output()"
]
Expand Down Expand Up @@ -926,9 +914,9 @@
"source": [
"# 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",
"jref = os.environ['jref']\n",
"print('Searching for the MDRIZTAB file:', mdz)\n",
"get_mdriztab = os.system('crds sync --hst --files ' +\n",
" mdz + ' --output-dir '+os.environ['jref'])"
"get_mdriztab = !crds sync --hst --files {mdz} --output-dir {jref}"
]
},
{
Expand Down Expand Up @@ -1062,9 +1050,9 @@
"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",
"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",
Expand All @@ -1086,8 +1074,8 @@
"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",
Expand Down

0 comments on commit db6d351

Please sign in to comment.