Skip to content

Commit

Permalink
Merge pull request #3113 from snbianco/ASB-28975-update-docs
Browse files Browse the repository at this point in the history
Move cloud functions into Observations, fix for docs and test
  • Loading branch information
bsipocz authored Oct 17, 2024
2 parents aa35035 + 4e422d8 commit 3e26521
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ mast
- Added function ``mast.Observations.get_unique_product_list`` to return the unique data products associated with
given observations. [#3096]

- Deprecated ``enable_cloud_dataset`` and ``disable_cloud_dataset`` in classes where they
are non-operational. They will be removed in a future release. [#3113]

mpc
^^^

Expand Down
13 changes: 8 additions & 5 deletions astroquery/mast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
This the base class for MAST queries.
"""
from astropy.utils import deprecated
from ..query import QueryWithLogin
from . import utils
from .auth import MastAuth
from .cloud import CloudAccess
from .discovery_portal import PortalAPI
from .services import ServiceAPI

Expand Down Expand Up @@ -82,6 +82,8 @@ def logout(self):
self._auth_obj.logout()
self._authenticated = False

@deprecated(since='v0.4.8',
message=('This function is non-operational and will be removed in a future release.'))
def enable_cloud_dataset(self, provider="AWS", profile=None, verbose=True):
"""
Enable downloading public files from S3 instead of MAST.
Expand All @@ -98,14 +100,15 @@ def enable_cloud_dataset(self, provider="AWS", profile=None, verbose=True):
Default True.
Logger to display extra info and warning.
"""
pass

self._cloud_connection = CloudAccess(provider, profile, verbose)

@deprecated(since='v0.4.8',
message=('This function is non-operational and will be removed in a future release.'))
def disable_cloud_dataset(self):
"""
Disables downloading public files from S3 instead of MAST
Disables downloading public files from S3 instead of MAST.
"""
self._cloud_connection = None
pass

def resolve_object(self, objectname):
"""
Expand Down
25 changes: 25 additions & 0 deletions astroquery/mast/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from astropy.table import Table, Row, unique, vstack
from astroquery import log
from astroquery.mast.cloud import CloudAccess

from ..utils import commons, async_to_sync
from ..utils.class_or_instance import class_or_instance
Expand Down Expand Up @@ -171,6 +172,30 @@ def _parse_caom_criteria(self, **criteria):

return position, mashup_filters

def enable_cloud_dataset(self, provider="AWS", profile=None, verbose=True):
"""
Enable downloading public files from S3 instead of MAST.
Requires the boto3 library to function.
Parameters
----------
provider : str
Which cloud data provider to use. We may in the future support multiple providers,
though at the moment this argument is ignored.
profile : str
Profile to use to identify yourself to the cloud provider (usually in ~/.aws/config).
verbose : bool
Default True.
Logger to display extra info and warning.
"""
self._cloud_connection = CloudAccess(provider, profile, verbose)

def disable_cloud_dataset(self):
"""
Disables downloading public files from S3 instead of MAST.
"""
self._cloud_connection = None

@class_or_instance
def query_region_async(self, coordinates, *, radius=0.2*u.deg, pagesize=None, page=None):
"""
Expand Down
7 changes: 2 additions & 5 deletions astroquery/mast/tests/test_mast_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,8 @@ def test_observations_get_cloud_uris_no_duplicates(self, msa_product_table):
# enable access to public AWS S3 bucket
Observations.enable_cloud_dataset(provider='AWS')

# Check for cloud URIs. Accept a NoResultsWarning if AWS S3
# doesn't have the file. It doesn't matter as we're only checking
# that the duplicate products have been culled to a single one.
with pytest.warns(NoResultsWarning):
uris = Observations.get_cloud_uris(products)
# Check that only one URI is returned
uris = Observations.get_cloud_uris(products)
assert len(uris) == 1

def test_observations_download_file(self, tmp_path):
Expand Down

0 comments on commit 3e26521

Please sign in to comment.