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

Source Code for Module ivs.catalogs.coralie

  1  # -*- coding: utf-8 -*- 
  2  """ 
  3  Interface to s1dA spectra from the Coralie spectrograph. 
  4  """ 
  5  import re 
  6  import sys 
  7  import glob 
  8  import os 
  9  import logging 
 10  import numpy as np 
 11  import astropy.io.fits as pf 
 12  from ivs.catalogs import sesame 
 13  from ivs.inout import ascii 
 14  from ivs.aux import loggers 
 15  from ivs import config 
 16   
 17  logger = logging.getLogger("CAT.CORALIE") 
 18  logger.addHandler(loggers.NullHandler) 
 19   
20 -def search(ID,radius=1.,filename=None):
21 """ 22 Retrieve datafiles from the Coralie catalogue. 23 24 We search on coordinates, pulled from SIMBAD. If the star ID is not 25 recognised, a string search is performed to match the 'targ name' field in the 26 FITS headers. 27 28 Only the s1d_A data are searched. 29 30 @param ID: ID of the star, understandable by SIMBAD 31 @type ID: str 32 @param radius: search radius around the coordinates 33 @type radius: 1 34 @param filename: write summary to outputfile if not None 35 @type filename: str 36 @return: record array with summary information on the observations, as well 37 as their location (column 'filename') 38 @rtype: numpy rec array 39 """ 40 data = ascii.read2recarray(config.get_datafile(os.path.join('catalogs','coralie'),'CoralieFullDataOverview.tsv'),splitchar='\t') 41 info = sesame.search(ID) 42 if info: 43 ra,dec = info['jradeg'],info['jdedeg'] 44 keep = np.sqrt((data['ra']-ra)**2 + (data['dec']-dec)**2) < radius/60. 45 else: 46 keep = [((re.compile(ID).search(objectn) is not None) and True or False) for objectn in data['object']] 47 keep = np.array(keep) 48 49 data = data[keep] 50 51 logger.info('Found %d spectra'%(len(data))) 52 53 if filename is not None: 54 ascii.write_array(data,filename,auto_width=True,header=True) 55 else: 56 return data
57 58 59 60
61 -def make_data_overview():
62 """ 63 Summarize all COralie data in a file for easy data retrieval. 64 """ 65 #-- all Coralie data directories 66 obj_files = [] 67 for root,dirs,files in os.walk(config.ivs_dirs['coralie']): 68 for name in files: 69 if 's1d_A' in name: 70 obj_files.append(os.path.join(root,name)) 71 72 #-- and summarize the contents in a tab separated file (some columns contain spaces) 73 outfile = open('CoralieFullDataOverview.tsv','w') 74 outfile.write('#unseq prog_id obsmode bvcor observer object ra dec bjd exptime date-avg filename\n') 75 outfile.write('#i i a20 >f8 a50 a50 >f8 >f8 >f8 >f8 a30 a200\n') 76 for i,obj_file in enumerate(obj_files): 77 print i,len(obj_files) 78 #-- keep track of: UNSEQ, BJD, BVCOR, OBSERVER, RA, DEC , PROG_ID, OBSMODE, EXPTIME, DATE-AVG, OBJECT and filename 79 contents = dict(unseq=-1,prog_id=-1,obsmode='CORALIE',bvcor=0,observer='nan', 80 object='nan',ra=np.nan,dec=np.nan, 81 bjd=np.nan,exptime=np.nan, 82 filename=os.path.realpath(obj_file)) 83 contents['date-avg'] = 'nan' 84 try: 85 header = pf.getheader(obj_file) 86 except: 87 continue 88 if 'ESO OBS TEXP' in header: contents['exptime'] = float(header['ESO OBS TEXP']) 89 if 'OBSERVER' in header: contents['observer'] = header['OBSERVER'] 90 if 'ESO DRS BJD' in header: contents['bjd'] = float(header['ESO DRS BJD']) 91 if 'ESO OBS FDATE' in header: contents['date-avg'] = header['ESO OBS FDATE'] 92 if 'ESO TEL TARG ALPHA' in header: contents['ra'] = float(header['ESO TEL TARG ALPHA']) 93 if 'ESO TEL TARG DELTA' in header: contents['dec'] = float(header['ESO TEL TARG DELTA']) 94 if 'ESO OBS TARG NAME' in header: contents['object'] = header['ESO OBS TARG NAME'] 95 96 outfile.write('%(unseq)d\t%(prog_id)d\t%(obsmode)s\t%(bvcor)f\t%(observer)s\t%(object)s\t%(ra)f\t%(dec)f\t%(bjd)f\t%(exptime)f\t%(date-avg)s\t%(filename)s\n'%contents) 97 outfile.flush() 98 outfile.close()
99 100 if __name__=="__main__": 101 args = sys.argv[1:] 102 if args and args[0]=='makedata': 103 make_data_overview() 104