# # astroquery example 1 from Sofie: IRSA example # # import numpy as np from astroquery.irsa import Irsa import astropy.units as u import astropy.coordinates as coord ​ #Coordinates to query around ra_in = 155 #deg dec_in = 49 #deg ​ #Maximum distance max_dist = 10 #arcsec ​ #Catalog catalog = "ptf_lightcurves" ​ #The query table = Irsa.query_region(coord.SkyCoord(ra_in,dec_in,unit=(u.deg,u.deg)), catalog = catalog, spatial='Cone', radius = max_dist * u.arcsec) ​ print ("Table header:\n",table.colnames) print ("\nThe table:\n",table) ​ ### Extract parameters from the output table ### ​ #Coordinates ra_out = np.array(table['ra']) #deg dec_out = np.array(table['dec']) #deg ​ #Object ID's oids = np.array(table['oid'],dtype='int64') ​ print ("ra",ra_out) # # astroquery example 2 from Sofie: VizieR example # # from astroquery.vizier import Vizier import astropy.units as u import astropy.coordinates as coord ​ #Coordinates to query around ra_in = 155.29594 #deg dec_in = 49.2251 #deg ​ #Maximum distance max_dist = 10 #arcsec ​ #Catalog catalog = "II/349/ps1" ​ #The query vquery = Vizier(columns=['objID', 'RAJ2000', 'DEJ2000', 'gmag', 'e_gmag', "+_r"]) ​ field = coord.SkyCoord(ra_in, dec_in, unit=(u.deg, u.deg), frame='icrs') ​ vquery.query_region(field,width=(max_dist*u.arcsec), catalog=catalog) ​ ​ if len(vquery.table)>0: table = vquery.table[0] print ("Table header:\n",table.colnames) print ("\nThe table:\n",table) ### Extract parameters from the output table ### #Object ID oids = table['objID'][0] #Coordinates ra_out = table['RAJ2000'][0] dec_out = table['DEJ2000'][0] #g magnitude g = table['gmag'][0] e_g = table['e_gmag'][0] #Distance from input coordinates r = table['_r'][0] print ("g:",g,"+-",e_g) else: print ("No sources found") # # # astroquery example 1 from Zoe # # import pandas as pd import astropy.units as u from astroquery.xmatch import XMatch import numpy as np import time as time ​ ​ start=time.time() ##cat1 is our own data on the computer, it could be changed to a dataset from one of the vizier cataloges catalog1=open('../PRIMUS/PRIMUS_2013_zcat_v1.csv') ​ ##cat2 catalog2='vizier:II/328/allwise' ​ ##search in this radius Radius=5 * u.arcsec ​ ​ table = XMatch.query(cat1=catalog2, cat2=catalog2, max_distance=Radius, colRA1='RA', colDec1='DEC', colRA2='ra', colDec2='dec') ​ df_xmat = pd.DataFrame(np.array(table)) # df_xmat.to_csv("../PRIMUS/xmatch.csv") print(df_xmat.head()) print(df_xmat.columns) ​ end=time.time() print("Query took",str(end-start) ,"seconds to fetch the data") ​ # # # astroquery example 2 from Zoe: # # from astroquery.sdss import SDSS import pandas as pd import time as time querytext="select top 1000 \ z, ra, dec, bestObjID, plate , class, zErr \ from specObj \ where 1.0 >z and \ z >0 and \ zWarning = 0" def query (): start=time.time() ​ query = querytext res = SDSS.query_sql(query) ​ df=res.to_pandas() print(len(df)) print(df.head()) print(df.columns) ​ ​ end=time.time() tt=end - start print("time elapsed:", tt) ​ query ()