Skip to content

Commit e1cebd9

Browse files
committed
add loggings to tools
1 parent 0c1ed0d commit e1cebd9

13 files changed

Lines changed: 87 additions & 60 deletions

File tree

concore.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77
import zmq
88
import numpy as np
99
logging.basicConfig(
10-
level=logging.INFO,
11-
format='%(levelname)s - %(message)s'
12-
) # Added for ZeroMQ
10+
level=logging.DEBUG,
11+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
12+
force=True
13+
)
14+
15+
#these lines mute the noisy library
16+
logging.getLogger('matplotlib').setLevel(logging.WARNING)
17+
logging.getLogger('PIL').setLevel(logging.WARNING)
18+
logging.getLogger('urllib3').setLevel(logging.WARNING)
19+
logging.getLogger('requests').setLevel(logging.WARNING)
20+
1321

1422
# if windows, create script to kill this process
1523
# because batch files don't provide easy way to know pid of last command

tools/bangbang.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22
import concore
3+
import logging
34

45

56
def bangbang_controller(ym):
@@ -19,12 +20,15 @@ def bangbang_controller(ym):
1920
init_simtime_u = "[0.0, 0.0,0.0]"
2021
init_simtime_ym = "[0.0, 70.0,91]"
2122
u = np.array([concore.initval(init_simtime_u)]).T
23+
24+
logging.info("Starting Bang-Bang Controller")
25+
2226
while(concore.simtime<concore.maxtime):
2327
while concore.unchanged():
2428
ym = concore.read(1,"ym",init_simtime_ym)
2529
ym = np.array(ym)
2630

2731
ustar = bangbang_controller(ym)
2832

29-
print(str(concore.simtime) + " u="+str(ustar) + "ym="+str(ym))
33+
logging.debug(f"{concore.simtime} u={ustar} ym={ym}")
3034
concore.write(1,"u",list(ustar),delta=0)

tools/cardiac_pm.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pulsatile_model_functions as pmf
33
import healthy_params as K
44
import concore
5+
import logging
56

67
#x0 = np.loadtxt('pulsatile_steady.txt')
78

@@ -20,6 +21,9 @@ def cardiac_pm(x0,u):
2021
init_simtime_u = "[0.0, 0.0,0.0]"
2122
init_simtime_ym = "[0.0, 70,0]"
2223
ym = np.array([concore.initval(init_simtime_ym)]).T
24+
25+
logging.info("Starting Cardiac PM Model")
26+
2327
while(concore.simtime<concore.maxtime):
2428
while concore.unchanged():
2529
u = concore.read(1,"u",init_simtime_u)
@@ -29,7 +33,7 @@ def cardiac_pm(x0,u):
2933

3034
#dummy = np.array([hr,mapp])
3135
dummy = np.array([mapp,hr])
32-
print(str(concore.simtime) + " u="+str(u) + "ym=" + str(dummy))
36+
logging.debug(f"{concore.simtime} u={u} ym={dummy}")
3337
#concore.write(1,"ym",list(np.array([hr,mapp])),delta=1)
3438
concore.write(1,"ym",list(np.array([mapp,hr])),delta=1)
3539

tools/cwrap.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55
from ast import literal_eval
66
import os
7+
import logging
78

89
#time.sleep(7)
910
timeout_max = 20
@@ -58,10 +59,10 @@
5859
except:
5960
init_simtime_ym = "[0.0, 0.0, 0.0]"
6061

61-
print(apikey)
62-
print(yuyu)
63-
print(name1+'='+init_simtime_u)
64-
print(name2+'='+init_simtime_ym)
62+
logging.info(f"API Key: {apikey}")
63+
logging.info(f"Yuyu: {yuyu}")
64+
logging.info(f"{name1}={init_simtime_u}")
65+
logging.info(f"{name2}={init_simtime_ym}")
6566

6667
while not os.path.exists(concore.inpath+'1/'+name1):
6768
time.sleep(concore.delay)
@@ -78,47 +79,45 @@
7879

7980

8081
while(concore.simtime<concore.maxtime):
81-
print("CW outer loop")
82+
logging.debug("CW outer loop")
8283
while concore.unchanged():
8384
u = concore.read(1,name1,init_simtime_u)
8485
f = {'file1': open(concore.inpath+'1/'+name1, 'rb')}
85-
print("CW: before post u="+str(u))
86-
print('http://www.controlcore.org/pm/'+yuyu+apikey+'&fetch='+name2)
86+
logging.debug(f"CW: before post u={u}")
87+
logging.debug(f'http://www.controlcore.org/pm/{yuyu}{apikey}&fetch={name2}')
8788
r = requests.post('http://www.controlcore.org/pm/'+yuyu+apikey+'&fetch='+name2, files=f,timeout=timeout_max)
8889
if r.status_code!=200:
89-
print("bad POST request "+str(r.status_code))
90+
logging.error(f"bad POST request {r.status_code}")
9091
quit()
9192
if len(r.text)!=0:
9293
try:
9394
t=literal_eval(r.text)[0]
9495
except:
95-
print("bad eval "+r.text)
96+
logging.error(f"bad eval {r.text}")
9697
timeout_count = 0
9798
t1 = time.perf_counter()
98-
print("CW: after post status="+str(r.status_code)+" r.content="+str(r.content)+" t="+str(t))
99+
logging.debug(f"CW: after post status={r.status_code} r.content={r.content} t={t}")
99100
#while r.text==oldym or len(r.content)==0:
100101
while oldt==t or len(r.content)==0:
101102
time.sleep(concore.delay)
102-
print("CW waiting status="+str(r.status_code)+" content="+ r.content.decode('utf-8')+" t="+str(t))
103+
logging.debug(f"CW waiting status={r.status_code} content={r.content.decode('utf-8')} t={t}")
103104
f = {'file1': open(concore.inpath+'1/'+name1, 'rb')}
104105
try:
105106
r = requests.post('http://www.controlcore.org/pm/'+yuyu+apikey+'&fetch='+name2, files=f,timeout=timeout_max)
106107
except:
107-
print("CW: bad request")
108+
logging.error("CW: bad request")
108109
timeout_count += 1
109110
if r.status_code!=200 or time.perf_counter()-t1 > 1.1*timeout_max: #timeout_count>100:
110-
print("timeout or bad POST request "+str(r.status_code))
111+
logging.error(f"timeout or bad POST request {r.status_code}")
111112
quit()
112113
if len(r.text)!=0:
113114
try:
114115
t=literal_eval(r.text)[0]
115116
except:
116-
print("bad eval "+r.text)
117+
logging.error(f"bad eval {r.text}")
117118
oldt = t
118119
oldym = r.text
119-
print("CW: oldym="+oldym+" t="+str(concore.simtime))
120+
logging.debug(f"CW: oldym={oldym} t={concore.simtime}")
120121
concore.write(1,name2,oldym)
121122
#concore.write(1,"ym",init_simtime_ym)
122-
print("retry="+str(concore.retrycount))
123-
124-
123+
logging.info(f"retry={concore.retrycount}")

tools/learn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import numpy as np
33
import matplotlib.pyplot as plt
44
import time
5+
import logging
56
GENERATE_PLOT = 1
67

78
concore.delay = 0.002
@@ -21,7 +22,7 @@
2122
ut[int(concore.simtime)] = np.array(u).T
2223
ymt[int(concore.simtime)] = np.array(ym).T
2324
oldsimtime = concore.simtime
24-
print("retry="+str(concore.retrycount))
25+
logging.info(f"retry={concore.retrycount}")
2526

2627
#################
2728
# plot inputs and outputs

tools/pid2.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import numpy as np
22
import concore
3+
import logging
4+
35
setpoint = 67.5
46
setpointF = 75.0
57
KpF = 0.1
@@ -51,14 +53,16 @@ def pid_controller(ym):
5153
init_simtime_u = "[0.0, 0.0,0.0]"
5254
init_simtime_ym = "[0.0, 70.0,91]"
5355
u = np.array([concore.initval(init_simtime_u)]).T
54-
print("Shannon's PID controller: setpoint is "+str(setpoint))
56+
57+
logging.info(f"Shannon's PID controller: setpoint is {setpoint}")
58+
5559
while(concore.simtime<concore.maxtime):
5660
while concore.unchanged():
5761
ym = concore.read(1,"ym",init_simtime_ym)
5862
ym = np.array(ym)
5963

6064
ustar = pid_controller(ym)
6165

62-
print(str(concore.simtime) + " u="+str(ustar) + "ym="+str(ym))
66+
logging.debug(f"{concore.simtime} u={ustar} ym={ym}")
6367
concore.write(1,"u",list(ustar),delta=0)
6468

tools/pidmayuresh.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import math
33
import concore
4+
import logging
45
dT = 0.1
56

67
sp = concore.tryparam('sp', 67.5)
@@ -19,7 +20,7 @@ def pid_controller(state, ym, sp, Kp, Ki, Kd, sigout, cin, low, up):
1920
elif cin == 'map':
2021
Error = sp - ym[0]
2122
else:
22-
print('invalid control input '+cin)
23+
logging.error(f'invalid control input {cin}')
2324
quit()
2425
P = Error
2526
I = I + Error*dT
@@ -37,15 +38,15 @@ def pid_controller(state, ym, sp, Kp, Ki, Kd, sigout, cin, low, up):
3738
init_simtime_ym = "[0.0, 70.0,91]"
3839
ym = np.array(concore.initval(init_simtime_ym))
3940
state = [0.0, 0.0]
40-
print("Mayuresh's PID controller: sp is "+str(sp))
41-
print(concore.params)
41+
logging.info(f"Mayuresh's PID controller: sp is {sp}")
42+
logging.info(concore.params)
4243
while(concore.simtime<concore.maxtime):
4344
while concore.unchanged():
4445
ym = concore.read(1,"ym",init_simtime_ym)
4546
ym = np.array(ym)
4647
(state,amp) = pid_controller(state,ym,sp,Kp,Ki,Kd,sigout,cin,0,3)
4748
u = np.array([amp,freq])
48-
print(str(concore.simtime) + " u="+str(u) + "ym="+str(ym))
49+
logging.debug(f"{concore.simtime} u={u} ym={ym}")
4950
concore.write(1,"u",list(u),delta=0)
5051

5152

tools/pidsig.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import math
33
import concore
4+
import logging
45
dT = 0.1
56
global Prev_Error, I, freq
67
Prev_Error = 0
@@ -42,7 +43,7 @@ def pid_controller(ym):
4243
elif cin == 'map':
4344
Error = sp - ym[0]
4445
else:
45-
print('invalid control input '+cin)
46+
logging.error(f'invalid control input {cin}')
4647
quit()
4748
P = Error
4849
I = I + Error*dT
@@ -60,8 +61,8 @@ def pid_controller(ym):
6061
init_simtime_u = "[0.0, 0.0,0.0]"
6162
init_simtime_ym = "[0.0, 70.0,91]"
6263
u = np.array([concore.initval(init_simtime_u)]).T
63-
print("Shannon's PID controller: sp is "+str(sp))
64-
print(concore.params)
64+
logging.info(f"Shannon's PID controller: sp is {sp}")
65+
logging.info(concore.params)
6566
while(concore.simtime<concore.maxtime):
6667
while concore.unchanged():
6768
ym = concore.read(1,"ym",init_simtime_ym)
@@ -72,7 +73,7 @@ def pid_controller(ym):
7273
else:
7374
ustar = pid_controller(ym)
7475

75-
print(str(concore.simtime) + " u="+str(ustar) + "ym="+str(ym))
76+
logging.info(f"{concore.simtime} u={ustar} ym={ym}")
7677
concore.write(1,"u",list(ustar),delta=0)
7778

7879

tools/plotu.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import concore
2+
import logging
23
import numpy as np
34
import matplotlib.pyplot as plt
45
import time
5-
print("plot u")
6+
logging.info("plot u")
67

78
concore.delay = 0.005
89
concore.default_maxtime(150)
@@ -15,9 +16,9 @@
1516
while concore.unchanged():
1617
u = concore.read(1,"u",init_simtime_u)
1718
concore.write(1,"u",u)
18-
print("u="+str(u))
19+
logging.info(f"u={u}")
1920
ut.append(np.array(u).T)
20-
print("retry="+str(concore.retrycount))
21+
logging.info(f"retry={concore.retrycount}")
2122

2223
#################
2324

tools/plotym.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import concore
2+
import logging
23
import numpy as np
34
import matplotlib.pyplot as plt
45
import time
5-
print("plot ym")
6+
logging.info("plot ym")
67

78
concore.delay = 0.005
89
concore.default_maxtime(150)
@@ -15,9 +16,9 @@
1516
while concore.unchanged():
1617
ym = concore.read(1,"ym",init_simtime_ym)
1718
concore.write(1,"ym",ym)
18-
print(" ym="+str(ym))
19+
logging.debug(f" ym={ym}")
1920
ymt.append(np.array(ym).T)
20-
print("retry="+str(concore.retrycount))
21+
logging.info(f"retry={concore.retrycount}")
2122

2223
#################
2324

0 commit comments

Comments
 (0)