Skip to content
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
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Hans Moritz Guenter <moritz.guenther@gmx.de>
Henrik Norman <honke.norman@gmail.com> <Honke.norman@gmail.com>
Henrik Norman <honke.norman@gmail.com> <hnorma@kth.se>
Jaladh Singhal <jaladhsinghal@gmail.com>
James Dempsey <james.dempsey@csiro.au> <dem040@csiro.au>
Javier Ballester <javier.ballester@ext.esa.int>
Javier Duran <jduran@sciops.esa.int>
Javier Duran <jduran@sciops.esa.int> <javier.duran@sciops.esa.int>
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ casda

- Add the ability to produce 2D and 3D cutouts from ASKAP images and cubes. [#2366]

- Use the standard ``login`` method for authenticating, which supports the system
keyring [#2386]

jplsbdb
^^^^^^^

Expand Down
10 changes: 9 additions & 1 deletion astroquery/casda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Conf(_config.ConfigNamespace):

server = _config.ConfigItem(
['https://casda.csiro.au/casda_vo_tools/sia2/query'],
'Name of the CASDA SIA server to use.'
'Address of the CASDA SIA server to use.'
)
timeout = _config.ConfigItem(
30,
Expand All @@ -25,6 +25,14 @@ class Conf(_config.ConfigNamespace):
['https://casda.csiro.au/casda_data_access/'],
'Address of the CASDA SODA server'
)
login_url = _config.ConfigItem(
['https://data.csiro.au/casda_vo_proxy/vo/tap/availability'],
'Address for test logins'
)
username = _config.ConfigItem(
'',
'Optional default username for CASDA archive.'
)


conf = Conf()
Expand Down
69 changes: 56 additions & 13 deletions astroquery/casda/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
from xml.etree import ElementTree
from datetime import datetime, timezone
import keyring

# 2. third party imports
import astropy.units as u
Expand All @@ -17,24 +18,22 @@
import numpy as np

# 3. local imports - use relative imports
# commonly required local imports shown below as example
# all Query classes should inherit from BaseQuery.
from ..query import BaseQuery
# has common functions required by most modules
from ..query import QueryWithLogin
from ..utils import commons
# prepend_docstr is a way to copy docstrings between methods
from ..utils import prepend_docstr_nosections
# async_to_sync generates the relevant query tools from _async methods
from ..utils import async_to_sync
# import configurable items declared in __init__.py
from . import conf
from ..exceptions import LoginError

# export all the public classes and methods
__all__ = ['Casda', 'CasdaClass']


@async_to_sync
class CasdaClass(BaseQuery):
class CasdaClass(QueryWithLogin):

"""
Class for accessing ASKAP data through the CSIRO ASKAP Science Data Archive (CASDA). Typical usage:
Expand All @@ -46,18 +45,62 @@ class CasdaClass(BaseQuery):
URL = conf.server
TIMEOUT = conf.timeout
POLL_INTERVAL = conf.poll_interval
USERNAME = conf.username
_soda_base_url = conf.soda_base_url
_login_url = conf.login_url
_uws_ns = {'uws': 'http://www.ivoa.net/xml/UWS/v1.0'}

def __init__(self, user=None, password=None):
def __init__(self):
super().__init__()
if user is None:
self._authenticated = False

def _login(self, *, username=None, store_password=False,
reenter_password=False):
"""
login to non-public data as a known user

Parameters
----------
username : str, optional
Username to the CASDA archive, uses ATNF OPAL credentials. If not given, it should be
specified in the config file.
store_password : bool, optional
Stores the password securely in your keyring. Default is False.
reenter_password : bool, optional
Asks for the password even if it is already stored in the
keyring. This is the way to overwrite an already stored passwork
on the keyring. Default is False.
"""

if username is None:
if not self.USERNAME:
raise LoginError("If you do not pass a username to login(), "
"you should configure a default one!")
else:
username = self.USERNAME

# Get password from keyring or prompt
password, password_from_keyring = self._get_password(
"astroquery:casda.csiro.au", username, reenter=reenter_password)

# Login to CASDA to test credentals
log.info("Authenticating {0} on CASDA ...".format(username))
auth = (username, password)
login_response = self._request("GET", self._login_url, auth=auth,
timeout=self.TIMEOUT, cache=False)
authenticated = login_response.status_code == 200

if authenticated:
log.info("Authentication successful!")
self.USERNAME = username
self._auth = (username, password)

# When authenticated, save password in keyring if needed
if password_from_keyring is None and store_password:
keyring.set_password("astroquery:casda.csiro.au", username, password)
else:
self._authenticated = True
# self._user = user
# self._password = password
self._auth = (user, password)
log.exception("Authentication failed")

return authenticated

def query_region_async(self, coordinates, radius=1*u.arcmin, height=None, width=None,
get_query_payload=False, cache=True):
Expand Down Expand Up @@ -274,7 +317,7 @@ def stage_data(self, table, verbose=False):

return self._complete_job(job_url, verbose)

def cutout(self, table, *, coordinates=None, radius=None, height=None,
def cutout(self, table, *, coordinates=None, radius=1*u.arcmin, height=None,
Copy link
Member

Choose a reason for hiding this comment

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

I think this was accidentally pulled in with one of the merge commits, please rebase to get rid of those and any unrelated changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The commit was intentional - just cleaning up a minor aspect that was missed in the last PR

width=None, band=None, channel=None, verbose=False):
"""
Produce a cutout from each selected file. All requests for data must use authentication. If you have access to
Expand Down
6 changes: 6 additions & 0 deletions astroquery/casda/tests/data/availability.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<availability xmlns="http://www.ivoa.net/xml/VOSIAvailability/v1.0">
<available>true</available>
<upSince>2022-04-07T11:11:40.006Z</upSince>
<note></note>
</availability>
Loading