Package ivs :: Package catalogs :: Module sesame
[hide private]
[frames] | no frames]

Source Code for Module ivs.catalogs.sesame

  1  # -*- coding: utf-8 -*- 
  2  """ 
  3  Interface to Sesame for general information on a star (SIMBAD) 
  4  """ 
  5  import urllib 
  6  import logging 
  7   
  8  import numpy as np 
  9  from ivs.units import conversions 
 10  from ivs.aux import xmlparser 
 11  from ivs.catalogs import vizier 
 12   
 13  logger = logging.getLogger("CAT.SESAME") 
 14   
15 -def get_URI(ID,db='S'):
16 """ 17 Build Sesame URI from available options. 18 19 @param ID: name of the star 20 @type ID: str 21 @keyword db: database (one of 'S','N', or 'A') 22 @type db: str 23 @return: uri name 24 @rtype: str 25 """ 26 #mirrors: 27 # http://vizier.cfa.harvard.edu/viz-bin/nph-sesame/-oxpsIF/~%s?%s' 28 ID = urllib.quote(ID) 29 return 'http://cdsweb.u-strasbg.fr/cgi-bin/nph-sesame/-oxpsIF/%s?%s'%(db,ID)
30 31 32 33 34 35
36 -def search(ID,db='S',fix=False):
37 """ 38 Query Simbad, NED and/or Vizier for information on an identifier. 39 40 This retrieves basic information on a star, e.g. as shown in a typical 41 Simbad page: coordinates, spectral type, fluxes, aliases, references... 42 43 Database C{db} is one of 'S' (SIMBAD), 'N' (NED), 'V' (Vizier) 44 or 'A' (all). 45 46 This function returns a (sometimes nested) dictionary. Example output is 47 given below, where nested dictionaries are shown with the separator '.' 48 between the keys. 49 50 If you set C{fix} to C{False}, following values will be updated: 51 52 1. the spectral type will be replaced by the one from the Skiff (2010) 53 catalog if possible. 54 2. The parallax will be replaced with the value from the new Van Leeuwen 55 reduction. 56 3. The galactic coordinates will be added (converted from RA and DEC) 57 4. The proper motions will be taken from the PPMXL catalog from Roeser 58 2010. 59 60 Example usage: 61 62 >>> info = search('vega',db='S') 63 >>> print info['jpos'] 64 18:36:56.33 +38:47:01.2 65 >>> print info['jdedeg'] 66 38.78369194 67 >>> print info['alias'][1] 68 * alf Lyr 69 >>> print info['plx']['v'] 70 128.93 71 >>> print info['mag']['B']['v'] 72 0.03 73 74 This is an exhaustive list of example contents:: 75 Vel.e = 0.9 76 Vel.q = A 77 Vel.r = 1979IAUS...30...57E 78 Vel.v = -13.9 79 alias = [u'V* alf Lyr', u'* alf Lyr', u'* 3 Lyr', u'ADS 11510 A', u'AG+38 1711', u'ASCC 507896', u'BD+38 3238', u'CCDM J18369+3847A', u'CEL 4636', u'CSI+38 3238 1', u'CSV 101745', u'1E 183515+3844.3', u'EUVE J1836+38.7', u'FK5 699', u'GC 25466', u'GCRV 11085', u'GEN# +1.00172167', u'GJ 721', u'HD 172167', u'HGAM 706', u'HIC 91262', u'HIP 91262', u'HR 7001', u'IDS 18336+3841 A', u'IRAS 18352+3844', u'IRC +40322', u'JP11 2999', u'LSPM J1836+3847', u'LTT 15486', u'2MASS J18365633+3847012', u'N30 4138', u'NAME VEGA', u'NLTT 46746', u'NSV 11128', u'8pc 128.93', u'PLX 4293.00', u'PLX 4293', u'PMC 90-93 496', u'PPM 81558', u'RAFGL 2208', u'ROT 2633', u'SAO 67174', u'SKY# 34103', u'TD1 22883', u'TYC 3105-2070-1', u'UBV 15842', u'UBV M 23118', u'USNO-B1.0 1287-00305764', u'USNO 882', u'uvby98 100172167 V', u'WDS J18369+3846A', u'Zkh 277', u'[HFE83] 1223'] 80 errDEmas = 5.4 81 errRAmas = 5.16 82 jdedeg = 38.78369194 83 jpos = 18:36:56.33 +38:47:01.2 84 jradeg = 279.234735 85 mag.B.q = C 86 mag.B.v = 0.03 87 mag.H.q = C 88 mag.H.r = 2003yCat.2246....0C 89 mag.H.v = -0.03 90 mag.I.q = E 91 mag.I.r = 2003AJ....125..984M 92 mag.I.v = 0.2 93 mag.J.q = C 94 mag.J.r = 2003yCat.2246....0C 95 mag.J.v = -0.18 96 mag.K.q = C 97 mag.K.r = 2003yCat.2246....0C 98 mag.K.v = 0.13 99 mag.R.q = E 100 mag.R.r = 2003AJ....125..984M 101 mag.R.v = 0.1 102 mag.V.q = C 103 mag.V.v = 0.03 104 nrefs = 1860.0 105 oid = @2900336 106 oname = NAME VEGA 107 otype = V* 108 plx.e = 0.55 109 plx.q = A 110 plx.r = [u'1997A', u'&', u'A...323L..49P'] 111 plx.v = 128.93 112 pm.e = 0.83 113 pm.epmDE = 0.6 114 pm.epmRA = 0.57 115 pm.pa = 35.0 116 pm.pmDE = 287.47 117 pm.pmRA = 201.03 118 pm.q = A 119 pm.r = [u'1997A', u'&', u'A...323L..49P'] 120 pm.v = 350.79 121 refPos = [u'1997A', u'&', u'A...323L..49P'] 122 spNum = 0.0000C800.0030.0000000000000000 123 spType = A0V 124 125 126 >>> info = search('vega',db='N') 127 >>> for key1 in sorted(info.keys()): 128 ... print '%s = %s'%(key1.ljust(8),info[key1]) 129 INFO = from cache 130 alias = [u'alpha Lyr', u'HR 7001', u'HD 172167', u'IRAS 18352+3844', u'IRAS F18352+3844'] 131 errDEmas = 4824.0 132 errRAmas = 19570.0 133 jdedeg = 38.782316 134 jpos = 18:36:55.70 +38:46:56.3 135 jradeg = 279.2321017 136 oname = VEGA 137 otype = !* 138 refPos = 1990IRASF.C...0000M 139 140 @param ID: name of the source 141 @type ID: str 142 @param db: database to use 143 @type db: str ('N','S','V','A') 144 @return: (nested) dictionary containing information on star 145 @rtype: dictionary 146 """ 147 base_url = get_URI(ID,db=db) 148 ff = urllib.urlopen(base_url) 149 xmlpage = "" 150 for line in ff.readlines(): 151 line_ = line[::-1].strip(' ')[::-1] 152 if line_[0]=='<': 153 line = line_ 154 xmlpage+=line.strip('\n') 155 database = xmlparser.XMLParser(xmlpage).content 156 try: 157 database = database['Sesame']['Target']['%s'%(db)]['Resolver'] 158 database = database[database.keys()[0]] 159 except KeyError,IndexError: 160 #-- we found nothing! 161 database = {} 162 ff.close() 163 164 if fix: 165 #-- fix the parallax: make sure we have the Van Leeuwen 2007 value. 166 # simbad seems to have changed to old values to the new ones somewhere 167 # in 2011. We check if this is the case for all stars: 168 if 'plx' in database and not ('2007' in database['plx']['r']): 169 data,units,comms = vizier.search('I/311/hip2',ID=ID) 170 if data is not None and len(data): 171 if not 'plx' in database: 172 database['plx'] = {} 173 database['plx']['v'] = data['Plx'][0] 174 database['plx']['e'] = data['e_Plx'][0] 175 database['plx']['r'] = 'I/311/hip2' 176 #-- fix the spectral type 177 data,units,comms = vizier.search('B/mk/mktypes',ID=ID) 178 if data is not None and len(data): 179 database['spType'] = data['SpType'][0] 180 if 'jpos' in database: 181 #-- add galactic coordinates (in degrees) 182 ra,dec = database['jpos'].split() 183 gal = conversions.convert('equatorial','galactic',(str(ra),str(dec)),epoch='2000') 184 gal = float(gal[0])/np.pi*180,float(gal[1])/np.pi*180 185 database['galpos'] = gal 186 #-- fix the proper motions 187 data,units,comms = vizier.search('I/317/sample',ID=ID) 188 if data is not None and len(data): 189 if not 'pm' in database: 190 database['pm'] = {} 191 database['pm']['pmRA'] = data['pmRA'][0] 192 database['pm']['pmDE'] = data['pmDE'][0] 193 database['pm']['epmRA'] = data['e_pmRA'][0] 194 database['pm']['epmDE'] = data['e_pmDE'][0] 195 database['pm']['r'] = 'I/317/sample' 196 return database
197 198 if __name__=="__main__": 199 import doctest 200 doctest.testmod() 201