-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
227 additions
and
79 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from astroquery.mast import Observations\n", | ||
"import numpy as np" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 22, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"5\n", | ||
"20\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"proposal_id = 15354\n", | ||
"\n", | ||
"# Query MAST for observations\n", | ||
"obs_table = Observations.query_criteria(\n", | ||
" obs_collection=\"HST\",\n", | ||
" proposal_id=[f\"{proposal_id}\"],\n", | ||
" dataRights=\"PUBLIC\",\n", | ||
")\n", | ||
"\n", | ||
"print(len(obs_table))\n", | ||
"\n", | ||
"# Get preview products\n", | ||
"products = Observations.get_product_list(obs_table)\n", | ||
"products = products[products[\"productType\"] == \"PREVIEW\"]\n", | ||
"\n", | ||
"match = \"total\"\n", | ||
"exclude = \"color\"\n", | ||
"match_mask = [match in row[\"productFilename\"] for row in products]\n", | ||
"exclude_mask = [exclude not in row[\"productFilename\"] for row in products]\n", | ||
"mask = [m and e for m, e in zip(match_mask, exclude_mask)]\n", | ||
"\n", | ||
"seed = 42\n", | ||
"n_max_images = 20\n", | ||
"\n", | ||
"products = products[mask][np.random.RandomState(seed=seed).choice(np.arange(len(products[mask])), n_max_images)]\n", | ||
"\n", | ||
"print(len(products))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 23, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"INFO: 19 of 20 products were duplicates. Only downloading 1 unique product(s). [astroquery.mast.observations]\n", | ||
"Downloading URL https://mast.stsci.edu/api/v0.1/Download/file?uri=mast:HST/product/hst_15354_01_acs_wfc_total_jdi601_drc.jpg to download_dir/mastDownload/HST/hst_15354_01_acs_wfc_total_jdi601/hst_15354_01_acs_wfc_total_jdi601_drc.jpg ... [Done]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import os\n", | ||
"\n", | ||
"download_dir = 'download_dir'\n", | ||
"\n", | ||
"Observations.download_products(\n", | ||
" products,\n", | ||
" extension=[\"jpg\", \"jpeg\"],\n", | ||
" productType=\"PREVIEW\",\n", | ||
" download_dir=download_dir,\n", | ||
")\n", | ||
"\n", | ||
"# Recursively find all images in \"total_images\" directory and bring them up to \"total_images\"\n", | ||
"for root, dirs, files in os.walk(download_dir):\n", | ||
" for file in files:\n", | ||
" if file.endswith((\".jpg\", \".jpeg\")):\n", | ||
" source = os.path.join(root, file)\n", | ||
" destination = os.path.join(download_dir, file)\n", | ||
"\n", | ||
" # Check if file already exists in the destination\n", | ||
" if not os.path.exists(destination):\n", | ||
" os.rename(source, destination)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "base", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.