-
Notifications
You must be signed in to change notification settings - Fork 0
/
15_TABLE2_csv_to_latex.py
60 lines (44 loc) · 1.88 KB
/
15_TABLE2_csv_to_latex.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
"""
Python 3.8 -- UTF-8
Ekaterina Ilin
MIT License (2022)
This script converts fit_parameters.csv to fit_parameters.tex
PRODUCES THE TEX FILE FOR TABLE 2 IN THE PAPER.
"""
import pandas as pd
if __name__ == "__main__":
# read in fit results table
df = pd.read_csv('results/fit_parameters.csv')
# give errors optionally
with_errors = True
# remodel table
df = df.drop(0,axis=0).rename(index=str,columns={"Unnamed: 0":" "})
df = df.set_index(" ").T.astype("float")
# make texable strings
if with_errors:
df[r"$a_1$"]=df.apply(lambda x: fr"${x['a']:.0f} \pm {x['ar']:.0f}$",axis=1)
df[r"$a_2$"]=df.apply(lambda x: fr"${x['b']:.0f} \pm {x['br']:.0f}$",axis=1)
df[r"$b_1$"]=df.apply(lambda x: fr"${x['c']:.0f} \pm {x['cr']:.0f}$",axis=1)
df[r"$b_2$"]=df.apply(lambda x: fr"${x['d']:.0f} \pm {x['dr']:.0f}$",axis=1)
df[r"$c$"]=df.apply(lambda x: fr"${x['e']:.0f} \pm {x['er']:.0f}$",axis=1)
else:
df[r"$a_1$"]=df.apply(lambda x: fr"${x['a']:.0f}$",axis=1)
df[r"$a_2$"]=df.apply(lambda x: fr"${x['b']:.0f}$",axis=1)
df[r"$b_1$"]=df.apply(lambda x: fr"${x['c']:.0f}$",axis=1)
df[r"$b_2$"]=df.apply(lambda x: fr"${x['d']:.0f}$",axis=1)
df[r"$c$"]=df.apply(lambda x: fr"${x['e']:.0f}$",axis=1)
# rename the columns
string = df[[r"$a_1$",r"$a_2$",r"$b_1$",r"$b_2$",r"$c$"]]
# make TeX table
string = string.T.reset_index().to_latex(escape=False,index=False)
# layout
string = string.replace(" spots"," FR")
string = string.replace("llllll","lccccc")
string = string.replace("midrule","hline")
string = string.replace("toprule","hline")
string = string.replace("bottomrule","hline")
# write to file
path = "results/fit_parameters.tex"
print("Write LaTeX table to file: ", path)
with open(path,"w") as f:
f.write(string)