Skip to content

Commit 1c0fb80

Browse files
mhsarmientojespinosaar
authored andcommitted
This new commit implements the comments done on the pull request #2077 and implements ticket GAIAPCR-1040:C9APP-149 Astropy error when working with tables downloaded in plain votable, fits, json, and ecsv formats
1 parent a039440 commit 1c0fb80

File tree

11 files changed

+367
-316
lines changed

11 files changed

+367
-316
lines changed

CHANGES.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
New Tools and Services
55
----------------------
66

7+
gaia
8+
^^^^
9+
- New method, rename_table, which allows the user to rename table and column names
10+
711

812
Service fixes and enhancements
913
------------------------------
@@ -29,6 +33,9 @@ gaia
2933
``astroquery.gaia.Gaia`` no longer ignore their ``columns`` argument when
3034
``radius`` is specified. [#2249]
3135

36+
- Enhanced methods 'launch_job' and 'launch_job_async' to avoid issues with the name provided by the user for the
37+
output file when the results are returned by the TAP in compressed format.
38+
3239
mast
3340
^^^^
3441

@@ -38,6 +45,7 @@ mast
3845

3946
- Adding the All-Sky PLATO Input Catalog ('plato') as a catalog option for methods of ``astroquery.mast.Catalogs``. [#2279]
4047

48+
4149
Infrastructure, Utility and Other Changes and Additions
4250
-------------------------------------------------------
4351

@@ -1133,4 +1141,4 @@ Infrastructure, Utility and Other Changes and Additions
11331141
0.1 (2013-09-19)
11341142
================
11351143

1136-
- Initial release. Includes features!
1144+
- Initial release. Includes features!

astroquery/gaia/core.py

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
1313
Created on 30 jun. 2016
1414
Modified on 18 Ene. 2022 by mhsarmiento
15-
1615
"""
1716
from requests import HTTPError
1817

@@ -33,6 +32,7 @@
3332
from astropy.table import Table
3433
from astropy import units as u
3534
import warnings
35+
from astroquery.exceptions import InputWarning
3636

3737

3838
class GaiaClass(TapPlus):
@@ -78,9 +78,9 @@ def login(self, user=None, password=None, credentials_file=None,
7878
verbose=False):
7979
"""Performs a login.
8080
User and password arguments can be used or a file that contains
81-
user name and password
82-
(2 lines: one for user name and the following one for the password).
83-
If no arguments are provided, a prompt asking for user name and
81+
username and password
82+
(2 lines: one for username and the following one for the password).
83+
If no arguments are provided, a prompt asking for username and
8484
password will appear.
8585
8686
Parameters
@@ -199,7 +199,7 @@ def load_data(self, ids, data_release=None, data_structure='INDIVIDUAL', retriev
199199
By default, this value will be set to False. If it is set to 'true'
200200
the Datalink items tags will not be checked.
201201
format : str, optional, default 'votable'
202-
loading format. Other available formats are 'csv', 'ecsv', 'votable_plain' and 'fits'
202+
loading format. Other available formats are 'csv', 'ecsv','json','votable_plain' and 'fits'
203203
output_file : string, optional, default None
204204
file where the results are saved.
205205
If it is not provided, the http response contents are returned.
@@ -371,12 +371,11 @@ def __query_object(self, coordinate, radius=None, width=None, height=None,
371371
----------
372372
coordinate : astropy.coordinate, mandatory
373373
coordinates center point
374-
radius : astropy.units, required if no 'width' nor 'height' are
375-
provided
374+
radius : astropy.units if no 'width' nor 'height' are provided
376375
radius (deg)
377-
width : astropy.units, required if no 'radius' is provided
376+
width : astropy.units if no 'radius' is provided
378377
box width
379-
height : astropy.units, required if no 'radius' is provided
378+
height : astropy.units if no 'radius' is provided
380379
box height
381380
async_job : bool, optional, default 'False'
382381
executes the query (job) in asynchronous/synchronous mode (default
@@ -451,11 +450,11 @@ def query_object(self, coordinate, radius=None, width=None, height=None,
451450
----------
452451
coordinate : astropy.coordinates, mandatory
453452
coordinates center point
454-
radius : astropy.units, required if no 'width'/'height' are provided
453+
radius : astropy.units if no 'width'/'height' are provided
455454
radius (deg)
456-
width : astropy.units, required if no 'radius' is provided
455+
width : astropy.units if no 'radius' is provided
457456
box width
458-
height : astropy.units, required if no 'radius' is provided
457+
height : astropy.units if no 'radius' is provided
459458
box height
460459
verbose : bool, optional, default 'False'
461460
flag to display information about the process
@@ -477,11 +476,11 @@ def query_object_async(self, coordinate, radius=None, width=None,
477476
----------
478477
coordinate : astropy.coordinates, mandatory
479478
coordinates center point
480-
radius : astropy.units, required if no 'width'/'height' are provided
479+
radius : astropy.units if no 'width'/'height' are provided
481480
radius
482-
width : astropy.units, required if no 'radius' is provided
481+
width : astropy.units if no 'radius' is provided
483482
box width
484-
height : astropy.units, required if no 'radius' is provided
483+
height : astropy.units if no 'radius' is provided
485484
box height
486485
verbose : bool, optional, default 'False'
487486
flag to display information about the process
@@ -511,8 +510,7 @@ def __cone_search(self, coordinate, radius, table_name=None,
511510
coordinates center point
512511
radius : astropy.units, mandatory
513512
radius
514-
table_name : str, optional, default main gaia table
515-
table name doing the cone search against
513+
table_name : str, optional, default main gaia table name doing the cone search against
516514
ra_column_name : str, optional, default ra column in main gaia table
517515
ra column doing the cone search against
518516
dec_column_name : str, optional, default dec column in main gaia table
@@ -539,6 +537,7 @@ def __cone_search(self, coordinate, radius, table_name=None,
539537
-------
540538
A Job object
541539
"""
540+
radiusDeg = None
542541
coord = self.__getCoordInput(coordinate, "coordinate")
543542
raHours, dec = commons.coord_to_radec(coord)
544543
ra = raHours * 15.0 # Converts to degrees
@@ -605,8 +604,7 @@ def cone_search(self, coordinate, radius=None,
605604
coordinates center point
606605
radius : astropy.units, mandatory
607606
radius
608-
table_name : str, optional, default main gaia table
609-
table name doing the cone search against
607+
table_name : str, optional, default main gaia table name doing the cone search against
610608
ra_column_name : str, optional, default ra column in main gaia table
611609
ra column doing the cone search against
612610
dec_column_name : str, optional, default dec column in main gaia table
@@ -655,8 +653,7 @@ def cone_search_async(self, coordinate, radius=None,
655653
coordinates center point
656654
radius : astropy.units, mandatory
657655
radius
658-
table_name : str, optional, default main gaia table
659-
table name doing the cone search against
656+
table_name : str, optional, default main gaia table name doing the cone search against
660657
ra_column_name : str, optional, default ra column in main gaia table
661658
ra column doing the cone search against
662659
dec_column_name : str, optional, default dec column in main gaia table
@@ -759,7 +756,7 @@ def cross_match(self, full_qualified_table_name_a=None,
759756
radius=1.0,
760757
background=False,
761758
verbose=False):
762-
"""Performs a cross match between the specified tables
759+
"""Performs a cross-match between the specified tables
763760
The result is a join table (stored in the user storage area)
764761
with the identifies of both tables and the distance.
765762
TAP+ only
@@ -861,9 +858,9 @@ def launch_job(self, query, name=None, output_file=None,
861858
if output_format in format_with_results_compressed:
862859
# In this case we will have to take also into account the .fits format
863860
if not output_file.endswith(compressed_extension):
864-
warnings.warn('WARNING!!! By default, results in "votable" and "fits" format are returned in '
861+
warnings.warn('By default, results in "votable" and "fits" format are returned in '
865862
f'compressed format therefore your file {output_file} '
866-
f'will be renamed to {output_file}.gz')
863+
f'will be renamed to {output_file}.gz', InputWarning)
867864
if output_format == 'votable':
868865
if output_file.endswith('.vot'):
869866
output_file_with_extension = output_file + '.gz'
@@ -925,7 +922,7 @@ def launch_job_async(self, query, name=None, output_file=None,
925922
A Job object
926923
"""
927924
compressed_extension = ".gz"
928-
format_with_results_compressed = ['votable', 'fits']
925+
format_with_results_compressed = ['votable', 'fits', 'ecsv']
929926
output_file_with_extension = output_file
930927

931928
if output_file is not None:
@@ -945,6 +942,16 @@ def launch_job_async(self, query, name=None, output_file=None,
945942
output_file_with_extension = output_file + '.gz'
946943
else:
947944
output_file_with_extension = output_file + '.fits.gz'
945+
elif output_format == 'ecsv':
946+
if output_file.endswith('.ecsv'):
947+
output_file_with_extension = output_file + '.gz'
948+
else:
949+
output_file_with_extension = output_file + '.ecsv.gz'
950+
# the output type is not compressed by default by the TAP SERVER but the users gives a .gz extension
951+
elif output_file.endswith(compressed_extension):
952+
output_file_renamed = output_file.removesuffix('.gz')
953+
warnings.warn(f'WARNING!!! The output format selected is not compatible with compression. {output_file}'
954+
f' will be renamed to {output_file}')
948955

949956
return TapPlus.launch_job_async(self, query=query,
950957
name=name,
@@ -957,25 +964,5 @@ def launch_job_async(self, query, name=None, output_file=None,
957964
upload_table_name=upload_table_name,
958965
autorun=autorun)
959966

960-
def rename_table(self, table_name=None, new_table_name=None, new_column_names_dict={},
961-
verbose=False):
962-
"""
963-
This new method allows to update the column names of a user table.
964-
header example: rename_table(table_name=old_table_name, new_table_name=new_table_name -optional-
965-
, new_column_names_dict=[old_column1:new_column1, old_column2:new_colum2...])
966-
Parameters
967-
----------
968-
table_name: str, required
969-
old name of the user's table
970-
new_table_name: str, required
971-
new name of the user's table
972-
new_column_names_dict: dict str:str, required
973-
dict with pairs "old_column1_name:new_column1_name"
974-
verbose : bool, optional, default 'False'
975-
flag to display information about the process
976-
"""
977-
return TapPlus.rename_table(self, table_name=table_name, new_table_name=new_table_name,
978-
new_column_names_dict=new_column_names_dict, verbose=verbose)
979-
980967

981968
Gaia = GaiaClass()
728 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)