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