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

Update to remove explicit sys calls #312

Merged
merged 11 commits into from
Oct 4, 2024
7 changes: 3 additions & 4 deletions notebooks/ACS/acs_reduction/acs_reduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@
"outputs": [],
"source": [
"for file in raw_files:\n",
" command_line_input = 'crds bestrefs --files {:} --sync-references=1 --update-bestrefs'.format(file)\n",
" os.system(command_line_input)"
" !crds bestrefs --files {file} --sync-references=1 --update-bestrefs"
]
},
{
Expand All @@ -357,7 +356,7 @@
"metadata": {},
"outputs": [],
"source": [
"os.system('calacs.e j9l960010_asn.fits')"
"!calacs.e j9l960010_asn.fits"
]
},
{
Expand Down Expand Up @@ -475,7 +474,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@
"# The following lines of code find and download the MDRIZTAB reference file.\n",
"mdz = fits.getval(input_files[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'])"
"!crds sync --hst --files {mdz} --output-dir {os.environ['jref']}"
]
},
{
Expand Down Expand Up @@ -1013,7 +1013,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@
"\n",
"print('Searching for the MDRIZTAB file:', mdz)\n",
"\n",
"get_mdriztab = os.system('crds sync --hst --files '+mdz+' --output-dir '+os.environ['iref'])"
"!crds sync --hst --files {mdz} --output-dir {os.environ['iref']}"
]
},
{
Expand Down Expand Up @@ -965,7 +965,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
14 changes: 5 additions & 9 deletions notebooks/DrizzlePac/mask_satellite/mask_satellite.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@
" os.rename(file, os.path.basename(file))\n",
" for file in flc_download['Local Path']:\n",
" os.rename(file, os.path.basename(file))\n",
" shutil.rmtree('mastDownload')\n",
"else:\n",
" pass"
" shutil.rmtree('mastDownload')"
]
},
{
Expand Down Expand Up @@ -273,9 +271,7 @@
" os.rename(file, os.path.basename(file))\n",
" for file in flc_download['Local Path']:\n",
" os.rename(file, os.path.basename(file))\n",
" shutil.rmtree('mastDownload')\n",
"else:\n",
" pass"
" shutil.rmtree('mastDownload')"
]
},
{
Expand Down Expand Up @@ -533,7 +529,7 @@
"\n",
"mdz = fits.getval(input_images[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'])"
"!crds sync --hst --files {mdz} --output-dir {os.environ['jref']}"
]
},
{
Expand Down Expand Up @@ -998,7 +994,7 @@
"\n",
"mdz = fits.getval(input_images[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['iref'])"
"!crds sync --hst --files {mdz} --output-dir {os.environ['iref']}"
]
},
{
Expand Down Expand Up @@ -1162,7 +1158,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
"source": [
"mdz = fits.getval(flt_files[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['iref'])"
"!crds sync --hst --files {mdz} --output-dir {os.environ['iref']}"
]
},
{
Expand Down Expand Up @@ -735,7 +735,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@
"input_images_f336w = sorted(glob.glob('iepw14g[46]q_flc.fits'))\n",
"mdz = fits.getval(input_images_f336w[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['iref'])"
"!crds sync --hst --files {mdz} --output-dir {os.environ['iref']}"
]
},
{
Expand Down Expand Up @@ -981,7 +981,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
9 changes: 5 additions & 4 deletions notebooks/WFC3/calwf3_recalibration/calwf3_recal_tvb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"from drizzlepac import astrodrizzle\n",
"from stwcs import updatewcs\n",
"\n",
"from wfc3tools import calwf3, pstat"
"from wfc3tools import calwf3, pstat\n",
"from IPython.display import clear_output"
]
},
{
Expand Down Expand Up @@ -222,8 +223,8 @@
"raw_files = glob.glob('*_raw.fits')\n",
"\n",
"for file in raw_files:\n",
" command_line_input = f'crds bestrefs --files {file} --sync-references=1 --update-bestrefs'\n",
" os.system(command_line_input)"
" !crds bestrefs --files {file} --sync-references=1 --update-bestrefs\n",
"clear_output()"
]
},
{
Expand Down Expand Up @@ -768,7 +769,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
16 changes: 11 additions & 5 deletions notebooks/WFC3/filter_transformations/filter_transformations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@
"metadata": {},
"outputs": [],
"source": [
"cmd_input = 'curl -O https://archive.stsci.edu/hlsps/reference-atlases/hlsp_reference-atlases_hst_multi_everything_multi_v11_sed.tar'\n",
"os.system(cmd_input)"
"!curl -O https://archive.stsci.edu/hlsps/reference-atlases/hlsp_reference-atlases_hst_multi_everything_multi_v11_sed.tar"
]
},
{
Expand All @@ -131,10 +130,17 @@
"source": [
"tar_archive = 'hlsp_reference-atlases_hst_multi_everything_multi_v11_sed.tar'\n",
"extract_to = 'hlsp_reference-atlases_hst_multi_everything_multi_v11_sed'\n",
"abs_extract_to = os.path.abspath(extract_to)\n",
"\n",
"with tarfile.open(tar_archive, 'r') as tar:\n",
" tar.extractall(path=extract_to)\n",
" for member in tar.getmembers():\n",
" member_path = os.path.abspath(os.path.join(abs_extract_to, member.name))\n",
" if member_path.startswith(abs_extract_to):\n",
" tar.extract(member, path=extract_to) \n",
" else:\n",
" print(f\"Skipped {member.name} due to potential security risk\")\n",
"\n",
"os.environ['PYSYN_CDBS'] = 'hlsp_reference-atlases_hst_multi_everything_multi_v11_sed/grp/redcat/trds/'"
"os.environ['PYSYN_CDBS'] = os.path.join(abs_extract_to, 'grp/redcat/trds/')"
]
},
{
Expand Down Expand Up @@ -553,7 +559,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
24 changes: 11 additions & 13 deletions notebooks/WFC3/flux_conversion_tool/flux_conversion_tool.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@
"metadata": {},
"outputs": [],
"source": [
"cmd_input = 'curl -O https://archive.stsci.edu/hlsps/reference-atlases/hlsp_reference-atlases_hst_multi_everything_multi_v11_sed.tar'\n",
"os.system(cmd_input)"
"!curl -O https://archive.stsci.edu/hlsps/reference-atlases/hlsp_reference-atlases_hst_multi_everything_multi_v11_sed.tar"
]
},
{
Expand All @@ -137,10 +136,17 @@
"source": [
"tar_archive = 'hlsp_reference-atlases_hst_multi_everything_multi_v11_sed.tar'\n",
"extract_to = 'hlsp_reference-atlases_hst_multi_everything_multi_v11_sed'\n",
"abs_extract_to = os.path.abspath(extract_to)\n",
"\n",
"with tarfile.open(tar_archive, 'r') as tar:\n",
" tar.extractall(path=extract_to)\n",
" for member in tar.getmembers():\n",
" member_path = os.path.abspath(os.path.join(abs_extract_to, member.name))\n",
" if member_path.startswith(abs_extract_to):\n",
" tar.extract(member, path=extract_to) \n",
" else:\n",
" print(f\"Skipped {member.name} due to potential security risk\")\n",
"\n",
"os.environ['PYSYN_CDBS'] = 'hlsp_reference-atlases_hst_multi_everything_multi_v11_sed/grp/redcat/trds/'"
"os.environ['PYSYN_CDBS'] = os.path.join(abs_extract_to, 'grp/redcat/trds/')"
]
},
{
Expand Down Expand Up @@ -803,14 +809,6 @@
"[Top of Page](#title)\n",
"<img style=\"float: right;\" src=\"https://raw.githubusercontent.com/spacetelescope/notebooks/master/assets/stsci_pri_combo_mark_horizonal_white_bkgd.png\" alt=\"Space Telescope Logo\" width=\"200px\"/> "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f708c513",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -829,7 +827,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
16 changes: 11 additions & 5 deletions notebooks/WFC3/photometry_examples/phot_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@
"metadata": {},
"outputs": [],
"source": [
"cmd_input = 'curl -O https://archive.stsci.edu/hlsps/reference-atlases/hlsp_reference-atlases_hst_multi_everything_multi_v11_sed.tar'\n",
"os.system(cmd_input)"
"!curl -O https://archive.stsci.edu/hlsps/reference-atlases/hlsp_reference-atlases_hst_multi_everything_multi_v11_sed.tar"
]
},
{
Expand All @@ -143,10 +142,17 @@
"source": [
"tar_archive = 'hlsp_reference-atlases_hst_multi_everything_multi_v11_sed.tar'\n",
"extract_to = 'hlsp_reference-atlases_hst_multi_everything_multi_v11_sed'\n",
"abs_extract_to = os.path.abspath(extract_to)\n",
"\n",
"with tarfile.open(tar_archive, 'r') as tar:\n",
" tar.extractall(path=extract_to)\n",
" for member in tar.getmembers():\n",
" member_path = os.path.abspath(os.path.join(abs_extract_to, member.name))\n",
" if member_path.startswith(abs_extract_to):\n",
" tar.extract(member, path=extract_to) \n",
" else:\n",
" print(f\"Skipped {member.name} due to potential security risk\")\n",
"\n",
"os.environ['PYSYN_CDBS'] = 'hlsp_reference-atlases_hst_multi_everything_multi_v11_sed/grp/redcat/trds/'"
"os.environ['PYSYN_CDBS'] = os.path.join(abs_extract_to, 'grp/redcat/trds/')"
]
},
{
Expand Down Expand Up @@ -874,7 +880,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.6"
}
},
"nbformat": 4,
Expand Down
Loading