1
2
3 """
4 A module for reading and managing text-based line profile data files.
5
6 Author: R. Lombaert
7
8 """
9
10 import os
11 from scipy import array
12
13 import cc.path
14 from cc.tools.io import DataIO
15 from cc.tools.readers.LPDataReader import LPDataReader
16
17
18
20
21 '''
22 A text file reader for line profile data.
23
24 '''
25
26 - def __init__(self,fn,star_name=None,*args,**kwargs):
27
28 '''
29 A txt file reader for line profile data.
30
31 Filename of the txt file is passed to the object upon creation.
32
33 Initialisation of the object will also check Vlsr in Star.dat and add
34 it as a keyword in the contents dictionary.
35
36 Text files must consist of two columns: velocity (km/s), flux (unit)
37
38 Additional args/kwargs are used for the dict creation of the parent of
39 Reader.
40
41 @param fn: The txt filename, including filepath.
42 @type fn: string
43
44 @keyword star_name: The star name if the filename doesn't follow naming
45 conventions. None otherwise.
46
47 (default: None)
48 @type star_name: str
49
50 '''
51
52 super(TxtReader, self).__init__(fn=fn,star_name=star_name,\
53 *args,**kwargs)
54 self.type = 'txt'
55 self.readTxt()
56 self.checkVlsr()
57
58
59
61
62 '''
63 Read the txt file.
64
65 Assumes Tmb flux values in K, with respect to velocity.
66
67 '''
68
69 data = DataIO.readCols(filename=self.fn,start_row=0,nans=1)
70 if self.fn[-6:] == '.ISPEC':
71 del data[0]
72 data[0] = data[0]/1000.
73 self['contents']['velocity'] = data[0]
74 self['contents']['flux'] = data[1]
75 if self['contents']['velocity'][0] > self['contents']['velocity'][-1]:
76 self['contents']['velocity'] = self['contents']['velocity'][::-1]
77 self['contents']['flux'] = self['contents']['flux'][::-1]
78 self['contents']['date_obs'] = 'N.A.'
79 self['contents']['vlsr'] = None
80