Skip to content

Commit 3d3dd0d

Browse files
authored
Merge pull request #2736 from mstcyr2/mast-docs-errorHandlingExamples
Adding error handling examples to mast docs
2 parents 748b5f1 + 1f10a03 commit 3d3dd0d

File tree

1 file changed

+88
-11
lines changed

1 file changed

+88
-11
lines changed

docs/mast/mast.rst

Lines changed: 88 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ Radius is an optional parameter and the default is 0.2 degrees.
8181
science SPITZER_SHA SSC Pipeline ... nan 19000016510 0.0
8282
science SPITZER_SHA SSC Pipeline ... nan 19000016510 0.0
8383

84+
Optional parameters must be labeled. For example the query above will produce
85+
an error if the "radius" field is not specified.
86+
87+
.. doctest-remote-data::
88+
89+
>>> obs_table = Observations.query_object("M8", ".02 deg")
90+
Traceback (most recent call last):
91+
...
92+
TypeError: ObservationsClass.query_object_async() takes 2 positional arguments but 3 were given
93+
8494

8595
Observation Criteria Queries
8696
----------------------------
@@ -210,6 +220,17 @@ To get a table of metadata associated with observation or product lists use the
210220
obsID Product Group ID ... Long integer, e.g. 2007590987
211221
obs_collection Mission ... HST, HLA, SWIFT, GALEX, Kepler, K2...
212222

223+
The `~astroquery.mast.ObservationsClass.get_metadata` function only accepts the strings
224+
"observations" or "products" as a parameter. Any other string or spelling will result
225+
in an error.
226+
227+
.. doctest-remote-data::
228+
229+
>>> meta_table = Observations.get_metadata("observation")
230+
Traceback (most recent call last):
231+
...
232+
astroquery.exceptions.InvalidQueryError: Unknown query type.
233+
213234

214235
Downloading Data
215236
================
@@ -391,6 +412,25 @@ which can be changed with the ``local_path`` keyword argument.
391412
>>> print(result)
392413
('COMPLETE', None, None)
393414

415+
The `~astroquery.mast.ObservationsClass.download_file` and `~astroquery.mast.ObservationsClass.download_products`
416+
methods are not interchangeable. Using the incorrect method for either single files or product lists will result
417+
in an error.
418+
419+
.. doctest-remote-data::
420+
421+
>>> result = Observations.download_products(product) # doctest: +IGNORE_OUTPUT
422+
Traceback (most recent call last):
423+
...
424+
RemoteServiceError: Error converting data type varchar to bigint.
425+
426+
.. doctest-remote-data::
427+
428+
>>> result = Observations.download_file(data_products)
429+
Traceback (most recent call last):
430+
...
431+
TypeError: can only concatenate str (not "Table") to str
432+
433+
394434
Cloud Data Access
395435
------------------
396436
Public datasets from the Hubble, Kepler and TESS telescopes are also available for free on Amazon Web Services
@@ -809,6 +849,22 @@ The TESS Input Catalog (TIC), Disk Detective Catalog, and PanSTARRS Catalog can
809849
J170314.11-035210.4 ... https://talk.diskdetective.org/#/subjects/AWI0005ckv
810850

811851

852+
The `~astroquery.mast.CatalogsClass.query_criteria` function requires at least one non-positional parameter.
853+
These parameters are the column names listed in the `field descriptions <https://mast.stsci.edu/api/v0/pages.html>`__
854+
of the catalog being queried. They do not include objectname, coordinates, or radius. Running a query with only positional
855+
parameters will result in an error.
856+
857+
.. doctest-remote-data::
858+
859+
>>> from astroquery.mast import Catalogs
860+
...
861+
>>> catalog_data = Catalogs.query_criteria(catalog="Tic",
862+
... objectname='M101', radius=1)
863+
Traceback (most recent call last):
864+
...
865+
astroquery.exceptions.InvalidQueryError: At least one non-positional criterion must be supplied.
866+
867+
812868
The PanSTARRS catalog also accepts additional parameters to allow for query refinement. These options include column selection,
813869
sorting, column criteria, page size and page number. Additional information on PanSTARRS queries may be found
814870
`here <https://catalogs.mast.stsci.edu/docs/panstarrs.html>`__.
@@ -871,6 +927,7 @@ Given an HSC Match ID, return all catalog results.
871927
410574498 63980492 ... -1.10056e-005 1.56577e-009 1.56577e-009 1.10056e-005
872928
410574497 63980492 ... -1.10056e-005 1.56577e-009 1.56577e-009 1.10056e-005
873929

930+
874931
HSC spectra accessed through this class as well. `~astroquery.mast.CatalogsClass.get_hsc_spectra`
875932
does not take any arguments, and simply loads all HSC spectra.
876933

@@ -921,7 +978,7 @@ TESSCut
921978
=======
922979

923980
TESSCut is MAST's tool to provide full-frame image (FFI) cutouts from the Transiting
924-
Exoplanet Survey Satellite (TESS). The cutouts can be made from either the Science
981+
Exoplanet Survey Satellite (TESS). The cutouts can be made from either the Science
925982
Processing Operation's Center (`SPOC <https://archive.stsci.edu/missions-and-data/tess>`__) FFI products,
926983
or the TESS Image CAlibrator (`TICA <https://archive.stsci.edu/hlsp/tica>`__) high-level science products.
927984
Cutouts from the TICA products are not available for sectors 1-26,
@@ -958,7 +1015,7 @@ Requesting a cutout by coordinate or objectname accesses the
9581015
`MAST TESScut API <https://mast.stsci.edu/tesscut/docs/getting_started.html#requesting-a-cutout>`__
9591016
and returns a target pixel file, with format described
9601017
`here <https://astrocut.readthedocs.io/en/latest/astrocut/file_formats.html#target-pixel-files>`__.
961-
Note that the product argument will default to request for SPOC cutouts when
1018+
Note that the product argument will default to request for SPOC cutouts when
9621019
not explicitly called for TICA.
9631020

9641021
.. doctest-remote-data::
@@ -975,8 +1032,9 @@ not explicitly called for TICA.
9751032
1 PIXELS 1 BinTableHDU 280 1196R x 12C [D, E, J, 25J, 25E, 25E, 25E, 25E, J, E, E, 38A]
9761033
2 APERTURE 1 ImageHDU 81 (5, 5) int32
9771034

978-
For users with time-sensitive targets who would like cutouts from the latest observations,
979-
we recommend requesting for the TICA product. Using the same target from the example above,
1035+
1036+
For users with time-sensitive targets who would like cutouts from the latest observations,
1037+
we recommend requesting for the TICA product. Using the same target from the example above,
9801038
this example shows a request for TICA cutouts:
9811039

9821040
.. doctest-remote-data::
@@ -1028,16 +1086,16 @@ simply with either the objectname or coordinates.
10281086
2 APERTURE 1 ImageHDU 97 (2136, 2078) int32
10291087

10301088
Note that the moving targets functionality does not currently support TICA, so the product
1031-
parameter will always default to SPOC.
1089+
parameter will result in an error when set to 'TICA'.
10321090

10331091
.. doctest-remote-data::
10341092

10351093
>>> from astroquery.mast import Tesscut
10361094
...
10371095
>>> hdulist = Tesscut.get_cutouts(objectname="Eleonora", product='tica', moving_target=True, size=5, sector=6)
1038-
WARNING: InputWarning: Only SPOC is available for moving targets queries. Defaulting to SPOC. [astroquery.mast.cutouts]
1039-
>>> hdulist[0][0].header['FFI_TYPE'] # doctest: +IGNORE_OUTPUT
1040-
'SPOC'
1096+
Traceback (most recent call last):
1097+
...
1098+
astroquery.exceptions.InvalidQueryError: Only SPOC is available for moving targets queries.
10411099

10421100
The `~astroquery.mast.TesscutClass.download_cutouts` function takes a product type ("TICA" or "SPOC", but defaults to "SPOC"),
10431101
coordinate, cutout size (in pixels or an angular quantity), or object name (e.g. "M104" or "TIC 32449963") and moving target
@@ -1098,8 +1156,8 @@ To access sector information for a particular coordinate, object, or moving targ
10981156
tess-s0008-1-1 8 1 1
10991157
tess-s0034-1-2 34 1 2
11001158

1101-
Note that because of the delivery cadence of the
1102-
TICA high level science products, later sectors will be available sooner with TICA than with
1159+
Note that because of the delivery cadence of the
1160+
TICA high level science products, later sectors will be available sooner with TICA than with
11031161
SPOC. Also note that TICA is not available for sectors 1-26. The following example is the same
11041162
query as above, but for TICA. Notice that products for sector 8 are no longer available,
11051163
but are now available for sector 61.
@@ -1152,7 +1210,6 @@ so the query will always default to SPOC.
11521210
>>> from astroquery.mast import Tesscut
11531211
...
11541212
>>> sector_table = Tesscut.get_sectors(objectname="Ceres", moving_target=True)
1155-
WARNING: InputWarning: Only SPOC is available for moving targets queries. Defaulting to SPOC. [astroquery.mast.cutouts]
11561213
>>> print(sector_table)
11571214
sectorName sector camera ccd
11581215
-------------- ------ ------ ---
@@ -1390,6 +1447,26 @@ The basic MAST query function returns query results as an `~astropy.table.Table`
13901447
Length = 77 rows
13911448

13921449

1450+
Many mast services, specifically JWST and Catalog services, require the two principal keywords, 'columns' and 'filters',
1451+
to list parameters. Positional services will also require right ascension and declination parameters, either in
1452+
addition to columns and filters or on their own. For example, the cone search service only requires the 'ra' and
1453+
'dec' parameters. Using the wrong service parameters will result in an error. Read the
1454+
`MAST API services documentation <https://mast.stsci.edu/api/v0/_services.html>`__ for more information on valid
1455+
service parameters.
1456+
1457+
.. doctest-remote-data::
1458+
1459+
>>> from astroquery.mast import Mast
1460+
...
1461+
>>> service = 'Mast.Caom.Cone'
1462+
>>> params = {'columns': "*",
1463+
... 'filters': {}}
1464+
>>> observations = Mast.service_request(service, params)
1465+
Traceback (most recent call last):
1466+
...
1467+
astroquery.exceptions.RemoteServiceError: Request Object is Missing Required Parameter : RA
1468+
1469+
13931470
If the output is not the MAST json result type it cannot be properly parsed into a `~astropy.table.Table`.
13941471
In this case, the async method should be used to get the raw http response, which can then be manually parsed.
13951472

0 commit comments

Comments
 (0)