Wildcard Handling with Astroquery.mast#


Learning Goals#

By the end of this tutorial, you will:

  • Use the wildcards available for astroquery.mast.Observations criteria queries

  • Broaden and refine astroquery.mast.Observations criteria queries

  • Fully utilize the instrument_name criteria, especially for JWST queries

  • Query for moving targets using target ephemeris and time criteria such as t_min and t_max

Introduction#

This Notebook demonstrates the use of wildcards in astroquery.mast.Observations criteria queries. The use of wildcards is encouraged for certain criteria types (namely, string object types) to ensure your query returns all results.

We will demonstrate 3 use-cases for wildcards when doing criteria queries and emphasize certain criteria where wildcard usage is highly encouraged, particularly for JWST queries. We will also use the last example to demonstrate the use of value ranges when working with float object criteria types.

The workflow for this notebook consists of:

  • Wildcard overview with astroquery.mast.Observations

    1. Wildcard Search with instrument_name

    2. Wildcard Search with instrument_name and proposal_id

    3. Wildcard Search a Time-sensitive Object with target_name and t_min

  • Resources

Imports#

import astropy.units as u
import matplotlib.pyplot as plt

from astropy.coordinates import SkyCoord
from astropy.table import Table, unique, vstack
from astropy.time import Time
from astroquery.mast import Observations

Wildcards with astroquery.mast.Observations#

The use of wildcards when making astroquery.mast.Observations queries can help ensure you retrieve all observations without leaving anything out. The available wildcards are % and *: % replaces a single character, while * replaces more than one character preceding, following, or in between the existing characters, depending on its placement. See the Observation Criteria Queries section in the astroquery.mast documentation for more information on the wildcards.

Wildcards are only available for certain criteria. string type objects accept wildcards, but float, integer, or any other objects do not accept wildcards.

Users may call the get_metadata method to see the list of query criteria and their data types. The criteria listed as string objects under the Data Type column are criteria that can be called with wildcards:

Observations.get_metadata("observations")
Table length=34
Column NameColumn LabelData TypeUnitsDescriptionExamples/Valid Values
str21str25str7str10str72str116
intentTypeObservation TypestringWhether observation is for science or calibration.Valid values: science, calibration
obs_collectionMissionstringCollectionE.g. SWIFT, PS1, HST, IUE
provenance_nameProvenance NamestringProvenance name, or source of dataE.g. TASOC, CALSTIS, PS1
instrument_nameInstrumentstringInstrument NameE.g. WFPC2/WFC, UVOT, STIS/CCD
projectProjectstringProcessing projectE.g. HST, HLA, EUVE, hlsp_legus
filtersFiltersstringInstrument filtersF469N, NUV, FUV, LOW DISP, MIRROR
wavelength_regionWavebandstringEnergy BandEUV, XRAY, OPTICAL
target_nameTarget NamestringTarget NameEx. COMET-67P-CHURYUMOV-GER-UPDATE
target_classificationTarget ClassificationstringType of targetEx. COMET;COMET BEING ORBITED BY THE ROSETTA SPACECRAFT;SOLAR SYSTEM
..................
s_regions_regionstringICRS ShapeSTC/S FootprintWill be ICRS circle or polygon. E.g. CIRCLE ICRS 17.71740689 -58.40043015 0.625
jpegURLjpegURLstringPreview Image URLhttps://archive.stsci.edu/hst/previews/N4QF/N4QF18090.jpg
distanceDistance (")floatarcsecAngular separation between searched coordinates and center of obsevation
obsidProduct Group IDintegerDatabase identifier for obs_idLong integer, e.g. 2007590987
dataRightsData RightsstringData Rightsvalid values: public,exclusive_access,restricted
mtFlagMoving TargetbooleanMoving Target FlagIf True, observation contains a moving target, if False or absent observation may or may not contain a moving target
srcDenNumber of Catalog ObjectsfloatNumber of cataloged objects found in observation
dataURLData URLstringData URL
proposal_typeProposal TypestringType of telescope proposalEg. 3PI, GO, GO/DD, HLA, GII, AIS
sequence_numberSequence NumberintegerSequence number, e.g. Kepler quarter or TESS sector

Case 1: Wildcard Search with instrument_name#

For our first example we will search for all NIRISS observations taken by a certain proposal/program PI. Our two query criteria are proposal_pi and instrument_name, which are both string object criteria. As such, both can be wildcarded for ease of use.

In fact, it is sometimes necessary to use wildcards when searching on instrument_name. Both HST and JWST use instrument configurations in this field to allow for more precise advanced searches (e.g. NIRISS/IMAGE and STIS/FUV-MAMA). When performing a “generic” search, you must include a wildcard or these more detailed results will be excluded.

We will demonstrate this by looking at the results for the query below:

observations = Observations.query_criteria(proposal_pi="Espinoza, Nestor",
                                           instrument_name="NIRISS*")
observations
Table masked=True length=159
intentTypeobs_collectionprovenance_nameinstrument_nameprojectfilterswavelength_regiontarget_nametarget_classificationobs_ids_ras_decdataproduct_typeproposal_picalib_levelt_mint_maxt_exptimeem_minem_maxobs_titlet_obs_releaseproposal_idproposal_typesequence_numbers_regionjpegURLdataURLdataRightsmtFlagsrcDenobsidobjID
str7str4str7str12str4str13str8str14str54str50float64float64str8str16int64float64float64float64float64float64str70float64str4str3int64str132str63str81str16boolfloat64str9str9
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDBD+60-1753Star; A dwarfsjw01512006001_03102_00001_nis261.2178777054549560.430788533141374imageEspinoza, Nestor259996.0620702546359996.064613773146164.82600.02800.0SOSS Wavelength and Trace59996.110925951512CAL--POLYGON 261.252753029 60.462639955 261.225211115 60.427085449 261.208745647 60.4302301 261.236255005 60.465792348mast:JWST/product/jw01512006001_03102_00001_nis_trapsfilled.jpgmast:JWST/product/jw01512006001_03102_00001_nis_rateints.fitsPUBLICFalsenan117933689448768167
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDBD+60-1753Star; A dwarfsjw01512001001_03101_00001_nis261.217877704760460.430788532878005imageEspinoza, Nestor259995.97115187559995.971279050935.494600.02800.0SOSS Wavelength and Trace59996.024178221512CAL--POLYGON 261.252854717 60.462614285 261.225198275 60.427081419 261.20874295 60.430238976 261.236366895 60.46577961mast:JWST/product/jw01512001001_03101_00001_nis_trapsfilled.jpgmast:JWST/product/jw01512001001_03101_00001_nis_rateints.fitsPUBLICFalsenan117933676448768176
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDBD+60-1753Star; A dwarfsjw01512008001_03102_00001_nis261.2178777055918360.43078853319328imageEspinoza, Nestor259996.08022652777459996.0827700463164.82600.02800.0SOSS Wavelength and Trace59996.151492961512CAL--POLYGON 261.252730504 60.46264644 261.225211108 60.427087691 261.20874365 60.430229805 261.23623048 60.46579629mast:JWST/product/jw01512008001_03102_00001_nis_trapsfilled.jpgmast:JWST/product/jw01512008001_03102_00001_nis_rateints.fitsPUBLICFalsenan117933747448768178
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDBD+60-1753Star; A dwarfsjw01512001001_03102_00001_nis261.2178777047764760.43078853288411imageEspinoza, Nestor259995.97207774305659995.97462126157164.82600.02800.0SOSS Wavelength and Trace59996.025648141512CAL--POLYGON 261.252854729 60.462614535 261.225198292 60.427081667 261.208742966 60.430239224 261.236366907 60.465779859mast:JWST/product/jw01512001001_03102_00001_nis_trapsfilled.jpgmast:JWST/product/jw01512001001_03102_00001_nis_rateints.fitsPUBLICFalsenan117933623448768199
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDBD+60-1753Star; A dwarfsjw01512004001_03102_00001_nis261.2178777051821660.43078853303793imageEspinoza, Nestor259996.0258858449159996.028429363425164.82600.02800.0SOSS Wavelength and Trace59996.080347211512CAL--POLYGON 261.252792594 60.462630755 261.225205457 60.427084782 261.208743988 60.430234529 261.236298593 60.465788255mast:JWST/product/jw01512004001_03102_00001_nis_trapsfilled.jpgmast:JWST/product/jw01512004001_03102_00001_nis_rateints.fitsPUBLICFalsenan117933696448768209
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDBD+60-1753Star; A dwarfsjw01512008001_03101_00001_nis261.217877705574860.430788533186806imageEspinoza, Nestor259996.0791695486159996.0792967245365.494600.02800.0SOSS Wavelength and Trace59996.157245321512CAL--POLYGON 261.252730067 60.462646244 261.225210527 60.427087522 261.208743082 60.430229652 261.236230055 60.465796111mast:JWST/product/jw01512008001_03101_00001_nis_trapsfilled.jpgmast:JWST/product/jw01512008001_03101_00001_nis_rateints.fitsPUBLICFalsenan117933750448768210
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDBD+60-1753Star; A dwarfsjw01512005001_03102_00001_nis261.2178777053181360.430788533089505imageEspinoza, Nestor259996.0439243402859996.046467858796164.82600.02800.0SOSS Wavelength and Trace59996.076724541512CAL--POLYGON 261.252773259 60.462635627 261.225208552 60.42708542 261.208745098 60.430232639 261.236277261 60.465790594mast:JWST/product/jw01512005001_03102_00001_nis_trapsfilled.jpgmast:JWST/product/jw01512005001_03102_00001_nis_rateints.fitsPUBLICFalsenan117933680448768234
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDBD+60-1753Star; A dwarfsjw01512009001_03101_00001_nis261.2178777057108660.430788533238406imageEspinoza, Nestor259996.0972198958359996.097347071765.494600.02800.0SOSS Wavelength and Trace59996.157627271512CAL--POLYGON 261.252709233 60.462652119 261.225212518 60.427089101 261.208743059 60.430228659 261.236207195 60.465799408mast:JWST/product/jw01512009001_03101_00001_nis_trapsfilled.jpgmast:JWST/product/jw01512009001_03101_00001_nis_rateints.fitsPUBLICFalsenan117933749448768236
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDBD+60-1753Star; A dwarfsjw01512010001_03102_00001_nis261.217877705861560.430788533295534imageEspinoza, Nestor259996.11599538194459996.11853890046164.82600.02800.0SOSS Wavelength and Trace59996.464699141512CAL--POLYGON 261.252692227 60.462659161 261.225218355 60.427091847 261.208746881 60.43022883 261.236188163 60.465803871mast:JWST/product/jw01512010001_03102_00001_nis_trapsfilled.jpgmast:JWST/product/jw01512010001_03102_00001_nis_rateints.fitsPUBLICFalsenan117933897448768272
...................................................................................................
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDECLIPTIC-RA80Calibration; External flat fieldjw01541005001_02107_00001_nis124.1008916666666819.23126111111111imageEspinoza, Nestor259688.6357691049859688.639372881946300.63600.02800.0NIRISS Sensitivity and Stability for Transiting Exoplanet Observations59774.85416661541COM--POLYGON 124.082255001 19.219349464 124.091099278 19.255547276 124.129643297 19.246978522 124.12082029 19.21078555mast:JWST/product/jw01541005001_02107_00001_nis_trapsfilled.jpgmast:JWST/product/jw01541005001_02107_00001_nis_rateints.fitsPUBLICFalsenan79661711510950742
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDECLIPTIC-RA80Calibration; External flat fieldjw01541005001_02105_00001_nis124.1008916666666819.23126111111111imageEspinoza, Nestor259688.6305772531359688.634181030095300.63600.02800.0NIRISS Sensitivity and Stability for Transiting Exoplanet Observations59774.85416661541COM--POLYGON 124.085148743 19.218701569 124.093993665 19.254899234 124.132537371 19.246329833 124.123713719 19.21013701mast:JWST/product/jw01541005001_02105_00001_nis_trapsfilled.jpgmast:JWST/product/jw01541005001_02105_00001_nis_rateints.fitsPUBLICFalsenan79661727510950785
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDECLIPTIC-RA80Calibration; External flat fieldjw01541005001_0210r_00001_nis124.1008916666666819.23126111111111imageEspinoza, Nestor259688.68771645451559688.69132023148300.63600.02800.0NIRISS Sensitivity and Stability for Transiting Exoplanet Observations59774.85416661541COM--POLYGON 124.07284721 19.21839799 124.081689382 19.25459625 124.120233664 19.246029444 124.111412762 19.209836026mast:JWST/product/jw01541005001_0210r_00001_nis_trapsfilled.jpgmast:JWST/product/jw01541005001_0210r_00001_nis_rateints.fitsPUBLICFalsenan79661746510950838
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDECLIPTIC-RA80Calibration; External flat fieldjw01541005001_0210f_00001_nis124.1008916666666819.23126111111111imageEspinoza, Nestor259688.65653278553559688.6601365625300.63600.02800.0NIRISS Sensitivity and Stability for Transiting Exoplanet Observations59774.85416661541COM--POLYGON 124.078634483 19.217102483 124.087477844 19.253300468 124.126021524 19.244732468 124.117199434 19.208539324mast:JWST/product/jw01541005001_0210f_00001_nis_trapsfilled.jpgmast:JWST/product/jw01541005001_0210f_00001_nis_rateints.fitsPUBLICFalsenan79661763510950882
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDECLIPTIC-RA80Calibration; External flat fieldjw01541005001_0210z_00001_nis124.1008916666666819.23126111111111imageEspinoza, Nestor259688.7084919984959688.71209577546300.63600.02800.0NIRISS Sensitivity and Stability for Transiting Exoplanet Observations59774.85416661541COM--POLYGON 124.069226757 19.216150803 124.078067971 19.252349246 124.116611924 19.243783236 124.10779198 19.207589636mast:JWST/product/jw01541005001_0210z_00001_nis_trapsfilled.jpgmast:JWST/product/jw01541005001_0210z_00001_nis_rateints.fitsPUBLICFalsenan79661781510950927
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDECLIPTIC-RA80Calibration; External flat fieldjw01541005001_0210d_00001_nis124.1008916666666819.23126111111111imageEspinoza, Nestor259688.6513424267459688.6549462037300.63600.02800.0NIRISS Sensitivity and Stability for Transiting Exoplanet Observations59774.85416661541COM--POLYGON 124.077907696 19.214207662 124.086750759 19.250405679 124.125293793 19.241837815 124.116472001 19.205644639mast:JWST/product/jw01541005001_0210d_00001_nis_trapsfilled.jpgmast:JWST/product/jw01541005001_0210d_00001_nis_rateints.fitsPUBLICFalsenan79661804510950976
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDECLIPTIC-RA100Calibration; External flat fieldjw04479007004_02103_00001_nis152.8751666666666711.701697222222222imageEspinoza, Nestor260447.3675141496560447.36888109954107.368600.02800.0SOSS background measurements60447.91789344479CAL--POLYGON 152.843388668 11.698975063 152.857138823 11.733597898 152.892661302 11.719892439 152.878935783 11.685270285mast:JWST/product/jw04479007004_02103_00001_nis_trapsfilled.jpgmast:JWST/product/jw04479007004_02103_00001_nis_rateints.fitsPUBLICFalsenan214679853518313279
scienceJWSTCALJWSTNIRISS/IMAGEJWSTCLEAR;GR700XDINFRAREDECLIPTIC-RA100Calibration; External flat fieldjw04479007004_02101_00001_nis152.8751666666666711.701697222222222imageEspinoza, Nestor260447.36214748298560447.36351443287107.368600.02800.0SOSS background measurements60447.922928174479CAL--POLYGON 152.839912725 11.690334176 152.85366209 11.724957149 152.889183601 11.711252047 152.875458874 11.676629754mast:JWST/product/jw04479007004_02101_00001_nis_trapsfilled.jpgmast:JWST/product/jw04479007004_02101_00001_nis_rateints.fitsPUBLICFalsenan214679854518313473
scienceJWSTCALJWSTNIRISS/SOSSJWSTCLEAR;GR700XDINFRAREDHAT-P-14Star; Exoplanet Systems; Exoplanets; F dwarfs; F starsjw01541-o001_t002_niriss_clear-gr700xd-substrip256260.1161771630844438.242156511096134spectrumEspinoza, Nestor359738.2612162559738.55248649305618855.408600.02800.0NIRISS Sensitivity and Stability for Transiting Exoplanet Observations59774.85416661541COM--POLYGON 260.16190084 38.23723653 260.11337623 38.23744814 260.11348554 38.24618148 260.16201952 38.24596704 260.16190084 38.23723653--mast:JWST/product/jw01541-o001_t002_niriss_clear-gr700xd-substrip256_x1dints.fitsPUBLICFalsenan213209384519972339
scienceJWSTCALJWSTNIRISS/SOSSJWSTCLEAR;GR700XDINFRAREDHAT-P-14Star; Exoplanet Systems; Exoplanets; F dwarfs; F starsjw01541001001_04102_00001-seg001_nis260.116177163368638.242156510427485imageEspinoza, Nestor259738.5539086689859738.55835982639329.64600.02800.0NIRISS Sensitivity and Stability for Transiting Exoplanet Observations59774.85416661541COM--POLYGON 260.071030426 38.2494554 260.119367245 38.246686364 260.11850644 38.23799955 260.070173177 38.240758867mast:JWST/product/jw01541001001_04102_00001-seg001_nis_ramp.jpgmast:JWST/product/jw01541001001_04102_00001-seg001_nis_rateints.fitsPUBLICFalsenan85700205541167861

Our query returned many NIRISS observations led by the PI Dr. Espinoza. Let’s get all the unique values under the instrument_name column to see what our * wildcard picked up.

set(observations['instrument_name'])
{np.str_('NIRISS/IMAGE'), np.str_('NIRISS/SOSS')}

Our observations have the advanced labeling; had we simply set instrument_name = "NIRISS", we would have missed several observations. For more details on this advanced labeling, see the JWST Instrument Names page.

A note of caution: There is such a thing as too many wildcards#

You can be too generous with the wildcards, so be sure to exercise caution in their use. Too much ambiguity can lead to unintended results. Let’s take a look at our example below.

observations = Observations.query_criteria(proposal_pi='Espinoza, Nestor',
                                           instrument_name='NIR*') # Surely only one instrument begins with 'NIR'
set(observations['instrument_name'])
{np.str_('NIRISS/IMAGE'), np.str_('NIRISS/SOSS'), np.str_('NIRSPEC/SLIT')}

This query returns NIRSPEC/SLIT observations in addition to the NIRISS ones, which is not what we intended.

Case 2: Wildcard Search with instrument_name and proposal_id#

Let’s add an additional string criterion and wildcard into the mix. We’ll do this with the proposal_id field which, despite its numeric content, is encoded as a string.

Let’s query for a four digit proposal/program IDs that begin with 15.

observations = Observations.query_criteria(proposal_pi='Espinoza, Nestor',
                                           instrument_name='NIRISS*',
                                           proposal_id=['15%%']) # Only a four digit result will match this

set(observations['proposal_id']), set(observations['instrument_name'])
({np.str_('1512'), np.str_('1541')},
 {np.str_('NIRISS/IMAGE'), np.str_('NIRISS/SOSS')})

Resources#

The following is a list of resources that were referenced throughout the tutorial, as well as some additional references that you may find useful:

Citations#

If you use any of astroquery’s tools for published research, please cite the authors. Follow this link for more information about citing astroquery:

About This Notebook#

If you have comments or questions on this notebook, please contact us through the Archive Help Desk e-mail at archive@stsci.edu.

Author: Jenny V. Medina
Keywords: astroquery, wildcards, moving target
Last Updated: Jun 2023