{ "cells": [ { "cell_type": "markdown", "id": "b0493e3e", "metadata": {}, "source": [ "# Large Downloads in `astroquery.mast`\n", "***\n", "For some programs stored in the MAST Archive, you may encounter issues when downloading data via the MAST Portal due to a large number of files. This applies particularly to JWST programs using Wide-Field Slitless Spectroscopy. It is preferable — and often, necessary — to use an API to get this data instead. In this tutorial, we'll use seemingly innocuous observations that expand into a considerable number of related files.\n", "\n", "To that end, this notebook will demonstrate:\n", "* Searching the MAST Portal for observations using the [astroquery.mast](https://astroquery.readthedocs.io/en/latest/mast/mast.html) API\n", "* Retreiving associated data products, without causing a timeout error\n", "* Downloading the desired subset of data products\n", "\n", "## Table of Contents\n", "* [Imports](#Imports)\n", "* [Search the MAST Archive](#Search-the-MAST-Archive)\n", "* [Retrieve Associated Products](#Retreive-Associated-Products)\n", "* [Filter and Download Products](#Filter-and-Download-Products)\n", "* [Further Reading](#Further-Reading)\n", "\n", "## Imports\n", "In order to run this notebook, we need: \n", "* `astroquery.mast` to access the MAST Archive\n", "* `astropy.table` to hold the results of our queries, combine them, and then filter them for unique products" ] }, { "cell_type": "code", "execution_count": 1, "id": "944d0474", "metadata": { "execution": { "iopub.execute_input": "2024-02-20T21:00:22.866993Z", "iopub.status.busy": "2024-02-20T21:00:22.866827Z", "iopub.status.idle": "2024-02-20T21:00:23.262578Z", "shell.execute_reply": "2024-02-20T21:00:23.261964Z" } }, "outputs": [], "source": [ "from astroquery.mast import Observations\n", "from astropy.table import unique, vstack, Table" ] }, { "cell_type": "markdown", "id": "0c21754e", "metadata": {}, "source": [ "## Search the MAST Archive\n", "The first step to downloading the data is finding the observations we're interested in. This is easiest to do using `query_criteria`, which allows us to specify criteria such as RA/Dec, filters, exposure time, and any other fields listed [here](https://mast.stsci.edu/api/v0/_c_a_o_mfields.html). \n", "\n", "In this example, we use `query_criteria` to find NIRCam observations from [JWST Program 1073](https://www.stsci.edu/cgi-bin/get-proposal-info?id=1073&observatory=JWST). When querying for JWST data, using `obs_collection = 'JWST'` greatly inreases the speed of the search by decreasing the number of potential matches. This applies to all mission available in MAST, including HST." ] }, { "cell_type": "code", "execution_count": 2, "id": "3507f9d9", "metadata": { "execution": { "iopub.execute_input": "2024-02-20T21:00:23.265057Z", "iopub.status.busy": "2024-02-20T21:00:23.264869Z", "iopub.status.idle": "2024-02-20T21:00:23.648290Z", "shell.execute_reply": "2024-02-20T21:00:23.647707Z" } }, "outputs": [], "source": [ "matched_obs = Observations.query_criteria(\n", " obs_collection = 'JWST'\n", " , proposal_id = '1073'\n", " , instrument_name = 'NIRCAM/IMAGE' # Be sure to specify the full \"instrument/mode\" configuration!\n", " )" ] }, { "cell_type": "code", "execution_count": 3, "id": "84997008", "metadata": { "execution": { "iopub.execute_input": "2024-02-20T21:00:23.650633Z", "iopub.status.busy": "2024-02-20T21:00:23.650434Z", "iopub.status.idle": "2024-02-20T21:00:23.661368Z", "shell.execute_reply": "2024-02-20T21:00:23.660853Z" } }, "outputs": [ { "data": { "text/html": [ "Table length=15\n", "
idx | dataproduct_type | filters | calib_level | t_exptime | proposal_pi | intentType | obsid | instrument_name |
---|---|---|---|---|---|---|---|---|
0 | image | F277W | 3 | 171.788 | Koekemoer, Anton M. | science | 83254329 | NIRCAM/IMAGE |
1 | image | F150W | 3 | 171.788 | Koekemoer, Anton M. | science | 83254330 | NIRCAM/IMAGE |
2 | image | F150W | 3 | 515.364 | Koekemoer, Anton M. | science | 76622656 | NIRCAM/IMAGE |
3 | image | F277W | 3 | 515.364 | Koekemoer, Anton M. | science | 76622650 | NIRCAM/IMAGE |
4 | image | F277W | 3 | 773.046 | Koekemoer, Anton M. | science | 83254500 | NIRCAM/IMAGE |
5 | image | F070W | 3 | 773.046 | Koekemoer, Anton M. | science | 83254519 | NIRCAM/IMAGE |
6 | image | F277W | 3 | 343.576 | Koekemoer, Anton M. | science | 75900624 | NIRCAM/IMAGE |
7 | image | F277W | 3 | 343.576 | Koekemoer, Anton M. | science | 83254380 | NIRCAM/IMAGE |
8 | image | F150W | 3 | 343.576 | Koekemoer, Anton M. | science | 118344942 | NIRCAM/IMAGE |
9 | image | F150W | 3 | 343.576 | Koekemoer, Anton M. | science | 75914186 | NIRCAM/IMAGE |
10 | image | F115W | 3 | 343.576 | Koekemoer, Anton M. | science | 83254391 | NIRCAM/IMAGE |
11 | image | F277W | 3 | 343.576 | Koekemoer, Anton M. | science | 75884422 | NIRCAM/IMAGE |
12 | image | F277W | 3 | 1374.304 | Koekemoer, Anton M. | science | 83254838 | NIRCAM/IMAGE |
13 | image | F150W | 3 | 687.152 | Koekemoer, Anton M. | science | 83254839 | NIRCAM/IMAGE |
14 | image | F115W | 3 | 687.152 | Koekemoer, Anton M. | science | 83254840 | NIRCAM/IMAGE |