Skip to content

Commit 9b2414c

Browse files
committed
add matplotlib fallback plotting
1 parent 0b5e37a commit 9b2414c

File tree

13 files changed

+806
-290
lines changed

13 files changed

+806
-290
lines changed

bin/ipynb_to_report

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@ output_filename="$(echo ${report_nb} | sed 's/ /_/g' | sed 's/.ipynb$//').tex"
88

99
export TEXINPUTS="${template_dir}//:"
1010

11+
export PYPOP_HEADLESS="TRUE"
12+
1113
jupyter nbconvert "${report_nb}" \
1214
--execute \
1315
--to latex \
14-
--template=${template_dir}/pop_report.tplx \
16+
--template latex \
17+
--template-file ${template_dir}/pop_report.tplx \
1518
--output=${output_filename}
1619

17-
texi2pdf ${output_filename}
20+
if [ $? -ne 0 ]; then
21+
echo Error: nbconvert failed - see documentation or PyPOP github for assistance.
22+
exit -1
23+
fi
24+
25+
texi2pdf ${output_filename} &>/dev/null
26+
27+
if [ $? -ne 0 ]; then
28+
echo Error: latex compilation failed. See ${output_filename/.tex/.log} for details
29+
exit -1
30+
fi
31+
32+
echo ${output_filename/.tex/.pdf} written successfully.

ipython_templates/pop_report.tplx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
((*- extends 'article.tplx' -*))
1+
((*- extends 'report.tex.j2' -*))
22

33
## Set pop_report class
44
((* block docclass *))
@@ -54,6 +54,12 @@
5454
cell.metadata.get("label", "")) )))
5555
((* endblock data_svg *))
5656

57+
((*- block data_html *))
58+
((* endblock data_html *))
59+
60+
((*- block data_text *))
61+
((* endblock data_text *))
62+
5763

5864
## macro to encapsulate output files in figures
5965
((* macro draw_figure_with_caption(filename, caption, label) -*))

pypop/backends/__init__.py

Whitespace-only changes.

pypop/backends/extrae/__init__.py

Whitespace-only changes.

pypop/backends/extrae/pcf.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright (c) 2019, The Numerical Algorithms Group, Ltd. All rights reserved.
2+
3+
"""\
4+
PCF File Parser
5+
---------------
6+
7+
Provides lightweight support for interrogating the contents of a PRV file, including all
8+
event types and id->string lookups for value types.
9+
"""
10+
11+
from collections import namedtuple
12+
13+
import pandas
14+
15+
Event = namedtuple("Event", ["ID", "Name", "State", "Values"])
16+
Value = namedtuple("Value", ["ID", "Name"])
17+
State = namedtuple("State", ["ID", "Name"])
18+
19+
class PCF:
20+
21+
def __init__(self, pcf_path):
22+
23+
self._pcf_path = pcf_path
24+
25+
self._state_names = {}
26+
self._event_names = {}
27+
self._event_states = {}
28+
self._event_vals = {}
29+
30+
self._states = None
31+
self._events = None
32+
self._parse_pcf()
33+
34+
@property
35+
def filename(self):
36+
return self._pcf_path
37+
38+
@property
39+
def event_names(self):
40+
return self._event_names
41+
42+
@property
43+
def event_values(self):
44+
return self._event_vals
45+
46+
@property
47+
def events(self):
48+
return self._events
49+
50+
51+
def _parse_pcf(self):
52+
53+
states = []
54+
events = []
55+
values = []
56+
57+
try:
58+
with open(self._pcf_path, "rt") as fh:
59+
block_mode = None
60+
for line in fh:
61+
if not line.strip():
62+
continue
63+
if not line[0].isdigit():
64+
block_mode = line.split()[0]
65+
continue
66+
67+
if block_mode == "EVENT_TYPE":
68+
elem = line.strip().split(maxsplit=2)
69+
event_id = int(elem[1])
70+
events.append(Event(event_id, elem[2], elem[0], {}))
71+
values[event_id] = []
72+
continue
73+
74+
if block_mode == "VALUES":
75+
elem = line.strip().split(maxsplit=1)
76+
value_id = int(elem[0])
77+
values[event_id].append(Value(value_id, elem[1]))
78+
79+
if block_mode == "STATES":
80+
elem = line.strip().split(maxsplit=1)
81+
state_id = int(elem[0])
82+
states.append(State(state_id, elem[1]))
83+
84+
except FileNotFoundError:
85+
pass
86+
87+
self._events = pandas.DataFrame(events)
88+
self._states = pandas.DataFrame(states)
89+
self._event_values = {k:pandas.DataFrame(v) for k,v in values.items}
90+
91+
File renamed without changes.

0 commit comments

Comments
 (0)