-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpt2tex2.py
executable file
·92 lines (75 loc) · 3.52 KB
/
rpt2tex2.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
#!/usr/bin/env python
# coding: utf-8
# author:[email protected] date: 04/07/2020
# Copyright (C) <2020> <Martin Mohan>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import argparse
import csv2tex
import argparse
import csv2tex
class rpt2tex2():
def __init__(self):
pass
def roctex2(self,froc,fcm,fcsv,caption,cref,crefonly):
csvfile=csv2tex.csv2tex(fcsv)
rpttab=csvfile.generatetab()
if crefonly:
label=cref.replace(".pdf","")
ftex=cref.replace(".pdf",".tex")
output="\n\\begin{figure}[H]\n\
\\centering\n\
\\includegraphics[width=1\\textwidth,height=.4\\textheight]{%s}\n\
\\caption{%sPlanets predicted as CONFIRMED}\n\
\\label{fig:%s}\n\
\\end{figure}" %(cref,caption,label)
else:
label=fcsv.replace(".csv","")
ftex=fcsv.replace(".csv",".tex")
output="\n\\begin{figure}[H]\n\
\\centering\n\
\\begin{subfigure}{.49\\textwidth}\n\
\\includegraphics[width = 1\\textwidth]{%s}\n\
\\end{subfigure}\n\
\\begin{subfigure}{.49\\textwidth}\n\
\\includegraphics[width = 1\\textwidth]{%s}\n\
\\end{subfigure}\n\
\\begin{subfigure}{1\\textwidth}\n\
\\csname %s\\endcsname\n\
\\end{subfigure}\n\
\\caption{%sConfusion Matrix, ROC Curve and Results}\n\
\\label{fig:%s}\n\
\\end{figure}" %(froc,fcm,rpttab,caption,label)
with open(ftex,'w') as f: f.write(output)
# print(f"Created file {ftex}")
return output
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Read rpt files generated by Treat4.py and create latex tex file including _roc.pdf, _cm.pdf, _rpt.csv (normlly called from Treat4.py)',formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument( "--froc", type=str, default="data/TK_GB_roc.pdf",
help="roc pdf (default: %(default)s)")
parser.add_argument( "--fcm", type=str, default="data/TK_GB_cm.pdf",
help="cm pdf (default: %(default)s)")
parser.add_argument( "--fcsv", type=str, default="data/TK_GB_rpt.csv",
help="csv file (default: %(default)s)")
parser.add_argument( "--cref", type=str, default="data/TKtest_GB_cref_CONFIRMED.pdf",
help="Add cref file - set to '' to ignore (default: %(default)s)")
parser.add_argument("--crefonly", action="store_true",
help="Only ouput cref")
parser.add_argument( "--caption", type=str, default="",
help="caption (default: %(default)s)")
argv=parser.parse_args()
myrpt=rpt2tex2()
output=myrpt.roctex2(argv.froc,argv.fcm,argv.fcsv,argv.caption,argv.cref,argv.crefonly)
print(output)