Skip to content

Commit d79c9b3

Browse files
committed
Docs
1 parent 8b6620e commit d79c9b3

5 files changed

Lines changed: 78 additions & 35 deletions

File tree

astroquery/mast/missions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,8 @@ def read_product(self, uri, *, mission=None, **kwargs):
998998
The mission to which the file belongs. If not provided, the current value of the ``mission`` attribute
999999
will be used.
10001000
**kwargs
1001-
Additional keyword arguments to be passed to the file reading function (e.g., `astropy.io.fits.open`
1002-
or `asdf.open`).
1001+
Additional keyword arguments to be passed to the file reading function (e.g., `~astropy.io.fits.open`
1002+
or `~asdf.open`).
10031003
"""
10041004
# Construct the full data URL based on mission
10051005
download_url = self._get_download_url(uri, mission=mission)

astroquery/mast/tests/test_mast_remote.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
)
3333
from ..utils import ResolverError
3434

35+
try:
36+
import asdf
37+
except ImportError:
38+
asdf = None
39+
3540

3641
@pytest.fixture(scope="module")
3742
def msa_product_table():
@@ -432,7 +437,7 @@ def test_missions_read_product_fits(self, uri, mission):
432437
('jwst', {'fileSetName': 'jw01189001001_02101_00001'}),
433438
('classy', {'Target': 'J0021+0052'}),
434439
('ullyses', {'host_galaxy_name': 'WLM', 'select_cols': ['observation_id']}),
435-
('roman', {'program': 3, 'pass_id': 1}),
440+
('roman', {'program': 163}),
436441
('iue', {'iue_data_id': 'LWR08496'}),
437442
])
438443
def test_missions_workflow(self, tmp_path, mission, query_params):
@@ -461,6 +466,17 @@ def test_missions_workflow(self, tmp_path, mission, query_params):
461466
if row['Status'] == 'COMPLETE':
462467
assert (row['Local Path']).is_file()
463468

469+
# Read a product
470+
product = None
471+
for prod in prods:
472+
if prod['filename'].endswith(('.fits', '.asdf')):
473+
product = prod
474+
break
475+
obj = m.read_product(product['uri'], mission=mission)
476+
if mission == 'roman' and asdf is not None:
477+
assert isinstance(obj, asdf.AsdfFile)
478+
assert isinstance(obj, fits.HDUList)
479+
464480
###################
465481
# MastClass tests #
466482
###################

docs/conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
# See astropy.sphinx.conf for which values are set there.
1313

1414
import datetime
15-
import os
1615
import sys
17-
import tomllib
1816
from pathlib import Path
1917

18+
import tomllib
19+
2020
# Load all of the global Astropy configuration
2121
try:
2222
from sphinx_astropy.conf.v1 import * # noqa
@@ -56,6 +56,7 @@
5656
'regions': ('https://astropy-regions.readthedocs.io/en/stable', None),
5757
'mocpy': ('https://cds-astro.github.io/mocpy', None),
5858
'pyvo': ('https://pyvo.readthedocs.io/en/stable', None),
59+
'asdf': ('https://asdf.readthedocs.io/en/stable/', None),
5960
})
6061

6162
# -- Project information ------------------------------------------------------

docs/mast/mast_missions.rst

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Mission-Specific Queries
44
************************
55

6-
The `~astroquery.mast.MastMissionsClass` class allows for search queries based on mission-specific
6+
The `~astroquery.mast.MastMissionsClass` class allows for search queries based on mission-specific
77
metadata for a given data collection. This metadata includes header keywords, proposal information, and observational parameters.
88
The following missions/products are currently available for search:
99

@@ -49,12 +49,12 @@ To search for JWST metadata, the ``mission`` attribute is reassigned to ``'JWST'
4949
Querying Missions
5050
==================
5151

52-
The MastMissions interface provides three closely related query methods. All three methods return results as an `~astropy.table.Table`
53-
and all three support column-based filtering, sorting, and result limiting. The primary difference between them is how positional
52+
The MastMissions interface provides three closely related query methods. All three methods return results as an `~astropy.table.Table`
53+
and all three support column-based filtering, sorting, and result limiting. The primary difference between them is how positional
5454
constraints are specified.
5555

5656
At a high level:
57-
- `~astroquery.mast.MastMissionsClass.query_criteria` is the most flexible method. It supports purely column-based queries,
57+
- `~astroquery.mast.MastMissionsClass.query_criteria` is the most flexible method. It supports purely column-based queries,
5858
purely positional queries, or a combination of both.
5959

6060
- `~astroquery.mast.MastMissionsClass.query_region` is a convenience wrapper for positional queries using coordinates.
@@ -78,7 +78,7 @@ using the `~astroquery.mast.MastMissionsClass.get_column_list` method.
7878

7979
Keyword arguments can also be used to refine results further. The following parameters are available:
8080

81-
- ``radius``: For positional searches only. Only return results within a certain distance from an object or set of coordinates.
81+
- ``radius``: For positional searches only. Only return results within a certain distance from an object or set of coordinates.
8282
Default is 3 arcminutes.
8383

8484
- ``limit``: The maximum number of results to return. Default is 5000.
@@ -99,25 +99,25 @@ Writing Queries
9999
----------------
100100

101101
The `~astroquery.mast.MastMissionsClass.query_criteria` method supports both positional parameters and column-based filters.
102-
Positional constraints are optional.
102+
Positional constraints are optional.
103103

104104
Supported positional parameters include:
105105

106106
- ``coordinates`` : Sky coordinates around which to perform a cone search.
107107
- ``object_name`` : Name(s) of the object(s) around which to perform a cone search.
108108
- ``resolver`` : Resolver service to use for object name resolution.
109-
- ``radius`` : Radius of the cone searches around the specified coordinates or object names. Can be defined as an `~astropy.units.Quantity`,
109+
- ``radius`` : Radius of the cone searches around the specified coordinates or object names. Can be defined as an `~astropy.units.Quantity`,
110110
a string with units (e.g., ``"10 arcsec"``), or a numeric value interpreted as degrees.
111111

112-
Multiple coordinates or objects may be queried in a single request. The ``coordinates`` and ``object_names`` parameters
112+
Multiple coordinates or objects may be queried in a single request. The ``coordinates`` and ``object_names`` parameters
113113
accept a single value, an iterable of values, or a comma-separated string. When multiple values are provided for either parameter,
114114
results matching *any* of the supplied positions are returned.
115115

116116
.. doctest-remote-data::
117117

118118
>>> from astropy.coordinates import SkyCoord
119119
>>> select_cols = ["sci_targname", "sci_pep_id", "sci_status"]
120-
>>> results = missions.query_criteria(coordinates=[SkyCoord(245.89675, -26.52575, unit='deg'), "205.54842 28.37728"],
120+
>>> results = missions.query_criteria(coordinates=[SkyCoord(245.89675, -26.52575, unit='deg'), "205.54842 28.37728"],
121121
... object_names=["M2", "M9"],
122122
... radius=0.1,
123123
... select_cols=select_cols,
@@ -168,13 +168,13 @@ Criteria syntax supports several operations:
168168

169169
- For numeric or date columns, select an inclusive range with the syntax ``'#..#'``.
170170

171-
- Wildcards are special characters used in search patterns to represent one or more unknown characters,
171+
- Wildcards are special characters used in search patterns to represent one or more unknown characters,
172172
allowing for flexible matching of strings. The wildcard character is ``*`` and it replaces any number
173173
of characters preceding, following, or in between existing characters, depending on its placement.
174174

175175
.. note::
176176

177-
For the Roman mission, query methods also support the ``pass_id`` parameter as an alias for the ``pass`` column,
177+
For the Roman mission, query methods also support the ``pass_id`` parameter as an alias for the ``pass`` column,
178178
which refers to a single iteration of a pass plan. This is to avoid conflicts with the reserved Python keyword.
179179

180180
.. doctest-remote-data::
@@ -196,7 +196,7 @@ Criteria syntax supports several operations:
196196
N4A702010 GAL-CLUS-0026+1653-ARCC F110W IMAGE
197197
N4A705010 GAL-CLUS-0026+1653-ARCC F110W IMAGE
198198

199-
The `~astroquery.mast.MastMissionsClass.query_region` and `~astroquery.mast.MastMissionsClass.query_object` methods are
199+
The `~astroquery.mast.MastMissionsClass.query_region` and `~astroquery.mast.MastMissionsClass.query_object` methods are
200200
convenience wrappers around `~astroquery.mast.MastMissionsClass.query_criteria`:
201201

202202
- `~astroquery.mast.MastMissionsClass.query_region` requires ``coordinates``.
@@ -209,7 +209,7 @@ Both methods also accept column-based criteria, which are applied in the same wa
209209

210210
>>> regionCoords = SkyCoord(210.80227, 54.34895, unit=('deg', 'deg'))
211211
>>> select_cols = ["sci_stop_time", "sci_targname", "sci_start_time", "sci_status"]
212-
>>> results = missions.query_region(regionCoords,
212+
>>> results = missions.query_region(regionCoords,
213213
... radius=3,
214214
... sci_pep_id=12556,
215215
... select_cols=select_cols,
@@ -226,8 +226,8 @@ Both methods also accept column-based criteria, which are applied in the same wa
226226

227227
.. doctest-remote-data::
228228

229-
>>> results = missions.query_object('M101',
230-
... radius=3,
229+
>>> results = missions.query_object('M101',
230+
... radius=3,
231231
... select_cols=select_cols,
232232
... sort_by='sci_targname')
233233
>>> results[:5] # doctest: +IGNORE_OUTPUT
@@ -248,11 +248,11 @@ Getting Product Lists
248248
----------------------
249249

250250
Each observation returned from a MAST query can have one or more associated data products. Given
251-
one or more datasets or dataset IDs, the `~astroquery.mast.MastMissionsClass.get_product_list` function
251+
one or more datasets or dataset IDs, the `~astroquery.mast.MastMissionsClass.get_product_list` function
252252
will return a `~astropy.table.Table` containing the associated data products.
253253

254-
`~astroquery.mast.MastMissionsClass.get_product_list` also includes an optional ``batch_size`` parameter,
255-
which controls how many datasets are sent to the MAST service per request. This can be useful for managing
254+
`~astroquery.mast.MastMissionsClass.get_product_list` also includes an optional ``batch_size`` parameter,
255+
which controls how many datasets are sent to the MAST service per request. This can be useful for managing
256256
memory usage or avoiding timeouts when requesting product lists for large numbers of datasets.
257257
If not provided, batch_size defaults to 1000.
258258

@@ -262,7 +262,7 @@ If not provided, batch_size defaults to 1000.
262262
... sci_hlsp='>1')
263263
>>> products = missions.get_product_list(datasets[:2], batch_size=1000)
264264
>>> print(products[:5]) # doctest: +IGNORE_OUTPUT
265-
product_key access dataset ... category size type
265+
product_key access dataset ... category size type
266266
---------------------------- ------ --------- ... ---------- --------- -------
267267
JBTAA0010_jbtaa0010_asn.fits PUBLIC JBTAA0010 ... AUX 11520 science
268268
JBTAA0010_jbtaa0010_drz.fits PUBLIC JBTAA0010 ... CALIBRATED 214655040 science
@@ -298,8 +298,8 @@ and any other of the product fields.
298298
The **AND** operation is applied between filters, and the **OR** operation is applied within each filter set, except in the case of negated values.
299299

300300
A filter value can be negated by prefiing it with ``!``, meaning that rows matching that value will be excluded from the results.
301-
When any negated value is present in a filter set, any positive values in that set are combined with **OR** logic, and the negated
302-
values are combined with **AND** logic against the positives.
301+
When any negated value is present in a filter set, any positive values in that set are combined with **OR** logic, and the negated
302+
values are combined with **AND** logic against the positives.
303303

304304
For example:
305305
- ``file_suffix=['A', 'B', '!C']`` → (file_suffix != C) AND (file_suffix == A OR file_suffix == B)
@@ -318,28 +318,53 @@ The filter below returns FITS products that are "science" type **and** less than
318318
>>> filtered = missions.filter_products(products,
319319
... extension='fits',
320320
... type='science',
321-
... size='<=20000',
321+
... size='<=20000',
322322
... file_suffix=['ASN', 'JIF'])
323323
>>> print(filtered) # doctest: +IGNORE_OUTPUT
324-
product_key access dataset ... category size type
324+
product_key access dataset ... category size type
325325
---------------------------- ------ --------- ... -------------- ----- -------
326326
JBTAA0010_jbtaa0010_asn.fits PUBLIC JBTAA0010 ... AUX 11520 science
327327
JBTAA0020_jbtaa0020_asn.fits PUBLIC JBTAA0020 ... AUX 11520 science
328328

329329

330+
Reading Data Products
331+
======================
332+
333+
The `~astroquery.mast.MastMissionsClass.read_product` function allows you to read a data product directly into memory as an `~astropy.io.fits.HDUList`
334+
or an `~asdf.AsdfFile` object. The function accepts a product URI or a direct filename (for certain missions) as input.
335+
336+
Products from the Roman Space Telescope mission are returned as ASDF files and can be read into memory as `~asdf.AsdfFile` objects.
337+
This requires the `~asdf` and ``fsspec`` packages to be installed. Other optional packages for reading products may be required depending on the product
338+
type and file format. These packages are ``gwcs``, ``lz4``, and ``roman_datamodels``. To install astroquery with all optional dependencies,
339+
use ``pip install astroquery[all]``.
340+
341+
Remember that this method returns an open file object, so it is the user's responsibility to close the file when finished. This can be done
342+
with a context manager or by calling the ``close()`` method on the returned object.
343+
344+
.. doctest-remote-data::
345+
>>> obj = missions.read_product("jbtaa0010_asn.fits") # doctest: +IGNORE_OUTPUT
346+
>>> print(type(obj))
347+
<class 'astropy.io.fits.hdu.hdulist.HDUList'>
348+
>>> obj.info() # doctest: +IGNORE_OUTPUT
349+
Filename: /Users/user/.astropy/cache/download/url/6555b8e890752df0de737940d3afb19d/contents
350+
No. Name Ver Type Cards Dimensions Format
351+
0 PRIMARY 1 PrimaryHDU 44 ()
352+
1 ASN 1 BinTableHDU 25 3R x 3C [14A, 14A, L]
353+
>>> obj.close()
354+
330355
Downloding Data
331356
===============
332357

333358
Downloading Data Products
334359
-------------------------
335360

336-
The `~astroquery.mast.MastMissionsClass.download_products` function accepts a table of products like the one above
337-
and will download the products to your local machine. Products may also be provided as dataset IDs with product filters,
361+
The `~astroquery.mast.MastMissionsClass.download_products` function accepts a table of products like the one above
362+
and will download the products to your local machine. Products may also be provided as dataset IDs with product filters,
338363
or as JSON product metadata sent by the MAST subscription service (either as a local JSON file or as in-memory data).
339364

340365
By default, products will be downloaded into the current working directory, in a subdirectory called ``mastDownload``.
341-
The full local filepaths will have the form ``mastDownload/<mission>/<Dataset ID>/file.`` You can change the download
342-
directory using the ``download_dir`` parameter. If ``flat=True`` is specified, all files will be downloaded directly into the
366+
The full local filepaths will have the form ``mastDownload/<mission>/<Dataset ID>/file.`` You can change the download
367+
directory using the ``download_dir`` parameter. If ``flat=True`` is specified, all files will be downloaded directly into the
343368
``download_dir`` without any subdirectories.
344369

345370
.. doctest-remote-data::
@@ -349,14 +374,14 @@ directory using the ``download_dir`` parameter. If ``flat=True`` is specified, a
349374
Downloading URL https://mast.stsci.edu/search/hst/api/v0.1/retrieve_product?product_name=JBTAA0020%2Fjbtaa0020_asn.fits to mastDownload/hst/JBTAA0020/jbtaa0020_asn.fits ... [Done]
350375
Downloading URL https://mast.stsci.edu/search/hst/api/v0.1/retrieve_product?product_name=JBTAA0020%2Fjbtaa0020_jif.fits to mastDownload/hst/JBTAA0020/jbtaa0020_jif.fits ... [Done]
351376
>>> print(manifest) # doctest: +IGNORE_OUTPUT
352-
Local Path Status Message URL
377+
Local Path Status Message URL
353378
--------------------------------------------- -------- ------- ----
354379
mastDownload/hst/JBTAA0010/jbtaa0010_asn.fits COMPLETE None None
355380
mastDownload/hst/JBTAA0010/jbtaa0010_jif.fits COMPLETE None None
356381
mastDownload/hst/JBTAA0020/jbtaa0020_asn.fits COMPLETE None None
357382
mastDownload/hst/JBTAA0020/jbtaa0020_jif.fits COMPLETE None None
358383

359-
The function also accepts dataset IDs and product filters as input for a more streamlined workflow.
384+
The function also accepts dataset IDs and product filters as input for a more streamlined workflow.
360385

361386
.. doctest-remote-data::
362387
>>> missions.download_products(['JBTAA0010', 'JBTAA0020'],
@@ -374,7 +399,7 @@ Downloading a Single File
374399
To download a single data product file, use the `~astroquery.mast.MastMissionsClass.download_file` function with
375400
a MAST URI as input. Some missions (e.g., HST, JWST) accept direct filenames as input, but others require a fully-qualified ``mast:`` URI.
376401

377-
The default is to download the file to the current working directory, but you can specify the download directory or filepath with
402+
The default is to download the file to the current working directory, but you can specify the download directory or filepath with
378403
the ``local_path`` keyword argument.
379404

380405
.. doctest-remote-data::

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ docs = [
5454
"sphinx-astropy>=1.5",
5555
"scipy",
5656
"fsspec[http]",
57+
"asdf"
5758
]
5859
all = [
5960
"mocpy>=0.12",

0 commit comments

Comments
 (0)