Skip to content

Commit 176f77f

Browse files
authored
Merge pull request #2936 from esdc-esac-esa-int/ESA_gaia_define_linking_param_get_datalinks
GAIA: Include the parameter linking_parameter in the function get_datalinks
2 parents 0663eac + e4305d3 commit 176f77f

File tree

6 files changed

+210
-39
lines changed

6 files changed

+210
-39
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ gaia
4545

4646
- For the functions cone_search, cone_search_async, launch_job and launch_job_async the data can be retrieved for the json output_format [##2927]
4747

48+
- The method ``get_datalinks`` can be used with the new parameter linking_parameter. It completes PR #2859. [#2936]
49+
4850

4951
hsa
5052
^^^

astroquery/gaia/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class Conf(_config.ConfigNamespace):
3737
'RVS_EPOCH',
3838
'RVS_TRANSIT']
3939

40+
VALID_LINKING_PARAMETERS = {'SOURCE_ID', 'TRANSIT_ID', 'IMAGE_ID'}
41+
4042

4143
conf = Conf()
4244

astroquery/gaia/core.py

Lines changed: 100 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class GaiaClass(TapPlus):
4646
MAIN_GAIA_TABLE_DEC = conf.MAIN_GAIA_TABLE_DEC
4747
ROW_LIMIT = conf.ROW_LIMIT
4848
VALID_DATALINK_RETRIEVAL_TYPES = conf.VALID_DATALINK_RETRIEVAL_TYPES
49+
VALID_LINKING_PARAMETERS = conf.VALID_LINKING_PARAMETERS
4950
GAIA_MESSAGES = "notification?action=GetNotifications"
5051

5152
def __init__(self, *, tap_plus_conn_handler=None,
@@ -174,7 +175,7 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL', retr
174175
175176
Parameters
176177
----------
177-
ids : str list, mandatory
178+
ids : str, int, str list or int list, mandatory
178179
list of identifiers
179180
data_release: str, optional, default None
180181
data release from which data should be taken. E.g. 'Gaia DR3'
@@ -287,10 +288,10 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL', retr
287288
params_dict['RETRIEVAL_TYPE'] = str(retrieval_type)
288289
params_dict['USE_ZIP_ALWAYS'] = 'true'
289290

290-
valid_param = {'SOURCE_ID', 'TRANSIT_ID', 'IMAGE_ID'}
291-
if linking_parameter not in valid_param:
291+
if linking_parameter not in self.VALID_LINKING_PARAMETERS:
292292
raise ValueError(
293-
f"Invalid linking_parameter value '{linking_parameter}' (Valid values: {', '.join(valid_param)})")
293+
f"Invalid linking_parameter value '{linking_parameter}' (Valid values: "
294+
f"{', '.join(self.VALID_LINKING_PARAMETERS)})")
294295
else:
295296
if linking_parameter != 'SOURCE_ID':
296297
params_dict['LINKING_PARAMETER'] = linking_parameter
@@ -388,22 +389,77 @@ def __get_data_files(output_file, path):
388389

389390
return files
390391

391-
def get_datalinks(self, ids, *, verbose=False):
392+
def get_datalinks(self, ids, *, linking_parameter='SOURCE_ID', verbose=False):
392393
"""Gets datalinks associated to the provided identifiers
393394
TAP+ only
394395
395396
Parameters
396397
----------
397-
ids : str list, mandatory
398+
ids : str, int, str list or int list, mandatory
398399
list of identifiers
400+
linking_parameter : str, optional, default SOURCE_ID, valid values: SOURCE_ID, TRANSIT_ID, IMAGE_ID
401+
By default, all the identifiers are considered as source_id
402+
SOURCE_ID: the identifiers are considered as source_id
403+
TRANSIT_ID: the identifiers are considered as transit_id
404+
IMAGE_ID: the identifiers are considered as sif_observation_id
399405
verbose : bool, optional, default 'False'
400406
flag to display information about the process
401407
402408
Returns
403409
-------
404410
A table object
411+
412+
Examples
413+
--------
414+
Id formats.
415+
416+
-- Gaia.get_datalinks(iids=1104405489608579584) # single id as an int
417+
418+
-- Gaia.get_datalinks(ids='1104405489608579584, 1809140662896080256') # multiple ids as a str
419+
420+
-- Gaia.get_datalinks(ids=(1104405489608579584, 1809140662896080256)) # multiple ids as an int list
421+
422+
-- Gaia.get_datalinks(ids=('1104405489608579584','1809140662896080256')) # multiple ids as str list
423+
-- Gaia.get_datalinks(ids='4295806720-38655544960') # range of ids as a str
424+
425+
-- Gaia.get_datalinks(ids='4295806720-38655544960, 549755818112-1275606125952') # multiple ranges of ids as
426+
a str
427+
428+
-- Gaia.get_datalinks(ids=('4295806720-38655544960', '549755818112-1275606125952') # multiple ranges of ids
429+
as a str list
430+
431+
-- Gaia.get_datalinks(ids='Gaia DR3 1104405489608579584') # single designator
432+
-- Gaia.get_datalinks(ids='Gaia DR3 1104405489608579584, Gaia DR3 1809140662896080256') # multiple
433+
designators as a str
434+
435+
-- Gaia.get_datalinks(ids=('Gaia DR3 1104405489608579584','Gaia DR3 1809140662896080256')) # multiple
436+
designators as a str list
437+
438+
-- Gaia.get_datalinks(ids='Gaia DR3 4295806720-Gaia DR3 38655544960') # range of designators as a str
439+
440+
-- Gaia.get_datalinks(ids='Gaia DR3 4295806720-Gaia DR3 38655544960, Gaia DR3 549755818112-Gaia DR3
441+
1275606125952') # multiple ranges of designators as a str
442+
443+
-- Gaia.get_datalinks(ids=('Gaia DR3 4295806720-Gaia DR3 38655544960', 'Gaia DR3 549755818112-Gaia DR3
444+
1275606125952')) # multiple ranges of designators as a str list
445+
446+
-- Gaia.get_datalinks(ids='Gaia DR3 4295806720-Gaia DR3 38655544960, Gaia DR2 549755818112-Gaia DR2
447+
1275606125952') # multiple ranges of designators with difference releases as a str
448+
449+
-- Gaia.get_datalinks(ids=('Gaia DR3 4295806720-Gaia DR3 38655544960', 'Gaia DR2 549755818112-Gaia DR2
450+
1275606125952')) # multiple ranges of designators with difference releases as a str list
405451
"""
406-
return self.__gaiadata.get_datalinks(ids=ids, verbose=verbose)
452+
453+
if linking_parameter not in self.VALID_LINKING_PARAMETERS:
454+
raise ValueError(
455+
f"Invalid linking_parameter value '{linking_parameter}' (Valid values: "
456+
f"{', '.join(self.VALID_LINKING_PARAMETERS)})")
457+
458+
final_linking_parameter = None
459+
if linking_parameter != 'SOURCE_ID':
460+
final_linking_parameter = linking_parameter
461+
462+
return self.__gaiadata.get_datalinks(ids=ids, linking_parameter=final_linking_parameter, verbose=verbose)
407463

408464
def __query_object(self, coordinate, *, radius=None, width=None, height=None,
409465
async_job=False, verbose=False, columns=()):
@@ -412,20 +468,20 @@ def __query_object(self, coordinate, *, radius=None, width=None, height=None,
412468
413469
Parameters
414470
----------
415-
coordinate : astropy.coordinate, mandatory
471+
coordinate : str or astropy.coordinate, mandatory
416472
coordinates center point
417-
radius : astropy.units if no 'width' nor 'height' are provided
473+
radius : str or astropy.units if no 'width' nor 'height' are provided
418474
radius (deg)
419-
width : astropy.units if no 'radius' is provided
475+
width : str or astropy.units if no 'radius' is provided
420476
box width
421-
height : astropy.units if no 'radius' is provided
477+
height : str or astropy.units if no 'radius' is provided
422478
box height
423479
async_job : bool, optional, default 'False'
424480
executes the query (job) in asynchronous/synchronous mode (default
425481
synchronous)
426482
verbose : bool, optional, default 'False'
427483
flag to display information about the process
428-
columns: list, optional, default []
484+
columns: list, optional, default ()
429485
if empty, all columns will be selected
430486
431487
Returns
@@ -486,18 +542,19 @@ def __query_object(self, coordinate, *, radius=None, width=None, height=None,
486542

487543
def query_object(self, coordinate, *, radius=None, width=None, height=None,
488544
verbose=False, columns=()):
489-
"""Launches a job
545+
"""Launches a synchronous cone search for the input search radius or the box on the sky, sorted by angular
546+
separation
490547
TAP & TAP+
491548
492549
Parameters
493550
----------
494-
coordinate : astropy.coordinates, mandatory
551+
coordinate : str or astropy.coordinates, mandatory
495552
coordinates center point
496-
radius : astropy.units if no 'width'/'height' are provided
553+
radius : str or astropy.units if no 'width'/'height' are provided
497554
radius (deg)
498-
width : astropy.units if no 'radius' is provided
555+
width : str or astropy.units if no 'radius' is provided
499556
box width
500-
height : astropy.units if no 'radius' is provided
557+
height : str or astropy.units if no 'radius' is provided
501558
box height
502559
verbose : bool, optional, default 'False'
503560
flag to display information about the process
@@ -514,18 +571,19 @@ def query_object(self, coordinate, *, radius=None, width=None, height=None,
514571

515572
def query_object_async(self, coordinate, *, radius=None, width=None,
516573
height=None, verbose=False, columns=()):
517-
"""Launches a job (async)
574+
"""Launches an asynchronous cone search for the input search radius or the box on the sky, sorted by angular
575+
separation
518576
TAP & TAP+
519577
520578
Parameters
521579
----------
522-
coordinate : astropy.coordinates, mandatory
580+
coordinate : str or astropy.coordinates, mandatory
523581
coordinates center point
524-
radius : astropy.units if no 'width'/'height' are provided
582+
radius : str or astropy.units if no 'width'/'height' are provided
525583
radius
526-
width : astropy.units if no 'radius' is provided
584+
width : str or astropy.units if no 'radius' is provided
527585
box width
528-
height : astropy.units if no 'radius' is provided
586+
height : str or astropy.units if no 'radius' is provided
529587
box height
530588
verbose : bool, optional, default 'False'
531589
flag to display information about the process
@@ -569,7 +627,7 @@ def __cone_search(self, coordinate, radius, *, table_name=None,
569627
when the job is executed in asynchronous mode, this flag specifies
570628
whether the execution will wait until results are available
571629
output_file : str, optional, default None
572-
file name where the results are saved if dump_to_file is True.
630+
file name where the results are saved if ``dump_to_file`` is True.
573631
If this parameter is not provided, the jobid is used instead
574632
output_format : str, optional, default 'votable_gzip'
575633
results format. Available formats are: 'votable', 'votable_plain',
@@ -647,17 +705,17 @@ def cone_search(self, coordinate, *, radius=None,
647705
648706
Parameters
649707
----------
650-
coordinate : astropy.coordinate, mandatory
708+
coordinate : str or astropy.coordinate, mandatory
651709
coordinates center point
652-
radius : astropy.units, mandatory
710+
radius : str or astropy.units, mandatory
653711
radius
654712
table_name : str, optional, default main gaia table name doing the cone search against
655713
ra_column_name : str, optional, default ra column in main gaia table
656714
ra column doing the cone search against
657715
dec_column_name : str, optional, default dec column in main gaia table
658716
dec column doing the cone search against
659717
output_file : str, optional, default None
660-
file name where the results are saved if dump_to_file is True.
718+
file name where the results are saved if ``dump_to_file`` is True.
661719
If this parameter is not provided, the jobid is used instead
662720
output_format : str, optional, default 'votable_gzip'
663721
results format. Available formats are: 'votable', 'votable_plain',
@@ -697,9 +755,9 @@ def cone_search_async(self, coordinate, *, radius=None,
697755
698756
Parameters
699757
----------
700-
coordinate : astropy.coordinate, mandatory
758+
coordinate : str or astropy.coordinate, mandatory
701759
coordinates center point
702-
radius : astropy.units, mandatory
760+
radius : str or astropy.units, mandatory
703761
radius
704762
table_name : str, optional, default main gaia table name doing the cone search against
705763
ra_column_name : str, optional, default ra column in main gaia table
@@ -711,7 +769,7 @@ def cone_search_async(self, coordinate, *, radius=None,
711769
specifies whether
712770
the execution will wait until results are available
713771
output_file : str, optional, default None
714-
file name where the results are saved if dump_to_file is True.
772+
file name where the results are saved if ``dump_to_file`` is True.
715773
If this parameter is not provided, the jobid is used instead
716774
output_format : str, optional, default 'votable_gzip'
717775
results format. Available formats are: 'votable', 'votable_plain',
@@ -772,6 +830,15 @@ def __getCoordInput(self, value, msg):
772830

773831
@staticmethod
774832
def correct_table_units(table):
833+
"""Correct format in the units of the columns
834+
TAP & TAP+
835+
836+
Parameters
837+
----------
838+
table : `~astropy.table.Table`, mandatory
839+
change the format of the units in the columns of the input table: '.' by ' ' and "'" by ""
840+
"""
841+
775842
for cn in table.colnames:
776843
col = table[cn]
777844
if isinstance(col.unit, u.UnrecognizedUnit):
@@ -877,7 +944,7 @@ def launch_job(self, query, *, name=None, output_file=None,
877944
name : str, optional, default None
878945
custom name defined by the user for the job that is going to be created
879946
output_file : str, optional, default None
880-
file name where the results are saved if dump_to_file is True.
947+
file name where the results are saved if ``dump_to_file`` is True.
881948
If this parameter is not provided, the jobid is used instead
882949
output_format : str, optional, default 'votable_gzip'
883950
results format. Available formats are: 'votable_gzip', 'votable', 'votable_plain',
@@ -892,7 +959,7 @@ def launch_job(self, query, *, name=None, output_file=None,
892959
resource to be uploaded to UPLOAD_SCHEMA
893960
upload_table_name : str, optional, default None
894961
resource temporary table name associated to the uploaded resource.
895-
This argument is required if upload_resource is provided.
962+
This argument is required if ``upload_resource`` is provided.
896963
897964
Returns
898965
-------
@@ -922,7 +989,7 @@ def launch_job_async(self, query, *, name=None, output_file=None,
922989
name : str, optional, default None
923990
custom name defined by the user for the job that is going to be created
924991
output_file : str, optional, default None
925-
file name where the results are saved if dump_to_file is True.
992+
file name where the results are saved if ``dump_to_file`` is True.
926993
If this parameter is not provided, the jobid is used instead
927994
output_format : str, optional, default 'votable_gzip'
928995
results format. Available formats are: 'votable_gzip', 'votable', 'votable_plain',
@@ -940,7 +1007,7 @@ def launch_job_async(self, query, *, name=None, output_file=None,
9401007
resource to be uploaded to UPLOAD_SCHEMA
9411008
upload_table_name : str, optional, default None
9421009
resource temporary table name associated to the uploaded resource.
943-
This argument is required if upload_resource is provided.
1010+
This argument is required if ``upload_resource`` is provided.
9441011
autorun : boolean, optional, default True
9451012
if 'True', sets 'phase' parameter to 'RUN',
9461013
so the framework can start the job.

0 commit comments

Comments
 (0)