1 | from __future__ import absolute_import
|
---|
2 |
|
---|
3 | import collections
|
---|
4 | import os
|
---|
5 | import pprint
|
---|
6 | import xlrd
|
---|
7 |
|
---|
8 | from mako.lookup import TemplateLookup
|
---|
9 |
|
---|
10 | class LoadParameters:
|
---|
11 | """Class to compute interferograms.
|
---|
12 | """
|
---|
13 |
|
---|
14 | def __init__(self, sky_spreadsheet='Sky.xlsx', sky_sheet='1point',
|
---|
15 | instrument_spreadsheet='FIInS_Instrument_cor3.xlsx'):
|
---|
16 | self.result = collections.OrderedDict()
|
---|
17 | self.result['substages'] = collections.OrderedDict()
|
---|
18 |
|
---|
19 | # access the relevant sheet of the spreadsheet
|
---|
20 | book = xlrd.open_workbook(sky_spreadsheet)
|
---|
21 | print 'names', book.sheet_names()
|
---|
22 | sheet = book.sheet_by_name(sky_sheet)
|
---|
23 |
|
---|
24 | sheet_dict = collections.OrderedDict()
|
---|
25 |
|
---|
26 | # Sheet has names in col 0, values in columns 1 to n
|
---|
27 | # Ignore row 0.
|
---|
28 |
|
---|
29 | # read column names
|
---|
30 | for row in range(1,sheet.nrows):
|
---|
31 | colname = sheet.cell(row, 0)
|
---|
32 | sheet_dict[colname.value] = {}
|
---|
33 | for col in range(1,sheet.ncols):
|
---|
34 | sheet_dict[colname.value][col] = sheet.cell(row,col).value
|
---|
35 |
|
---|
36 | self.result['substages']['Sky'] = sheet_dict
|
---|
37 |
|
---|
38 | # the instrument spreadsheet
|
---|
39 | instrument_book = xlrd.open_workbook(instrument_spreadsheet)
|
---|
40 | for sheet in instrument_book.sheets():
|
---|
41 |
|
---|
42 | if sheet.name == 'FTSpectrograph':
|
---|
43 | sheet_dict = collections.OrderedDict()
|
---|
44 |
|
---|
45 | # ignore first row of sheet
|
---|
46 | # second row of sheet has column names
|
---|
47 | name_row = 1
|
---|
48 | # subsequent rows have entries, only one of which is
|
---|
49 | # 'selected'
|
---|
50 | select_col = None
|
---|
51 |
|
---|
52 | # read column names
|
---|
53 | for col in range(sheet.ncols):
|
---|
54 | sheet_dict[sheet.cell(name_row,col).value] = \
|
---|
55 | collections.OrderedDict()
|
---|
56 | if 'Selection' in sheet.cell(name_row,col).value:
|
---|
57 | select_col = col
|
---|
58 |
|
---|
59 | # sanity check
|
---|
60 | if select_col is None:
|
---|
61 | raise Exception, \
|
---|
62 | 'No Selection column in FTSpectrograph spreadsheet'
|
---|
63 |
|
---|
64 | # read entries from first 'selected' row
|
---|
65 | for row in range(name_row+1,sheet.nrows):
|
---|
66 | if int(sheet.cell(row,select_col).value) > 0:
|
---|
67 | for col in range(sheet.ncols):
|
---|
68 | sheet_dict[sheet.cell(name_row,col).value][row] = \
|
---|
69 | sheet.cell(row,col).value
|
---|
70 | break
|
---|
71 |
|
---|
72 | # resulting dict should contain the entries from the
|
---|
73 | # selected spreadsheet row
|
---|
74 |
|
---|
75 | self.result['substages'][sheet.name] = sheet_dict
|
---|
76 |
|
---|
77 | elif sheet.name == 'FTSMechanical':
|
---|
78 | sheet_dict = collections.OrderedDict()
|
---|
79 |
|
---|
80 | # Sheet has names in col 0, values in col 1.
|
---|
81 | # Ignore row 0.
|
---|
82 | name_col = 0
|
---|
83 | entry_col = 1
|
---|
84 |
|
---|
85 | # read column names
|
---|
86 | for row in range(1,sheet.nrows):
|
---|
87 | sheet_dict[sheet.cell(row,name_col).value] = \
|
---|
88 | collections.OrderedDict()
|
---|
89 | sheet_dict[sheet.cell(row,name_col).value][entry_col] = \
|
---|
90 | sheet.cell(row,entry_col).value
|
---|
91 |
|
---|
92 | self.result['substages'][sheet.name] = sheet_dict
|
---|
93 |
|
---|
94 | elif sheet.name == 'Telescope':
|
---|
95 | sheet_dict = collections.OrderedDict()
|
---|
96 |
|
---|
97 | # Sheet has names in col 0, values in col 1, units in col 3.
|
---|
98 | # Ignore rows 0 and 1.
|
---|
99 | name_col = 0
|
---|
100 | entry_col = 1
|
---|
101 |
|
---|
102 | # read column names
|
---|
103 | for row in range(2,sheet.nrows):
|
---|
104 | sheet_dict[sheet.cell(row,name_col).value] = \
|
---|
105 | sheet.cell(row,entry_col).value
|
---|
106 |
|
---|
107 | self.result['substages'][sheet.name] = sheet_dict
|
---|
108 |
|
---|
109 | elif sheet.name == 'Interferometer':
|
---|
110 | sheet_dict = collections.OrderedDict()
|
---|
111 |
|
---|
112 | # ignore first 4 rows of sheet
|
---|
113 | # 5th row of sheet has column names
|
---|
114 | name_row = 4
|
---|
115 | # subsequent rows have entries, only one of which is
|
---|
116 | # 'selected'
|
---|
117 | select_col = None
|
---|
118 |
|
---|
119 | # read column names
|
---|
120 | for col in range(sheet.ncols):
|
---|
121 | sheet_dict[sheet.cell(name_row,col).value] = \
|
---|
122 | collections.OrderedDict()
|
---|
123 | if 'Select' in sheet.cell(name_row,col).value:
|
---|
124 | select_col = col
|
---|
125 |
|
---|
126 | # sanity check
|
---|
127 | if select_col is None:
|
---|
128 | raise Exception, \
|
---|
129 | 'No Selection column in Interferometer spreadsheet'
|
---|
130 |
|
---|
131 | # read entries from first 'selected' row
|
---|
132 | for row in range(name_row+1,sheet.nrows):
|
---|
133 | select_cell = str(sheet.cell(row,select_col).value)
|
---|
134 | select_val = 0
|
---|
135 | try:
|
---|
136 | select_val = int(float(select_cell))
|
---|
137 | except:
|
---|
138 | pass
|
---|
139 |
|
---|
140 | if select_val == 1:
|
---|
141 | for col in range(sheet.ncols):
|
---|
142 | sheet_dict[sheet.cell(name_row,col).value][row] = \
|
---|
143 | sheet.cell(row,col).value
|
---|
144 | break
|
---|
145 |
|
---|
146 | # resulting dict should contain the entries from the
|
---|
147 | # selected spreadsheet row
|
---|
148 |
|
---|
149 | self.result['substages'][sheet.name] = sheet_dict
|
---|
150 |
|
---|
151 | elif sheet.name == 'ColdOptics':
|
---|
152 | sheet_dict = collections.OrderedDict()
|
---|
153 |
|
---|
154 | # Sheet has names in col 0, values in col 1.
|
---|
155 | # Ignore rows 0 and 1 and final row.
|
---|
156 | # Ignore cols 2 and higher - duplicate information.
|
---|
157 | name_col = 0
|
---|
158 | entry_col = 1
|
---|
159 |
|
---|
160 | # read column names
|
---|
161 | for row in range(2,sheet.nrows-1):
|
---|
162 | sheet_dict[sheet.cell(row,name_col).value] = \
|
---|
163 | collections.OrderedDict()
|
---|
164 | sheet_dict[sheet.cell(row,name_col).value][entry_col] = \
|
---|
165 | sheet.cell(row,entry_col).value
|
---|
166 |
|
---|
167 | self.result['substages'][sheet.name] = sheet_dict
|
---|
168 |
|
---|
169 | elif sheet.name == 'Background':
|
---|
170 | sheet_dict = collections.OrderedDict()
|
---|
171 |
|
---|
172 | # Sheet has names in col 0, values in col 1.
|
---|
173 | # Ignore rows 0 and 1.
|
---|
174 | name_col = 0
|
---|
175 | entry_col = 1
|
---|
176 |
|
---|
177 | for row in range(2,sheet.nrows):
|
---|
178 | sheet_dict[sheet.cell(row,name_col).value] = \
|
---|
179 | collections.OrderedDict()
|
---|
180 | sheet_dict[sheet.cell(row,name_col).value][entry_col] = \
|
---|
181 | sheet.cell(row,entry_col).value
|
---|
182 |
|
---|
183 | self.result['substages'][sheet.name] = sheet_dict
|
---|
184 |
|
---|
185 | elif sheet.name == 'WarmOptics':
|
---|
186 | sheet_dict = collections.OrderedDict()
|
---|
187 |
|
---|
188 | # Sheet has names in col 0, values in col 1.
|
---|
189 | # Ignore rows 0 and 1.
|
---|
190 | name_col = 0
|
---|
191 | entry_col = 1
|
---|
192 |
|
---|
193 | for row in range(2,sheet.nrows):
|
---|
194 | sheet_dict[sheet.cell(row,name_col).value] = \
|
---|
195 | collections.OrderedDict()
|
---|
196 | sheet_dict[sheet.cell(row,name_col).value][entry_col] = \
|
---|
197 | sheet.cell(row,entry_col).value
|
---|
198 |
|
---|
199 | self.result['substages'][sheet.name] = sheet_dict
|
---|
200 |
|
---|
201 | elif sheet.name == 'Detectors':
|
---|
202 | sheet_dict = collections.OrderedDict()
|
---|
203 |
|
---|
204 | # Sheet has names in col 0, values in col 1.
|
---|
205 | # Ignore rows 0 and 1.
|
---|
206 | name_col = 0
|
---|
207 | entry_col = 1
|
---|
208 |
|
---|
209 | for row in range(2,sheet.nrows):
|
---|
210 | sheet_dict[sheet.cell(row,name_col).value] = \
|
---|
211 | collections.OrderedDict()
|
---|
212 | sheet_dict[sheet.cell(row,name_col).value][entry_col] = \
|
---|
213 | sheet.cell(row,entry_col).value
|
---|
214 |
|
---|
215 | self.result['substages'][sheet.name] = sheet_dict
|
---|
216 |
|
---|
217 | elif sheet.name == 'SimulatorControl':
|
---|
218 | sheet_dict = collections.OrderedDict()
|
---|
219 |
|
---|
220 | # Sheet has names in col 0, values in col 1.
|
---|
221 | # Ignore row 0.
|
---|
222 | name_col = 0
|
---|
223 | entry_col = 1
|
---|
224 |
|
---|
225 | for row in range(1,sheet.nrows):
|
---|
226 | sheet_dict[sheet.cell(row,name_col).value] = \
|
---|
227 | collections.OrderedDict()
|
---|
228 | sheet_dict[sheet.cell(row,name_col).value][entry_col] = \
|
---|
229 | sheet.cell(row,entry_col).value
|
---|
230 |
|
---|
231 | self.result['substages'][sheet.name] = sheet_dict
|
---|
232 |
|
---|
233 | else:
|
---|
234 | print 'loadparameters skipping', sheet.name
|
---|
235 |
|
---|
236 | def run(self):
|
---|
237 | return self.result
|
---|