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

Source Code for Module ivs.catalogs.kepler

  1  """ 
  2  Retrieve light curves from the Kepler satellite mission. 
  3  """ 
  4  import urllib 
  5  import os 
  6  import astropy.io.fits as pf 
  7  import logging 
  8  import numpy as np 
  9  from ivs.catalogs import mast 
 10  from ivs.units import conversions 
 11  from ivs.inout import ascii 
 12  from ivs.inout import fits 
 13  from ivs import config 
 14   
 15  logger = logging.getLogger("CAT.KEPLER") 
 16   
17 -def download_light_curve(KIC,directory=''):
18 """ 19 Download a light curve file from the data archive. 20 21 @param KIC: kic number 22 @type KIC: integer 23 @param directory: directory to save data to, defaults to cwd 24 @type directory: string 25 @return: list of filenames 26 @rtype: list of str 27 """ 28 #-- get info on what is available 29 results,units,comms = mast.search('kepler/data_search',ktc_kepler_id=KIC) 30 #-- reconstruct the links 31 links = [] 32 for name in results['Dataset Name']: 33 num = '%09d'%(int(KIC)) 34 folder = num[:4] 35 links.append("http://archive.stsci.edu/pub/kepler/lightcurves/%s/%s/%s_llc.fits"%(folder,num,name.lower())) 36 filenames = [] 37 #-- and download the files 38 logger.info("Found %d public/proprietary light curves for KIC%s"%(len(links),KIC)) 39 for base_url in links: 40 url = urllib.URLopener() 41 filename = os.path.basename(base_url) 42 if directory: 43 filename = os.path.join(directory,filename) 44 try: 45 filen,msg = url.retrieve(base_url,filename=filename) 46 except IOError: 47 logger.info('... %s is proprietary'%(base_url)) 48 else: 49 logger.info('... downloaded %s'%(filename)) 50 filenames.append(filen) 51 url.close() 52 53 return filenames
54
55 -def get_data(KIC):
56 """ 57 Retrieve Kepler timeseries from a remote data repository. 58 59 Fields are 'HJD','flux','e_flux','bkg','quarter'. 60 61 @param KIC: kic number or list of filenames 62 @type KIC: integer or list 63 @return: data, header 64 @rtype: recarray, dict 65 """ 66 times = [] 67 flux = [] 68 e_flux = [] 69 background = [] 70 quarter = [] 71 if isinstance(KIC,str) or isinstance(KIC,int): 72 filenames = download_light_curve(KIC) 73 else: 74 filenames = KIC 75 for filename in filenames: 76 header = pf.getheader(filename) 77 data = fits.read2recarray(filename,ext='LIGHTCURVE') 78 times.append(data['TIME']+2454833.) 79 flux.append(data['SAP_FLUX']) 80 e_flux.append(data['SAP_FLUX_ERR']) 81 background.append(data['SAP_BKG']) 82 quarter.append(np.ones(len(data))*header['quarter']) 83 data = np.rec.fromarrays([np.hstack(times),np.hstack(flux),np.hstack(e_flux), 84 np.hstack(background),np.hstack(quarter)], 85 names=['HJD','flux','e_flux','bkg','quarter']) 86 return data,header
87 88
89 -def systematics(units='muHz'):
90 """ 91 Return a list of known systematic effects from the Kepler satellite. 92 """ 93 ffile = config.get_datafile('catalogs/kepler','systematics.dat') 94 systems = ascii.read2recarray(ffile) 95 systems['frequency'] = conversions.nconvert(systems['unit'],units,systems['frequency']) 96 systems['e_frequency'] = conversions.nconvert(systems['unit'],units,systems['e_frequency']) 97 systems['w_frequency'] = conversions.nconvert(systems['unit'],units,systems['w_frequency']) 98 return systems
99