Astroquery: Exploring Metadata from the James Webb Space Telescope#


Learning Goals#

By the end of this tutorial, you will:

  • Understand how to use the astroquery.mast module to access metadata from the James Webb Space Telescope (JWST).

  • Run metadata queries based on coordinates, an object name, or non-positional criteria.

  • Use optional search parameters to further refine query results.

Table of Contents#

Introduction#

Welcome! This tutorial focuses on using the astroquery.mast module to search for metadata from the James Webb Space Telescope (JWST). Launched in December of 2021, JWST is an advanced space observatory designed for observations in the infrared light spectrum.

The Mikulski Archive for Space Telescopes (MAST) hosts publicly accessible data products from space telescopes like JWST. astroquery.mast provides access to a broad set of JWST metadata, including header keywords, proposal information, and observational parameters. The available metadata can also be found using the MAST JWST Search interface.

Please note that astroquery.mast.MastMissions and the MAST JWST Search API do not yet support data product downloads.

Imports#

This notebook uses the following packages:

  • astroquery.mast to query the MAST Archive

  • astropy.coordinates to assign coordinates of interest

from astroquery.mast import MastMissions
from astropy.coordinates import SkyCoord

Querying MAST for JWST Metadata#

Setup#

In order to make queries on JWST metadata, we will have to perform some setup. First, we will instantiate an object of the MastMissions class and assign its mission to be 'jwst'. Its service is set to the default of 'search'.

# Create MastMissions object and assign mission to 'jwst'
missions = MastMissions(mission='jwst')

print(f'Mission: {missions.mission}')
print(f'Service: {missions.service}')
Mission: jwst
Service: search

When writing queries, keyword arguments can be used to specify output characteristics (see the following section) and filter on values like instrument, exposure type, and proposal ID. The available column names for a mission are returned by the get_column_list function. Below, we will print out the name, data type, and description for the first 10 columns in JWST metadata.

# Get available columns for JWST mission
columns = missions.get_column_list()
columns[:10]
Table length=10
namedata_typedescription
str17str9str1594
search_posstringSearch Position (RA and Dec)
ArchiveFileIDintegerArchiveFileID
fileSetNamestringOf the form jwpppppooovvv_ggsaa_eeeee where ppppp - Program Number, ooo - Observation Number, vvv - Visit Number, gg - Visit Group, s - Parallel Sequence id (1 prime, 2-5 parallel), aa - Activity (base 36), and eeeee - Exposure Number, all padded by zeros where necessary. Source-based data set names are expressed as jwppppp-oOOO_tTTT_instrument, where: ppppp - Program number, OOO - observation number, TTT - target number, and instrument - Instrument name
productLevelstringProduct levels, 1b is an uncalibrated FITS file, 2a = countrate exposure, 2b = calibrated (exposure-based), 2bs = calibrated (source-based), 2c = cosmic-ray-flagged (exposure-based), 2cs = cosmic-ray-flagged (source-based), and 3 = combined data.
targpropstringProposer prefered name for the target
targnamestringStandard astronomical catalog name for the target
targ_raraRight Ascension (J2000), from 0 to 360, in degrees
targ_decdecDeclination (J2000), from -90 to +90, in degrees
instrumestringIdentifies the instrument used to acquire the data.
exp_typestringExposure type is used by DMS to direct Science Data Processing code (SDP) and calibration, as well as provide metadata for archive searches. For a given template the EXP_TYPE keyword value is obtained for each exposure from the EXPOSURE_TYPE exposure-level parameter in the Observatory Status File (OSF). In a few cases, additional information is required to set the value for the EXP_TYPE keyword

Optional Search Parameters#

Before we dive in to the actual queries, it’s important to know how we can refine our results with optional keyword arguments. The following parameters are available:

  • radius: For positional searches only. Only return results within a certain distance from an object or set of coordinates. Default is 3 arcminutes.

  • limit: The maximum number of results to return. Default is 5000.

  • offset: Skip the first n results. Useful for paging through results.

  • select_cols: A list of columns to be returned in the response.

As we walk through different types of queries, we will see these parameters in action!

Query by Object Name#

We’ve reached our first query! We can use object names to perform metadata queries using the query_object function.

To start, let’s query for the Messier 1 object, a supernova remnant in the Taurus constellation. You may know it better as the Crab Nebula!

# Query for Messier 1 ('M1')
results = missions.query_object('M1')

# Display the first 5 results
print(f'Total number of results: {len(results)}')
results[:5]
Total number of results: 249
Table masked=True length=5
ArchiveFileIDfileSetNameproductLeveltargproptarg_ratarg_decinstrumeexp_typeopticalElementsdate_obsdurationprogramobservtnvisitpublicReleaseDatepi_nameproposal_typeproposal_cycletargtypeaccesscal_verang_seps_region
int64str25str14str18float64float64str6str9str153str27float64int64int64int64str19str10str2int64str5str6str5float64str1417
244890661jw01714001003_02101_000011b, 2a, 2b, 2cCRAB-NEBULA83.6360495833333322.01641666666667MIRIMIR_IMAGEF560W2023-02-24T02:49:57.2040000138.7521714132024-02-24T13:38:23Temim, TeaGO1FIXEDPUBLIC2.0.10.0POLYGON ICRS 83.620763784 22.002789691 83.654481962 22.001837212 83.655563535 22.033234147 83.621792264 22.034478016
244890685jw01714001003_02101_000021b, 2a, 2b, 2cCRAB-NEBULA83.6360495833333322.01641666666667MIRIMIR_IMAGEF560W2023-02-24T02:53:39.2200000138.7521714132024-02-24T13:38:36Temim, TeaGO1FIXEDPUBLIC2.0.10.0POLYGON ICRS 83.615725007 22.003119338 83.649443299 22.002167938 83.650523705 22.033564908 83.616752308 22.034807696
244890676jw01714001003_02101_000031b, 2a, 2b, 2cCRAB-NEBULA83.6360495833333322.01641666666667MIRIMIR_IMAGEF560W2023-02-24T02:57:23.9880000138.7521714132024-02-24T13:36:13Temim, TeaGO1FIXEDPUBLIC2.0.10.0POLYGON ICRS 83.616528154 22.007520938 83.650247486 22.006569363 83.651328117 22.037966327 83.617555678 22.039209290
244890655jw01714001003_02101_000041b, 2a, 2b, 2cCRAB-NEBULA83.6360495833333322.01641666666667MIRIMIR_IMAGEF560W2023-02-24T03:01:06.0030000138.7521714132024-02-24T13:35:43Temim, TeaGO1FIXEDPUBLIC2.0.10.0POLYGON ICRS 83.620386882 22.006718593 83.654105998 22.005766255 83.655187449 22.037163195 83.621415234 22.038406922
244890605jw01714001003_02103_000011b, 2a, 2b, 2cCRAB-NEBULA83.6360495833333322.01641666666667MIRIMIR_IMAGEF1130W2023-02-24T03:06:50.0870000105.4521714132024-02-24T13:36:54Temim, TeaGO1FIXEDPUBLIC2.0.10.0POLYGON ICRS 83.620747224 22.002797268 83.654465081 22.001844591 83.655546548 22.033241738 83.621775841 22.034485516

There were 250 total results, meaning that 250 JWST datasets were targeting the Crab Nebula. Now, let’s try refining our search a bit more.

  • Each dataset is associated with a celestial coordinate, given by targ_ra (right ascension) and targ_dec (declination). By default, the query returns all datasets that fall within 3 arcminutes from the object’s coordinates. Let’s set the radius parameter to be 1 arcminute instead.

  • Say that we’re not interested in the first 4 results. We can assign offset to skip a certain number of rows.

  • By default, a subset of recommended columns are returned for each query. However, we can specify exactly which columns to return using the select_cols keyword argument. The ArchiveFileID column is included automatically.

# Refined query for Messier 1 ('M1')
results = missions.query_object('M1',
                                radius=1,  # Search within a 1 arcminute radius
                                offset=4,  # Skip the first 4 results
                                select_cols=['fileSetName', 'targprop', 'date_obs'])  # Select certain columns

# Display the first 5 results
print(f'Total number of results: {len(results)}')
results[:5]
Total number of results: 161
Table masked=True length=5
ArchiveFileIDfileSetNametargpropdate_obss_region
int64str25str18str27str1417
244890605jw01714001003_02103_00001CRAB-NEBULA2023-02-24T03:06:50.0870000POLYGON ICRS 83.620747224 22.002797268 83.654465081 22.001844591 83.655546548 22.033241738 83.621775841 22.034485516
244890641jw01714001003_02103_00002CRAB-NEBULA2023-02-24T03:09:58.8230000POLYGON ICRS 83.615708382 22.003127034 83.649426355 22.002175472 83.650506615 22.033572655 83.616735782 22.034815315
244890635jw01714001003_02103_00003CRAB-NEBULA2023-02-24T03:13:07.5590000POLYGON ICRS 83.616511436 22.007528594 83.650230450 22.006576867 83.651310924 22.037974045 83.617539048 22.039216871
244890611jw01714001003_02103_00004CRAB-NEBULA2023-02-24T03:16:18.9830000POLYGON ICRS 83.620370189 22.006726264 83.654088987 22.005773770 83.655170286 22.037170923 83.621398634 22.038414517
244890629jw01714001003_02105_00001CRAB-NEBULA2023-02-24T03:21:10.3800000POLYGON ICRS 83.620742930 22.002804912 83.654460815 22.001852254 83.655542067 22.033249470 83.621771597 22.034493185

Exercise 1#

Now it’s your turn! Try querying for the Whirlpool Galaxy object. Search within a radius of 1 arcminute, skip the first 300 results, and select the fileSetName and opticalElements columns.

# # Query for Whirlpool Galaxy
# results = missions.query_object(...)  # Write your query!

# # Display the first 5 results
# print(f'Total number of results: {len(results)}')
# results[:5]

Query by Region#

The missions object also allows us to query by a region in the sky. By passing in a set of coordinates to the query_region function, we can return datasets that fall within a certain radius value of that point. This type of search is also known as a cone search.

# Create coordinate object
coords = SkyCoord(210.80227, 54.34895, unit=('deg'))

# Query for results within 10 arcminutes of coords
results = missions.query_region(coords, radius=10)

# Display results
print(f'Total number of results: {len(results)}')
results[:5]
Total number of results: 574
Table masked=True length=5
ArchiveFileIDfileSetNameproductLeveltargproptarg_ratarg_decinstrumeexp_typeopticalElementsdate_obsdurationprogramobservtnvisitpublicReleaseDatepi_nameproposal_typeproposal_cycletargtypeaccesscal_verang_seps_region
int64str36str14str25float64float64str7str17str89str27float64int64int64int64str19str25str6int64str7str16str6float64str2821
240850266jw01995001002_02101_000011b, 2a, 2b, 2cMESSIER-101210.87646554.36092777777778NIRCAMNRC_IMAGEF115W;CLEAR, F444W;CLEAR2023-05-30T15:53:41.4040000311.3661995122024-05-30T23:57:44Freedman, Wendy L.GO1FIXEDPUBLIC2.0.10.0POLYGON ICRS 210.885405667 54.363539181 210.903686820 54.349472486 210.927631420 54.359958338 210.909710699 54.374069380
240850260jw01995001002_02101_000021b, 2a, 2b, 2cMESSIER-101210.87646554.36092777777778NIRCAMNRC_IMAGEF115W;CLEAR, F444W;CLEAR2023-05-30T16:00:29.4040000311.3661995122024-05-30T23:55:45Freedman, Wendy L.GO1FIXEDPUBLIC2.0.10.0POLYGON ICRS 210.843638596 54.346485701 210.861621019 54.332379602 210.885819711 54.342694913 210.868007005 54.356993477
240850156jw01995001002_02101_000031b, 2a, 2b, 2cMESSIER-101210.87646554.36092777777778NIRCAMNRC_IMAGEF115W;CLEAR, F444W;CLEAR2023-05-30T16:07:06.7160000311.3661995122024-05-30T23:55:43Freedman, Wendy L.GO1FIXEDPUBLIC2.0.10.0POLYGON ICRS 210.844059704 54.346499323 210.862041993 54.332393164 210.886240795 54.342708393 210.868428223 54.357007017
240849851jw01995001003_02101_000011b, 2a, 2b, 2cMESSIER-101210.87646554.36092777777778NIRCAMNRC_IMAGEF115W;CLEAR, F444W;CLEAR2023-05-30T16:23:18.9390000311.3661995132024-05-30T23:49:52Freedman, Wendy L.GO1FIXEDPUBLIC2.0.10.0POLYGON ICRS 210.837964482 54.374557592 210.875409895 54.345677384 210.924326179 54.366758903 210.888373410 54.395950436
240849515jw01995001003_02101_000021b, 2a, 2b, 2cMESSIER-101210.87646554.36092777777778NIRCAMNRC_IMAGEF115W;CLEAR, F444W;CLEAR2023-05-30T16:29:56.1220000311.3661995132024-05-30T23:42:15Freedman, Wendy L.GO1FIXEDPUBLIC2.0.10.0POLYGON ICRS 210.814759400 54.342150595 210.832749852 54.328048799 210.856938736 54.338369897 210.839117838 54.352664198

395 JWST datasets fall within our cone search. In other words, their target coordinates are within 10 arcminutes of the coordinates that we defined.

Exercise 2:#

JWST has observed the star Vega, which has a right ascension of 279.23473 degrees and a declination of 38.78369 degrees. Use the query_region function to search for datasets within 15 arcminutes of Vega. Select the fileSetName, targprop, targ_ra, and targ_dec columns.

# # Vega coordinates
# vega = SkyCoord(_, _, unit=('deg'))  # Fill in with Vega's coordinates

# # Query for datasets around Vega
# results = missions.query_region(...)  # Write your query!

# # Display the first 5 results
# print(f'Total number of results: {len(results)}')
# results[:5]

Query by Criteria#

In some cases, we may want to run queries with non-positional parameters. To accomplish this, we use the query_criteria function.

For any of our query functions, we can filter our results by the value of columns in the dataset.

Let’s say that we only want observations from JWST’s Near Infrared Camera (NIRCam) instrument, and that we only want datasets connected to program number 1189.

# Query with column criteria
results = missions.query_criteria(instrume='NIRCAM',  # From Near Infrared Camera
                                  program=1189,
                                  select_cols=['fileSetName', 'instrume', 'exp_type', 'program', 'pi_name'])

# Display the first 5 results
print(f'Total number of results: {len(results)}')
results[:5]
Total number of results: 79
Table masked=True length=5
ArchiveFileIDfileSetNameinstrumeexp_typeprogrampi_names_region
int64str25str6str13int64str17str931
248476425jw01189010001_02101_00001NIRCAMNRC_IMAGE1189Roellig, Thomas LPOLYGON ICRS 277.120172080 26.849875305 277.132098971 26.835443799 277.148131087 26.845798799 277.136492608 26.860301167
248476431jw01189010001_02101_00002NIRCAMNRC_IMAGE1189Roellig, Thomas LPOLYGON ICRS 277.120504877 26.847671217 277.144537450 26.818512371 277.176774641 26.839236061 277.153714071 26.868685780
248476413jw01189010001_02101_00003NIRCAMNRC_IMAGE1189Roellig, Thomas LPOLYGON ICRS 277.136816889 26.856546237 277.148340587 26.841976875 277.164498570 26.852047061 277.153228186 26.866725025
248475864jw01189010001_02101_00004NIRCAMNRC_IMAGE1189Roellig, Thomas LPOLYGON ICRS 277.119663090 26.843112943 277.143694918 26.813954244 277.175930652 26.834678131 277.152870785 26.864127708
248475903jw01189010001_04101_00001NIRCAMNRC_IMAGE1189Roellig, Thomas LPOLYGON ICRS 277.120171897 26.849875466 277.132100171 26.835444596 277.148132310 26.845799169 277.136492187 26.860300978

To exclude and filter out a certain value from the results, we can prepend the value with !.

Let’s run the same query as above, but this time, we will filter out datasets coming from the NIRCam instrument.

# Filtered query, excluding NIRCam datasets
results = missions.query_criteria(program=1189,
                                  instrume='!NIRCAM',  # Exclude datasets from the NIRCam instrument
                                  select_cols=['fileSetName', 'instrume', 'exp_type', 'program', 'pi_name'])

# Display the first 5 results
print(f'Total number of results: {len(results)}')
results[:5]
Total number of results: 92
Table masked=True length=5
ArchiveFileIDfileSetNameinstrumeexp_typeprogrampi_names_region
int64str36str7str17int64str17str429
248474248jw01189001001_02101_00001NIRSPECNRS_WATA1189Roellig, Thomas LPOLYGON ICRS 57.028706514 -60.379718934 57.029997036 -60.379034506 57.028628578 -60.378418468 57.027338587 -60.379103093
248474269jw01189001001_02101_00002NIRSPECNRS_TACONFIRM1189Roellig, Thomas LPOLYGON ICRS 57.028868052 -60.379725570 57.030158570 -60.379041140 57.028790110 -60.378425103 57.027500121 -60.379109730
248474336jw01189001001_04101_00001NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029098138 -60.378811466 57.027719263 -60.379546534 57.027799291 -60.379582617 57.029178187 -60.378847556
248474158jw01189001001_04101_00002NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029431441 -60.378633666 57.028052583 -60.379368738 57.028132612 -60.379404822 57.029511491 -60.378669756
248474176jw01189001001_04101_00003NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029845143 -60.378413088 57.028466303 -60.379148165 57.028546331 -60.379184248 57.029925192 -60.378449179

We can also use wildcards for more advanced filtering. Let’s use the same query from above, but we will add an exposure type filter for fixed slits (FS) spectroscopy.

# Filtered query with wildcard
results = missions.query_criteria(program=1189,
                                  instrume='!NIRCAM',  # Exclude datasets from the NIRCam instrument
                                  exp_type='*FIXEDSLIT*', # Any exposure type that contains 'FIXEDSLIT'
                                  select_cols=['fileSetName', 'instrume', 'exp_type', 'program', 'pi_name'])

# Display the first 10 results
print(f'Total number of results: {len(results)}')
results[:10]
Total number of results: 38
Table masked=True length=10
ArchiveFileIDfileSetNameinstrumeexp_typeprogrampi_names_region
int64str36str7str17int64str17str121
248474336jw01189001001_04101_00001NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029098138 -60.378811466 57.027719263 -60.379546534 57.027799291 -60.379582617 57.029178187 -60.378847556
248474158jw01189001001_04101_00002NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029431441 -60.378633666 57.028052583 -60.379368738 57.028132612 -60.379404822 57.029511491 -60.378669756
248474176jw01189001001_04101_00003NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029845143 -60.378413088 57.028466303 -60.379148165 57.028546331 -60.379184248 57.029925192 -60.378449179
248474380jw01189001001_06101_00001NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029094706 -60.378814882 57.027715806 -60.379549981 57.027795835 -60.379586065 57.029174756 -60.378850973
248473626jw01189001001_06101_00002NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029428241 -60.378637024 57.028049357 -60.379372127 57.028129386 -60.379408211 57.029508291 -60.378673115
248474140jw01189001001_06101_00003NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029841922 -60.378416519 57.028463057 -60.379151626 57.028543086 -60.379187710 57.029921972 -60.378452609
248474272jw01189001001_08101_00001NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029093839 -60.378817409 57.027714791 -60.379552569 57.027794819 -60.379588653 57.029173888 -60.378853500
248474371jw01189001001_08101_00002NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029427587 -60.378639357 57.028048551 -60.379374519 57.028128579 -60.379410603 57.029507635 -60.378675448
248474167jw01189001001_08101_00003NIRSPECNRS_FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029841266 -60.378418864 57.028462251 -60.379154030 57.028542278 -60.379190114 57.029921315 -60.378454954
248474035jw01189002001_03102_00001MIRIMIR_LRS-FIXEDSLIT1189Roellig, Thomas LPOLYGON ICRS 57.029000075 -60.378579009 57.028710817 -60.378582026 57.028770560 -60.379893934 57.029060321 -60.379890607

To filter by multiple values for a single column, we use a string of the values delimited by commas.

To illustrate this, we will use a slightly different query. We query for datasets that have a fixed slits spectroscopy exposure type and targets with moving coordinates (targtype='MOVING'). We will add another filter to match three different last names for principal investigators (PIs).

# Filtered query with multiple values
results = missions.query_criteria(exp_type='*FIXEDSLIT*', # Any exposure type that contains 'FIXEDSLIT'
                                  targtype='MOVING',  # Only return moving targets
                                  pi_name='Stansberry, Parker, Lunine',  # Last name of PI can be any of these 3 values
                                  select_cols=['fileSetName', 'targtype', 'instrume', 'exp_type', 'program', 'pi_name'])

# Display the first 10 results
print(f'Total number of results: {len(results)}')
results[:10]
Total number of results: 15
Table masked=True length=10
ArchiveFileIDfileSetNameinstrumeexp_typeprogrampi_nametargtypes_region
int64str25str4str17int64str21str6str125
245400831jw01191018001_03102_00001MIRIMIR_LRS-FIXEDSLIT1191Stansberry, John A.MOVINGPOLYGON ICRS 27.119130631 -0.633808628 27.118993907 -0.633850603 27.119380875 -0.635104608 27.119517747 -0.635062267
245401185jw01191018001_03102_00002MIRIMIR_LRS-FIXEDSLIT1191Stansberry, John A.MOVINGPOLYGON ICRS 27.118986627 -0.633313429 27.118849904 -0.633355404 27.119236871 -0.634609408 27.119373743 -0.634567068
245424730jw01191-o018_t002_miriMIRIMIR_LRS-FIXEDSLIT1191Stansberry, John A.MOVINGPOLYGON ICRS 27.118933045 -0.633289957 27.119494797 -0.635109701 27.119358137 -0.635151883 27.118796384 -0.633332139
240569542jw01254001001_03102_00001MIRIMIR_LRS-FIXEDSLIT1254Parker, Alex HarrisonMOVINGPOLYGON ICRS 200.084989101 21.875603741 200.084839511 21.875638116 200.084501536 21.874363824 200.084651465 21.874329687
240569426jw01254001001_03102_00002MIRIMIR_LRS-FIXEDSLIT1254Parker, Alex HarrisonMOVINGPOLYGON ICRS 200.085097655 21.876183716 200.084948065 21.876218091 200.084610087 21.874943800 200.084760016 21.874909662
240581763jw01254-o001_t001_miriMIRIMIR_LRS-FIXEDSLIT1254Parker, Alex HarrisonMOVINGPOLYGON ICRS 200.085077697 21.876190767 200.084587433 21.874341477 200.084437789 21.874375643 200.084928050 21.876224932
243416315jw01273001001_04102_00001MIRIMIR_LRS-FIXEDSLIT1273Lunine, Jonathan I.MOVINGPOLYGON ICRS 218.302364746 15.229464463 218.302216747 15.229456762 218.302291894 15.228146471 218.302440133 15.228154490
243416980jw01273001001_04102_00002MIRIMIR_LRS-FIXEDSLIT1273Lunine, Jonathan I.MOVINGPOLYGON ICRS 218.302255562 15.230070428 218.302107563 15.230062728 218.302182711 15.228752436 218.302330951 15.228760456
243416133jw01273009001_04102_00001MIRIMIR_LRS-FIXEDSLIT1273Lunine, Jonathan I.MOVINGPOLYGON ICRS 218.299827529 15.232021871 218.299679528 15.232014170 218.299754675 15.230703879 218.299902916 15.230711898
243416070jw01273009001_04102_00002MIRIMIR_LRS-FIXEDSLIT1273Lunine, Jonathan I.MOVINGPOLYGON ICRS 218.299717915 15.232627744 218.299569914 15.232620043 218.299645062 15.231309752 218.299793303 15.231317771

For columns with numeric or date values, we can filter using comparison values:

  • <: Return values less than or before the given number/date

  • >: Return values greater than or after the given number/date

  • <=: Return values less than or equal to the given number/date

  • >=: Return values greater than or equal to the given number/date

As an example, let’s write a query to return all datasets with an observation date before February 1, 2022.

# Query using comparison operator
results = missions.query_criteria(date_obs='<2022-02-01',  # Must be observed before February 1, 2022
                                  select_cols=['fileSetName', 'program', 'date_obs'])

# Display results
print(f'Total number of results: {len(results)}')
results
Total number of results: 7
Table masked=True length=7
ArchiveFileIDfileSetNamedate_obsprograms_region
int64str25str27int64str117
215731832jw01173001001_02101_000012022-01-28T14:23:42.61800001173POLYGON ICRS 49.866526985 43.426041553 49.866521841 43.425150113 49.865098509 43.425154454 49.865103669 43.426045898
215731918jw01173002001_02101_000012022-01-28T14:36:10.11100001173POLYGON ICRS 49.834781123 43.401405192 49.833461500 43.417145218 49.855003580 43.418000890 49.856390566 43.402332025
215731590jw01173003001_02101_000012022-01-28T15:00:36.65500001173POLYGON ICRS 49.833309699 43.387232397 49.830574836 43.418875799 49.873651838 43.420534037 49.876269543 43.389175750
215731714jw01173004001_02101_000012022-01-28T15:09:07.18300001173POLYGON ICRS 49.871773665 43.425721414 49.871768435 43.424829974 49.870345111 43.424834387 49.870350357 43.425725831
215731607jw01173005001_02101_000012022-01-28T15:26:34.22700001173POLYGON ICRS 49.871781960 43.425717246 49.871776730 43.424825806 49.870353406 43.424830219 49.870358652 43.425721663
215731710jw01173006001_02101_000012022-01-28T15:34:23.46900001173POLYGON ICRS 49.871796487 43.425726630 49.871791257 43.424835190 49.870367933 43.424839603 49.870373179 43.425731048
215731494jw01173007001_02101_000012022-01-28T15:43:44.30100001173POLYGON ICRS 49.833398209 43.387251737 49.830663382 43.418895140 49.873740398 43.420553352 49.876358069 43.389195064

For numeric or date data types, we can also filter with ranges. This requires the following syntax: '#..#'.

Let’s write a query that uses range syntax to return datasets that belong to a program number between 1150 and 1155. We will also select for exposure durations that are greater than or equal to 100 seconds.

# Query using range operator
results = missions.query_criteria(program='1150..1155', # Program number between 1150 and 1155
                                  duration='>100',  # Exposure duration is greater than or equal to 100 seconds
                                  select_cols=['fileSetName', 'program', 'duration'])

# Display results
print(f'Total number of results: {len(results)}')
results
Total number of results: 77
Table masked=True length=77
ArchiveFileIDfileSetNamedurationprograms_region
int64str25float64int64str121
56863496jw01151001001_02101_00001203.9991151POLYGON ICRS 267.823568791 74.579914311 267.758823468 74.583483609 267.745046642 74.566390683 267.809916760 74.562619353
56863482jw01151001001_02101_00002203.9991151POLYGON ICRS 267.832636673 74.568022765 267.766940456 74.571687792 267.753017936 74.554394205 267.818800515 74.550472738
56863512jw01151001001_03101_00001214.7351151POLYGON ICRS 268.091803329 74.608826495 267.943092794 74.616030022 267.912318626 74.578289816 268.058609787 74.570410560
56863582jw01151001001_05101_00001203.9991151POLYGON ICRS 267.823569171 74.579914010 267.758823764 74.583483198 267.745047350 74.566390249 267.809917556 74.562619029
56863557jw01151001001_05101_00002203.9991151POLYGON ICRS 267.832637174 74.568022531 267.766940886 74.571687467 267.753018708 74.554393860 267.818801363 74.550472484
56863823jw01151001001_06101_00001214.7351151POLYGON ICRS 268.091803198 74.608826549 267.943092604 74.616029989 267.912318750 74.578289765 268.058609977 74.570410594
56863493jw01151001001_08101_00001203.9991151POLYGON ICRS 267.818105646 74.572500244 267.753393956 74.576073744 267.739607888 74.558981714 267.804444175 74.555206172
56875469jw01151020001_03101_00001214.7351151POLYGON ICRS 241.403250845 62.406808505 241.320362209 62.395214146 241.341730845 62.357890793 241.424148058 62.368600633
56875337jw01151021001_02102_00001118.1041151POLYGON ICRS 267.913114360 74.594280874 267.847798665 74.598304471 267.832287729 74.581187911 267.897484698 74.576921755
...............
56968123jw01155005001_0210a_00002150.3151155POLYGON ICRS 268.948931490 65.883692410 268.862026455 65.888823867 268.848510660 65.853853484 268.935616643 65.847844473
56968107jw01155005001_0210b_00001150.3151155POLYGON ICRS 268.943367232 65.865137421 268.900206631 65.867886945 268.893348799 65.850424281 268.936614729 65.847418646
56968099jw01155005001_0210b_00002150.3151155POLYGON ICRS 268.897309483 65.868076519 268.854801968 65.870734177 268.848044059 65.853472441 268.890674791 65.850613599
56967383jw01155007001_02102_000011191.7811155POLYGON ICRS 268.953421618 65.883348262 268.910258263 65.885838025 268.903866273 65.868430578 268.947013758 65.865693295
56967393jw01155007001_02103_000011191.7811155POLYGON ICRS 268.900582798 65.867357807 268.858088887 65.870023805 268.851308616 65.852766994 268.893929725 65.849900846
56967357jw01155007001_02104_000011191.7811155POLYGON ICRS 268.907471989 65.885893297 268.865026422 65.888465047 268.858577317 65.871266296 268.901022967 65.868503644
56969123jw01155-o001_t018_nircam150.3151155POLYGON ICRS 268.950105056 65.884072557 268.906939249 65.886554426 268.900565087 65.869142126 268.943721766 65.866414693
56968129jw01155-o003_t018_nircam246.9461155POLYGON ICRS 268.897309446 65.868076445 268.854801924 65.870734081 268.848044068 65.853472341 268.890674808 65.850613522
56968698jw01155-o005_t018_nircam246.9461155POLYGON ICRS 268.897309130 65.868076445 268.854801607 65.870734077 268.848043759 65.853472337 268.890674500 65.850613521
56969356jw01155-o007_t018_nircam4767.1241155POLYGON ICRS 268.954186883 65.883302799 268.865270829 65.889082353 268.851081068 65.852428662 268.939873462 65.846657355

Exercise 3#

It’s time to apply all that you’ve learned! Write a non-positional query based on the following:

  • Fixed targets (HINT: targtype='FIXED')

  • Instument is Mid-Infrared Instrument (MIRI) or Fine Guidance Sensor (FGS)

  • Proposal type should NOT include General Observers (GO)

  • Exposure type includes the string 'IMAGE'

  • Right ascension is between 70 and 75 degrees

  • Program number is less than 1200.

  • Skip the first 5 entries.

  • Select the following columns: fileSetName, targtype, instrume, proposal_type, exp_type, targ_ra, program

# # A non-positional query with column criteria
# results = missions.query_criteria(...)  # Write your query here!

# # Display results
# print(f'Total number of results: {len(results)}')
# results

Additional Resources#

Exercise Solutions#

Exercise 1#

# Query for Whirlpool Galaxy
results = missions.query_object('Whirlpool',
                                radius=1,  # Search radius of 1 arcminute
                                offset=300,  # Skip the first 300 rows
                                select_cols=['fileSetName', 'opticalElements'])

# Display the first 5 results
print(f'Total number of results: {len(results)}')
results[:5]
Total number of results: 93
Table masked=True length=5
ArchiveFileIDfileSetNameopticalElementss_region
int64str25str12str121
239439476jw03435006001_16101_00002F100LP;G140MPOLYGON ICRS 202.479792673 47.194664201 202.481599708 47.194664201 202.481599708 47.195968681 202.479792673 47.195968681
239439515jw03435006001_24101_00002F170LP;G235MPOLYGON ICRS 202.479797906 47.194662185 202.481604924 47.194662185 202.481604924 47.195966514 202.479797906 47.195966514
239439053jw03435006001_32101_00002F170LP;G235MPOLYGON ICRS 202.479798157 47.194662236 202.481605176 47.194662236 202.481605176 47.195966564 202.479798157 47.195966564
239438758jw03435006001_40101_00002F290LP;G395MPOLYGON ICRS 202.479800918 47.194661243 202.481608015 47.194661243 202.481608015 47.195965715 202.479800918 47.195965715
239438713jw03435006001_48101_00002F290LP;G395MPOLYGON ICRS 202.479801192 47.194661268 202.481608289 47.194661268 202.481608289 47.195965740 202.479801192 47.195965740

Exercise 2#

# Vega coordinates
vega = SkyCoord(279.23473, 38.78369, unit=('deg'))

# Query for datasets around Vega
results = missions.query_region(vega,
                                radius=15,  # Search radius of 15 arcminutes
                                select_cols=['fileSetName', 'targprop', 'targ_ra', 'targ_dec'])

# Display the first 5 results
print(f'Total number of results: {len(results)}')
results[:5]
Total number of results: 65
Table masked=True length=5
ArchiveFileIDfileSetNametargproptarg_ratarg_decs_region
int64str25str20float64float64str823
248497983jw01193026001_02101_00001VEGA279.236426614517138.78556769656323POLYGON ICRS 279.221729906 38.783407254 279.235141651 38.771659296 279.250116156 38.782158642 279.236818815 38.793910852
248508904jw01193026001_02101_00002VEGA279.236426615314138.7855676974483POLYGON ICRS 279.217902494 38.787018585 279.231315639 38.775271128 279.246290259 38.785771032 279.232991522 38.797522747
248508862jw01193026001_02101_00003VEGA279.236426616117238.78556769833999POLYGON ICRS 279.222650603 38.789514812 279.236063428 38.777766807 279.251039278 38.788266099 279.237740866 38.800018357
248508856jw01193026001_02101_00004VEGA279.236426616916338.78556769922733POLYGON ICRS 279.225070348 38.786370476 279.238482174 38.774622188 279.253457727 38.785121165 279.240160310 38.796873703
248497965jw01193027001_02101_00001VEGA-COPY-MIRI-CORON279.236426619141138.78556770169765POLYGON ICRS 279.224084557 38.786582274 279.232078751 38.779668261 279.241455366 38.786108038 279.233482375 38.793052680

Exercise 3#

# A non-positional query with column criteria
results = missions.query_criteria(targtype='FIXED',  # Fixed target
                                  instrume='MIRI, FGS',  # Select MIRI and FGS observations
                                  proposal_type='!GO',  # Not from a general observer proposal
                                  exp_type='*IMAGE*',  # Contains the string "IMAGE"
                                  targ_ra='70..75',  # Between 70 and 75
                                  program='<1200',  # Less than 1200
                                  offset=5,  # Skip the first 5 results
                                  select_cols=['fileSetName', 'targtype', 'instrume', 'proposal_type', 
                                               'exp_type', 'targ_ra', 'program'])

# Display results
print(f'Total number of results: {len(results)}')
results
Total number of results: 11
Table masked=True length=11
ArchiveFileIDfileSetNametarg_rainstrumeexp_typeprogramproposal_typetargtypes_region
int64str25float64str4str9int64str3str5str429
248471913jw01189005001_02101_0000674.72636096419268MIRIMIR_IMAGE1189GTOFIXEDPOLYGON ICRS 74.725719694 64.586578222 74.715281227 64.580172133 74.730349733 64.575679989 74.740807167 64.582080055
248472330jw01189005001_02101_0000774.72636096470079MIRIMIR_IMAGE1189GTOFIXEDPOLYGON ICRS 74.724549789 64.587997075 74.714111044 64.581590906 74.729180522 64.577098878 74.739638235 64.583499024
248472309jw01189005001_02101_0000874.72636096498769MIRIMIR_IMAGE1189GTOFIXEDPOLYGON ICRS 74.724549252 64.587997065 74.714110498 64.581590899 74.729179970 64.577098867 74.739637691 64.583499011
248472541jw01189015001_02101_0000174.72636283572731MIRIMIR_IMAGE1189GTOFIXEDPOLYGON ICRS 74.684302128 64.625731395 74.649537688 64.598230580 74.713855035 64.583216686 74.749315203 64.610609057
248472550jw01189015001_02101_0000274.72636283828966MIRIMIR_IMAGE1189GTOFIXEDPOLYGON ICRS 74.685737146 64.625665776 74.650971143 64.598165344 74.715287436 64.583150742 74.750749157 64.610542722
248472183jw01189015001_02103_0000174.72636284145068MIRIMIR_IMAGE1189GTOFIXEDPOLYGON ICRS 74.684301080 64.625731312 74.649536360 64.598230563 74.713853552 64.583216548 74.749314000 64.610608852
248472123jw01189015001_02103_0000274.72636284400116MIRIMIR_IMAGE1189GTOFIXEDPOLYGON ICRS 74.685736953 64.625665846 74.650970886 64.598165430 74.715287143 64.583150801 74.750748928 64.610542765
248473441jw01189015001_02105_0000174.72636284716218MIRIMIR_IMAGE1189GTOFIXEDPOLYGON ICRS 74.684301124 64.625731452 74.649536403 64.598230704 74.713853594 64.583216689 74.749314042 64.610608992
248473411jw01189015001_02105_0000274.7263628497248MIRIMIR_IMAGE1189GTOFIXEDPOLYGON ICRS 74.685737105 64.625666012 74.650971069 64.598165589 74.715287342 64.583150973 74.750749096 64.610542944
248559760jw01189-o005_t002_miri74.72636096235495MIRIMIR_IMAGE1189GTOFIXEDPOLYGON ICRS 74.738145569 64.583944141 74.739445075 64.584739203 74.724356226 64.589237446 74.720784971 64.587046313 74.719770193 64.587348697 74.719767534 64.587347065 74.709343677 64.580950286 74.715827577 64.579004333 74.724398345 64.576449390 74.724401121 64.576451090 74.725503844 64.577124884 74.730349617 64.575679956 74.739761970 64.581440555 74.740805466 64.582080562 74.738462096 64.582779411 74.739638235 64.583499024
248572260jw01189-o015_t002_miri74.72636283572731MIRIMIR_IMAGE1189GTOFIXEDPOLYGON ICRS 74.750058197 64.610009612 74.750742303 64.610544319 74.685737105 64.625666012 74.685475157 64.625459046 74.684303621 64.625731152 74.649556531 64.598247176 74.666365542 64.594305094 74.713851740 64.583215754 74.714123155 64.583422930 74.715287143 64.583150801

Citations#

If you use astroquery for published research, please cite the authors. Follow these links for more information about citing astroquery:

About this Notebook#

Author(s): Sam Bianco
Keyword(s): Tutorial, JWST, Astroquery, MastMissions
First published: June 2024
Last updated: June 2024


Top of Page Space Telescope Logo