improve ultrasound plot clients
- make plot window not to raise to the front on replot - chmod +x
This commit is contained in:
parent
6f547f0781
commit
f8e3bd9ad2
14
bin/peus-plot
Normal file → Executable file
14
bin/peus-plot
Normal file → Executable file
@ -1,19 +1,24 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
# Add import path for inplace usage
|
||||||
|
sys.path.insert(0, str(Path(__file__).absolute().parents[1]))
|
||||||
|
|
||||||
from frappy.client.interactive import Client
|
from frappy.client.interactive import Client
|
||||||
from frappy_psi.iqplot import Plot
|
from frappy_psi.iqplot import Plot
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print('Usage: python peusplot.py <maxY>')
|
print('Usage: peus-plot <maxY>')
|
||||||
|
|
||||||
|
|
||||||
def get_modules(name):
|
def get_modules(name):
|
||||||
return list(filter(None, (globals().get(name % i) for i in range(10))))
|
return list(filter(None, (globals().get(name % i) for i in range(10))))
|
||||||
|
|
||||||
|
|
||||||
secnode = Client('localhost:5000')
|
secnode = Client('pc13252:5000')
|
||||||
time_size = {'time', 'size'}
|
time_size = {'time', 'size'}
|
||||||
int_mods = [u] + get_modules('roi%d')
|
int_mods = [u] + get_modules('roi%d')
|
||||||
t_rois = get_modules('roi%d')
|
t_rois = get_modules('roi%d')
|
||||||
@ -35,12 +40,11 @@ try:
|
|||||||
while True:
|
while True:
|
||||||
curves = np.array(u.get_curves())
|
curves = np.array(u.get_curves())
|
||||||
iqplot.plot(curves,
|
iqplot.plot(curves,
|
||||||
rois=[(r.time, r.time + r.size) for r in int_mods],
|
rois=[(r.time - r.size * 0.5, r.time + r.size * 0.5) for r in int_mods],
|
||||||
average=([r.time for r in t_rois],
|
average=([r.time for r in t_rois],
|
||||||
[r.value for r in i_rois],
|
[r.value for r in i_rois],
|
||||||
[r.value for r in q_rois]))
|
[r.value for r in q_rois]))
|
||||||
plt.pause(0.5)
|
if not iqplot.pause(0.5):
|
||||||
if iqplot.fig is None: # graph window closed
|
|
||||||
break
|
break
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
iqplot.close()
|
iqplot.close()
|
||||||
|
10
bin/us-plot
Normal file → Executable file
10
bin/us-plot
Normal file → Executable file
@ -1,8 +1,13 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
# Add import path for inplace usage
|
||||||
|
sys.path.insert(0, str(Path(__file__).absolute().parents[1]))
|
||||||
|
|
||||||
from frappy.client.interactive import Client
|
from frappy.client.interactive import Client
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
from frappy.iqplot import Pause
|
||||||
|
|
||||||
Client('pc13252:5000')
|
Client('pc13252:5000')
|
||||||
|
|
||||||
@ -40,7 +45,7 @@ else:
|
|||||||
npoints = float(sys.argv[3])
|
npoints = float(sys.argv[3])
|
||||||
|
|
||||||
fig, ax = plt.subplots(figsize=(15,3))
|
fig, ax = plt.subplots(figsize=(15,3))
|
||||||
fig.canvas.mpl_connect('close_event', on_close)
|
pause = Pause(fig)
|
||||||
try:
|
try:
|
||||||
get_signal = iq.get_signal
|
get_signal = iq.get_signal
|
||||||
print('plotting RUS signal')
|
print('plotting RUS signal')
|
||||||
@ -52,8 +57,7 @@ else:
|
|||||||
|
|
||||||
lines = [plot(s, ax, '-', xs) for s in signal]
|
lines = [plot(s, ax, '-', xs) for s in signal]
|
||||||
|
|
||||||
while True:
|
while pause(0.5):
|
||||||
plt.pause(0.5)
|
|
||||||
plt.draw()
|
plt.draw()
|
||||||
xs, signal = get_signal(start, end, npoints)
|
xs, signal = get_signal(start, end, npoints)
|
||||||
for line, sig in zip(lines, signal):
|
for line, sig in zip(lines, signal):
|
||||||
|
@ -6,10 +6,40 @@ Created on Tue Feb 4 11:07:56 2020
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
# disable the behaviour of raising the window to the front each time it is updated
|
||||||
|
plt.rcParams["figure.raise_window"] = False
|
||||||
|
|
||||||
|
|
||||||
NAN = float('nan')
|
NAN = float('nan')
|
||||||
|
|
||||||
|
|
||||||
|
class Pause:
|
||||||
|
"""allows to leave the plot loop when the window is closed
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
pause = Pause(fig)
|
||||||
|
|
||||||
|
# do initial plots
|
||||||
|
plt.show()
|
||||||
|
while pause(0.5):
|
||||||
|
# do plot updates
|
||||||
|
plt.draw()
|
||||||
|
"""
|
||||||
|
def __init__(self, fig):
|
||||||
|
fig.canvas.mpl_connect('close_event', self.on_close)
|
||||||
|
self.running = True
|
||||||
|
|
||||||
|
def on_close(self, event):
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
def __call__(self, interval):
|
||||||
|
try:
|
||||||
|
plt.pause(interval)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return self.running
|
||||||
|
|
||||||
|
|
||||||
def rect(x1, x2, y1, y2):
|
def rect(x1, x2, y1, y2):
|
||||||
return np.array([[x1,x2,x2,x1,x1],[y1,y1,y2,y2,y1]])
|
return np.array([[x1,x2,x2,x1,x1],[y1,y1,y2,y2,y1]])
|
||||||
|
|
||||||
@ -29,6 +59,10 @@ class Plot:
|
|||||||
self.first = True
|
self.first = True
|
||||||
self.fig = None
|
self.fig = None
|
||||||
|
|
||||||
|
def pause(self, interval):
|
||||||
|
"""will be overridden when figure is created"""
|
||||||
|
return False
|
||||||
|
|
||||||
def set_line(self, iax, name, data, fmt, **kwds):
|
def set_line(self, iax, name, data, fmt, **kwds):
|
||||||
"""
|
"""
|
||||||
plot or update a line
|
plot or update a line
|
||||||
@ -57,9 +91,6 @@ class Plot:
|
|||||||
self.fig = None
|
self.fig = None
|
||||||
self.first = True
|
self.first = True
|
||||||
|
|
||||||
def on_close(self, event):
|
|
||||||
self.fig = None
|
|
||||||
|
|
||||||
def plot(self, curves, rois=None, average=None):
|
def plot(self, curves, rois=None, average=None):
|
||||||
boxes = rects(rois[1:], self.yaxis[0])
|
boxes = rects(rois[1:], self.yaxis[0])
|
||||||
pbox = rect(*rois[0], *self.yaxis[1])
|
pbox = rect(*rois[0], *self.yaxis[1])
|
||||||
@ -74,7 +105,7 @@ class Plot:
|
|||||||
if self.first:
|
if self.first:
|
||||||
plt.ion()
|
plt.ion()
|
||||||
self.fig, axleft = plt.subplots(figsize=(15,7))
|
self.fig, axleft = plt.subplots(figsize=(15,7))
|
||||||
self.fig.canvas.mpl_connect('close_event', self.on_close)
|
self.pause = Pause(self.fig)
|
||||||
plt.title("I/Q", fontsize=14)
|
plt.title("I/Q", fontsize=14)
|
||||||
axleft.set_xlim(0, curves[0][-1])
|
axleft.set_xlim(0, curves[0][-1])
|
||||||
self.ax = [axleft, axleft.twinx()]
|
self.ax = [axleft, axleft.twinx()]
|
||||||
@ -104,5 +135,6 @@ class Plot:
|
|||||||
self.first = False
|
self.first = False
|
||||||
|
|
||||||
plt.draw()
|
plt.draw()
|
||||||
|
# TODO: do not know why this is needed:
|
||||||
self.fig.canvas.draw()
|
self.fig.canvas.draw()
|
||||||
self.fig.canvas.flush_events()
|
self.fig.canvas.flush_events()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user