Skip to content

Commit b787ee2

Browse files
authored
Merge pull request #2317 from jaymedina/explicit-kwargs
Make `astroquery.mast` methods take explicit kwargs
2 parents 3342888 + 5de8905 commit b787ee2

File tree

5 files changed

+51
-40
lines changed

5 files changed

+51
-40
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ mast
5656
- Adding the All-Sky PLATO Input Catalog ('plato') as a catalog option for
5757
methods of ``astroquery.mast.Catalogs``. [#2279]
5858

59+
- Optional keyword arguments for are now keyword only in ``astroquery.mast.Observations``, ``astroquery.mast.Catalogs``, and ``astroquery.mast.Cutouts``. [#2317]
60+
5961
sdss
6062
^^^^
6163

astroquery/mast/collections.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def __init__(self):
4848
self.catalog_limit = None
4949
self._current_connection = None
5050

51-
def _parse_result(self, response, verbose=False):
51+
def _parse_result(self, response, *, verbose=False):
5252

53-
results_table = self._current_connection._parse_result(response, verbose)
53+
results_table = self._current_connection._parse_result(response, verbose=verbose)
5454

5555
if len(results_table) == self.catalog_limit:
5656
warnings.warn("Maximum catalog results returned, may not include all sources within radius.",
@@ -59,7 +59,7 @@ def _parse_result(self, response, verbose=False):
5959
return results_table
6060

6161
@class_or_instance
62-
def query_region_async(self, coordinates, radius=0.2*u.deg, catalog="Hsc",
62+
def query_region_async(self, coordinates, *, radius=0.2*u.deg, catalog="Hsc",
6363
version=None, pagesize=None, page=None, **kwargs):
6464
"""
6565
Given a sky position and radius, returns a list of catalog entries.
@@ -161,10 +161,10 @@ def query_region_async(self, coordinates, radius=0.2*u.deg, catalog="Hsc",
161161
for prop, value in kwargs.items():
162162
params[prop] = value
163163

164-
return self._current_connection.service_request_async(service, params, pagesize, page)
164+
return self._current_connection.service_request_async(service, params, pagesize=pagesize, page=page)
165165

166166
@class_or_instance
167-
def query_object_async(self, objectname, radius=0.2*u.deg, catalog="Hsc",
167+
def query_object_async(self, objectname, *, radius=0.2*u.deg, catalog="Hsc",
168168
pagesize=None, page=None, version=None, **kwargs):
169169
"""
170170
Given an object name, returns a list of catalog entries.
@@ -204,11 +204,16 @@ def query_object_async(self, objectname, radius=0.2*u.deg, catalog="Hsc",
204204

205205
coordinates = utils.resolve_object(objectname)
206206

207-
return self.query_region_async(coordinates, radius, catalog,
208-
version=version, pagesize=pagesize, page=page, **kwargs)
207+
return self.query_region_async(coordinates,
208+
radius=radius,
209+
catalog=catalog,
210+
version=version,
211+
pagesize=pagesize,
212+
page=page,
213+
**kwargs)
209214

210215
@class_or_instance
211-
def query_criteria_async(self, catalog, pagesize=None, page=None, **criteria):
216+
def query_criteria_async(self, catalog, *, pagesize=None, page=None, **criteria):
212217
"""
213218
Given an set of filters, returns a list of catalog entries.
214219
See column documentation for specific catalogs `here <https://mast.stsci.edu/api/v0/pages.htmll>`__.
@@ -310,7 +315,7 @@ def query_criteria_async(self, catalog, pagesize=None, page=None, **criteria):
310315
return self._current_connection.service_request_async(service, params, pagesize=pagesize, page=page)
311316

312317
@class_or_instance
313-
def query_hsc_matchid_async(self, match, version=3, pagesize=None, page=None):
318+
def query_hsc_matchid_async(self, match, *, version=3, pagesize=None, page=None):
314319
"""
315320
Returns all the matches for a given Hubble Source Catalog MatchID.
316321
@@ -347,10 +352,10 @@ def query_hsc_matchid_async(self, match, version=3, pagesize=None, page=None):
347352

348353
params = {"input": match}
349354

350-
return self._current_connection.service_request_async(service, params, pagesize, page)
355+
return self._current_connection.service_request_async(service, params, pagesize=pagesize, page=page)
351356

352357
@class_or_instance
353-
def get_hsc_spectra_async(self, pagesize=None, page=None):
358+
def get_hsc_spectra_async(self, *, pagesize=None, page=None):
354359
"""
355360
Returns all Hubble Source Catalog spectra.
356361
@@ -375,7 +380,7 @@ def get_hsc_spectra_async(self, pagesize=None, page=None):
375380

376381
return self._current_connection.service_request_async(service, params, pagesize, page)
377382

378-
def download_hsc_spectra(self, spectra, download_dir=None, cache=True, curl_flag=False):
383+
def download_hsc_spectra(self, spectra, *, download_dir=None, cache=True, curl_flag=False):
379384
"""
380385
Download one or more Hubble Source Catalog spectra.
381386

astroquery/mast/cutouts.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def __init__(self):
110110
}
111111
self._service_api_connection.set_service_params(services, "tesscut")
112112

113-
def get_sectors(self, coordinates=None, radius=0*u.deg, objectname=None, moving_target=False, mt_type=None):
113+
def get_sectors(self, *, coordinates=None, radius=0*u.deg, objectname=None, moving_target=False, mt_type=None):
114114
"""
115115
Get a list of the TESS data sectors whose footprints intersect
116116
with the given search area.
@@ -204,7 +204,7 @@ def get_sectors(self, coordinates=None, radius=0*u.deg, objectname=None, moving_
204204
warnings.warn("Coordinates are not in any TESS sector.", NoResultsWarning)
205205
return Table(sector_dict)
206206

207-
def download_cutouts(self, coordinates=None, size=5, sector=None, path=".", inflate=True,
207+
def download_cutouts(self, *, coordinates=None, size=5, sector=None, path=".", inflate=True,
208208
objectname=None, moving_target=False, mt_type=None):
209209
"""
210210
Download cutout target pixel file(s) around the given coordinates with indicated size.
@@ -316,7 +316,7 @@ def download_cutouts(self, coordinates=None, size=5, sector=None, path=".", infl
316316
localpath_table['Local Path'] = [path+x for x in cutout_files]
317317
return localpath_table
318318

319-
def get_cutouts(self, coordinates=None, size=5, sector=None,
319+
def get_cutouts(self, *, coordinates=None, size=5, sector=None,
320320
objectname=None, moving_target=False, mt_type=None):
321321
"""
322322
Get cutout target pixel file(s) around the given coordinates with indicated size,
@@ -442,7 +442,7 @@ def __init__(self):
442442
"astrocut": {"path": "astrocut"}}
443443
self._service_api_connection.set_service_params(services, "zcut")
444444

445-
def get_surveys(self, coordinates, radius="0d"):
445+
def get_surveys(self, coordinates, *, radius="0d"):
446446
"""
447447
Gives a list of deep field surveys available for a position in the sky
448448
@@ -481,7 +481,7 @@ def get_surveys(self, coordinates, radius="0d"):
481481
warnings.warn("Coordinates are not in an available deep field survey.", NoResultsWarning)
482482
return survey_json
483483

484-
def download_cutouts(self, coordinates, size=5, survey=None, cutout_format="fits", path=".", inflate=True, **img_params):
484+
def download_cutouts(self, coordinates, *, size=5, survey=None, cutout_format="fits", path=".", inflate=True, **img_params):
485485
"""
486486
Download cutout FITS/image file(s) around the given coordinates with indicated size.
487487
@@ -575,7 +575,7 @@ def download_cutouts(self, coordinates, size=5, survey=None, cutout_format="fits
575575
localpath_table['Local Path'] = [path+x for x in cutout_files]
576576
return localpath_table
577577

578-
def get_cutouts(self, coordinates, size=5, survey=None):
578+
def get_cutouts(self, coordinates, *, size=5, survey=None):
579579
"""
580580
Get cutout FITS file(s) around the given coordinates with indicated size,
581581
and return them as a list of `~astropy.io.fits.HDUList` objects.

astroquery/mast/observations.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ObservationsClass(MastQueryWithLogin):
5656
_caom_filtered = 'Mast.Caom.Filtered'
5757
_caom_products = 'Mast.Caom.Products'
5858

59-
def _parse_result(self, responses, verbose=False): # Used by the async_to_sync decorator functionality
59+
def _parse_result(self, responses, *, verbose=False): # Used by the async_to_sync decorator functionality
6060
"""
6161
Parse the results of a list of `~requests.Response` objects and returns an `~astropy.table.Table` of results.
6262
@@ -179,7 +179,7 @@ def _parse_caom_criteria(self, **criteria):
179179
return position, mashup_filters
180180

181181
@class_or_instance
182-
def query_region_async(self, coordinates, radius=0.2*u.deg, pagesize=None, page=None):
182+
def query_region_async(self, coordinates, *, radius=0.2*u.deg, pagesize=None, page=None):
183183
"""
184184
Given a sky position and radius, returns a list of MAST observations.
185185
See column documentation `here <https://mast.stsci.edu/api/v0/_c_a_o_mfields.html>`__.
@@ -219,10 +219,10 @@ def query_region_async(self, coordinates, radius=0.2*u.deg, pagesize=None, page=
219219
'dec': coordinates.dec.deg,
220220
'radius': radius.deg}
221221

222-
return self._portal_api_connection.service_request_async(service, params, pagesize, page)
222+
return self._portal_api_connection.service_request_async(service, params, pagesize=pagesize, page=page)
223223

224224
@class_or_instance
225-
def query_object_async(self, objectname, radius=0.2*u.deg, pagesize=None, page=None):
225+
def query_object_async(self, objectname, *, radius=0.2*u.deg, pagesize=None, page=None):
226226
"""
227227
Given an object name, returns a list of MAST observations.
228228
See column documentation `here <https://mast.stsci.edu/api/v0/_c_a_o_mfields.html>`__.
@@ -252,10 +252,10 @@ def query_object_async(self, objectname, radius=0.2*u.deg, pagesize=None, page=N
252252

253253
coordinates = utils.resolve_object(objectname)
254254

255-
return self.query_region_async(coordinates, radius, pagesize, page)
255+
return self.query_region_async(coordinates, radius=radius, pagesize=pagesize, page=page)
256256

257257
@class_or_instance
258-
def query_criteria_async(self, pagesize=None, page=None, **criteria):
258+
def query_criteria_async(self, *, pagesize=None, page=None, **criteria):
259259
"""
260260
Given an set of criteria, returns a list of MAST observations.
261261
Valid criteria are returned by ``get_metadata("observations")``
@@ -302,7 +302,7 @@ def query_criteria_async(self, pagesize=None, page=None, **criteria):
302302

303303
return self._portal_api_connection.service_request_async(service, params)
304304

305-
def query_region_count(self, coordinates, radius=0.2*u.deg, pagesize=None, page=None):
305+
def query_region_count(self, coordinates, *, radius=0.2*u.deg, pagesize=None, page=None):
306306
"""
307307
Given a sky position and radius, returns the number of MAST observations in that region.
308308
@@ -343,7 +343,7 @@ def query_region_count(self, coordinates, radius=0.2*u.deg, pagesize=None, page=
343343

344344
return int(self._portal_api_connection.service_request(service, params, pagesize, page)[0][0])
345345

346-
def query_object_count(self, objectname, radius=0.2*u.deg, pagesize=None, page=None):
346+
def query_object_count(self, objectname, *, radius=0.2*u.deg, pagesize=None, page=None):
347347
"""
348348
Given an object name, returns the number of MAST observations.
349349
@@ -369,9 +369,9 @@ def query_object_count(self, objectname, radius=0.2*u.deg, pagesize=None, page=N
369369

370370
coordinates = utils.resolve_object(objectname)
371371

372-
return self.query_region_count(coordinates, radius, pagesize, page)
372+
return self.query_region_count(coordinates, radius=radius, pagesize=pagesize, page=page)
373373

374-
def query_criteria_count(self, pagesize=None, page=None, **criteria):
374+
def query_criteria_count(self, *, pagesize=None, page=None, **criteria):
375375
"""
376376
Given an set of filters, returns the number of MAST observations meeting those criteria.
377377
@@ -450,7 +450,7 @@ def get_product_list_async(self, observations):
450450

451451
return self._portal_api_connection.service_request_async(service, params)
452452

453-
def filter_products(self, products, mrp_only=False, extension=None, **filters):
453+
def filter_products(self, products, *, mrp_only=False, extension=None, **filters):
454454
"""
455455
Takes an `~astropy.table.Table` of MAST observation data products and filters it based on given filters.
456456
@@ -505,7 +505,7 @@ def filter_products(self, products, mrp_only=False, extension=None, **filters):
505505

506506
return products[np.where(filter_mask)]
507507

508-
def download_file(self, uri, local_path=None, base_url=None, cache=True, cloud_only=False):
508+
def download_file(self, uri, *, local_path=None, base_url=None, cache=True, cloud_only=False):
509509
"""
510510
Downloads a single file based on the data URI
511511
@@ -582,7 +582,7 @@ def download_file(self, uri, local_path=None, base_url=None, cache=True, cloud_o
582582

583583
return status, msg, url
584584

585-
def _download_files(self, products, base_dir, cache=True, cloud_only=False,):
585+
def _download_files(self, products, base_dir, *, cache=True, cloud_only=False,):
586586
"""
587587
Takes an `~astropy.table.Table` of data products and downloads them into the directory given by base_dir.
588588
@@ -658,7 +658,7 @@ def _download_curl_script(self, products, out_dir):
658658
'Message': [msg]})
659659
return manifest
660660

661-
def download_products(self, products, download_dir=None,
661+
def download_products(self, products, *, download_dir=None,
662662
cache=True, curl_flag=False, mrp_only=False, cloud_only=False, **filters):
663663
"""
664664
Download data products.
@@ -715,7 +715,7 @@ def download_products(self, products, download_dir=None,
715715
products = vstack(product_lists)
716716

717717
# apply filters
718-
products = self.filter_products(products, mrp_only, **filters)
718+
products = self.filter_products(products, mrp_only=mrp_only, **filters)
719719

720720
if not len(products):
721721
warnings.warn("No products to download.", NoResultsWarning)
@@ -726,15 +726,19 @@ def download_products(self, products, download_dir=None,
726726
download_dir = '.'
727727

728728
if curl_flag: # don't want to download the files now, just the curl script
729-
manifest = self._download_curl_script(products, download_dir)
729+
manifest = self._download_curl_script(products,
730+
download_dir)
730731

731732
else:
732733
base_dir = download_dir.rstrip('/') + "/mastDownload"
733-
manifest = self._download_files(products, base_dir, cache, cloud_only)
734+
manifest = self._download_files(products,
735+
base_dir=base_dir,
736+
cache=cache,
737+
cloud_only=cloud_only)
734738

735739
return manifest
736740

737-
def get_cloud_uris(self, data_products, include_bucket=True, full_url=False):
741+
def get_cloud_uris(self, data_products, *, include_bucket=True, full_url=False):
738742
"""
739743
Takes an `~astropy.table.Table` of data products and returns the associated cloud data uris.
740744
@@ -763,7 +767,7 @@ def get_cloud_uris(self, data_products, include_bucket=True, full_url=False):
763767

764768
return self._cloud_connection.get_cloud_uri_list(data_products, include_bucket, full_url)
765769

766-
def get_cloud_uri(self, data_product, include_bucket=True, full_url=False):
770+
def get_cloud_uri(self, data_product, *, include_bucket=True, full_url=False):
767771
"""
768772
For a given data product, returns the associated cloud URI.
769773
If the product is from a mission that does not support cloud access an
@@ -806,7 +810,7 @@ class MastClass(MastQueryWithLogin):
806810
more flexible but less user friendly than `ObservationsClass`.
807811
"""
808812

809-
def _parse_result(self, responses, verbose=False): # Used by the async_to_sync decorator functionality
813+
def _parse_result(self, responses, *, verbose=False): # Used by the async_to_sync decorator functionality
810814
"""
811815
Parse the results of a list of `~requests.Response` objects and returns an `~astropy.table.Table` of results.
812816
@@ -827,7 +831,7 @@ def _parse_result(self, responses, verbose=False): # Used by the async_to_sync
827831
return self._portal_api_connection._parse_result(responses, verbose)
828832

829833
@class_or_instance
830-
def service_request_async(self, service, params, pagesize=None, page=None, **kwargs):
834+
def service_request_async(self, service, params, *, pagesize=None, page=None, **kwargs):
831835
"""
832836
Given a Mashup service and parameters, builds and excecutes a Mashup query.
833837
See documentation `here <https://mast.stsci.edu/api/v0/class_mashup_1_1_mashup_request.html>`__

astroquery/mast/tests/test_mast_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def test_catalogs_query_object(self):
516516
assert '441662144' in result['ID']
517517

518518
result = mast.Catalogs.query_object('M1',
519-
radius=0.001,
519+
radius=0.2,
520520
catalog='plato')
521521
assert 'PICidDR1' in result.colnames
522522

0 commit comments

Comments
 (0)