-
Notifications
You must be signed in to change notification settings - Fork 3
/
index_vdif_waterfalls.py
executable file
·61 lines (44 loc) · 1.87 KB
/
index_vdif_waterfalls.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
#!/usr/bin/env python
import os
import re
import sys
def index_waterfalls(dirname):
imgdir = os.path.join(dirname, 'img')
fname_hash = { } # (imtype,pol,frame_ix) -> filename
all_indices = set()
for fname in os.listdir(imgdir):
for imtype in [ 'full', 'thumbnail' ]:
for pol in [ 0, 1 ]:
prefix = '%s_pol%d_frame' % (imtype, pol)
if not fname.startswith(prefix):
continue
m = re.match(r'(\d+)\.png', fname[len(prefix):])
if not m:
continue
frame_ix = int(m.group(1))
fname_hash[imtype,pol,frame_ix] = fname
all_indices.add(frame_ix)
html_filename = os.path.join(dirname, 'index.html')
html = open(html_filename, 'w')
print >>html, '<html><head><title>%s</title></head>' % os.path.basename(dirname)
print >>html, '<body><table cellspacing="10">'
for frame_ix in sorted(all_indices):
print >>html, '<tr> <td> Frame %d' % frame_ix
for pol in [0,1]:
full = fname_hash.get(('full',pol,frame_ix), None)
thumb = fname_hash.get(('thumbnail',pol,frame_ix), None)
if thumb and full:
print >>html, '<td> <a href="img/%s"> <img src="img/%s"> </a>' % (full, thumb)
elif thumb and not full:
print >>html, '<td> <img src="img/%s">' % thumb
elif not thumb and full:
print >>html, '<td> <a href="img/%s"> pol %d </a>' % (full, pol)
else:
print >>html, '<td>'
print >>html, '</table></body></html>'
print >>sys.stderr, 'wrote', html_filename
if __name__ == '__main__':
if len(sys.argv) != 2:
print >>sys.stderr, 'usage: index_vdif_waterfalls.py <waterfall_outdir>'
sys.exit(2)
index_waterfalls(sys.argv[1])