Skip to content

Commit

Permalink
Add data filter for tarfile extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
FDauphin committed Sep 12, 2024
1 parent 56debdb commit bf96106
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions notebooks/WFC3/mast_api_psf/download_psf_cutouts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -304,23 +304,12 @@
"metadata": {},
"outputs": [],
"source": [
"def get_safe_members(members):\n",
" for member in members:\n",
" member_name = member.name\n",
" condition = (\n",
" member_name.startswith('..') or \\\n",
" member_name.startswith('/') or \\\n",
" member_name.startswith('\\\\')\n",
" )\n",
" if not condition:\n",
" yield member\n",
" \n",
"with tarfile.open(filename_bundle, 'r:gz') as tar:\n",
" path_mast = tar.getnames()[0]\n",
" print (f'Path to MAST PSF Cutouts: {path_mast}')\n",
" print(f'Path to MAST PSF Cutouts: {path_mast}')\n",
" members = tar.getmembers()\n",
" safe_members = get_safe_members(members)\n",
" tar.extractall(members=safe_members)"
" tar.extractall(filter='data')"
]
},
{
Expand Down

0 comments on commit bf96106

Please sign in to comment.