Astroquery Documentation Release 0.3.7
Total Page:16
File Type:pdf, Size:1020Kb
astroquery Documentation Release 0.3.7 Adam Ginsburg Mar 29, 2018 Contents I Introduction3 II Installation7 III Requirements 17 IV Using astroquery 21 V Available Services 25 VI Catalog, Archive, and Other 393 i ii astroquery Documentation, Release 0.3.7 This is the documentation for the Astroquery affiliated package of astropy. Code and issue tracker are on GitHub. Contents 1 astroquery Documentation, Release 0.3.7 2 Contents Part I Introduction 3 astroquery Documentation, Release 0.3.7 Astroquery is a set of tools for querying astronomical web forms and databases. There are two other packages with complimentary functionality as Astroquery: astropy.vo is in the Astropy core and pyvo is an Astropy affiliated package. They are more oriented to general virtual observatory discovery and queries, whereas Astroquery has web service specific interfaces. Check out the A Gallery of Queries for some nice examples. 5 astroquery Documentation, Release 0.3.7 6 Part II Installation 7 astroquery Documentation, Release 0.3.7 The latest version of astroquery can be conda installed while the latest and development versions can be pip installed or be downloaded directly from GitHub. 9 astroquery Documentation, Release 0.3.7 10 CHAPTER 1 Using pip $ pip install astroquery and the ‘bleeding edge’ master version: $ pip install https://github.com/astropy/astroquery/archive/master.zip 11 astroquery Documentation, Release 0.3.7 12 Chapter 1. Using pip CHAPTER 2 Using conda It is also possible to install the latest astroquery with anaconda from the astropy channel: $ conda install -c astropy astroquery 13 astroquery Documentation, Release 0.3.7 14 Chapter 2. Using conda CHAPTER 3 Building from source The development version can be obtained and installed from github: $ # If you have a github account: $ git clone [email protected]:astropy/astroquery.git $ # If you do not: $ git clone https://github.com/astropy/astroquery.git $ cd astroquery $ python setup.py install 15 astroquery Documentation, Release 0.3.7 16 Chapter 3. Building from source Part III Requirements 17 astroquery Documentation, Release 0.3.7 Astroquery works with Python 2.7 and 3.4 or later. The following packages are required for astroquery installation & use: • numpy >= 1.9 • astropy (>=1.0) • requests • keyring • Beautiful Soup • html5lib and for running the tests: • curl The following packages are optional dependencies and are required for the full functionality of the alma module: • APLpy • pyregion 19 astroquery Documentation, Release 0.3.7 20 Part IV Using astroquery 21 astroquery Documentation, Release 0.3.7 All astroquery modules are supposed to follow the same API. In its simplest form, the API involves queries based on coordinates or object names. Some simple examples, using SIMBAD: >>> from astroquery.simbad import Simbad >>> result_table= Simbad.query_object("m1") >>> result_table.pprint(show_unit=True) MAIN_ID RA DEC RA_PREC ... COO_QUAL COO_WAVELENGTH COO_BIBCODE "h:m:s" "d:m:s" ... ------- ----------- ----------- ------- ... -------- -------------- ------------------- M 1 05 34 31.94 +22 00 52.2 6 ... C R 2011A&A...533A..10L All query tools allow coordinate-based queries: >>> from astropy import coordinates >>> import astropy.units asu >>> # works only for ICRS coordinates: >>> c= coordinates.SkyCoord("05h35m17.3s -05d23m28s", frame= 'icrs') >>> r=5*u.arcminute >>> result_table= Simbad.query_region(c, radius=r) >>> result_table.pprint(show_unit=True, max_width=80, max_lines=5) MAIN_ID RA DEC ... COO_WAVELENGTH COO_BIBCODE "h:m:s" "d:m:s" ... ------------ ------------ ------------ ... -------------- ------------------- M 42 05 35 17.3 -05 23 28 ... 1981MNRAS.194..693L ... ... ... ... ... ... V* V2114 Ori 05 35 01.671 -05 26 36.30 ... I 2003yCat.2246....0C For additional guidance and examples, read the documentation for the individual services below. 23 astroquery Documentation, Release 0.3.7 24 Part V Available Services 25 astroquery Documentation, Release 0.3.7 If you’re new to Astroquery, a good place to start is the A Gallery of Queries: 27 astroquery Documentation, Release 0.3.7 28 CHAPTER 4 A Gallery of Queries A series of queries folks have performed for research or for kicks. 4.1 Example 1 This illustrates querying Vizier with specific keyword, and the use of astropy.coordinates to describe a query. Vizier’s keywords can indicate wavelength & object type, although only object type is shown here. >>> from astroquery.vizier import Vizier >>> v= Vizier(keywords=[ 'stars:white_dwarf']) >>> from astropy import coordinates >>> from astropy import units as u >>> c= coordinates.SkyCoord(0,0,unit=( 'deg','deg'),frame='icrs') >>> result=v.query_region(c, radius=2*u.deg) >>> print(len(result)) 31 >>> result[0].pprint() LP Rem Name RA1950 DE1950 Rmag l_Pmag Pmag u_Pmag spClass pm pmPA _RA.icrs _DE.icrs -------- --- ---- -------- -------- ---- ------ ---- ------ ------- ------ ---- -------- -------- 584-0063 00 03 23 +00 01.8 18.1 18.3 f 0.219 93 00 05 57 +00 18.7 643-0083 23 50 40 +00 33.4 15.9 17.0 k 0.197 93 23 53 14 +00 50.3 584-0030 23 54 05 -01 32.3 16.6 17.7 k 0.199 193 23 56 39 -01 15.4 4.2 Example 2 This illustrates adding new output fields to SIMBAD queries. Run list_votable_fields to get the full list of valid fields. >>> from astroquery.simbad import Simbad >>> s= Simbad() (continues on next page) 29 astroquery Documentation, Release 0.3.7 (continued from previous page) >>> # bibcodelist(date1-date2) lists the number of bibliography >>> # items referring to each object over that date range >>> s.add_votable_fields('bibcodelist(2003-2013)') >>> r=s.query_object( 'm31') >>> r.pprint() MAIN_ID RA DEC RA_PREC DEC_PREC COO_ERR_MAJA COO_ERR_MINA COO_ERR_ANGLE COO_QUAL COO_ ,!WAVELENGTH COO_BIBCODE BIBLIST_2003_2013 ------- ------------ ------------ ------- -------- ------------ ------------ ------------- -------- ---- ,!---------- ------------------- ----------------- M 31 00 42 44.330 +41 16 07.50 7 7 nan nan 0 B␣ ,! I 2006AJ....131.1163S 3758 4.3 Example 3 This illustrates finding the spectral type of some particular star. >>> from astroquery.simbad import Simbad >>> customSimbad= Simbad() >>> customSimbad.add_votable_fields('sptype') >>> result= customSimbad.query_object( 'g her') >>> result['MAIN_ID'][0] 'V* g Her' >>> result['SP_TYPE'][0] 'M6III' 4.4 Example 4 >>> from astroquery.simbad import Simbad >>> customSimbad= Simbad() >>> # We've seen errors where ra_prec was NAN, but it's an int: that's a problem >>> # this is a workaround we adapted >>> customSimbad.add_votable_fields('ra(d)','dec(d)') >>> customSimbad.remove_votable_fields('coordinates') >>> from astropy import coordinates >>> C= coordinates.SkyCoord(0,0,unit=( 'deg','deg'), frame='icrs') >>> result= customSimbad.query_region(C, radius= '2 degrees') >>> result[:5].pprint() MAIN_ID RA_d DEC_d ------------- ----------- ------------ ALFALFA 5-186 0.00000000 0.00000000 ALFALFA 5-188 0.00000000 0.00000000 ALFALFA 5-206 0.00000000 0.00000000 ALFALFA 5-241 0.00000000 0.00000000 ALFALFA 5-293 0.00000000 0.00000000 4.5 Example 5 This illustrates a simple usage of the open_exoplanet_catalogue module. Finding the mass of a specific planet: 30 Chapter 4. A Gallery of Queries astroquery Documentation, Release 0.3.7 >>> from astroquery import open_exoplanet_catalogue as oec >>> from astroquery.open_exoplanet_catalogue import findvalue >>> cata= oec.get_catalogue() >>> kepler68b= cata.find(".//planet[name= 'Kepler-68 b']") >>> print(findvalue( kepler68b, 'mass')) 0.02105109 4.6 Example 6 Grab some data from ALMA, then analyze it using the Spectral Cube package after identifying some spectral lines in the data. from astroquery.alma import Alma from astroquery.splatalogue import Splatalogue from astroquery.simbad import Simbad from astropy import units as u from astropy import constants from spectral_cube import SpectralCube m83table= Alma.query_object( 'M83', public=True) m83urls= Alma.stage_data(m83table[ 'Member ous id']) # Sometimes there can be duplicates: avoid them with # list(set()) m83files= Alma.download_and_extract_files(list(set(m83urls[ 'URL']))) m83files= m83files Simbad.add_votable_fields('rvel') m83simbad= Simbad.query_object( 'M83') rvel= m83simbad[ 'RVel_Rvel'][0]*u.Unit(m83simbad['RVel_Rvel'].unit) for fn in m83files: if 'line' in fn: cube= SpectralCube.read(fn) # Convert frequencies to their rest frequencies frange=u.Quantity([cube.spectral_axis.min(), cube.spectral_axis.max()])*(1+rvel/constants.c) # Query the top 20 most common species in the frequency range of the # cube with an upper energy state <= 50K lines= Splatalogue.query_lines(frange[0], frange[1], top20= 'top20', energy_max=50, energy_type='eu_k', only_NRAO_recommended=True) lines.pprint() # Change the cube coordinate system to be in velocity with respect # to the rest frequency (in the M83 rest frame) rest_frequency= lines[ 'Freq-GHz'][0]*u.GHz/(1+rvel/constants.c) vcube= cube.with_spectral_unit(u.km/u.s, rest_value=rest_frequency, velocity_convention='radio') # Write the cube with the specified line name fmt="{Species}{Resolved QNs}" row= lines[0] linename= fmt.format(**dict(zip(row.colnames,row.data))) (continues on next page) 4.6. Example 6 31 astroquery Documentation, Release 0.3.7 (continued from previous page) vcube.write('M83_ALMA_{linename}.fits'.format(linename=linename)) 4.7 Example 7 Find ALMA pointings that have been observed toward M83, then overplot the various fields-of view on a 2MASS im- age retrieved from SkyView. See http://nbviewer.ipython.org/gist/keflavich/19175791176e8d1fb204 for the notebook. There is an even more sophisticated