-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmakeCV.py
More file actions
executable file
·1300 lines (1053 loc) · 47.3 KB
/
Copy pathmakeCV.py
File metadata and controls
executable file
·1300 lines (1053 loc) · 47.3 KB
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Make sure ADS_TOKEN is part of the environment variables
import numpy as np
import json
from tqdm import tqdm
import copy
import sys
import time
import os
import ssl
import urllib.request
import urllib.error
import urllib.parse
import requests
import html
from database import papers, talks, group
from datetime import datetime, timezone
import shutil
import warnings
import re
import unicodedata
from glob import glob
context = ssl._create_unverified_context()
relativepathwebsiterepo = os.path.abspath(os.getcwd())+"/../website"
is_github_actions = os.getenv("GITHUB_ACTIONS", "").lower() == "true"
#### Utils ####
def hindex(citations):
return sum(x >= i + 1 for i, x in enumerate(sorted( list(citations), reverse=True)))
def roundto100(N):
return int(N/100)*100
def slugify(text):
# Normalize unicode characters to closest ASCII equivalent
text = unicodedata.normalize('NFKD', text).encode('ascii', 'ignore').decode('ascii')
# Convert to lowercase
text = text.lower()
# Remove all characters except alphanumerics, spaces, and hyphens
text = re.sub(r'[^\w\s-]', '', text)
# Replace spaces and underscores with hyphens
text = re.sub(r'[\s_]+', '-', text)
# Collapse multiple hyphens
text = re.sub(r'-+', '-', text)
# Strip leading/trailing hyphens
return text.strip('-')
def nameinitial(name):
parts = name.split()
return f"{parts[0][0]}. {' '.join(parts[1:])}"
def lastupdated(out):
now_utc = datetime.now(timezone.utc)
formatted = now_utc.strftime("%Y-%m-%d %H:%M:%S %Z")
out.append("")
out.append("<br><br>")
out.append("*Last updated: "+formatted+"*")
def journaldict():
# Conversion dictionary for journal names
journalconversion = {}
journalconversion['\prd'] = ["Physical Review D", "PRD"]
journalconversion['\prdrc'] = ["Physical Review D", "PRD"]
journalconversion['\prdl'] = ["Physical Review D", "PRD"]
journalconversion['\prl'] = ["Physical Review Letters", "PRL"]
journalconversion['\prr'] = ["Physical Review Research", "PRR"]
journalconversion['\mnras'] = ["Monthly Notices of the Royal Astronomical Society", "MNRAS"]
journalconversion['\mnrasl'] = ["Monthly Notices of the Royal Astronomical Society", "MNRAS"]
journalconversion['\cqg'] = ["Classical and Quantum Gravity", "CQG"]
journalconversion['\\aap'] = ["Astronomy & Astrophysics", "A&A"]
journalconversion['\\apj'] = ["Astrophysical Journal", "APJ"]
journalconversion['\\apjl'] = ["Astrophysical Journal", "APJ"]
journalconversion['\grg'] = ["General Relativity and Gravitation", "GRG"]
journalconversion['\lrr'] = ["Living Reviews in Relativity", "LRR"]
journalconversion['\\natastro'] = ["Nature Astronomy", "NatAstro"]
journalconversion['Proceedings of the International Astronomical Union'] = ["IAU Proceedigs", "IAU"]
journalconversion['Journal of Physics: Conference Series'] = ["Journal of Physics: Conference Series", "JoPCS"]
journalconversion['Journal of Open Source Software'] = ["Journal of Open Source Software", "JOSS"]
journalconversion['Astrophysics and Space Science Proceedings'] = ["Astrophysics and Space Science Proceedings", "AaSSP"]
journalconversion['Caltech Undergraduate Research Journal'] = ["Caltech Undergraduate Research Journal", "CURJ"]
journalconversion['Chapter in: Handbook of Gravitational Wave Astronomy, Springer, Singapore'] = ['Book contribution', 'book']
journalconversion['Rendiconti Lincei. Scienze Fisiche e Naturali'] = ['Rendiconti Lincei', 'Lincei']
journalconversion['Proceedings of the 57th Rencontres de Moriond'] = ['Moriond proceedings', 'Moriond']
journalconversion['Proceedings of the International Congress of Basic Science, International Press'] = ['ICBS proceedings', 'ICBS']
journalconversion["arXiv e-prints"] = ["arXiv", "arXiv"]
return journalconversion
def convertjournal(j):
journalconversion=journaldict()
if j in journalconversion:
return journalconversion[j]
else:
return [j, j]
def apply_journal_conversion(lines):
journalconversion=journaldict()
converted = []
# Sort tags by length descending
sorted_tags = sorted(journalconversion.keys(), key=len, reverse=True)
for line in lines:
new_line = line
for tag in sorted_tags:
full_name, short_name = journalconversion[tag]
if short_name == "book":
continue # Skip conversion for 'book'
if tag in new_line:
new_line = new_line.replace(tag, full_name)
converted.append(new_line)
return converted
#### Get citations ####
# def ads_citations(papers,testing=False):
# print('Get citations from ADS')
# ads.config.token = os.getenv("ADS_TOKEN")
# tot = len(np.concatenate([papers[k]['data'] for k in papers]))
# with tqdm(total=tot) as pbar:
# for k in papers:
# for p in papers[k]['data']:
# if p['ads']:
# #print("here", p['ads'])
# if testing:
# p['ads_citations'] = np.random.randint(0, 100)
# p['ads_found'] = p['ads']
# else:
# n_retries=0
# p['ads_citations'] = 0
# p['ads_found'] = ""
# while n_retries<10:
# try:
# q=list(ads.SearchQuery(bibcode=p['ads'], fl=['bibcode', 'citation_count']))[0]
# citation_count=q.citation_count
# if citation_count is not None:
# p['ads_citations'] = citation_count
# else:
# print("Warning: citation count is None.", p['ads'])
# p['ads_citations'] = 0
# p['ads_found'] = q.bibcode
# except:
# retry_time = 10 #req.getheaders()["retry-in"]
# print('ADS API error: retry in', retry_time, 's. -- '+p['ads'])
# time.sleep(retry_time)
# n_retries = n_retries + 1
# if n_retries==11:
# print('ADS API error: giving up -- '+p['ads'])
# continue
# else:
# break
# else:
# p['ads_citations'] = 0
# p['ads_found'] = ""
# pbar.update(1)
# return papers
def ads_citations(papers,testing=False):
print('Get citations from ADS')
#with open('/Users/dgerosa/reps/dotfiles/adstoken.txt') as f:
# #ads.config.token = f.read()
# token = f.read()
token = os.getenv("ADS_TOKEN")
if not token and not testing:
raise RuntimeError("ADS_TOKEN is missing. Set ADS_TOKEN in your environment (GitHub Actions secret) before running.")
tot = len(np.concatenate([papers[k]['data'] for k in papers]))
with tqdm(total=tot) as pbar:
for k in papers:
for p in papers[k]['data']:
if p['ads']:
if testing:
p['ads_citations'] = np.random.randint(0, 100)
p['ads_found'] = p['ads']
else:
n_retries=0
p['ads_citations'] = 0
p['ads_found'] = ""
while n_retries<10:
try:
#if True:
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="Unverified HTTPS request is being made to host")
r = requests.get(
"https://api.adsabs.harvard.edu/v1/search/query?q="+p['ads'].replace("&","%26")+"&fl=citation_count,bibcode",
headers={'Authorization': 'Bearer ' + token},
verify=False,
timeout=30,
)
q= r.json()['response']['docs']
#print(p['ads'], q)
if len(q)!=1:
raise ValueError("ADS error in "+str(p['ads']))
q=q[0]
if q['citation_count'] is not None:
p['ads_citations'] = q['citation_count']
else:
print("Warning: citation count is None.", p['ads'])
p['ads_citations'] = 0
p['ads_found'] = q['bibcode']
except:
retry_time = 10 #req.getheaders()["retry-in"]
print('ADS API error: retry in', retry_time, 's. -- '+p['ads'])
time.sleep(retry_time)
n_retries = n_retries + 1
if n_retries==11:
print('ADS API error: giving up -- '+p['ads'])
#raise ValueError("ADS error in "+p['ads'])
continue
else:
break
else:
p['ads_citations'] = 0
p['ads_found'] = ""
pbar.update(1)
return papers
def inspire_citations(papers,testing=False):
print('Get citations from INSPIRE')
tot = len(np.concatenate([papers[k]['data'] for k in papers]))
with tqdm(total=tot) as pbar:
for k in papers:
for p in papers[k]['data']:
if p['inspire']:
if testing:
p['inspire_citations'] = np.random.randint(0, 100)
else:
n_retries=0
while n_retries<10:
try:
req = urllib.request.urlopen("https://inspirehep.net/api/literature?q=texkey:"+p['inspire'],context=context)
except urllib.error.HTTPError as e:
if e.code == 429:
retry_time = 10 #req.getheaders()["retry-in"]
print('INSPIRE API error: retry in', retry_time, 's. -- '+p['inspire'])
time.sleep(retry_time)
n_retries = n_retries + 1
continue
else:
raise ValueError("INSPIRE error in "+p['inspire'])
else:
q = json.loads(req.read().decode("utf-8"))
n = len(q['hits']['hits'])
if n!=1:
raise ValueError("INSPIRE error in "+b)
p['inspire_citations']=q['hits']['hits'][0]['metadata']['citation_count']
break
else:
p['inspire_citations'] = 0
pbar.update(1)
return papers
#### CV latex ####
def parsepapers(papers,filename="parsepapers.tex"):
print('Parse papers from database')
out=[]
for k in ['submitted','published','proceedings']:
i = len(papers[k]['data'])
if i>=1:
out.append("\\textcolor{color1}{\\textbf{"+papers[k]['label']+":}}")
out.append("\\vspace{-0.5cm}")
out.append("")
out.append("\cvitem{}{\small\hspace{-1cm}\\begin{longtable}{rp{0.3cm}p{15.8cm}}")
out.append("%")
for p in papers[k]['data']:
#out.append("\\textbf{"+str(i)+".} & & \\textit{"+p['title'].replace("_","\\_").strip(".")+".}")
title = p['title'].replace("_", "\\_").rstrip(".")
if not title.endswith("?"):
title += "."
out.append(f"\\textbf{{{i}.}} & & \\textit{{{title}}}")
out.append("\\newline{}")
out.append(p['author'].replace("D. Gerosa","\\textbf{D. Gerosa}").strip(".")+".")
out.append("\\newline{}")
line=""
if p['link']:
line +="\href{"+p['link']+"}"
if p['journal']:
line+="{"+p['journal'].strip(".")+"}. "
if 'erratum' in p.keys():
if p['errlink']:
line +="\href{"+p['errlink']+"}"
if p['erratum']:
line+="{Erratum: "+p['erratum'].strip(".")+"}. "
if p['arxiv']:
line+="\href{https://arxiv.org/abs/"+p['arxiv'].split(":")[1].split(" ")[0].split(" ")[0]+"}{"+p['arxiv'].strip(".")+".}"
out.append(line)
if p['more']:
out.append("\\newline{}")
out.append("\\textcolor{color1}{$\\bullet$} "+p['more'].strip(".")+".")
out.append("\\vspace{0.09cm}\\\\")
out.append("%")
i=i-1
out.append("\end{longtable} }")
with open(filename,"w") as f: f.write("\n".join(out))
def metricspapers(papers,filename="metricspapers.tex"):
print('Compute papers metrics')
out=[]
out.append("\cvitem{}{\\begin{tabular}{rcl}")
out.append("\\textcolor{mark_color}{\\textbf{Publications}}: &\hspace{0.3cm} &")
out.append("\\textbf{"+str(len(papers['published']['data']))+"} papers published in major peer-reviewed journals,")
if len(papers['submitted']['data'])>1:
out.append("\\textbf{"+str(len(papers['submitted']['data']))+"} papers in submission stage,")
elif len(papers['submitted']['data'])==1:
out.append("\\textbf{"+str(len(papers['submitted']['data']))+"} paper in submission stage,")
out.append("\\\\ & &")
out.append("\\textbf{"+str(len(papers['proceedings']['data']))+"} other publications (white papers, proceedings, etc.)")
out.append("\\\\ & &")
first_author = []
for k in ['submitted','published','proceedings']:
for p in papers[k]['data']:
if "D. Gerosa" not in p['author']:
raise ValueError("Looks like you're not an author:", p['title'])
first_author.append( p['author'].split("D. Gerosa")[0]=="" )
out.append("(out of which \\textbf{"+str(np.sum(first_author))+"} first-authored papers and")
press_release = []
for k in ['submitted','published','proceedings']:
for p in papers[k]['data']:
press_release.append("press release" in p['more'])
out.append("\\textbf{"+str(np.sum(press_release))+"} papers covered by press releases).")
out.append("\end{tabular} }")
# including long-authorlist
ads_citations = np.concatenate([[p['ads_citations'] for p in papers[k]['data']] for k in papers])
inspire_citations = np.concatenate([[p['inspire_citations'] for p in papers[k]['data']] for k in papers])
max_citations_including = np.maximum(ads_citations,inspire_citations)
totalnumber_including = np.sum(max_citations_including)
hind_including = hindex(max_citations_including)
# excluding long-authorlist
ads_citations = np.concatenate([[p['ads_citations'] for p in papers[k]['data']] for k in ['submitted','published']])
inspire_citations = np.concatenate([[p['inspire_citations'] for p in papers[k]['data']] for k in ['submitted','published']])
max_citations_excluding = np.maximum(ads_citations,inspire_citations)
totalnumber_excluding = np.sum(max_citations_excluding)
hind_excluding = hindex(max_citations_excluding)
print("\tTotal number of citations:", totalnumber_including, totalnumber_excluding)
print("\th-index:", hind_including, hind_excluding)
out.append("Summary metrics reported using ADS and InSpire excluding [including] long-authorlist papers:")
out.append("\\\\")
out.append("\\textcolor{mark_color}{\\textbf{Total number of citations}}: >"+str(roundto100(totalnumber_excluding))+" [>"+str(roundto100(totalnumber_including))+"]")
out.append(" --- ")
out.append("\\textcolor{mark_color}{\\textbf{h-index}}: "+str(hind_excluding)+" ["+str(hind_including)+"].")
out.append("\\\\")
out.append("\\textcolor{mark_color}{\\textbf{Web links to list services}}:")
out.append("\href{https://davidegerosa.com/myads}{\\textsc{ADS}};")
out.append("\href{https://davidegerosa.com/myinspire}{\\textsc{InSpire}};")
out.append("\href{http://davidegerosa.com/myarxiv}{\\textsc{arXiv}};")
out.append("\href{https://davidegerosa.com/myorcid}{\\textsc{ORCID}}.")
with open(filename,"w") as f: f.write("\n".join(out))
def parsetalks(talks,filename="parsetalks.tex"):
print('Parse talks from database')
out=[]
out.append("Invited talks marked with *.")
out.append("\\vspace{0.2cm}")
out.append("")
for k in ['conferences','seminars','lectures','posters','outreach']:
out.append("\\textcolor{color1}{\\textbf{"+talks[k]['label']+":}}")
out.append("\\vspace{-0.5cm}")
out.append("")
out.append("\cvitem{}{\small\hspace{-1cm}\\begin{longtable}{rp{0.3cm}p{15.8cm}}")
out.append("%")
i = len(talks[k]['data'])
for p in talks[k]['data']:
if p["invited"]:
mark="*"
else:
mark=""
out.append("\\textbf{"+str(i)+".} & "+mark+" & \\textit{"+p['title'].strip(".")+".}")
out.append("\\newline{}")
out.append(p['what'].strip(".")+", "+p['where'].strip(".")+", "+p['when'].strip(".")+".")
if p['more']:
out.append("\\newline{}")
out.append("\\textcolor{color1}{$\\bullet$} "+p['more'].strip(".")+".")
out.append("\\vspace{0.05cm}\\\\")
out.append("%")
i=i-1
out.append("\end{longtable} }")
with open(filename,"w") as f: f.write("\n".join(out))
def metricstalks(talks,filename="metricstalks.tex"):
print('Compute talks metrics')
out=[]
out.append("\cvitem{}{\\begin{tabular}{rcl}")
out.append("\\textcolor{mark_color}{\\textbf{Presentations}}: &\hspace{0.3cm} &")
out.append("\\textbf{"+str(len(talks['conferences']['data']))+"} talks at conferences,")
out.append("\\textbf{"+str(len(talks['seminars']['data']))+"} talks at department seminars,")
out.append("\\textbf{"+str(len(talks['posters']['data']))+"} posters at conferences,")
out.append("\\\\ & &")
invited = []
for k in ['conferences','seminars','posters']:
for p in talks[k]['data']:
invited.append(p['invited'])
plural = "s" if len(talks['lectures']['data'])>1 else ""
out.append("(out of which \\textbf{"+str(np.sum(invited))+"} invited presentations),")
out.append("\\textbf{"+str(len(talks['lectures']['data']))+"} lecture"+plural+" at PhD schools,")
out.append("\\textbf{"+str(len(talks['outreach']['data']))+"} outreach talks.")
out.append("\end{tabular} }")
with open(filename,"w") as f: f.write("\n".join(out))
def parsegroup(group,filename="parsegroup.tex"):
print('Parse group from database')
out=[]
out.append("Current group members marked with *.")
def current(x):
if x['current']:
return "*"
else:
return ""
def name(x):
return "\\textit{"+x['name'].replace(" ","~")+"}"
for k in ['fellowships','postdocs','phd','msc','bsc']:
out.append("")
out.append("\\vspace{0.2cm}")
out.append("\\textbf{"+group[k]['labellong']+":}")
out.append("")
if k=="fellowships":
for x in group[k]['data']:
out.append("\\cvitemwithcomment{}{\hspace{0.4cm}$\circ\;$ "+name(x)+" ("+x['where']+", "+x['fellowship']+")."+current(x)+"}{"+x['start']+"-"+x['end']+"}")
out.append("\\vspace{-0.1cm}")
elif k in ["postdocs","phd"]:
for x in group[k]['data']:
out.append("\\cvitemwithcomment{}{\hspace{0.4cm}$\circ\;$ "+name(x)+" ("+x['where']+")."+current(x)+"}{"+x['start']+"-"+x['end']+"}")
out.append("\\vspace{-0.1cm}")
elif k in ["msc","bsc"]:
for x in group[k]['data']:
out.append(
"\\cvitemwithcomment{}{\\hspace{0.4cm}$\\circ\\;$ "
+ name(x)
+ " ("
+ x['where']
+ ", "
+ x['what']
+ ")."
+ current(x)
+ "}{"
+ str(x['year'])
+ "}"
)
out.append("\\vspace{-0.1cm}")
with open(filename,"w") as f: f.write("\n".join(out))
def metricsgroup(group, filename="metricsgroup.tex"):
print('Compute group metrics')
def n_current(k):
return sum(1 for x in group[k]['data'] if x['current'])
fellowships_total = len(group['fellowships']['data'])
fellowships_current = n_current('fellowships')
postdocs_total = len(group['postdocs']['data'])
postdocs_current = n_current('postdocs')
phd_total = len(group['phd']['data'])
phd_current = n_current('phd')
msc_total = len(group['msc']['data'])
msc_current = n_current('msc')
bsc_total = len(group['bsc']['data'])
bsc_current = n_current('bsc')
out = []
def bullet(line):
out.append("\\cvitemwithcomment{}{\\hspace{0.4cm}$\\circ\\;$ " + line + "}{}")
out.append("\\vspace{-0.1cm}")
bullet(
"Host of \\textbf{"
+ str(fellowships_total)
+ " postdoctoral fellows} supported by external fellowships ("
+ str(fellowships_current)
+ " currently in my group)."
)
bullet(
"Employer of \\textbf{"
+ str(postdocs_total)
+ " postdoctoral researchers} hired on grants ("
+ str(postdocs_current)
+ " currently in my group)."
)
bullet(
"Supervisor of \\textbf{"
+ str(phd_total)
+ " PhD students} ("
+ str(phd_current)
+ " currently in my group)."
)
bullet(
"Supervisor of \\textbf{"
+ str(msc_total)
+ " MSc thesis projects} ("
+ str(msc_current)
+ " currently in my group)."
)
bullet(
"Supervisor of \\textbf{"
+ str(bsc_total)
+ " BSc thesis projects} ("
+ str(bsc_current)
+ " currently in my group)."
)
with open(filename, "w") as f:
f.write("\n".join(out))
def CVshort(filename='CVshort.tex'):
with open('CV.tex', 'r') as f:
CV = f.read()
CVshort = "%".join(CV.split("%mark_CVshort")[::2])
with open(filename, 'w') as f:
f.write(CVshort)
def buildbib(filename='publist.bib'):
print("Build bib file from ADS")
token = os.getenv("ADS_TOKEN")
if not token:
raise RuntimeError("ADS_TOKEN is missing. Set ADS_TOKEN in your environment before building the bibliography.")
with open(filename, 'r') as f:
publist = f.read()
stored = []
for p in publist.split('@'):
if "BibDesk" not in p:
stored.append(p.split("{")[1].split(",")[0])
tot = len(np.concatenate([papers[k]['data'] for k in papers]))
with tqdm(total=tot) as pbar:
for k in papers:
for p in papers[k]['data']:
if p['ads_found'] and p['ads_found'] not in stored:
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="Unverified HTTPS request is being made to host")
r = requests.get(
"https://api.adsabs.harvard.edu/v1/export/bibtex/"
+ urllib.parse.quote(p['ads_found'], safe=""),
headers={'Authorization': 'Bearer ' + token},
verify=False,
timeout=30,
)
r.raise_for_status()
bib = r.text.strip()
if not bib:
raise ValueError("ADS returned an empty BibTeX export for "+p['ads_found'])
# q=list(ads.SearchQuery(bibcode=p['ads_found'], fl=['bibtex']))[0]
# bib = q.bibtex
# if "journal =" in bib:
# j = bib.split("journal =")[1].split("}")[0].split("{")[1]
# bib = bib.replace(j,convertjournal(j)[0])
with open(filename, 'a') as f:
f.write(bib)
pbar.update(1)
#### Website markdown ####
def markdownpapers(papers,filename="_publications.md"):
print('Markdown paper list for website')
out=[]
papertype= ['submitted','published','proceedings']
out.append("## Summary")
for k in papertype:
i = len(papers[k]['data'])
out.append("**"+str(i)+"** ["+papers[k]['label']+"](#"+slugify(papers[k]['label'])+")")
if k!=papertype[-1]:
out[-1]+=("\\")
else:
out.append("")
out.append("")
out.append("---")
out.append("")
for k in papertype:
i = len(papers[k]['data'])
if i>=1:
out.append("## "+papers[k]['label'])
out.append("")
for p in papers[k]['data']:
name = p['author'].replace("D. Gerosa","**D. Gerosa**").strip(".")
name = name.replace("\\`o", "o'")
name = name.replace("\\v{s}", "s")
out.append("**"+str(i)+".**")
#out.append("*"+p['title'].strip(".").replace("$", "$$")+"*.\\")
title = p['title'].rstrip(".").replace("$", "$$")
if not title.endswith("?"):
title += "."
out.append("*" + title + "*\\")
out.append(name+".\\")
line=""
# if p['link']:
# line+='['
# if p['journal']:
# line+=p['journal'].strip(".")
# if p['link']:
# line+="]("+p['link']+")"
# if p['journal']:
# line+=". "
# if 'erratum' in p.keys():
# line+=" Erratum: "
# if p['errlink']:
# line+='['
# if p['erratum']:
# line+=p['erratum'].strip(".")
# if p['errlink']:
# line+="]("+p['errlink']+")"
# line+='. '
if p['link']:
line += '<a href="' + p['link'] + '" style="color: inherit; text-decoration: none;">'
if p['journal']:
line += p['journal'].strip(".")
if p['link']:
line += '</a>'
if p['journal']:
line += '. '
if 'erratum' in p:
line += ' Erratum: '
if p['errlink']:
line += '<a href="' + p['errlink'] + '" style="color: inherit; text-decoration: none;">'
if p['erratum']:
line += p['erratum'].strip(".")
if p['errlink']:
line += '</a>'
line += '. '
if p['arxiv']:
line += '<a href="https://arxiv.org/abs/' + p['arxiv'].split(":")[1].split()[0] + '" style="color: inherit; text-decoration: none;">' + p['arxiv'].strip(".") + '</a>.'
#line+="["+p['arxiv'].strip(".")+"](https://arxiv.org/abs/"+p['arxiv'].split(":")[1].split(" ")[0].split(" ")[0]+")."
out.append(line)
if p['more']:
out[-1]+="\\"
out.append(p['more'].strip(".")+".")
i=i-1
out.append(" ")
#break
#continue
out.append("")
out.append("---")
out.append("")
out = apply_journal_conversion(out)
lastupdated(out)
with open(filename,"w") as f: f.write("\n".join(out))
def markdowntalks(talks, filename="_talks.md"):
print('Markdown talk list for website')
out = []
out.append("Invited talks marked with ✦.")
out.append("")
out.append("## Summary")
categories = ['conferences', 'seminars', 'lectures', 'posters', 'outreach']
for k in categories:
total = len(talks[k]['data'])
invited = sum(1 for p in talks[k]['data'] if p.get("invited", False))
label = "["+talks[k]['label']+"](#"+slugify(talks[k]['label'])+")"
# Format like: 78 (34✦) Conferences
summary_line = f"**{total}**"
if invited > 0:
summary_line += f" (**{invited}**✦)"
summary_line += f" {label}"
# Add continuation backslash except last category
if k != categories[-1]:
summary_line += " \\"
out.append(summary_line)
out.append("")
out.append("---")
out.append("")
for k in categories:
i = len(talks[k]['data'])
if i >= 1:
out.append(f"## {talks[k]['label']}")
out.append("")
for p in talks[k]['data']:
mark = "✦ " if p.get("invited", False) else ""
out.append(f"**{i}.** {mark}*{p['title'].strip('.')}* \\\\")
out.append(f"{p['what'].strip('.')}, {p['where'].strip('.')}, {p['when'].strip('.')}.")
#handle cases where recodring key is missing
if 'recording' not in p:
p['recording'] = ""
if p['recording'] or p['more']:
out[-1] += " \\\\"
if p['recording']:
out.append(f' [Recording]({p["recording"]}).')
if p['more']:
more = re.sub(r'\\textbf{(.*?)}', r'\1', p['more'].strip("."))
out.append(more + ".")
out.append("")
i -= 1
out.append("")
out.append("---")
out.append("")
lastupdated(out)
with open(filename, "w") as f:
f.write("\n".join(out))
def markdowngroup(group, filename="_group.md"):
print('Markdown group list for website')
out = []
# Intro
out.append("Here are the amazing people in my group. Come visit and chat science with us! If you're interested in joining, please check out the [jobs](/jobs) page.")
out.append("")
#out.append("<br>")
#out.append("")
out.append("## Current group members")
# CURRENT MEMBERS
merged_current = []
for x in group['fellowships']['data']:
if x.get("current", False) and x.get("bio"):
merged_current.append({
"name": x["name"].replace("~", " "),
"role": x["fellowship"],
"email": x.get("email", ""),
"bio": x.get("bio", ""),
"order": 0
})
for x in group['postdocs']['data']:
if x.get("current", False) and x.get("bio"):
merged_current.append({
"name": x["name"].replace("~", " "),
"role": "Postdoc",
"email": x.get("email", ""),
"bio": x.get("bio", ""),
"order": 0
})
for x in group['phd']['data']:
if x.get("current", False):
merged_current.append({
"name": x["name"].replace("~", " "),
"role": "PhD student",
"email": x.get("email", ""),
"bio": x.get("bio", ""),
"order": 1
})
merged_current = sorted(merged_current, key=lambda x: x["order"])
#merged_current.insert(len(merged_current), {
merged_current.insert(0, {
"name": "Davide Gerosa",
"role": "Associate professor",
"email": "davide.gerosa@unimib.it",
"bio": "That's me, running, gravity, football, rock music, some more gravity. Astrophysics when I want to remember things are real, mountains when I want to see things are beautiful."
})
# for x in merged_current:
# out.append(f"**{x['name']}** ")
# out.append(f"*{x['role']}*; ")
# if x['email']:
# out[-1] += f"[{x['email']}](mailto:{x['email']}) "
# if x['bio']:
# out.append(f"{x['bio']}")
# out.append("")
out.append("<div class=\"people-list\">")
for x in merged_current:
out.append(f"<div class=\"person\">")
out.append(f" <img src=\"{{{{ '/images/{slugify(x['name'])}.jpg' | relative_url }}}}\" alt=\"{x['name']}\" class=\"person-photo\">")
out.append(f" <div class=\"person-text\">")
out.append(f" <strong>{x['name']}</strong><br>")
out.append(f" {x['role']}<br>")
if x['email']:
#out[-1] += f"[{x['email']}](mailto:{x['email']}) "
#Link in html format
out.append(f"<a href=\"mailto:{x['email']}\">{x['email']}</a><br>")
if x['bio']:
out.append(f" <em>{x['bio']}</em>")
out.append(f" </div>")
out.append(f"</div>")
out.append("</div>")
# MSc and BSc current
msc_current = [x for x in group['msc']['data'] if x.get("current", False)]
bsc_current = [x for x in group['bsc']['data'] if x.get("current", False)]
if msc_current or bsc_current:
out.append("## Current MSc and Bsc students")
out.append("Here are the amazing students who are currently completing research projects with us in the group… Taking the first fun steps into the perilous world of black holes!")
out.append("")
for x in msc_current:
out.append(f"- **{x['name'].replace('~', ' ')}**, MSc thesis, {x['where']}, {x['year']}.")
for x in bsc_current:
out.append(f"- **{x['name'].replace('~', ' ')}**, BSc thesis, {x['where']}, {x['year']}.")
out.append("")
out.append("<br>")
out.append("")
out.append("---")
#out.append("<br>")
out.append("")
# FORMER MEMBERS
out.append("# Former group members")
out.append("")
out.append("...and here are those who passed through our group at some stage. Thank you all!")
out.append("")
def former_section(title, entries):
if entries:
out.append(f"## {title}")
out.append("")
for x in entries:
line = f"- **{x['name']}**. {x['where']}, {x['years']}."
then_fmt = format_then(x.get("note", ""))
if then_fmt:
line += f" {then_fmt}"
out.append(line)
out.append("")
def format_then(then_str):
if not then_str:
return ""
then_str = re.sub(
r'arXiv:(\d{4}\.\d{5})',
r'[arXiv:\1](https://arxiv.org/abs/\1)',
then_str.strip()
)
if then_str and not then_str.endswith('.'):
then_str += '.'
return then_str
def exclude_from_markdown(entry):
return entry.get("bio", "") is None
def extract_former_longterm(data):
entries = []
for x in data:
if not x.get("current", False) and not exclude_from_markdown(x):
start = str(x.get("start", ""))
end = str(x.get("end", ""))
years = f"{start}–{end}" if start and end else start or end
entries.append({
"name": x["name"].replace("~", " "),
"where": x["where"],
"years": years,
"note": x.get("note", ""),
"start": start,
"end": end
})
return entries
def parse_year(value):
if not value:
return -1
m = re.search(r"\d{4}", str(value))
return int(m.group(0)) if m else -1
def extract_former_shortterm(data):
entries = []
for x in data:
if not x.get("current", False) and not exclude_from_markdown(x):
entries.append({
"name": x["name"].replace("~", " "),
"where": x["where"],
"years": str(x["year"]),
"note": x.get("note", "")
})
return entries
former_fellowships = extract_former_longterm(group['fellowships']['data'])
former_postdocs = extract_former_longterm(group['postdocs']['data'])
former_phds = extract_former_longterm(group['phd']['data'])
former_mscs = extract_former_shortterm(group['msc']['data'])
former_bscs = extract_former_shortterm(group['bsc']['data'])
former_postdocs_all = former_fellowships + former_postdocs
former_postdocs_all = sorted(
former_postdocs_all,
key=lambda x: (
-parse_year(x.get("end", "")),
-parse_year(x.get("start", "")),
x["name"].lower()
)
)
former_section("Former postdocs", former_postdocs_all)
former_section("Former PhD students", former_phds)
former_section("Former MSc students", former_mscs)
former_section("Former BSc students", former_bscs)
out.append("<br>")