forked from ControlCore-Project/concore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotym.py
More file actions
55 lines (44 loc) · 1.26 KB
/
Copy pathplotym.py
File metadata and controls
55 lines (44 loc) · 1.26 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
import concore
import logging
import numpy as np
import matplotlib.pyplot as plt
import time
logging.info("plot ym")
concore.delay = 0.005
concore.default_maxtime(150)
init_simtime_u = "[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]"
init_simtime_ym = "[0.0, 0.0, 0.0]"
ut = []
ymt = []
plt.ion() # Enable interactive mode
fig, (ax1, ax2) = plt.subplots(2, 1)
line1, = ax1.plot([], [])
ax1.set_ylabel('MAP (mmHg)')
ax1.legend(['MAP'], loc=0)
line2, = ax2.plot([], [])
ax2.set_xlabel('Cycles '+str(concore.params))
ax2.set_ylabel('HR (bpm)')
ax2.legend(['HR'], loc=0)
ym = concore.initval(init_simtime_ym)
while(concore.simtime<concore.maxtime):
while concore.unchanged():
ym = concore.read(1,"ym",init_simtime_ym)
concore.write(1,"ym",ym)
logging.debug(f" ym={ym}")
ymt.append(np.array(ym).T)
#real-time update
Nsim = len(ymt)
xdata = range(Nsim)
# Extract columns and update lines directly
line1.set_data(xdata, [x[0].item() for x in ymt])
line2.set_data(xdata, [x[1].item() for x in ymt])
for ax in (ax1, ax2):
ax.relim()
ax.autoscale_view()
plt.pause(0.001) # Render update
logging.info(f"retry={concore.retrycount}")
#################
# Final Save & cleanup
plt.ioff()
plt.savefig("hrmap.pdf")
plt.show()