Skip to content

Commit 2a6b34c

Browse files
mhsarmientojespinosaar
authored andcommitted
This new implementation:
- Rename the output file name given by the user with the correct extension (By default, fits and votable results are returned in compressed format) - Improves the help for methods 'launch_job' and 'launch_job_async'. The help for the parameter 'name' was missing in those methods.
1 parent 66b513a commit 2a6b34c

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

astroquery/gaia/core.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from astropy.io import fits
3333
from astropy.table import Table
3434
from astropy import units as u
35+
import warnings
3536

3637

3738
class GaiaClass(TapPlus):
@@ -429,7 +430,8 @@ def __query_object(self, coordinate, radius=None, width=None, height=None,
429430
dist ASC
430431
""".format(**{'row_limit': "TOP {0}".format(self.ROW_LIMIT) if self.ROW_LIMIT > 0 else "",
431432
'ra_column': self.MAIN_GAIA_TABLE_RA, 'dec_column': self.MAIN_GAIA_TABLE_DEC,
432-
'columns': columns, 'table_name': self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE, 'ra': ra, 'dec': dec,
433+
'columns': columns, 'table_name': self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE,
434+
'ra': ra, 'dec': dec,
433435
'width': widthDeg.value, 'height': heightDeg.value})
434436
if async_job:
435437
job = self.launch_job_async(query, verbose=verbose)
@@ -566,7 +568,8 @@ def __cone_search(self, coordinate, radius, table_name=None,
566568
""".format(**{'ra_column': ra_column_name,
567569
'row_limit': "TOP {0}".format(self.ROW_LIMIT) if self.ROW_LIMIT > 0 else "",
568570
'dec_column': dec_column_name, 'columns': columns, 'ra': ra, 'dec': dec,
569-
'radius': radiusDeg, 'table_name': table_name or self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE})
571+
'radius': radiusDeg,
572+
'table_name': table_name or self.MAIN_GAIA_TABLE or conf.MAIN_GAIA_TABLE})
570573

571574
if async_job:
572575
return self.launch_job_async(query=query,
@@ -823,12 +826,14 @@ def launch_job(self, query, name=None, output_file=None,
823826
----------
824827
query : str, mandatory
825828
query to be executed
829+
name : str, optional, default None
830+
custom name defined by the user for the job that is going to be created
826831
output_file : str, optional, default None
827832
file name where the results are saved if dumpToFile is True.
828833
If this parameter is not provided, the jobid is used instead
829834
output_format : str, optional, default 'votable'
830835
results format. Available formats are: 'votable', 'votable_plain',
831-
'fits', 'csv' and 'json', default is 'votable'.
836+
'fits', 'csv', 'ecsv' and 'json', default is 'votable'.
832837
Returned results for 'votable' and 'fits' formats are compressed
833838
gzip files.
834839
verbose : bool, optional, default 'False'
@@ -845,8 +850,30 @@ def launch_job(self, query, name=None, output_file=None,
845850
-------
846851
A Job object
847852
"""
853+
compressed_extension = ".gz"
854+
format_with_results_compressed = ['votable', 'fits']
855+
output_file_with_extension = output_file
856+
857+
if output_file is not None:
858+
if output_format in format_with_results_compressed:
859+
# In this case we will have to take also into account the .fits format
860+
if not output_file.endswith(compressed_extension):
861+
warnings.warn('WARNING!!! By default, results in "votable" and "fits" format are returned in '
862+
f'compressed format therefore your file {output_file} '
863+
f'will be renamed to {output_file}.gz')
864+
if output_format == 'votable':
865+
if output_file.endswith('.vot'):
866+
output_file_with_extension = output_file + '.gz'
867+
else:
868+
output_file_with_extension = output_file + '.vot.gz'
869+
elif output_format == 'fits':
870+
if output_file.endswith('.fits'):
871+
output_file_with_extension = output_file + '.gz'
872+
else:
873+
output_file_with_extension = output_file + '.fits.gz'
874+
848875
return TapPlus.launch_job(self, query=query, name=name,
849-
output_file=output_file,
876+
output_file=output_file_with_extension,
850877
output_format=output_format,
851878
verbose=verbose,
852879
dump_to_file=dump_to_file,
@@ -864,6 +891,8 @@ def launch_job_async(self, query, name=None, output_file=None,
864891
----------
865892
query : str, mandatory
866893
query to be executed
894+
name : str, optional, default None
895+
custom name defined by the user for the job that is going to be created
867896
output_file : str, optional, default None
868897
file name where the results are saved if dumpToFile is True.
869898
If this parameter is not provided, the jobid is used instead
@@ -892,9 +921,31 @@ def launch_job_async(self, query, name=None, output_file=None,
892921
-------
893922
A Job object
894923
"""
924+
compressed_extension = ".gz"
925+
format_with_results_compressed = ['votable', 'fits']
926+
output_file_with_extension = output_file
927+
928+
if output_file is not None:
929+
if output_format in format_with_results_compressed:
930+
# In this case we will have to take also into account the .fits format
931+
if not output_file.endswith(compressed_extension):
932+
warnings.warn('WARNING!!! By default, results in "votable" and "fits" format are returned in '
933+
f'compressed format therefore your file {output_file} '
934+
f'will be renamed to {output_file}.gz')
935+
if output_format == 'votable':
936+
if output_file.endswith('.vot'):
937+
output_file_with_extension = output_file + '.gz'
938+
else:
939+
output_file_with_extension = output_file + '.vot.gz'
940+
elif output_format == 'fits':
941+
if output_file.endswith('.fits'):
942+
output_file_with_extension = output_file + '.gz'
943+
else:
944+
output_file_with_extension = output_file + '.fits.gz'
945+
895946
return TapPlus.launch_job_async(self, query=query,
896947
name=name,
897-
output_file=output_file,
948+
output_file=output_file_with_extension,
898949
output_format=output_format,
899950
verbose=verbose,
900951
dump_to_file=dump_to_file,

astroquery/utils/tap/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ def launch_job(self, query, name=None, output_file=None,
245245
----------
246246
query : str, mandatory
247247
query to be executed
248+
name : str, optional, default None
249+
custom name defined by the user for the job that is going to be created
248250
output_file : str, optional, default None
249251
file name where the results are saved if dumpToFile is True.
250252
If this parameter is not provided, the jobid is used instead
@@ -357,6 +359,8 @@ def launch_job_async(self, query, name=None, output_file=None,
357359
----------
358360
query : str, mandatory
359361
query to be executed
362+
name : str, optional, default None
363+
custom name defined by the user for the job that is going to be created
360364
output_file : str, optional, default None
361365
file name where the results are saved if dumpToFile is True.
362366
If this parameter is not provided, the jobid is used instead

0 commit comments

Comments
 (0)