简体   繁体   中英

AstroPy: How to delete a table from a TableList

I am searching for astronomical sources through Vizier catalogs with AstroPy's Vizier Queries package. After running the code, I get back a TableList which includes a list of catalogs.

opticalViz = Vizier(columns=['_RAJ2000', '_DEJ2000','B-V', 'Vmag', 'Bmag'], 
                   keywords = ['optical'])
catalog_list = opticalViz.query_region(coord.SkyCoord('00 57 27.09 -73 25 14.4', 
                                                      unit=(u.hourangle, u.deg)), 
                                                     radius = Angle((0,0,6.3), unit = u.deg) )

print(catalog_list)

which outputs

TableList with 18 tables:
    '0:I/221/smc' with 3 column(s) and 1 row(s) 
    '1:I/252/out' with 4 column(s) and 1 row(s) 
    '2:I/271/out' with 3 column(s) and 1 row(s) 
    '3:I/284/out' with 3 column(s) and 1 row(s) 
    '4:I/297/out' with 4 column(s) and 1 row(s) 
    '5:I/305/out' with 4 column(s) and 1 row(s) 
    '6:I/317/sample' with 3 column(s) and 1 row(s) 
    '7:I/319/xpm' with 4 column(s) and 1 row(s) 
    '8:I/320/spm4' with 4 column(s) and 1 row(s) 
    '9:I/322A/out' with 4 column(s) and 1 row(s) 
    '10:I/337/gaia' with 3 column(s) and 2 row(s) 
    '11:I/339/hsoy' with 3 column(s) and 1 row(s) 
    '12:I/345/gaia2' with 3 column(s) and 3 row(s) 
    '13:II/236/smc' with 4 column(s) and 1 row(s) 
    '14:II/336/apass9' with 5 column(s) and 1 row(s) 
    '15:IV/38/tic' with 4 column(s) and 3 row(s) 
    '16:J/A+A/586/A81/table5' with 5 column(s) and 1 row(s) 
    '17:J/AJ/123/855/table1' with 4 column(s) and 3 row(s) 

This acts very much like a dictionary with the keys being the catalog name and the values being tables. I would like to be able to delete a specific catalog/table by the key name. However, when I try to use del catalog_list['I/345/gaia2'] I get an error saying list indices must be numbers.

Can anyone shine light on what exactly a TableList is and how to delete specific elements from it?

TableLists are wrappers around OrderedDict's. They are used in astroquery to give a minimal representation of the tables returned from a service.

You can find out more here: https://astroquery.readthedocs.io/en/latest/api/astroquery.utils.TableList.html#astroquery.utils.TableList and here: https://astroquery.readthedocs.io/en/latest/vizier/vizier.html#query-an-object

However, your question doesn't give any hint about why you want to delete entries from the list. I'm not sure TableLists support the sort of operation you want to perform. The source code might be helpful, or you might want to convert to a list or a dict of tables before removing entries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM