diff --git a/astroquery/noirlab/core.py b/astroquery/noirlab/core.py index 40015b365e..9e0bab8920 100644 --- a/astroquery/noirlab/core.py +++ b/astroquery/noirlab/core.py @@ -3,14 +3,12 @@ This does DB access through web-services. """ -import json import astropy.io.fits as pyfits import astropy.table from ..query import BaseQuery from ..utils import async_to_sync from ..utils.class_or_instance import class_or_instance from . import conf -#!import requests __all__ = ['Noirlab', 'NoirlabClass'] # specifies what to import @@ -32,7 +30,7 @@ def __init__(self, which='file'): """ self._api_version = None self._adsurl = f'{self.NAT_URL}/api/adv_search' - + if which == 'hdu': self.siaurl = f'{self.NAT_URL}/api/sia/vohdu' self._adss_url = f'{self._adsurl}/hasearch' @@ -79,7 +77,7 @@ def service_metadata(self, cache=True): url = f'{self.siaurl}?FORMAT=METADATA&format=json' response = self._request('GET', url, timeout=self.TIMEOUT, cache=cache) return response.json()[0] - + @class_or_instance def query_region(self, coordinate, radius=0.1, cache=True): """Query for NOIRLab observations by region of the sky. @@ -111,7 +109,6 @@ def query_region(self, coordinate, radius=0.1, cache=True): response.raise_for_status() return astropy.table.Table(data=response.json()) - def core_fields(self, cache=True): """List the available CORE fields. CORE fields are faster to search than AUX fields..""" @@ -121,7 +118,6 @@ def core_fields(self, cache=True): response.raise_for_status() return response.json() - def aux_fields(self, instrument, proctype, cache=True): """List the available AUX fields. AUX fields are ANY fields in the Archive FITS files that are not core DB fields. These are generally @@ -145,19 +141,6 @@ def categoricals(self, cache=True): response.raise_for_status() return response.json() - #! @class_or_instance - #! def _query_ads(self, jdata, limit=1000): - #! print(f'DBG-0: ADS jdata={jdata}') - #! adsurl = f'{self.adsurl}/?limit={limit}' - #! print(f'DBG-0: adsurl = {adsurl}') - #! # Following fails - #! # #! response = self._request('POST',adsurl, data=json.dumps(jdata)) - #! response = requests.post(adsurl, json=jdata) - #! print(f'DBG-0: ADS response={response}') - #! print(f'DBG-0: ADS response.content={response.content}') - #! print(f'DBG-0: ADS response.json()={response.json()}') - #! return astropy.table.Table(data=response.json()) - @class_or_instance def query_metadata(self, qspec, limit=1000, cache=True): self._validate_version() @@ -168,22 +151,9 @@ def query_metadata(self, qspec, limit=1000, cache=True): else: jdata = qspec - print(f'DBG-0: query_metadata.url = {url}') - # headers = {'accept': 'application/json'} - # headers = {'Content-Type': 'application/json'} - - # Following fails: - response = self._request('POST', url, json=jdata, timeout=self.TIMEOUT,) - - #! response = requests.post(url, - #! timeout=self.TIMEOUT, - #! json=jdata) + response = self._request('POST', url, json=jdata, timeout=self.TIMEOUT) response.raise_for_status() - # #!print(f'DBG-0: ADS response={response}') - # #!print(f'DBG-0: ADS response.content={response.content}') - # #!print(f'DBG-0: ADS response.json()={response.json()}') return astropy.table.Table(rows=response.json()) - #return response.json() #@@@ Should return table def retrieve(self, fileid, cache=True): url = f'{self.NAT_URL}/api/retrieve/{fileid}/' @@ -203,5 +173,6 @@ def get_token(self, email, password, cache=True): timeout=self.TIMEOUT) response.raise_for_status() return response.json() - + + Noirlab = NoirlabClass() diff --git a/astroquery/noirlab/tests/test_noirlab_remote.py b/astroquery/noirlab/tests/test_noirlab_remote.py index 1227514ff1..c6092c210c 100644 --- a/astroquery/noirlab/tests/test_noirlab_remote.py +++ b/astroquery/noirlab/tests/test_noirlab_remote.py @@ -5,11 +5,9 @@ from astropy import units as u from astropy.coordinates import SkyCoord from astropy.tests.helper import remote_data -import astropy.io.fits as pyfits # Local packages from .. import Noirlab from . import expected as exp -# #!import pytest # performs similar tests as test_module.py, but performs # the actual HTTP request rather than monkeypatching them. @@ -20,9 +18,9 @@ @remote_data class TestNoirlabClass(object): - ############################################################### - ### (2) SIA; /api/sia/ - ### + # ############################################################### + # ### (2) SIA; /api/sia/ + # ### # voimg, vohdu def test_service_metadata(self): @@ -32,7 +30,7 @@ def test_service_metadata(self): print(f'DBG: test_service_metadata={actual}') expected = exp.service_metadata assert actual == expected - + def test_query_region_0(self): """Search FILES using default type (which) selector""" @@ -64,9 +62,9 @@ def test_query_region_2(self): expected = exp.query_region_2 assert expected.issubset(actual) - ############################################################### - ### (7) Advanced Search; /api/adv_search/ - ### + # ############################################################### + # ### (7) Advanced Search; /api/adv_search/ + # ### # # (2) aux_{file,hdu}_fields// # (2) core_{file,hdu}_fields/ @@ -74,9 +72,9 @@ def test_query_region_2(self): # (2) {f,h}asearch # cat_list - ## - ## File (default type) - ## + # ## + # ## File (default type) + # ## def test_aux_file_fields(self): """List the available AUX FILE fields.""" @@ -89,7 +87,7 @@ def test_aux_file_fields(self): def test_core_file_fields(self): """List the available CORE FILE fields.""" r = Noirlab().core_fields() - actual = r # set(list(r['md5sum'])) + actual = r print(f'DBG: test_core_file_fields={actual}') expected = exp.core_file_fields assert actual == expected @@ -97,28 +95,27 @@ def test_core_file_fields(self): def test_query_file_metadata(self): """Search FILE metadata.""" qspec = { - "outfields" : [ + "outfields": [ "md5sum", "archive_filename", "original_filename", "instrument", "proc_type" ], - "search" : [ + "search": [ ['original_filename', 'c4d_', 'contains'] ] } r = Noirlab().query_metadata(qspec, limit=3) - actual = r # set(list(r['md5sum'])) + actual = r print(f'DBG: test_query_file_metadata={actual.pformat_all()}') expected = exp.query_file_metadata assert actual.pformat_all() == expected - - ## - ## HDU - ## + # ## + # ## HDU + # ## def test_aux_hdu_fields(self): """List the available AUX HDU fields.""" @@ -131,7 +128,7 @@ def test_aux_hdu_fields(self): def test_core_hdu_fields(self): """List the available CORE HDU fields.""" r = Noirlab(which='hdu').core_fields() - actual = r # set(list(r['md5sum'])) + actual = r print(f'DBG: test_core_hdu_fields={actual}') expected = exp.core_hdu_fields assert actual == expected @@ -139,14 +136,14 @@ def test_core_hdu_fields(self): def test_query_hdu_metadata(self): """Search HDU metadata.""" qspec = { - "outfields" : [ + "outfields": [ "fitsfile__archive_filename", "fitsfile__caldat", "fitsfile__instrument", "fitsfile__proc_type", "AIRMASS" # AUX field. Slows search ], - "search" : [ + "search": [ ["fitsfile__caldat", "2017-08-14", "2017-08-16"], ["fitsfile__instrument", "decam"], ["fitsfile__proc_type", "raw"] @@ -154,27 +151,25 @@ def test_query_hdu_metadata(self): } r = Noirlab(which='hdu').query_metadata(qspec, limit=3) - actual = r # set(list(r['md5sum'])) + actual = r print(f'DBG: test_query_hdu_metadata={actual.pformat_all()}') expected = exp.query_hdu_metadata assert actual.pformat_all() == expected - ## - ## Agnostic - ## + # ## + # ## Agnostic + # ## def test_categoricals(self): """List categories.""" r = Noirlab().categoricals() - actual = r # set(list(r['md5sum'])) + actual = r print(f'DBG: test_categoricals={actual}') expected = exp.categoricals assert actual == expected - - - ############################################################### - ### (3) Other + # ############################################################## + # ### (3) Other # get_token # retrieve/ # version @@ -186,7 +181,6 @@ def test_retrieve(self): expected = exp.retrieve assert actual == expected - def test_version(self): r = Noirlab().version() assert r < 3.0 @@ -197,6 +191,3 @@ def test_get_token(self): 'No active account found with the given credentials'} print(f'DBG: test_get_token={actual}') assert actual == expected - - -