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

Source Code for Module ivs.catalogs.p7

  1  """ 
  2  Retrieve data from the P7 photometer. 
  3  """ 
  4  import logging 
  5  import os 
  6  import astropy.io.fits as pf 
  7  import numpy as np 
  8  from ivs.aux import loggers 
  9  from ivs.catalogs import sesame 
 10  from ivs.inout import fits 
 11  from ivs import config 
 12           
 13  logger = logging.getLogger("") 
 14  logger.addHandler(loggers.NullHandler) 
 15   
 16   
 17   
18 -def getP7Data(ID=None,code=None,include_nans=True):
19 """ 20 Extract P7 timeseries from the catalog. 21 22 WARNING: only B{very} few target ID's can be resolved (HD,HIP,SAO and that's 23 about it) 24 25 WARNING: there could be nan's in the data somewhere. If you don't want 26 nan's anywhere, set 'include_nans' to False. 27 28 @param ID: target ID (limited!) 29 @type ID: str 30 @param code: target's GENEVA code (e.g. 100180642 for HD180642) 31 @type code: int 32 @return: record array containing times (HJD) and corresponding GENEVA mags, 33 and a dictionary with header information (only source=P7) 34 @rtype: np record array,dict 35 """ 36 if ID is not None: 37 if not 'HD' in ID or not 'SAO' in ID or not 'HIC' in ID: 38 info = sesame.search(ID) 39 print info 40 if 'alias' in info: 41 for alias in info['alias']: 42 if 'HD' in alias: 43 ID = alias 44 break 45 if 'SAO' in alias: 46 ID = alias 47 break 48 if 'HIC' in alias: 49 ID = alias 50 break 51 # this should resolve the GENEVA name 52 code = _geneva_name_resolver(ID=ID) 53 54 catfile = config.get_datafile('catalogs/p7','p7photometry.fits') 55 ff = pf.open(catfile) 56 57 valid = ff[1].data.field('CODE')==code 58 hjd = ff[1].data.field('HJD')[valid] 59 U = ff[1].data.field('U')[valid] 60 B = ff[1].data.field('B')[valid] 61 B1 = ff[1].data.field('B1')[valid] 62 B2 = ff[1].data.field('B2')[valid] 63 V = ff[1].data.field('V')[valid] 64 V1 = ff[1].data.field('V1')[valid] 65 G = ff[1].data.field('G')[valid] 66 ff.close() 67 68 data = np.rec.fromarrays([hjd,U,B,B1,B2,V,V1,G],names='HJD,U,B,B1,B2,V,V1,G') 69 70 logger.info('Retrieved %d photometric points from P7'%(len(data))) 71 72 if not include_nans: 73 nans = np.isnan(data['HJD']) 74 for name in data.dtype.names: 75 nans = nans | np.isnan(data[name]) 76 data = data[-nans] 77 logger.info('Keeping %d photometric points without "NaN" from P7'%(len(data))) 78 79 return data,{'source':'P7'}
80 81
82 -def _geneva_name_resolver(code=None,ID=None):
83 """ 84 Resolve the GENEVA object codes. 85 86 @param ID: target ID (not implemented yet) 87 @type ID: str 88 @param code: target's GENEVA code (e.g. 100180642 for HD180642) 89 @type code: int 90 @return: Geneva code or target ID (dependent on input) 91 @rtype: str 92 """ 93 if code is not None: 94 if not isinstance(code,str): 95 code = '%+09d'%(code) 96 if code[1:3]=='10': ID = 'HD'+code[3:] 97 elif code[1:3]=='15': ID = 'SAO'+code[3:] 98 elif code[1:3]=='16': ID = 'HIC'+code[3:] 99 elif code[1:3]=='17': ID = 'PPM'+code[3:] 100 elif code[:3]=='-00': ID = 'BD%s%s %s'%(code[0],code[3:5],code[5:]) 101 elif code[:3]=='+00': ID = 'BD%s%s %s'%(code[0],code[3:5],code[5:]) 102 return ID 103 104 elif ID is not None: 105 if 'HD' in ID: code = '10%06d'%(int(ID.split('HD')[1])) 106 elif 'SAO' in ID: code = '15%06d'%(int(ID.split('SAO')[1])) 107 elif 'HIC' in ID: code = '16%06d'%(int(ID.split('HIC')[1])) 108 elif 'PPM' in ID: code = '17%06d'%(int(ID.split('PPM')[1])) 109 else: code = ID 110 return int(code)
111