Skip to content

Pass in resolver name to MAST query functions #3292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ utils.tap
- The method ``upload_table`` accepts file formats accepted by astropy's
``Table.read()``. [#3295]

mast
^^^^

- Added ``resolver`` parameter to query methods to specify the resolver to use when resolving object names to coordinates. [#3292]

- Added ``resolve_all`` parameter to ``MastClass.resolve_object`` to resolve object names and return
coordinates for all available resolvers. [#3292]


Infrastructure, Utility and Other Changes and Additions
-------------------------------------------------------
Expand Down
22 changes: 17 additions & 5 deletions astroquery/mast/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def query_region_async(self, coordinates, *, radius=0.2*u.deg, catalog="Hsc",

@class_or_instance
def query_object_async(self, objectname, *, radius=0.2*u.deg, catalog="Hsc",
pagesize=None, page=None, version=None, **criteria):
pagesize=None, page=None, version=None, resolver=None, **criteria):
"""
Given an object name, returns a list of catalog entries.
See column documentation for specific catalogs `here <https://mast.stsci.edu/api/v0/pages.html>`__.
Expand All @@ -316,11 +316,16 @@ def query_object_async(self, objectname, *, radius=0.2*u.deg, catalog="Hsc",
Can be used to override the default pagesize for (set in configs) this query only.
E.g. when using a slow internet connection.
page : int, optional
Defaulte None.
Default None.
Can be used to override the default behavior of all results being returned
to obtain a specific page of results.
version : int, optional
Version number for catalogs that have versions. Default is highest version.
resolver : str, optional
The resolver to use when resolving a named target into coordinates. Valid options are "SIMBAD" and "NED".
If not specified, the default resolver order will be used. Please see the
`STScI Archive Name Translation Application (SANTA) <https://mastresolver.stsci.edu/Santa-war/>`__
for more information. Default is None.
**criteria
Catalog-specific keyword args.
These can be found in the `service documentation <https://mast.stsci.edu/api/v0/_services.html>`__.
Expand All @@ -339,7 +344,7 @@ def query_object_async(self, objectname, *, radius=0.2*u.deg, catalog="Hsc",
response : list of `~requests.Response`
"""

coordinates = utils.resolve_object(objectname)
coordinates = utils.resolve_object(objectname, resolver=resolver)

return self.query_region_async(coordinates,
radius=radius,
Expand All @@ -350,7 +355,7 @@ def query_object_async(self, objectname, *, radius=0.2*u.deg, catalog="Hsc",
**criteria)

@class_or_instance
def query_criteria_async(self, catalog, *, pagesize=None, page=None, **criteria):
def query_criteria_async(self, catalog, *, pagesize=None, page=None, resolver=None, **criteria):
"""
Given an set of filters, returns a list of catalog entries.
See column documentation for specific catalogs `here <https://mast.stsci.edu/api/v0/pages.html>`__.
Expand All @@ -365,6 +370,11 @@ def query_criteria_async(self, catalog, *, pagesize=None, page=None, **criteria)
page : int, optional
Can be used to override the default behavior of all results being returned to obtain
one specific page of results.
resolver : str, optional
The resolver to use when resolving a named target into coordinates. Valid options are "SIMBAD" and "NED".
If not specified, the default resolver order will be used. Please see the
`STScI Archive Name Translation Application (SANTA) <https://mastresolver.stsci.edu/Santa-war/>`__
for more information. Default is None.
**criteria
Criteria to apply. At least one non-positional criteria must be supplied.
Valid criteria are coordinates, objectname, radius (as in `query_region` and `query_object`),
Expand Down Expand Up @@ -395,7 +405,9 @@ def query_criteria_async(self, catalog, *, pagesize=None, page=None, **criteria)
radius = criteria.pop('radius', 0.2*u.deg)

if objectname or coordinates:
coordinates = utils.parse_input_location(coordinates, objectname)
coordinates = utils.parse_input_location(coordinates=coordinates,
objectname=objectname,
resolver=resolver)

# if radius is just a number we assume degrees
radius = coord.Angle(radius, u.deg)
Expand Down
21 changes: 17 additions & 4 deletions astroquery/mast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,31 @@ def disable_cloud_dataset(self):
"""
pass

def resolve_object(self, objectname):
def resolve_object(self, objectname, *, resolver=None, resolve_all=False):
"""
Resolves an object name to a position on the sky.

Parameters
----------
objectname : str
Name of astronomical object to resolve.
resolver : str, optional
The resolver to use when resolving a named target into coordinates. Valid options are "SIMBAD" and "NED".
If not specified, the default resolver order will be used. Please see the
`STScI Archive Name Translation Application (SANTA) <https://mastresolver.stsci.edu/Santa-war/>`__
for more information. If ``resolve_all`` is True, this parameter will be ignored. Default is None.
resolve_all : bool, optional
If True, will try to resolve the object name using all available resolvers ("NED", "SIMBAD").
Function will return a dictionary where the keys are the resolver names and the values are the
resolved coordinates. Default is False.

Returns
-------
response : `~astropy.coordinates.SkyCoord`
The sky position of the given object.
response : `~astropy.coordinates.SkyCoord`, dict
If ``resolve_all`` is False, returns a `~astropy.coordinates.SkyCoord` object with the resolved coordinates.
If ``resolve_all`` is True, returns a dictionary where the keys are the resolver names and the values are
`~astropy.coordinates.SkyCoord` objects with the resolved coordinates.
"""
return utils.resolve_object(objectname)
return utils.resolve_object(objectname,
resolver=resolver,
resolve_all=resolve_all)
44 changes: 33 additions & 11 deletions astroquery/mast/cutouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(self):
self._service_api_connection.set_service_params(services, "tesscut")

def get_sectors(self, *, coordinates=None, radius=0*u.deg, product='SPOC', objectname=None,
moving_target=False, mt_type=None):
moving_target=False, mt_type=None, resolver=None):
"""
Get a list of the TESS data sectors whose footprints intersect
with the given search area.
Expand Down Expand Up @@ -152,6 +152,11 @@ def get_sectors(self, *, coordinates=None, radius=0*u.deg, product='SPOC', objec
first majorbody is tried and then smallbody if a matching majorbody is not found.

NOTE: If moving_target is supplied, this argument is ignored.
resolver : str, optional
The resolver to use when resolving a named target into coordinates. Valid options are "SIMBAD" and "NED".
If not specified, the default resolver order will be used. Please see the
`STScI Archive Name Translation Application (SANTA) <https://mastresolver.stsci.edu/Santa-war/>`__
for more information. Default is None.

Returns
-------
Expand Down Expand Up @@ -187,7 +192,9 @@ def get_sectors(self, *, coordinates=None, radius=0*u.deg, product='SPOC', objec
else:

# Get Skycoord object for coordinates/object
coordinates = parse_input_location(coordinates, objectname)
coordinates = parse_input_location(coordinates=coordinates,
objectname=objectname,
resolver=resolver)

# If radius is just a number we assume degrees
radius = Angle(radius, u.deg)
Expand Down Expand Up @@ -223,7 +230,8 @@ def get_sectors(self, *, coordinates=None, radius=0*u.deg, product='SPOC', objec
return Table(sector_dict)

def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SPOC', path=".",
inflate=True, objectname=None, moving_target=False, mt_type=None, verbose=False):
inflate=True, objectname=None, moving_target=False, mt_type=None, resolver=None,
verbose=False):
"""
Download cutout target pixel file(s) around the given coordinates with indicated size.

Expand Down Expand Up @@ -280,6 +288,11 @@ def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SP
first majorbody is tried and then smallbody if a matching majorbody is not found.

NOTE: If moving_target is supplied, this argument is ignored.
resolver : str, optional
The resolver to use when resolving a named target into coordinates. Valid options are "SIMBAD" and "NED".
If not specified, the default resolver order will be used. Please see the
`STScI Archive Name Translation Application (SANTA) <https://mastresolver.stsci.edu/Santa-war/>`__
for more information. Default is None.

Returns
-------
Expand Down Expand Up @@ -310,7 +323,9 @@ def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SP
else:

# Get Skycoord object for coordinates/object
coordinates = parse_input_location(coordinates, objectname)
coordinates = parse_input_location(coordinates=coordinates,
objectname=objectname,
resolver=resolver)

astrocut_request = f"astrocut?ra={coordinates.ra.deg}&dec={coordinates.dec.deg}"

Expand Down Expand Up @@ -359,7 +374,7 @@ def download_cutouts(self, *, coordinates=None, size=5, sector=None, product='SP
return localpath_table

def get_cutouts(self, *, coordinates=None, size=5, product='SPOC', sector=None,
objectname=None, moving_target=False, mt_type=None):
objectname=None, moving_target=False, mt_type=None, resolver=None):
"""
Get cutout target pixel file(s) around the given coordinates with indicated size,
and return them as a list of `~astropy.io.fits.HDUList` objects.
Expand Down Expand Up @@ -408,6 +423,11 @@ def get_cutouts(self, *, coordinates=None, size=5, product='SPOC', sector=None,
first majorbody is tried and then smallbody if a matching majorbody is not found.

NOTE: If moving_target is supplied, this argument is ignored.
resolver : str, optional
The resolver to use when resolving a named target into coordinates. Valid options are "SIMBAD" and "NED".
If not specified, the default resolver order will be used. Please see the
`STScI Archive Name Translation Application (SANTA) <https://mastresolver.stsci.edu/Santa-war/>`__
for more information. Default is None.

Returns
-------
Expand Down Expand Up @@ -457,7 +477,9 @@ def get_cutouts(self, *, coordinates=None, size=5, product='SPOC', sector=None,
param_dict['product'] = product.upper()

# Get Skycoord object for coordinates/object
coordinates = parse_input_location(coordinates, objectname)
coordinates = parse_input_location(coordinates=coordinates,
objectname=objectname,
resolver=resolver)

param_dict["ra"] = coordinates.ra.deg
param_dict["dec"] = coordinates.dec.deg
Expand Down Expand Up @@ -531,7 +553,7 @@ def get_surveys(self, coordinates, *, radius="0d"):
"""

# Get Skycoord object for coordinates/object
coordinates = parse_input_location(coordinates)
coordinates = parse_input_location(coordinates=coordinates)
radius = Angle(radius, u.deg)

params = {"ra": coordinates.ra.deg,
Expand Down Expand Up @@ -596,7 +618,7 @@ def download_cutouts(self, coordinates, *, size=5, survey=None, cutout_format="f
Cutout file(s) for given coordinates
"""
# Get Skycoord object for coordinates/object
coordinates = parse_input_location(coordinates)
coordinates = parse_input_location(coordinates=coordinates)
size_dict = _parse_cutout_size(size)

path = os.path.join(path, '')
Expand Down Expand Up @@ -675,7 +697,7 @@ def get_cutouts(self, coordinates, *, size=5, survey=None):
"""

# Get Skycoord object for coordinates/object
coordinates = parse_input_location(coordinates)
coordinates = parse_input_location(coordinates=coordinates)

param_dict = _parse_cutout_size(size)
param_dict["ra"] = coordinates.ra.deg
Expand Down Expand Up @@ -760,7 +782,7 @@ def download_cutouts(self, coordinates, *, size=5, path=".", inflate=True, verbo
"""

# Get Skycoord object for coordinates/object
coordinates = parse_input_location(coordinates)
coordinates = parse_input_location(coordinates=coordinates)

# Build initial astrocut request
astrocut_request = f"astrocut?ra={coordinates.ra.deg}&dec={coordinates.dec.deg}"
Expand Down Expand Up @@ -829,7 +851,7 @@ def get_cutouts(self, coordinates, *, size=5):
"""

# Get Skycoord object for coordinates/object
coordinates = parse_input_location(coordinates)
coordinates = parse_input_location(coordinates=coordinates)

param_dict = _parse_cutout_size(size)

Expand Down
20 changes: 16 additions & 4 deletions astroquery/mast/missions.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def query_region_async(self, coordinates, *, radius=3*u.arcmin, limit=5000, offs

@class_or_instance
def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u.arcmin,
limit=5000, offset=0, select_cols=None, **criteria):
limit=5000, offset=0, select_cols=None, resolver=None, **criteria):
"""
Given a set of search criteria, returns a list of mission metadata.

Expand All @@ -246,6 +246,11 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u.
the number of records you wish to skip before selecting records.
select_cols: list, None
Default None. Names of columns that will be included in the astropy table
resolver : str, optional
The resolver to use when resolving a named target into coordinates. Valid options are "SIMBAD" and "NED".
If not specified, the default resolver order will be used. Please see the
`STScI Archive Name Translation Application (SANTA) <https://mastresolver.stsci.edu/Santa-war/>`__
for more information. Default is None.
**criteria
Criteria to apply. At least one non-positional criterion must be supplied.
Valid criteria are coordinates, objectname, radius (as in
Expand All @@ -268,7 +273,9 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u.

# Parse user input location
if objectname or coordinates:
coordinates = utils.parse_input_location(coordinates, objectname)
coordinates = utils.parse_input_location(coordinates=coordinates,
objectname=objectname,
resolver=resolver)

# if radius is just a number we assume degrees
radius = coord.Angle(radius, u.arcmin)
Expand Down Expand Up @@ -300,7 +307,7 @@ def query_criteria_async(self, *, coordinates=None, objectname=None, radius=3*u.

@class_or_instance
def query_object_async(self, objectname, *, radius=3*u.arcmin, limit=5000, offset=0,
select_cols=None, **criteria):
select_cols=None, resolver=None, **criteria):
"""
Given an object name, returns a list of matching rows.

Expand All @@ -321,6 +328,11 @@ def query_object_async(self, objectname, *, radius=3*u.arcmin, limit=5000, offse
the number of records you wish to skip before selecting records.
select_cols: list, None
Default None. Names of columns that will be included in the astropy table
resolver : str, optional
The resolver to use when resolving a named target into coordinates. Valid options are "SIMBAD" and "NED".
If not specified, the default resolver order will be used. Please see the
`STScI Archive Name Translation Application (SANTA) <https://mastresolver.stsci.edu/Santa-war/>`__
for more information. Default is None.
**criteria
Other mission-specific criteria arguments.
All valid filters can be found using `~astroquery.mast.missions.MastMissionsClass.get_column_list`
Expand All @@ -332,7 +344,7 @@ def query_object_async(self, objectname, *, radius=3*u.arcmin, limit=5000, offse
response : list of `~requests.Response`
"""

coordinates = utils.resolve_object(objectname)
coordinates = utils.resolve_object(objectname, resolver=resolver)

return self.query_region_async(coordinates, radius=radius, limit=limit, offset=offset,
select_cols=select_cols, **criteria)
Expand Down
Loading
Loading