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

Gaia: Define new constant USE_NAMES_OVER_IDS that gives preference to name over ID attributes of columns as the names of columns in the astropy.table.Table instance. #2967

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a4dde9c
GAIAPCR-1313 Update gaia astroquery to read votable columns names bas…
Mar 9, 2024
61eb9e6
GAIAPCR-1313 Update gaia astroquery to read votable columns names bas…
Mar 9, 2024
2138134
GAIAPCR-1313 Update gaia astroquery to read votable columns names bas…
Mar 9, 2024
66aea1c
GAIAPCR-1313 Move function load_async_job to class TAP to make use of…
Mar 10, 2024
543fda9
GAIAPCR-1313 Simplify function get_current_column_values_for_update
Mar 10, 2024
ce729fa
GAIAPCR-1313 Format file
Mar 10, 2024
50ee8fb
GAIAPCR-1313 Format file
Mar 10, 2024
46c27a6
GAIAPCR-1313 Revert changes where the label _TapPlus_ for private var…
Mar 10, 2024
20fa044
GAIAPCR-1313 New tests
Mar 11, 2024
03cb37f
GAIAPCR-1313 New remote test to check the funcntion search_async_jobs
Mar 11, 2024
6fead2c
GAIAPCR-1313 Reformat file
Mar 11, 2024
74f7582
GAIAPCR-1313 Move function search_async_jobs to class Tap
Mar 11, 2024
173fdcf
GAIAPCR-1313 Update documentation and include info in the file CHANGES
Mar 15, 2024
1d9c914
GAIAPCR-1313 Update PR number
Mar 15, 2024
1db2786
GAIAPCR-1313 Fix PEP 8 issues
Mar 15, 2024
852e621
Fixing ecsv case
bsipocz May 1, 2024
2fc6daa
GAIAPCR-1313 the use_names_over_ids is only used for votable
May 1, 2024
2f428cc
GAIAPCR-1313 Fix Code style checks
May 1, 2024
b71c058
GAIAPCR-1313 Include new file extensions
May 1, 2024
4422b7e
GAIAPCR-1313 Make use of astropy_format to check if the format is a v…
May 1, 2024
65a00ad
MAINT: fix int32 default on windows issue
bsipocz May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ gaia
- For the functions that return files in FITS/ECSV format, the files are now provided as uncompressed files.
[#2983]

- New parameter USE_NAMES_OVER_IDS that gives preference to ``name`` over ID attributes of columns as the names of
columns in the `astropy.table.Table` instance. By default, value True is set, that gives name preference. [#2967]

- Fix method search_async_jobs in the class TapPlus. [#2967]

jplhorizons
^^^^^^^^^^^
Expand Down Expand Up @@ -252,7 +256,6 @@ gaia

- Default Gaia catalog updated to DR3. [#2596]


heasarc
^^^^^^^

Expand Down
77 changes: 29 additions & 48 deletions astroquery/gaia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class GaiaClass(TapPlus):
VALID_DATALINK_RETRIEVAL_TYPES = conf.VALID_DATALINK_RETRIEVAL_TYPES
VALID_LINKING_PARAMETERS = conf.VALID_LINKING_PARAMETERS
GAIA_MESSAGES = "notification?action=GetNotifications"
USE_NAMES_OVER_IDS = True
"""When `True` use the ``name`` attributes of columns as the names of columns in the `astropy.table.Table` instance.
Since names are not guaranteed to be unique, this may cause some columns to be renamed by appending numbers to
the end. Otherwise, use the ID attributes as the column names.
"""

def __init__(self, *, tap_plus_conn_handler=None,
datalink_handler=None,
Expand All @@ -64,7 +69,8 @@ def __init__(self, *, tap_plus_conn_handler=None,
data_context="data",
datalink_context="datalink",
connhandler=tap_plus_conn_handler,
verbose=verbose)
verbose=verbose,
use_names_over_ids=self.USE_NAMES_OVER_IDS)
# Data uses a different TapPlus connection
if datalink_handler is None:
self.__gaiadata = TapPlus(url=gaia_data_server,
Expand All @@ -74,16 +80,16 @@ def __init__(self, *, tap_plus_conn_handler=None,
table_edit_context="TableTool",
data_context="data",
datalink_context="datalink",
verbose=verbose)
verbose=verbose,
use_names_over_ids=self.USE_NAMES_OVER_IDS)
else:
self.__gaiadata = datalink_handler

# Enable notifications
if show_server_messages:
self.get_status_messages()

def login(self, *, user=None, password=None, credentials_file=None,
verbose=False):
def login(self, *, user=None, password=None, credentials_file=None, verbose=False):
"""Performs a login.
User and password arguments can be used or a file that contains
username and password
Expand All @@ -104,18 +110,15 @@ def login(self, *, user=None, password=None, credentials_file=None,
"""
try:
log.info("Login to gaia TAP server")
TapPlus.login(self, user=user, password=password,
credentials_file=credentials_file,
verbose=verbose)
TapPlus.login(self, user=user, password=password, credentials_file=credentials_file, verbose=verbose)
except HTTPError:
log.error("Error logging in TAP server")
return
new_user = self._TapPlus__user
new_password = self._TapPlus__pwd
try:
log.info("Login to gaia data server")
TapPlus.login(self.__gaiadata, user=new_user, password=new_password,
verbose=verbose)
TapPlus.login(self.__gaiadata, user=new_user, password=new_password, verbose=verbose)
except HTTPError:
log.error("Error logging in data server")
log.error("Logging out from TAP server")
Expand All @@ -139,8 +142,7 @@ def login_gui(self, *, verbose=False):
new_password = self._TapPlus__pwd
try:
log.info("Login to gaia data server")
TapPlus.login(self.__gaiadata, user=new_user, password=new_password,
verbose=verbose)
TapPlus.login(self.__gaiadata, user=new_user, password=new_password, verbose=verbose)
except HTTPError:
log.error("Error logging in data server")
log.error("Logging out from TAP server")
Expand Down Expand Up @@ -304,9 +306,7 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL', retr
log.error("Creation of the directory %s failed" % path)

try:
self.__gaiadata.load_data(params_dict=params_dict,
output_file=output_file,
verbose=verbose)
self.__gaiadata.load_data(params_dict=params_dict, output_file=output_file, verbose=verbose)
files = Gaia.__get_data_files(output_file=output_file, path=path)
except Exception as err:
raise err
Expand Down Expand Up @@ -342,7 +342,6 @@ def __get_data_files(output_file, path):
if '.fits' in key:
tables = []
with fits.open(value) as hduList:
# print(hduList)
num_hdus = len(hduList)
for i in range(1, num_hdus):
table = Table.read(hduList[i], format='fits')
Expand All @@ -357,8 +356,7 @@ def __get_data_files(output_file, path):

elif '.csv' in key:
tables = []
table = Table.read(value, format='ascii.csv',
fast_reader=False)
table = Table.read(value, format='ascii.csv', fast_reader=False)
tables.append(table)
files[key] = tables

Expand Down Expand Up @@ -492,8 +490,7 @@ def __query_object(self, coordinate, *, radius=None, width=None, height=None,
coord = self.__getCoordInput(coordinate, "coordinate")

if radius is not None:
job = self.__cone_search(coord, radius, async_job=async_job,
verbose=verbose, columns=columns)
job = self.__cone_search(coord, radius, async_job=async_job, verbose=verbose, columns=columns)
else:
raHours, dec = commons.coord_to_radec(coord)
ra = raHours * 15.0 # Converts to degrees
Expand Down Expand Up @@ -541,8 +538,7 @@ def __query_object(self, coordinate, *, radius=None, width=None, height=None,
job = self.launch_job(query, verbose=verbose)
return job.get_results()

def query_object(self, coordinate, *, radius=None, width=None, height=None,
verbose=False, columns=()):
def query_object(self, coordinate, *, radius=None, width=None, height=None, verbose=False, columns=()):
"""Launches a synchronous cone search for the input search radius or the box on the sky, sorted by angular
separation
TAP & TAP+
Expand All @@ -566,12 +562,10 @@ def query_object(self, coordinate, *, radius=None, width=None, height=None,
-------
The job results (astropy.table).
"""
return self.__query_object(coordinate, radius=radius,
width=width, height=height, async_job=False,
return self.__query_object(coordinate, radius=radius, width=width, height=height, async_job=False,
verbose=verbose, columns=columns)

def query_object_async(self, coordinate, *, radius=None, width=None,
height=None, verbose=False, columns=()):
def query_object_async(self, coordinate, *, radius=None, width=None, height=None, verbose=False, columns=()):
"""Launches an asynchronous cone search for the input search radius or the box on the sky, sorted by angular
separation
TAP & TAP+
Expand All @@ -595,9 +589,8 @@ def query_object_async(self, coordinate, *, radius=None, width=None,
-------
The job results (astropy.table).
"""
return self.__query_object(coordinate, radius=radius, width=width,
height=height, async_job=True, verbose=verbose,
columns=columns)
return self.__query_object(coordinate, radius=radius, width=width, height=height, async_job=True,
verbose=verbose, columns=columns)

def __cone_search(self, coordinate, radius, *, table_name=None,
ra_column_name=MAIN_GAIA_TABLE_RA,
Expand Down Expand Up @@ -680,17 +673,10 @@ def __cone_search(self, coordinate, radius, *, table_name=None,
'table_name': table_name or self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE})

if async_job:
return self.launch_job_async(query=query,
output_file=output_file,
output_format=output_format,
verbose=verbose,
dump_to_file=dump_to_file,
background=background)
return self.launch_job_async(query=query, output_file=output_file, output_format=output_format,
verbose=verbose, dump_to_file=dump_to_file, background=background)
else:
return self.launch_job(query=query,
output_file=output_file,
output_format=output_format,
verbose=verbose,
return self.launch_job(query=query, output_file=output_file, output_format=output_format, verbose=verbose,
dump_to_file=dump_to_file)

def cone_search(self, coordinate, *, radius=None,
Expand Down Expand Up @@ -809,23 +795,19 @@ def __getQuantityInput(self, value, msg):
raise ValueError(f"{msg} must be either a string or astropy.coordinates")

if isinstance(value, str):
q = Quantity(value)
return q
return Quantity(value)
else:
return value

def __checkCoordInput(self, value, msg):
if not (isinstance(value, str) or isinstance(value,
commons.CoordClasses)):
if not (isinstance(value, str) or isinstance(value, commons.CoordClasses)):
raise ValueError(f"{msg} must be either a string or astropy.coordinates")

def __getCoordInput(self, value, msg):
if not (isinstance(value, str) or isinstance(value,
commons.CoordClasses)):
if not (isinstance(value, str) or isinstance(value, commons.CoordClasses)):
raise ValueError(f"{msg} must be either a string or astropy.coordinates")
if isinstance(value, str):
c = commons.parse_coordinates(value)
return c
return commons.parse_coordinates(value)
else:
return value

Expand Down Expand Up @@ -866,8 +848,7 @@ def load_user(self, user_id, *, verbose=False):
A user
"""

return self.is_valid_user(user_id=user_id,
verbose=verbose)
return self.is_valid_user(user_id=user_id, verbose=verbose)

def cross_match(self, *, full_qualified_table_name_a,
full_qualified_table_name_b,
Expand Down