Skip to content
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

WIP: NRAO Archive Query replacement #3015

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 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
37 changes: 18 additions & 19 deletions astroquery/nrao/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

from ..exceptions import LoginError
from ..utils import commons
from ..utils.process_asyncs import async_to_sync
from ..query import BaseQuery, QueryWithLogin, BaseVOQuery
from . import conf, auth_urls, tap_urls
from astroquery.exceptions import CorruptDataWarning
Expand Down Expand Up @@ -144,8 +143,12 @@ def _gen_sql(payload):
return sql + where


class NraoAuth(BaseVOQuery, BaseQuery):
pass
# class NraoAuth(BaseVOQuery, BaseQuery):
# """
# TODO: this needs to be implemented
# """
# pass


class NraoClass(BaseQuery):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you still want to inherit this from BaseVOQuery, so the session things passed through pyvo correctly.

TIMEOUT = conf.timeout
Expand All @@ -161,7 +164,7 @@ def __init__(self):
self._sia_url = None
self._tap_url = None
self._datalink_url = None
self._auth = NraoAuth()
# TODO self._auth = NraoAuth()

@property
def auth(self):
Expand Down Expand Up @@ -235,7 +238,7 @@ def query_tap(self, query, maxrec=None):
def _get_dataarchive_url(self):
return tap_urls[0]

def query_object_async(self, object_name, *, payload=None, **kwargs):
def query_object(self, object_name, *, payload=None, **kwargs):
"""
Query the archive for a source name.

Expand All @@ -250,9 +253,9 @@ def query_object_async(self, object_name, *, payload=None, **kwargs):
payload['source_name_resolver'] = object_name
else:
payload = {'source_name_resolver': object_name}
return self.query_async(payload=payload, **kwargs)
return self.query(payload=payload, **kwargs)

def query_region_async(self, coordinate, radius, *,
def query_region(self, coordinate, radius, *,
get_query_payload=False,
payload=None, **kwargs):
"""
Expand Down Expand Up @@ -282,9 +285,9 @@ def query_region_async(self, coordinate, radius, *,
if get_query_payload:
return payload

return self.query_async(payload=payload, **kwargs)
return self.query(payload=payload, **kwargs)

def query_async(self, payload, *, get_query_payload=False,
def query(self, payload, *, get_query_payload=False,
maxrec=None, **kwargs):
"""
Perform a generic query with user-specified payload
Expand All @@ -300,12 +303,12 @@ def query_async(self, payload, *, get_query_payload=False,
Flag to indicate whether to simply return the payload.
maxrec : integer
Cap on the amount of records returned. Default is no limit.
[ we don't know for sure that this is implemented for NRAO ]

Returns
-------

Table with results. Columns are those in the NRAO ObsCore model
(see ``help_tap``) unless ``legacy_columns`` argument is set to True.
Table with results.
"""

if payload is None:
Expand All @@ -316,9 +319,7 @@ def query_async(self, payload, *, get_query_payload=False,
payload[arg] = '{} {}'.format(payload[arg], value)
else:
payload[arg] = value
print(payload)
query = _gen_sql(payload)
print(query)
if get_query_payload:
# Return the TAP query payload that goes out to the server rather
# than the unprocessed payload dict from the python side
Expand All @@ -339,8 +340,10 @@ def _get_data(self, solr_id, email=None, workflow='runBasicMsWorkflow',
apply_flags=True
):
"""
Defining this as a private function for now because it's using an
unverified API
This private function can, under a very limited set of circumstances,
be used to retrieve the data download page from the NRAO data handler.
Because the data handler is run through a fairly complex, multi-step,
private API, we are not yet ready to make this service public.

Parameters
----------
Expand Down Expand Up @@ -419,17 +422,13 @@ def _get_data(self, solr_id, email=None, workflow='runBasicMsWorkflow',
)
presp.raise_for_status()

# DEBUG print(f"presp.url: {presp.url}")
# DEBUG print(f"cookies: {self._session.cookies}")
resp2 = self._request('GET', presp.url, cache=False)
resp2.raise_for_status()

for row in resp2.text.split():
if 'window.location.href=' in row:
subrespurl = row.split("'")[1]

# DEBUG print(f"subrespurl: {subrespurl}")
# DEBUG print(f"cookies: {self._session.cookies}")
nextresp = self._request('GET', subrespurl, cache=False)
wait_url = nextresp.url
nextresp.raise_for_status()
Expand Down
Empty file.
1 change: 1 addition & 0 deletions astroquery/nrao/tests/data/nrao-empty.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dataproduct_type calib_level obs_collection obs_id s_ra s_dec s_fov obs_publisher_did access_url access_format target_name s_region s_resolution t_min t_max t_exptime t_resolution freq_min freq_max em_min em_max em_res_power em_xel o_ucd facility_name instrument_name pol_states configuration access_estsize num_antennas max_uv_dist spw_names center_frequencies bandwidths nums_channels spectral_resolutions aggregate_bandwidth
Loading
Loading