@@ -75,6 +75,23 @@ def _cached_query_tap(tap, query: str, *, maxrec=10000):
75
75
return tap .search (query , maxrec = maxrec ).to_table ()
76
76
77
77
78
+ @dataclass (frozen = True )
79
+ class _Column :
80
+ """A class to define a column in a SIMBAD query."""
81
+ table : str
82
+ name : str
83
+ alias : str = field (default = None )
84
+
85
+
86
+ @dataclass (frozen = True )
87
+ class _Join :
88
+ """A class to define a join between two tables."""
89
+ table : str
90
+ column_left : Any
91
+ column_right : Any
92
+ join_type : str = field (default = "JOIN" )
93
+
94
+
78
95
class SimbadClass (BaseVOQuery ):
79
96
"""The class for querying the SIMBAD web service.
80
97
@@ -84,30 +101,15 @@ class SimbadClass(BaseVOQuery):
84
101
"""
85
102
SIMBAD_URL = 'https://' + conf .server + '/simbad/sim-script'
86
103
87
- @dataclass (frozen = True )
88
- class Column :
89
- """A class to define a column in a SIMBAD query."""
90
- table : str
91
- name : str
92
- alias : str = field (default = None )
93
-
94
- @dataclass (frozen = True )
95
- class Join :
96
- """A class to define a join between two tables."""
97
- table : str
98
- column_left : Any
99
- column_right : Any
100
- join_type : str = field (default = "JOIN" )
101
-
102
104
def __init__ (self , ROW_LIMIT = None ):
103
105
super ().__init__ ()
104
106
# to create the TAPService
105
107
self ._server = conf .server
106
108
self ._tap = None
107
109
self ._hardlimit = None
108
110
# attributes to construct ADQL queries
109
- self ._columns_in_output = None # a list of Simbad.Column
110
- self .joins = [] # a list of Simbad.Join
111
+ self ._columns_in_output = None # a list of _Column
112
+ self .joins = [] # a list of _Join
111
113
self .criteria = [] # a list of strings
112
114
self .ROW_LIMIT = ROW_LIMIT
113
115
@@ -165,7 +167,7 @@ def hardlimit(self):
165
167
166
168
@property
167
169
def columns_in_output (self ):
168
- """A list of Simbad.Column .
170
+ """A list of _Column .
169
171
170
172
They will be included in the output of the following methods:
171
173
@@ -178,7 +180,7 @@ def columns_in_output(self):
178
180
179
181
"""
180
182
if self ._columns_in_output is None :
181
- self ._columns_in_output = [Simbad . Column ("basic" , item )
183
+ self ._columns_in_output = [_Column ("basic" , item )
182
184
for item in conf .default_columns ]
183
185
return self ._columns_in_output
184
186
@@ -277,7 +279,7 @@ def _get_bundle_columns(self, bundle_name):
277
279
278
280
Returns
279
281
-------
280
- list[Simbad.Column ]
282
+ list[simbad._Column ]
281
283
The list of columns corresponding to the selected bundle.
282
284
"""
283
285
basic_columns = set (map (str .casefold , set (self .list_columns ("basic" )["column_name" ])))
@@ -287,10 +289,10 @@ def _get_bundle_columns(self, bundle_name):
287
289
288
290
if bundle_name in bundle_entries :
289
291
bundle = bundle_entries [bundle_name ]
290
- columns = [Simbad . Column ("basic" , column ) for column in basic_columns
292
+ columns = [_Column ("basic" , column ) for column in basic_columns
291
293
if column .startswith (bundle ["tap_startswith" ])]
292
294
if "tap_column" in bundle :
293
- columns = [Simbad . Column ("basic" , column ) for column in bundle ["tap_column" ]] + columns
295
+ columns = [_Column ("basic" , column ) for column in bundle ["tap_column" ]] + columns
294
296
return columns
295
297
296
298
def _add_table_to_output (self , table ):
@@ -308,7 +310,7 @@ def _add_table_to_output(self, table):
308
310
table = table .casefold ()
309
311
310
312
if table == "basic" :
311
- self .columns_in_output .append (Simbad . Column (table , "*" ))
313
+ self .columns_in_output .append (_Column (table , "*" ))
312
314
return
313
315
314
316
linked_to_basic = self .list_linked_tables ("basic" )
@@ -329,10 +331,10 @@ def _add_table_to_output(self, table):
329
331
alias = [f'"{ table } .{ column } "' if not column .startswith (table ) else None for column in columns ]
330
332
331
333
# modify the attributes here
332
- self .columns_in_output += [Simbad . Column (table , column , alias )
334
+ self .columns_in_output += [_Column (table , column , alias )
333
335
for column , alias in zip (columns , alias )]
334
- self .joins += [Simbad . Join (table , Simbad . Column ("basic" , link ["target_column" ]),
335
- Simbad . Column (table , link ["from_column" ]))]
336
+ self .joins += [_Join (table , _Column ("basic" , link ["target_column" ]),
337
+ _Column (table , link ["from_column" ]))]
336
338
337
339
def add_votable_fields (self , * args ):
338
340
"""Add columns to the output of a SIMBAD query.
@@ -360,8 +362,8 @@ def add_votable_fields(self, *args):
360
362
>>> from astroquery.simbad import Simbad
361
363
>>> simbad = Simbad()
362
364
>>> simbad.add_votable_fields('sp_type', 'sp_qual', 'sp_bibcode') # doctest: +REMOTE_DATA
363
- >>> simbad.columns_in_output[0] # doctest: +REMOTE_DATA
364
- SimbadClass.Column(table=' basic', name='main_id ', alias=None)
365
+ >>> simbad.get_votable_fields() # doctest: +REMOTE_DATA
366
+ ['basic.main_id', ' basic.ra ', 'basic.dec ', 'basic.coo_err_maj', 'basic.coo_err_min', ...
365
367
"""
366
368
367
369
# the legacy way of adding fluxes is the only case-dependant option
@@ -375,9 +377,9 @@ def add_votable_fields(self, *args):
375
377
flux_filter = re .findall (r"\((\w+)\)" , arg )[0 ]
376
378
if len (flux_filter ) == 1 and flux_filter .islower ():
377
379
flux_filter = flux_filter + "_"
378
- self .joins .append (self . Join ("allfluxes" , self . Column ("basic" , "oid" ),
379
- self . Column ("allfluxes" , "oidref" )))
380
- self .columns_in_output .append (self . Column ("allfluxes" , flux_filter ))
380
+ self .joins .append (_Join ("allfluxes" , _Column ("basic" , "oid" ),
381
+ _Column ("allfluxes" , "oidref" )))
382
+ self .columns_in_output .append (_Column ("allfluxes" , flux_filter ))
381
383
args .remove (arg )
382
384
383
385
# casefold args
@@ -391,7 +393,7 @@ def add_votable_fields(self, *args):
391
393
bundles = output_options [output_options ["type" ] == "bundle of basic columns" ]["name" ]
392
394
393
395
# Add columns from basic
394
- self .columns_in_output += [Simbad . Column ("basic" , column ) for column in args if column in basic_columns ]
396
+ self .columns_in_output += [_Column ("basic" , column ) for column in args if column in basic_columns ]
395
397
396
398
# Add tables
397
399
tables_to_add = [table for table in args if table in all_tables ]
@@ -415,7 +417,7 @@ def add_votable_fields(self, *args):
415
417
# some columns are still there but under a new name
416
418
if field_type == "alias" :
417
419
tap_column = field_data ["tap_column" ]
418
- self .columns_in_output .append (Simbad . Column ("basic" , tap_column ))
420
+ self .columns_in_output .append (_Column ("basic" , tap_column ))
419
421
warning_message = (f"'{ votable_field } ' has been renamed '{ tap_column } '. You'll see it "
420
422
"appearing with its new name in the output table" )
421
423
warnings .warn (warning_message , DeprecationWarning , stacklevel = 2 )
@@ -462,7 +464,7 @@ def reset_votable_fields(self):
462
464
- `query_criteria`.
463
465
464
466
"""
465
- self .columns_in_output = [Simbad . Column ("basic" , item )
467
+ self .columns_in_output = [_Column ("basic" , item )
466
468
for item in conf .default_columns ]
467
469
self .joins = []
468
470
self .criteria = []
@@ -555,9 +557,9 @@ def query_object(self, object_name, *, wildcard=False,
555
557
"""
556
558
top , columns , joins , instance_criteria = self ._get_query_parameters ()
557
559
558
- columns .append (Simbad . Column ("ident" , "id" , "matched_id" ))
560
+ columns .append (_Column ("ident" , "id" , "matched_id" ))
559
561
560
- joins .append (Simbad . Join ("ident" , Simbad . Column ("basic" , "oid" ), Simbad . Column ("ident" , "oidref" )))
562
+ joins .append (_Join ("ident" , _Column ("basic" , "oid" ), _Column ("ident" , "oidref" )))
561
563
562
564
if wildcard :
563
565
instance_criteria .append (rf" regexp(id, '{ _wildcard_to_regexp (object_name )} ') = 1" )
@@ -626,10 +628,10 @@ def query_objects(self, object_names, *, wildcard=False, criteria=None,
626
628
instance_criteria .append (f"({ criteria } )" )
627
629
628
630
if wildcard :
629
- columns .append (Simbad . Column ("ident" , "id" , "matched_id" ))
630
- joins += [Simbad . Join ("ident" , Simbad . Column ("basic" , "oid" ),
631
- Simbad . Column ( "ident" , "oidref" ))]
632
- list_criteria = [ f"regexp(id, ' { _wildcard_to_regexp ( object_name ) } ') = 1" for object_name in object_names ]
631
+ columns .append (_Column ("ident" , "id" , "matched_id" ))
632
+ joins += [_Join ("ident" , _Column ("basic" , "oid" ), _Column ( "ident" , "oidref" ))]
633
+ list_criteria = [ f"regexp(id, ' { _wildcard_to_regexp ( object_name ) } ') = 1"
634
+ for object_name in object_names ]
633
635
instance_criteria += [f'({ " OR " .join (list_criteria )} )' ]
634
636
635
637
return self ._query (top , columns , joins , instance_criteria ,
@@ -640,16 +642,15 @@ def query_objects(self, object_names, *, wildcard=False, criteria=None,
640
642
upload = Table ({"user_specified_id" : object_names ,
641
643
"object_number_id" : list (range (1 , len (object_names ) + 1 ))})
642
644
upload_name = "TAP_UPLOAD.script_infos"
643
- columns .append (Simbad . Column (upload_name , "*" ))
645
+ columns .append (_Column (upload_name , "*" ))
644
646
645
- left_joins = [Simbad . Join ("ident" , Simbad . Column (upload_name , "user_specified_id" ),
646
- Simbad . Column ("ident" , "id" ), "LEFT JOIN" ),
647
- Simbad . Join ("basic" , Simbad . Column ("basic" , "oid" ),
648
- Simbad . Column ("ident" , "oidref" ), "LEFT JOIN" )]
647
+ left_joins = [_Join ("ident" , _Column (upload_name , "user_specified_id" ),
648
+ _Column ("ident" , "id" ), "LEFT JOIN" ),
649
+ _Join ("basic" , _Column ("basic" , "oid" ),
650
+ _Column ("ident" , "oidref" ), "LEFT JOIN" )]
649
651
for join in joins :
650
- left_joins .append (Simbad .Join (join .table ,
651
- join .column_left ,
652
- join .column_right , "LEFT JOIN" ))
652
+ left_joins .append (_Join (join .table , join .column_left ,
653
+ join .column_right , "LEFT JOIN" ))
653
654
return self ._query (top , columns , left_joins , instance_criteria ,
654
655
from_table = upload_name ,
655
656
get_query_payload = get_query_payload ,
@@ -814,9 +815,9 @@ def query_catalog(self, catalog, *, criteria=None, get_query_payload=False,
814
815
"""
815
816
top , columns , joins , instance_criteria = self ._get_query_parameters ()
816
817
817
- columns .append (Simbad . Column ("ident" , "id" , "catalog_id" ))
818
+ columns .append (_Column ("ident" , "id" , "catalog_id" ))
818
819
819
- joins += [Simbad . Join ("ident" , Simbad . Column ("basic" , "oid" ), Simbad . Column ("ident" , "oidref" ))]
820
+ joins += [_Join ("ident" , _Column ("basic" , "oid" ), _Column ("ident" , "oidref" ))]
820
821
821
822
instance_criteria .append (fr"id LIKE '{ catalog } %'" )
822
823
if criteria :
@@ -848,13 +849,11 @@ def query_bibobj(self, bibcode, *, criteria=None,
848
849
"""
849
850
top , columns , joins , instance_criteria = self ._get_query_parameters ()
850
851
851
- joins += [Simbad .Join ("has_ref" , Simbad .Column ("basic" , "oid" ),
852
- Simbad .Column ("has_ref" , "oidref" )),
853
- Simbad .Join ("ref" , Simbad .Column ("has_ref" , "oidbibref" ),
854
- Simbad .Column ("ref" , "oidbib" ))]
852
+ joins += [_Join ("has_ref" , _Column ("basic" , "oid" ), _Column ("has_ref" , "oidref" )),
853
+ _Join ("ref" , _Column ("has_ref" , "oidbibref" ), _Column ("ref" , "oidbib" ))]
855
854
856
- columns += [Simbad . Column ("ref" , "bibcode" ),
857
- Simbad . Column ("has_ref" , "obj_freq" )]
855
+ columns += [_Column ("ref" , "bibcode" ),
856
+ _Column ("has_ref" , "obj_freq" )]
858
857
859
858
instance_criteria .append (f"bibcode = '{ _adql_parameter (bibcode )} '" )
860
859
if criteria :
@@ -1071,11 +1070,11 @@ def query_criteria(self, *args, get_query_payload=False, **kwargs):
1071
1070
added_criteria = f"({ CriteriaTranslator .parse (' & ' .join (list (list (args ) + list_kwargs )))} )"
1072
1071
instance_criteria .append (added_criteria )
1073
1072
if "otypes." in added_criteria :
1074
- joins .append (self . Join ("otypes" , self . Column ("basic" , "oid" ),
1075
- self . Column ("otypes" , "oidref" )))
1073
+ joins .append (_Join ("otypes" , _Column ("basic" , "oid" ),
1074
+ _Column ("otypes" , "oidref" )))
1076
1075
if "allfluxes." in added_criteria :
1077
- joins .append (self . Join ("allfluxes" , self . Column ("basic" , "oid" ),
1078
- self . Column ("allfluxes" , "oidref" )))
1076
+ joins .append (_Join ("allfluxes" , _Column ("basic" , "oid" ),
1077
+ _Column ("allfluxes" , "oidref" )))
1079
1078
return self ._query (top , columns , joins , instance_criteria ,
1080
1079
get_query_payload = get_query_payload )
1081
1080
0 commit comments