Package ComboCode :: Package cc :: Package ivs :: Package catalogs :: Module corot
[hide private]
[frames] | no frames]

Source Code for Module ComboCode.cc.ivs.catalogs.corot

  1  """ 
  2  Retrieve CoRoT data from a local data repository. 
  3   
  4  check out http://nsted.ipac.caltech.edu/ 
  5  """ 
  6   
  7  import logging 
  8  import os 
  9  import urllib 
 10  from astropy.io import fits as pyfits 
 11  import glob 
 12  import numpy as np 
 13  from cc.ivs.aux import loggers 
 14  from cc.ivs.catalogs import sesame 
 15  from cc.ivs.catalogs import vizier 
 16  from cc.ivs.io import fits 
 17  import cc.path 
 18  #from ivs import config 
 19   
 20  logger = logging.getLogger("CAT.COROT") 
 21  logger.addHandler(loggers.NullHandler()) 
 22   
23 -def get_sismo_data(ID):
24 """ 25 Retrieve CoRoT timeseries from a local data repository. 26 27 The output record array has fields 'HJD', 'flux', 'e_flux', 'flag'. 28 29 @param ID: ID of the target: either an integer (CoRoT ID), an SIMBAD-recognised 30 target name, or a valid CoRoT FITS file 31 @type ID: int or str 32 @return: data, header 33 @rtype: numpy recarray, dict 34 """ 35 #-- data on one target can be spread over multiple files: collect the 36 # data 37 data = [] 38 39 if isinstance(ID,str) and os.path.isfile(ID): 40 header = pyfits.getheader(ID) 41 times,flux,error,flags = fits.read_corot(ID) 42 data.append([times,flux,error,flags]) 43 else: 44 #-- resolve the target's name: it's either a target name or CoRoT ID. 45 try: 46 ID = int(ID) 47 except ValueError: 48 info = sesame.search(ID,db='S') 49 IDs = [alias for alias in info['alias'] if 'HD' in alias] 50 if len(IDs)!=1: 51 logger.error("Data retrieval for %s not possible. Reason: no HD number resolved" % (ID)) 52 return 53 ID = IDs[0] 54 #-- collect the files containing data on the target 55 #catfiles = config.glob((os.sep).join(['catalogs','corot','sismo']),'*.fits') 56 fn_sismo = os.path.join(cc.path.ivsdata,'catalogs','corot','sismo','*.fits') 57 catfiles = glob.glob(fn_sismo) 58 catfiles.sort() 59 for catfile in catfiles: 60 try: 61 header = pyfits.getheader(catfile) 62 except IOError: 63 continue 64 if header['starname']==ID or header['corotid'].replace(' ','')=='%s'%(ID): 65 times,flux,error,flags = fits.read_corot(catfile) 66 data.append([times,flux,error,flags]) 67 #-- now make a record array and sort according to times 68 if not data: 69 raise ValueError('target {0} not in offline CoRoT data repository'.format(ID)) 70 data = np.hstack(data) 71 data = np.rec.fromarrays(data,dtype=[('HJD','>f8'),('flux','>f8'),('e_flux','>f8'),('flag','i')]) 72 sa = np.argsort(data['HJD']) 73 return data[sa],header
74
75 -def get_exo_data(ID,type_data='white'):
76 """ 77 Retrieve CoRoT timeseries from a remote data repository. 78 79 The output record array has fields 'HJD', 'flux', 'e_flux', 'flag'. 80 81 @param ID: ID of the target: either an integer (CoRoT ID), an SIMBAD-recognised 82 target name, or a valid CoRoT FITS file 83 @type ID: int or str 84 @param type_data: 'white' or 'colors' (if available!) 85 @type type_data: str 86 @return: data, header 87 @rtype: numpy recarray, dict 88 """ 89 cat,units,comms = get_exo_catalog() 90 header = None 91 data = [] 92 if isinstance(ID,str) and os.path.isfile(ID): 93 header = pyfits.getheader(ID) 94 times,flux,error,flags = fits.read_corot(ID) 95 data.append([times,flux,error,flags]) 96 else: 97 #-- resolve the target's name: it's either a target name or CoRoT ID. 98 try: 99 ID = int(ID) 100 except ValueError: 101 logger.error("Data retrieval for %s not possible. Reason: ID not resolved" % (ID)) 102 return None 103 #-- collect the files containing data on the target 104 for filename in cat['FileName'][cat['CoRoT']==ID]: 105 url = urllib.URLopener() 106 filen,msg = url.retrieve(filename) 107 try: 108 header = pyfits.getheader(filen) 109 except IOError: 110 continue 111 times,flux,error,flags = fits.read_corot(filen,type_data=type_data) 112 url.close() 113 data.append([times,flux,error,flags]) 114 115 #-- now make a record array and sort according to times 116 if not data: 117 raise ValueError('target {0} not in online CoRoT data repository'.format(ID)) 118 data = np.hstack(data) 119 data = np.rec.fromarrays(data,dtype=[('HJD','>f8'),('flux','>f8'),('e_flux','>f8'),('flag','i')]) 120 sa = np.argsort(data['HJD']) 121 return data[sa],header
122 123
124 -def get_exo_catalog():
125 """ 126 Retrieve the locally saved CoRoT exoplanet database. 127 """ 128 exofile= os.path.join(cc.path.ivsdata,'catalogs','corot','exo','exo.tsv') 129 #exofile = config.get_datafile('catalogs/corot/exo','exo.tsv') 130 data,units,comms = vizier.tsv2recarray(exofile) 131 return data,units,comms
132
133 -def resolve(corot_id):
134 """ 135 Convert a CoRoT ID to ra,dec. 136 137 @param corot_id: CoRoT exoplanet identification number 138 @type corot_id: int 139 @return: RA, DEC (degrees) 140 @rtype: float,float 141 """ 142 exofile= os.path.join(cc.path.ivsdata,'catalogs','corot','exo','exo.tsv') 143 #exofile = config.get_datafile('catalogs/corot/exo','exo.tsv') 144 data,units,comms = vizier.tsv2recarray(exofile) 145 index = np.argmin(np.abs(data['CoRoT']-corot_id)) 146 if data['CoRoT'][index]-corot_id==0: 147 logger.info('CoRoT %s resolved to RA=%s, DEC=%s'%(corot_id,data[index]['_RAJ2000'],data[index]['_DEJ2000'])) 148 return data[index]['_RAJ2000'],data[index]['_DEJ2000'] 149 else: 150 logger.info('CoRoT %s not resolved by CoRoT catalog')
151