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

renamed and deprecated Observations and Observations class for the gemini and mast module #1885

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ esa.xmm_newton
- Use astroquery downloader tool to get progressbar, caching, and prevent
memory leaks. [#2087]

observations
Copy link
Member

Choose a reason for hiding this comment

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

There should be two changelog entries, one under MAST and one under Gemeni.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a massive breaking change for users, we need to have a deprecation period where the old syntax still works but a deprecation message is displayed. Check out https://docs.astropy.org/en/stable/api/astropy.utils.decorators.deprecated.html#astropy.utils.decorators.deprecated

Would it be a good idea to assign the old name of the class to the new name
e.g ObservationsClass = GeminiObservationsClass()
and display a deprecated message saying ObservationsClass is deprecated. Use GeminiObservationsClass instead

Copy link
Member

Choose a reason for hiding this comment

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

You can use this PR as an example for renaming and deprecating a class: astropy/astropy#9445

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! Thanks @bsipocz

^^^^^^^^^^^^

- Renamed and deprecated Observations and ObservationsClass in MAST
and GEMINI modules. [#1885]

gaia
^^^^

Expand Down
4 changes: 2 additions & 2 deletions astroquery/gemini/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class Conf(_config.ConfigNamespace):

conf = Conf()

from .core import ObservationsClass, Observations
from .core import GeminiObservationsClass, GeminiObservations

__all__ = ['Observations', 'ObservationsClass', 'conf']
__all__ = ['GeminiObservations', 'GeminiObservationsClass', 'conf']
12 changes: 10 additions & 2 deletions astroquery/gemini/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from astroquery import log
from astropy import units
from astropy.table import Table, MaskedColumn
from astropy.utils import deprecated

from astroquery.gemini.urlhelper import URLHelper
import numpy as np
Expand All @@ -21,7 +22,7 @@
from ..exceptions import AuthenticationWarning


__all__ = ['Observations', 'ObservationsClass'] # specifies what to import
__all__ = ['GeminiObservations', 'GeminiObservationsClass'] # specifies what to import


__valid_instruments__ = [
Expand Down Expand Up @@ -97,7 +98,7 @@
]


class ObservationsClass(QueryWithLogin):
class GeminiObservationsClass(QueryWithLogin):

server = conf.server
url_helper = URLHelper(server)
Expand Down Expand Up @@ -526,4 +527,11 @@ def _gemini_json_to_table(json):
"release",
"dec"]


@deprecated(since='v0.4.3', alternative='GeminiObservationsClass')
class ObservationsClass(GeminiObservationsClass):
pass


GeminiObservations = GeminiObservationsClass()
Observations = ObservationsClass()
Copy link
Member

Choose a reason for hiding this comment

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

This line is causing the warning. I guess the brute force way is to silence the warning just for this line...?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the issue is that if I put a filter in __init__.py, then we rightly don't get the warning at module import time. However, then we don't get it at all for any usage of Observations, and that's what probably users used the most as the docs is full of Observations.xzy().

12 changes: 6 additions & 6 deletions astroquery/gemini/tests/test_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ def data_path(filename):

def test_observations_query_region(patch_get):
""" test query against a region of the sky """
result = gemini.Observations.query_region(coords, radius=0.3 * units.deg)
result = gemini.GeminiObservations.query_region(coords, radius=0.3 * units.deg)
assert isinstance(result, Table)
assert len(result) > 0


def test_observations_query_criteria(patch_get):
""" test query against an instrument/program via criteria """
result = gemini.Observations.query_criteria(instrument='GMOS-N', program_id='GN-CAL20191122',
result = gemini.GeminiObservations.query_criteria(instrument='GMOS-N', program_id='GN-CAL20191122',
observation_type='BIAS',
utc_date=(date(2019, 10, 1), date(2019, 11, 25)))
assert isinstance(result, Table)
Expand All @@ -82,26 +82,26 @@ def test_observations_query_criteria(patch_get):

def test_observations_query_criteria_radius_defaults(patch_get):
""" test query against an instrument/program via criteria """
result = gemini.Observations.query_criteria(instrument='GMOS-N', program_id='GN-CAL20191122',
result = gemini.GeminiObservations.query_criteria(instrument='GMOS-N', program_id='GN-CAL20191122',
observation_type='BIAS')
global saved_request
assert(saved_request is not None and 'args' in saved_request and len(saved_request['args']) >= 2)
assert('/sr=' not in saved_request['args'][1])
saved_request = None
result = gemini.Observations.query_criteria(instrument='GMOS-N', program_id='GN-2016A-Q-9',
result = gemini.GeminiObservations.query_criteria(instrument='GMOS-N', program_id='GN-2016A-Q-9',
observation_type='BIAS', coordinates=coords)
assert(saved_request is not None and 'args' in saved_request and len(saved_request['args']) >= 2)
assert('/sr=0.300000d' in saved_request['args'][1])
saved_request = None
result = gemini.Observations.query_criteria(instrument='GMOS-N', program_id='GN-2016A-Q-9',
result = gemini.GeminiObservations.query_criteria(instrument='GMOS-N', program_id='GN-2016A-Q-9',
observation_type='BIAS', objectname='m101')
assert(saved_request is not None and 'args' in saved_request and len(saved_request['args']) >= 2)
assert('/sr=0.300000d' in saved_request['args'][1])


def test_observations_query_raw(patch_get):
""" test querying raw """
result = gemini.Observations.query_raw('GMOS-N', 'BIAS', progid='GN-CAL20191122')
result = gemini.GeminiObservations.query_raw('GMOS-N', 'BIAS', progid='GN-CAL20191122')
assert isinstance(result, Table)
assert len(result) > 0

Expand Down
12 changes: 6 additions & 6 deletions astroquery/gemini/tests/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@
class TestGemini:
def test_observations_query_region(self):
""" test query against a region of the sky against actual archive """
result = gemini.Observations.query_region(coords, radius=0.3 * units.deg)
result = gemini.GeminiObservations.query_region(coords, radius=0.3 * units.deg)
assert isinstance(result, Table)
assert len(result) > 0

def test_observations_query_criteria(self):
""" test query against an instrument/program via criteria against actual archive """
result = gemini.Observations.query_criteria(instrument='GMOS-N', program_id='GN-CAL20191122',
result = gemini.GeminiObservations.query_criteria(instrument='GMOS-N', program_id='GN-CAL20191122',
observation_type='BIAS')
assert isinstance(result, Table)
assert len(result) > 0

def test_observations_query_criteria_ascending_sort(self):
""" test query against an instrument/program via criteria against actual archive """
result = gemini.Observations.query_criteria(instrument='GMOS-N', program_id='GN-CAL20191122',
result = gemini.GeminiObservations.query_criteria(instrument='GMOS-N', program_id='GN-CAL20191122',
observation_type='BIAS', orderby='filename_asc')
assert isinstance(result, Table)
assert len(result) > 0
Expand All @@ -52,7 +52,7 @@ def test_observations_query_criteria_ascending_sort(self):

def test_observations_query_criteria_descending_sort(self):
""" test query against an instrument/program via criteria against actual archive """
result = gemini.Observations.query_criteria(instrument='GMOS-N', program_id='GN-CAL20191122',
result = gemini.GeminiObservations.query_criteria(instrument='GMOS-N', program_id='GN-CAL20191122',
observation_type='BIAS', orderby='filename_desc')
assert isinstance(result, Table)
assert len(result) > 0
Expand All @@ -62,15 +62,15 @@ def test_observations_query_criteria_descending_sort(self):

def test_observations_query_raw(self):
""" test querying raw against actual archive """
result = gemini.Observations.query_raw('GMOS-N', 'BIAS', progid='GN-CAL20191122')
result = gemini.GeminiObservations.query_raw('GMOS-N', 'BIAS', progid='GN-CAL20191122')
assert isinstance(result, Table)
assert len(result) > 0

def test_get_file(self):
""" test querying raw against actual archive """
tempdir = tempfile.mkdtemp('_gemini_test')
filename = '20190105_GN-CAL20190105_obslog.txt'
gemini.Observations.get_file(filename, download_dir=tempdir)
gemini.GeminiObservations.get_file(filename, download_dir=tempdir)
filepath = os.path.join(tempdir, filename)
assert os.path.isfile(filepath)
assert os.stat(filepath).st_size == 7624
Expand Down
4 changes: 2 additions & 2 deletions astroquery/mast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class Conf(_config.ConfigNamespace):
conf = Conf()

from .cutouts import TesscutClass, Tesscut, ZcutClass, Zcut
Copy link
Member

Choose a reason for hiding this comment

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

Keep this line unchanged, that will fix the docs build.

from .observations import Observations, ObservationsClass, MastClass, Mast
from .observations import MastObservations, MastObservationsClass, MastClass, Mast
from .collections import Catalogs, CatalogsClass
from .missions import MastMissions, MastMissionsClass
from .core import MastQueryWithLogin
from . import utils

__all__ = ['Observations', 'ObservationsClass',
__all__ = ['MastObservations', 'MastObservationsClass',
'Catalogs', 'CatalogsClass',
'MastMissions', 'MastMissionsClass',
'Mast', 'MastClass',
Expand Down
18 changes: 9 additions & 9 deletions astroquery/mast/observations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
MAST Observations
=================
MAST MastObservations
=====================

This module contains various methods for querying MAST observations.
"""
Expand Down Expand Up @@ -37,14 +37,14 @@
from . import conf, utils
from .core import MastQueryWithLogin

__all__ = ['Observations', 'ObservationsClass',
__all__ = ['MastObservations', 'MastObservationsClass',
'MastClass', 'Mast']


@async_to_sync
class ObservationsClass(MastQueryWithLogin):
class MastObservationsClass(MastQueryWithLogin):
"""
MAST Observations query class.
MAST MastObservations query class.

Class for querying MAST observational data.
"""
Expand Down Expand Up @@ -173,7 +173,7 @@ def _parse_caom_criteria(self, **criteria):
# if radius is just a number we assume degrees
radius = coord.Angle(radius, u.deg)

# build the coordinates string needed by ObservationsClass._caom_filtered_position
# build the coordinates string needed by MastObservationsClass._caom_filtered_position
position = ', '.join([str(x) for x in (coordinates.ra.deg, coordinates.dec.deg, radius.deg)])

return position, mashup_filters
Expand Down Expand Up @@ -327,7 +327,7 @@ def query_region_count(self, coordinates, *, radius=0.2*u.deg, pagesize=None, pa
response : int
"""

# build the coordinates string needed by ObservationsClass._caom_filtered_position
# build the coordinates string needed by MastObservationsClass._caom_filtered_position
coordinates = commons.parse_coordinates(coordinates)

# if radius is just a number we assume degrees
Expand Down Expand Up @@ -807,7 +807,7 @@ class MastClass(MastQueryWithLogin):
MAST query class.

Class that allows direct programatic access to the MAST Portal,
more flexible but less user friendly than `ObservationsClass`.
more flexible but less user friendly than `MastObservationsClass`.
"""

def _parse_result(self, responses, *, verbose=False): # Used by the async_to_sync decorator functionality
Expand Down Expand Up @@ -864,5 +864,5 @@ def service_request_async(self, service, params, *, pagesize=None, page=None, **
return self._portal_api_connection.service_request_async(service, params, pagesize, page, **kwargs)


Observations = ObservationsClass()
MastObservations = MastObservationsClass()
Mast = MastClass()
Loading