-
Notifications
You must be signed in to change notification settings - Fork 13
/
gen_footprint_md.py
143 lines (116 loc) · 4.25 KB
/
gen_footprint_md.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
'''
This is a script that will parse the configuration file and generate a
markdown file with different tables populated with the different entries in
the configuration file.
'''
try:
import ConfigParser
except ImportError:
import configparser as ConfigParser
def gen_markdown():
md_file = 'footprint_config.md'
f = open(md_file, 'w')
fn = 'footprint.cfg'
backgrounds, cmb, cmbpol, lss = process_config(fn)
f.write('This page is automatically constructed from the configuration ')
f.write('file and is meant as an easier way to see what surveys are ')
f.write('included in the configuration file')
f.write('\n\n')
# Write the background table
f.write('# Backgrounds\n')
f.write('\n')
f.write('This table lists all the different backgrounds in the ')
f.write('configuration file that can be added to the footprint figure ')
f.write('by inputting a string instead of a Healpix map.\n')
f.write('\n')
f.write('| Experiment | ID | Description | File |\n')
f.write('|------------|----|-------------|------|\n')
for tmp in backgrounds:
line = '| ' + tmp[0] + ' | ' + tmp[1] + ' | ' + tmp[2] + ' | '
if tmp[4] is None:
line += '|\n'
else:
line += ' [Link](' + tmp[4] + ') |\n'
line = line.replace('"', '')
f.write(line)
f.write('\n')
# Write the CMB temperature anisotropy table
f.write('# CMB Temperature Anisotropy Surveys\n')
f.write('\n')
f.write('This next table lists all the surveys associated with CMB ')
f.write('temperature anisotropy experiments\n')
f.write('\n')
f.write('| Experiment | ID | Description | File |\n')
f.write('|------------|----|-------------|------|\n')
for tmp in cmb:
line = '| ' + tmp[0] + ' | ' + tmp[1] + ' | ' + tmp[2] + ' | '
if tmp[4] is None:
line += '|\n'
else:
line += ' [Link](' + tmp[4] + ') |\n'
line = line.replace('"', '')
f.write(line)
f.write('\n')
# Write the CMB polarization table
f.write('# CMB Polarization Surveys\n')
f.write('\n')
f.write('This next table lists all the surveys associated with CMB ')
f.write('polarization experiments\n')
f.write('\n')
f.write('| Experiment | ID | Description | File |\n')
f.write('|------------|----|-------------|------|\n')
for tmp in cmbpol:
line = '| ' + tmp[0] + ' | ' + tmp[1] + ' | ' + tmp[2] + ' | '
if tmp[4] is None:
line += '|\n'
else:
line += ' [Link](' + tmp[4] + ') |\n'
line = line.replace('"', '')
f.write(line)
f.write('\n')
# Write the LSS table
f.write('# Large-Scale Structure Surveys\n')
f.write('\n')
f.write('This next table lists all the surveys associated with LSS ')
f.write('surveys\n')
f.write('\n')
f.write('| Experiment | ID | Description | File |\n')
f.write('|------------|----|-------------|------|\n')
for tmp in lss:
line = '| ' + tmp[0] + ' | ' + tmp[1] + ' | ' + tmp[2] + ' | '
if tmp[4] is None:
line += '|\n'
else:
line += ' [Link](' + tmp[4] + ') |\n'
line = line.replace('"', '')
f.write(line)
f.write('\n')
f.close()
def process_config(fn):
config = ConfigParser.ConfigParser()
config.read(fn)
# Add the entries to the correct table
background = []
cmb = []
cmbpol = []
lss = []
for section in config.sections():
tableval = config.get(section, 'survey_type')
descr = config.get(section, 'description')
citation = config.get(section, 'citation')
expr_name = config.get(section, 'instrument')
try:
url = config.get(section, 'url')
except:
url = None
if tableval == 'background':
background.append([expr_name, section, descr, citation, url])
elif tableval == 'cmb':
cmb.append([expr_name, section, descr, citation, url])
elif tableval == 'cmbpol':
cmbpol.append([expr_name, section, descr, citation, url])
elif tableval == 'lss':
lss.append([expr_name, section, descr, citation, url])
return background, cmb, cmbpol, lss
if __name__ == '__main__':
gen_markdown()