12
12
13
13
Created on 30 jun. 2016
14
14
Modified on 18 Ene. 2022 by mhsarmiento
15
-
16
15
"""
17
16
from requests import HTTPError
18
17
33
32
from astropy .table import Table
34
33
from astropy import units as u
35
34
import warnings
35
+ from astroquery .exceptions import InputWarning
36
36
37
37
38
38
class GaiaClass (TapPlus ):
@@ -78,9 +78,9 @@ def login(self, user=None, password=None, credentials_file=None,
78
78
verbose = False ):
79
79
"""Performs a login.
80
80
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
84
84
password will appear.
85
85
86
86
Parameters
@@ -199,7 +199,7 @@ def load_data(self, ids, data_release=None, data_structure='INDIVIDUAL', retriev
199
199
By default, this value will be set to False. If it is set to 'true'
200
200
the Datalink items tags will not be checked.
201
201
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'
203
203
output_file : string, optional, default None
204
204
file where the results are saved.
205
205
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,
371
371
----------
372
372
coordinate : astropy.coordinate, mandatory
373
373
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
376
375
radius (deg)
377
- width : astropy.units, required if no 'radius' is provided
376
+ width : astropy.units if no 'radius' is provided
378
377
box width
379
- height : astropy.units, required if no 'radius' is provided
378
+ height : astropy.units if no 'radius' is provided
380
379
box height
381
380
async_job : bool, optional, default 'False'
382
381
executes the query (job) in asynchronous/synchronous mode (default
@@ -451,11 +450,11 @@ def query_object(self, coordinate, radius=None, width=None, height=None,
451
450
----------
452
451
coordinate : astropy.coordinates, mandatory
453
452
coordinates center point
454
- radius : astropy.units, required if no 'width'/'height' are provided
453
+ radius : astropy.units if no 'width'/'height' are provided
455
454
radius (deg)
456
- width : astropy.units, required if no 'radius' is provided
455
+ width : astropy.units if no 'radius' is provided
457
456
box width
458
- height : astropy.units, required if no 'radius' is provided
457
+ height : astropy.units if no 'radius' is provided
459
458
box height
460
459
verbose : bool, optional, default 'False'
461
460
flag to display information about the process
@@ -477,11 +476,11 @@ def query_object_async(self, coordinate, radius=None, width=None,
477
476
----------
478
477
coordinate : astropy.coordinates, mandatory
479
478
coordinates center point
480
- radius : astropy.units, required if no 'width'/'height' are provided
479
+ radius : astropy.units if no 'width'/'height' are provided
481
480
radius
482
- width : astropy.units, required if no 'radius' is provided
481
+ width : astropy.units if no 'radius' is provided
483
482
box width
484
- height : astropy.units, required if no 'radius' is provided
483
+ height : astropy.units if no 'radius' is provided
485
484
box height
486
485
verbose : bool, optional, default 'False'
487
486
flag to display information about the process
@@ -511,8 +510,7 @@ def __cone_search(self, coordinate, radius, table_name=None,
511
510
coordinates center point
512
511
radius : astropy.units, mandatory
513
512
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
516
514
ra_column_name : str, optional, default ra column in main gaia table
517
515
ra column doing the cone search against
518
516
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,
539
537
-------
540
538
A Job object
541
539
"""
540
+ radiusDeg = None
542
541
coord = self .__getCoordInput (coordinate , "coordinate" )
543
542
raHours , dec = commons .coord_to_radec (coord )
544
543
ra = raHours * 15.0 # Converts to degrees
@@ -605,8 +604,7 @@ def cone_search(self, coordinate, radius=None,
605
604
coordinates center point
606
605
radius : astropy.units, mandatory
607
606
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
610
608
ra_column_name : str, optional, default ra column in main gaia table
611
609
ra column doing the cone search against
612
610
dec_column_name : str, optional, default dec column in main gaia table
@@ -655,8 +653,7 @@ def cone_search_async(self, coordinate, radius=None,
655
653
coordinates center point
656
654
radius : astropy.units, mandatory
657
655
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
660
657
ra_column_name : str, optional, default ra column in main gaia table
661
658
ra column doing the cone search against
662
659
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,
759
756
radius = 1.0 ,
760
757
background = False ,
761
758
verbose = False ):
762
- """Performs a cross match between the specified tables
759
+ """Performs a cross- match between the specified tables
763
760
The result is a join table (stored in the user storage area)
764
761
with the identifies of both tables and the distance.
765
762
TAP+ only
@@ -861,9 +858,9 @@ def launch_job(self, query, name=None, output_file=None,
861
858
if output_format in format_with_results_compressed :
862
859
# In this case we will have to take also into account the .fits format
863
860
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 '
865
862
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 )
867
864
if output_format == 'votable' :
868
865
if output_file .endswith ('.vot' ):
869
866
output_file_with_extension = output_file + '.gz'
@@ -925,7 +922,7 @@ def launch_job_async(self, query, name=None, output_file=None,
925
922
A Job object
926
923
"""
927
924
compressed_extension = ".gz"
928
- format_with_results_compressed = ['votable' , 'fits' ]
925
+ format_with_results_compressed = ['votable' , 'fits' , 'ecsv' ]
929
926
output_file_with_extension = output_file
930
927
931
928
if output_file is not None :
@@ -945,6 +942,16 @@ def launch_job_async(self, query, name=None, output_file=None,
945
942
output_file_with_extension = output_file + '.gz'
946
943
else :
947
944
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 } ' )
948
955
949
956
return TapPlus .launch_job_async (self , query = query ,
950
957
name = name ,
@@ -957,25 +964,5 @@ def launch_job_async(self, query, name=None, output_file=None,
957
964
upload_table_name = upload_table_name ,
958
965
autorun = autorun )
959
966
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
-
980
967
981
968
Gaia = GaiaClass ()
0 commit comments