-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv2tex.py
59 lines (46 loc) · 1.85 KB
/
csv2tex.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
#!/usr/bin/env python
# -*- coding: utf8 -*-
# My imports
from __future__ import division
import pandas as pd
import argparse
def paramError(s1, s2):
"""Add together s1 and s2 with the right delimiter \pm and surroundings $$
Inputs
------
s1 : pandas Series
A pandas Series with main parameter, e.g. Teff
s2 : pandas Series
A pandas Series with error, e.g. Tefferr
Output
------
sout : pandas Series
A new series with format like this: $5777 \\pm 42$
"""
sout = '$' + s1.astype('str') + ' \pm ' + s2.astype('str') + '$'
return sout
def _parser():
parser = argparse.ArgumentParser(description='Convert the result file to a TeX table')
parser.add_argument('-i', help='Input file', default='results.csv')
parser.add_argument('-o', help='Output TeX table', default=None)
parser.add_argument('-d', help='Delimiter for input csv file', default=r'\s+')
return parser.parse_args()
if __name__ == '__main__':
args = _parser()
df = pd.read_csv(args.i, delimiter=args.d, comment='#')
if args.o is None:
output = args.i.rpartition('.')[0] + '.tex'
else:
output = args.o
junk = ['fixteff', 'fixlogg', 'fixfeh', 'fixvt', 'outlier', 'weights',
'model', 'refine', 'EPcrit', 'RWcrit', 'ABdiffcrit']
df.drop(junk, inplace=True, axis=1)
df['teff'] = paramError(df['teff'], df['tefferr'])
df['logg'] = paramError(df['logg'], df['loggerr'])
df['feh'] = paramError(df['feh'], df['feherr'])
df['vt'] = paramError(df['vt'], df['vterr'])
df['loggastero'] = paramError(df['loggastero'], df['dloggastero'])
df['loggLC'] = paramError(df['loggLC'], df['dloggLC'])
junk = ['tefferr', 'loggerr', 'feherr', 'vterr', 'dloggastero', 'dloggLC', 'convergence']
df.drop(junk, inplace=True, axis=1)
df.to_latex(buf=output, index=False, escape=False)