-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogramlist.py
executable file
·127 lines (120 loc) · 5.01 KB
/
programlist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#! /usr/bin/env python3
## Version of Feb 12 2016
import sys
sys.path.append('/home/lachaume/Dropbox/python/')
import os
import re
import numpy
import codecs
from MPG.utils import structured_array_from_excel
def get_program_filename(tel, period, path='.', format='xls'):
basename = 'programmes-{}-P{}.{}'.format(tel, period, format)
filename = os.path.join(path, basename)
return filename
class ProgramList(numpy.ndarray):
def __new__(cls, tel, period, path='.', honour_omit=True):
path = BasicLog(tel=tel, period=period, path=path).get_path()
filename = get_program_filename(tel, period, path=path, format='xls')
arr = structured_array_from_excel(filename, cls=cls)
if honour_omit:
arr = arr[arr['Link'] != 'omit']
arr.lookup_ = {p: pid for pid in arr['PID']
for p in re.split(',\s*', pid)}
arr.corr = structured_array_from_excel(filename, cls=cls, sheetnum=1)
arr.path = path
arr.tel = tel
arr.period = period
for r in range(arr.size):
ids = arr[r]['Identifiers']
if len(ids):
for pid in re.split(',\\s*', ids):
arr.lookup_[pid] = arr[r]['PID']
arr.period = period
return arr
def __getitem__(self, i):
item = numpy.ndarray.__getitem__(self, i)
if isinstance(i, str) and i in self.dtype.names:
item = numpy.array(item.tolist())
return item
def lookup(self, pid, target=None, date=None, ins=None):
# print('lookup', pid, ins)
if target is not None or date is not None:
# print(self.corr)
for line in self.corr:
if line['PID'] in pid:
t = line['Target']
d1, d2 = line['Start'], line['End']
# print((line['PID'], t, d1, date, d2))
if t != '' and not re.search(t, target):
continue
if d1 != '' and date < d1:
continue
if d2 != '' and date > d2:
continue
pid = line['Nominal PID']
if pid in self['PID']:
return self[self['PID'] == pid][0]
try:
return self[self.lookup_[pid] == self['PID']][0]
except:
prog = self[-1].copy()
prog['TAC'] = 'N/A'
prog['PID'] = pid
prog['Title'] = 'Unidentified programme'
prog['Surname'] = 'Unknown'
prog['Name'] = ''
prog['Instrument'] = ins
prog['Identifiers'] = '???'
prog['Link'] = 'no'
return prog
def save_as_html(self):
ESOURL = 'http://archive.eso.org/wdb/wdb/eso/sched_rep_arc/query'
tel, period, path = self.tel, self.period, self.path
filename = get_program_filename(tel, period, path=path, format='htm')
fh = codecs.open(filename, 'wb', 'utf-8')
fh.write(' <tbody>\n')
last_tac = None
for row in self:
tac, pid, link = row['TAC'], row['PID'], row['Link']
title, pi = row['Title'], row['Name'] + ' ' + row['Surname']
if pid != 'TBD':
# Link to proposal
if link != 'no':
if link[0:7] == 'http://':
url = link
else:
url = 'proposals/'
if link == 'yes':
if period >= 100:
url += pid[7:11] + '.pdf'
else:
url += pid[6:10] + '.pdf'
else:
url += link + '.pdf'
title = '<a href="{}">{}</a>'.format(url, title)
# Fix PID and link to archive
# print(tac, pid, link, title, pi)
if pid[-1] != ')':
print('fix pid:', pid)
pid += '(A)'
link = '{}?progid={}'.format(ESOURL, pid)
pid = '<a href="{}">{}</a>'.format(link, pid)
cols = [tac, pid, pi, row['Instrument'], title, row['Hours'],
row['Moon'], row['Trans.'], row['Seeing'], row['Airmass']]
# Not breakable
for i in [1, 2]:
cols[i] = '<span class="atomic">{}</span>'.format(cols[i])
if last_tac is not None and last_tac != tac:
fh.write(' </tbody><tbody>\n')
last_tac = tac
fh.write(' <tr>\n')
for col in cols:
fh.write(u' <td>{}</td>\n'.format(col))
fh.write(' </tr>\n')
fh.write(' </tbody>')
def publish_to(self, rdir):
tel, period, path = self.tel, self.period, self.path
rdir = '{}/P{}'.format(rdir, period)
filename = get_program_filename(tel, period, path=path, format='htm')
os.system('scp -r {} {}/proposals {}'.format(filename, path, rdir))
from MPG.esolog import BasicLog