From 9b9f7f63994171979222095d10a849dac5640f5a Mon Sep 17 00:00:00 2001 From: Gagandeep Anand <30330521+gsanand@users.noreply.github.com> Date: Wed, 3 Jul 2024 13:08:15 -0400 Subject: [PATCH] Add files via upload --- .../align_multiple_visits.ipynb | 50 ++++++++----------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/notebooks/DrizzlePac/align_multiple_visits/align_multiple_visits.ipynb b/notebooks/DrizzlePac/align_multiple_visits/align_multiple_visits.ipynb index 7bcd62402..56f63be55 100644 --- a/notebooks/DrizzlePac/align_multiple_visits/align_multiple_visits.ipynb +++ b/notebooks/DrizzlePac/align_multiple_visits/align_multiple_visits.ipynb @@ -193,11 +193,9 @@ "outputs": [], "source": [ "for flc in glob.glob(\"./mastDownload/HST/*/*flc.fits\"):\n", - " flc_name = os.path.basename(flc)\n", + " flc_name = os.path.split(flc)[-1]\n", " os.rename(flc, flc_name)\n", - "\n", - "if os.path.exists(\"mastDownload\"):\n", - " shutil.rmtree(\"mastDownload\")" + "shutil.rmtree(\"mastDownload/\")" ] }, { @@ -540,18 +538,14 @@ "rootname_A = \"j9irw4b1q\"\n", "rootname_B = \"j9irw5kaq\"\n", "\n", + "# make a subdirectory for storing images\n", + "os.mkdir('images')\n", "\n", - "def rename_file(old_file_name, new_file_name):\n", - " if os.path.exists(old_file_name):\n", - " os.rename(old_file_name, new_file_name)\n", - " else:\n", - " print(f\"File {old_file_name} does not exist and cannot be renamed to {new_file_name}\")\n", - "\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", - "rename_file(f\"residuals_{rootname_A}_flc.png\", f\"residuals_{rootname_A}_flc_rscale.png\")\n", - "rename_file(f\"residuals_{rootname_B}_flc.png\", f\"residuals_{rootname_B}_flc_rscale.png\")\n", - "rename_file(f\"vector_{rootname_A}_flc.png\", f\"vector_{rootname_A}_flc_rscale.png\")\n", - "rename_file(f\"vector_{rootname_B}_flc.png\", f\"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\")" ] }, { @@ -561,8 +555,8 @@ "outputs": [], "source": [ "# read images\n", - "img_A = mpimg.imread(f\"residuals_{rootname_A}_flc_rscale.png\")\n", - "img_B = mpimg.imread(f\"residuals_{rootname_B}_flc_rscale.png\")\n", + "img_A = mpimg.imread(f\"images/residuals_{rootname_A}_flc_rscale.png\")\n", + "img_B = mpimg.imread(f\"images/residuals_{rootname_B}_flc_rscale.png\")\n", "\n", "# display images\n", "fig, axs = plt.subplots(1, 2, figsize=(10, 10), dpi=200)\n", @@ -582,8 +576,8 @@ "outputs": [], "source": [ "# read images\n", - "img_A = mpimg.imread(f\"vector_{rootname_A}_flc_rscale.png\")\n", - "img_B = mpimg.imread(f\"vector_{rootname_B}_flc_rscale.png\")\n", + "img_A = mpimg.imread(f\"images/vector_{rootname_A}_flc_rscale.png\")\n", + "img_B = mpimg.imread(f\"images/vector_{rootname_B}_flc_rscale.png\")\n", "\n", "# display images\n", "fig, axs = plt.subplots(1, 2, figsize=(10, 10), dpi=100)\n", @@ -710,11 +704,11 @@ "outputs": [], "source": [ "# Give the 'fit residual plots' a unique name for comparison with other tests.\n", - "os.rename(f\"residuals_{rootname_A}_flc.png\", f\"residuals_{rootname_A}_flc_general.png\")\n", - "os.rename(f\"residuals_{rootname_B}_flc.png\", f\"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", - "os.rename(f\"vector_{rootname_A}_flc.png\", f\"vector_{rootname_A}_flc_general.png\")\n", - "os.rename(f\"vector_{rootname_B}_flc.png\", f\"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\")" ] }, { @@ -731,8 +725,8 @@ "outputs": [], "source": [ "# read images\n", - "img_A = mpimg.imread(f\"residuals_{rootname_A}_flc_general.png\")\n", - "img_B = mpimg.imread(f\"residuals_{rootname_B}_flc_general.png\")\n", + "img_A = mpimg.imread(f\"images/residuals_{rootname_A}_flc_general.png\")\n", + "img_B = mpimg.imread(f\"images/residuals_{rootname_B}_flc_general.png\")\n", "\n", "# display images\n", "fig, axs = plt.subplots(1, 2, figsize=(20, 10), dpi=200)\n", @@ -751,8 +745,8 @@ "outputs": [], "source": [ "# read images\n", - "img_A = mpimg.imread(f\"vector_{rootname_A}_flc_general.png\")\n", - "img_B = mpimg.imread(f\"vector_{rootname_B}_flc_general.png\")\n", + "img_A = mpimg.imread(f\"images/vector_{rootname_A}_flc_general.png\")\n", + "img_B = mpimg.imread(f\"images/vector_{rootname_B}_flc_general.png\")\n", "\n", "# display images\n", "fig, axs = plt.subplots(1, 2, figsize=(10, 10), dpi=100)\n", @@ -1102,7 +1096,7 @@ "\n", "\n", " Created: 14 Dec 2018; C. Shanahan & J. Mack\n", - " Updated: XX May 2024; G. Anand & J. Mack \n", + " Updated: 03 Jul 2024; G. Anand & J. Mack \n", "\n", "**Source:** GitHub [spacetelescope/hst_notebooks](https://github.com/spacetelescope/hst_notebooks)\n", "\n", @@ -1157,7 +1151,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.11.7" } }, "nbformat": 4,