-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanita_author_tool.py
executable file
·373 lines (231 loc) · 9.01 KB
/
anita_author_tool.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/usr/bin/env python
## ANITA Author Tool to save time on author lists...
# Cosmin Deaconu <[email protected]>
# apologies for the semicolons, it's a reflex at this point...
# This is about as brute force as it gets :)
import sys
prefix = "anita_" #prefix for all output files (first argument overrideS)
collaboration = "ANITA" # (second argument overrides)
if len(sys.argv) > 1:
prefix = sys.argv[1]
if len(sys.argv) > 2:
collaboration = sys.argv[2]
## may need to do more here!
def tex_escape(string):
return string.replace("&","\&")
def html_escape(string):
return string.replace("&","&")
# Start by opening the institutes.in
finst = open("institutes.in")
institutes = {}
for line in finst.readlines():
line = line.strip()
if len(line) == 0:
continue
if line[0] == "#":
continue
tokens = line.split("|");
if len(tokens) < 2:
continue
inst_id = tokens[0].strip()
inst_addr = tokens[1].strip()
inst_short = inst_addr if len(tokens) < 3 else tokens[2].strip()
if inst_id in institutes:
print( "WARNING: duplicate ID \"%s\" found! Replacing existing." % (inst_id))
institutes[inst_id] = (inst_addr, inst_short)
# Then open the authors list
fauth = open("authors.in")
lineno = 0
authors = []
sorted_institutes = []
institute_numbers = {}
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
institute_letters = {}
for line in fauth.readlines():
line = line.strip()
lineno+=1
if len(line) == 0:
continue
if line[0] == "#":
continue
tokens = line.split("|");
if len(tokens) == 1:
print(" WARNING: No affiliation on line %d" % (lineno))
author = tokens[0].strip()
affiliations = []
for t in tokens[1:]:
aff = t.strip()
if aff not in institutes:
print(" WARNING, no key for %s found in institutes.in" % (aff))
else:
if aff not in sorted_institutes:
sorted_institutes.append(aff)
institute_numbers[aff] = len(sorted_institutes)
institute_letters[aff] = letters[len(sorted_institutes)-1]
affiliations.append(aff)
authors.append((author,affiliations))
# authors.txt
f_authors_txt = open(prefix +"authors.txt","w")
first = True
for author in authors:
if not first:
f_authors_txt.write(", ");
f_authors_txt.write(author[0] + " ");
for aff in author[1]:
f_authors_txt.write("[%d]" % (institute_numbers[aff]) );
first = False
f_authors_txt.write("\n\n");
for i in range(len(sorted_institutes)):
f_authors_txt.write("%d: %s\n"%( i+1, institutes[sorted_institutes[i]][0]))
f_authors_txt.close()
# authors.html
f_authors_html = open(prefix +"authors.html","w")
f_authors_html.write("<p align='center'>")
first = True
for author in authors:
if not first:
f_authors_html.write(", \n");
f_authors_html.write(author[0]);
f_authors_html.write("<sup>");
first_aff = True
for aff in author[1]:
if not first_aff:
f_authors_html.write(",");
f_authors_html.write("<a href='#%s'>%d</a>" % (aff, institute_numbers[aff]) );
first_aff = False
f_authors_html.write("</sup>");
first = False
f_authors_html.write("<br>(<b>%s Collaboration</b>)\n" % (collaboration));
f_authors_html.write("</p>\n\n");
for i in range(len(sorted_institutes)):
f_authors_html.write("<br> <a name='%s'\\> <sup>%d</sup> %s\n"%(sorted_institutes[i], i+1, html_escape(institutes[sorted_institutes[i]][0])))
f_authors_html.close()
# revtex_authors.tex
f_revtex_authors = open(prefix + "revtex_authors.tex","w")
f_revtex_authors.write("%% Collaboration author file for %s in revtex format\n" % (collaboration))
f_revtex_authors.write("%% \\input this file in main body (make sure you also do the institutes file in the preamble!) \n\n" )
for author in authors:
name = author[0].replace(" ","~")
f_revtex_authors.write(" \\author{%s}" % (name))
if author[1] is not None:
for aff in author[1]:
f_revtex_authors.write("\\at%s" % (aff))
f_revtex_authors.write("\n")
f_revtex_authors.write("\\collaboration{%s Collaboration}\\noaffiliation\n" % (collaboration));
f_revtex_authors.close()
# revtex_institutes.tex
f_revtex_institutes = open(prefix + "revtex_institutes.tex","w")
f_revtex_institutes.write("%% Collaboration institute file for %s in revtex format\n" % (collaboration))
f_revtex_institutes.write("%% \\input this file in the preamble (make sure you also do the author file in the body!) \n\n")
for key in sorted_institutes:
addr = tex_escape(institutes[key][0]) ;
f_revtex_institutes.write("\\newcommand{\\at%s}{\\affiliation{%s}}\n" % (key, addr));
f_revtex_institutes.close()
# aas_authors.tex
f_aas_authors = open(prefix + "aas_authors.tex","w")
f_aas_authors.write("%% Collaboration author file for %s in aas format\n" % (collaboration))
f_aas_authors.write("%% \\input this file in main body (make sure you also do the institutes file in the preamble!) \n\n" )
for author in authors:
name = author[0].replace(" ","~")
f_aas_authors.write("\\author{%s}" % (name))
if author[1] is not None:
for aff in author[1]:
f_aas_authors.write("\n\\at%s" % (aff))
f_aas_authors.write("\n")
f_aas_authors.write("\\collaboration{1000}{%s Collaboration}\n" % (collaboration));
f_aas_authors.close()
# aas_institutes.tex
f_aas_institutes = open(prefix + "aas_institutes.tex","w")
f_aas_institutes.write("%% Collaboration institute file for %s in aas format\n" % (collaboration))
f_aas_institutes.write("%% \\input this file in the preamble (make sure you also do the author file in the body!) \n\n")
for key in sorted_institutes:
addr = tex_escape(institutes[key][0]) ;
f_aas_institutes.write("\\newcommand{\\at%s}{\\affiliation{%s}}\n" % (key, addr));
f_aas_institutes.close()
#elsarticle_authors.tex
f_elsarticle_authors = open(prefix + "elsarticle_authors.tex","w");
f_elsarticle_authors.write("%% authorlist for elsarticle publications for %s collaboration\n\n" % (collaboration) );
f_elsarticle_authors.write("\\collaboration{%s Collaboration}\n\n" % (collaboration));
for key in sorted_institutes:
num = institute_numbers[key];
addr = tex_escape(institutes[key][0]) ;
f_elsarticle_authors.write("\\address[%d]{%s}\n" % (num, addr));
f_elsarticle_authors.write("\n\n");
for author in authors:
name = author[0].replace(" ","~")
affs = ""
for aff in author[1]:
if affs != "":
affs += ","
affs += str(institute_numbers[aff])
f_elsarticle_authors.write("\\author[%s]{%s}\n" % (affs,name))
f_elsarticle_authors.close()
#sissa_authors.tex
f_sissa_authors = open(prefix + "sissa_authors.tex","w");
f_sissa_authors.write("%% authorlist for elsarticle publications for %s collaboration\n\n" % (collaboration) );
for author in authors:
name = author[0].replace(" ","~")
affs = ""
for aff in author[1]:
if affs != "":
affs += ","
affs += str(institute_letters[aff])
f_sissa_authors.write("\\author[%s]{%s}\n" % (affs,name))
f_sissa_authors.write("\n\n");
for key in sorted_institutes:
letter = institute_letters[key];
addr = tex_escape(institutes[key][0]) ;
f_sissa_authors.write("\\affiliation[%s]{%s}\n" % (letter, addr));
f_sissa_authors.write("\n\n");
f_sissa_authors.write("\\collaboration{%s Collaboration}\n\n" % (collaboration));
f_sissa_authors.close()
# pos_authors.tex
f_pos_authors = open(prefix +"pos_authors.tex","w")
f_pos_authors.write("%% PoS list for %s Collaboration\n\n" % (collaboration));
first = True
f_pos_authors.write("\\author{\n");
f_pos_authors.write(" (%s Collaboration)\n" % (collaboration));
for author in authors:
name = author[0].replace(" ","~")
if not first:
f_pos_authors.write(",\n");
f_pos_authors.write(" %s" % (name));
affs = ""
for aff in author[1]:
if affs != "":
affs += ","
affs += str(institute_numbers[aff])
f_pos_authors.write("$^{%s}$"%(affs))
first = False
f_pos_authors.write("\n\n\\\\\n");
first = True
for i in range(len(sorted_institutes)):
if not first:
f_pos_authors.write(",\n")
f_pos_authors.write(" $^{%d}$%s"%( i+1, tex_escape(institutes[sorted_institutes[i]][1])))
first = False
f_pos_authors.write("\n}\n");
f_pos_authors.close()
## ICRC authors
f_icrc_authors = open(prefix + "icrc_authors.tex","w");
f_icrc_authors.write("%% ICRC list for %s Collaboration\n\n" % (collaboration));
first = True
num_institutes = 0
f_icrc_authors.write("\\noindent\n")
for author in authors:
name = author[0].replace(" ","~")
if not first:
f_icrc_authors.write(", \n");
f_icrc_authors.write(name);
first_aff = True
for aff in author[1]:
if not first_aff:
f_icrc_authors.write("\\textsuperscript{,}");
if institute_numbers[aff] > num_institutes:
f_icrc_authors.write("\\footnote[%d]{%s\label{inst%d}}" % (institute_numbers[aff], institutes[aff][0], institute_numbers[aff]))
num_institutes+=1
else:
f_icrc_authors.write("\\textsuperscript{%d}" % (institute_numbers[aff]) );
first_aff = False
first = False
f_icrc_authors.close()