-
Notifications
You must be signed in to change notification settings - Fork 0
/
fdm_base.py
130 lines (100 loc) · 5.04 KB
/
fdm_base.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Generic framewise displacement computation and plotting
import matlab
import numpy as np
import pyqtgraph as pg
import fdm_settings as s
class FD:
def __init__(self, module = None):
self.module = module
# names of the dofs
self.names = ['X','Y','Z','pitch','roll','yaw', 'FD']
# TODO : remove if not needed
self.mode = {'tr': ['tr', 'translational','tr_sa'], 'rot' : ['rot', 'rotational','rot_sa'], 'fd':['FD', 'fd','FD_sa']}
self.plotBgColor = s.PLOT_BACKGROUND_COLOR
k = np.array(list(matlab.double([[1e-05,1e-05,1e-05,1e-05,1e-05,1e-05]])))
self.data = np.array(k).astype(np.float)
self.radius = s.DEFAULT_FD_RADIUS
self.threshold = s.DEFAULT_FD_THRESHOLDS
self.xmax = s.PLOT_INITIAL_XMAX
self.smooth_fwhm = s.REGRESSION_SMOOTH_FWHM
# FD computation
def _di(self, i):
return np.array(self.data[i][0:3])
def _ri(self, i):
return np.array(self.data[i][3:6])
def _ij_FD(self,i,j): # displacement from i to j
return sum(np.absolute(self._di(j)-self._di(i))) + \
sum(np.absolute(self._ri(j)-self._ri(i))) * self.radius
def all_fd(self):
fd = np.zeros(self.data.shape[0])
for i in range(1, self.data.shape[0]):
fd[i] = self._ij_FD(i-1,i)
return fd
# create Plot
def create_mc_plot(self, parent, layoutplot, eventfilter = None, nme="MC"):
mctrotplot = pg.PlotWidget(parent, name=nme)
mctrotplot.setBackground(self.plotBgColor)
if layoutplot != None:
layoutplot.addWidget(mctrotplot)
p = mctrotplot.getPlotItem()
p.setTitle('MC', size='')
p.setLabel('left', "Amplitude [a.u.]")
p.setMenuEnabled(enableMenu=True)
p.setMouseEnabled(x=False, y=False)
if eventfilter is not None:
p.installEventFilter(eventfilter)
return mctrotplot
def draw_mc_plots(self, init, outputSamples, plotitem, md):
if not outputSamples:
return
# get data, compute X from data length
k = np.array(outputSamples['motCorrParam'])
self.data = np.array(k).astype(np.float)
x = np.arange(1, self.data.shape[0] + 1, dtype=np.float64)
# retrieve plot information from openNFT
mctrrot = plotitem
# initialise plot
if init:
mctrrot.clear()
if md in self.mode['tr']:
mctrrot.setTitle('Translational Displacement', size='')
mctrrot.setLabel('left', "Amplitude [mm]")
for i in range(0, 3):
mctrrot.plot(x=x, y=self.data[:, i], pen=s.PLOT_PEN_COLORS[i], name=self.names[i])
elif md in self.mode['rot']:
mctrrot.setTitle('Rotational Displacement', size='')
mctrrot.setLabel('left', "Angle [rad]")
for i in range(3, 6):
mctrrot.plot(x=x, y=self.data[:, i], pen=s.PLOT_PEN_COLORS[i], name=self.names[i])
elif md in self.mode['fd']:
mctrrot.setTitle('Framewise Displacement', size='')
mctrrot.setLabel('left', "FD [mm]")
mctrrot.plot(x=x, y=self.all_fd(), pen=s.PLOT_PEN_COLORS[0], name='FD')
for i,t in enumerate(self.threshold):
mctrrot.plot(x=np.arange(0,self.xmax, dtype=np.float64), y=float(t)*np.ones(self.xmax), pen=s.PLOT_PEN_COLORS[i+1], name='thr' + str(i))
else:
mctrrot.setTitle('MC', size='')
mctrrot.setLabel('left', "Amplitude [a.u.]")
for i in range(0, 6):
mctrrot.plot(x=x, y=self.data[:, i],pen=s.PLOT_PEN_COLORS[i], name=self.names[i])
mctrrot.disableAutoRange(axis=pg.ViewBox.XAxis)
# adapt xmax
if len(x) > self.xmax-5:
self.xmax+=30
mctrrot.setXRange(1, self.xmax)
if md in self.mode['tr']:
for i,plt in enumerate(mctrrot.listDataItems()):
plt.setData(x=x, y=self.data[:, i])
elif md in self.mode['rot']:
for i,plt in enumerate(mctrrot.listDataItems()):
plt.setData(x=x, y=self.data[:, i+3])
elif md in self.mode['fd']:
for i,plt in enumerate(mctrrot.listDataItems()):
if i == 0:
plt.setData(x=x, y=self.all_fd())
else:
t = self.threshold[i-1]
plt.setData(x=np.arange(0,self.xmax, dtype=np.float64), y=float(t)*np.ones(self.xmax))
else: # legacy
for i,plt in enumerate(mctrrot.listDataItems()):
plt.setData(x=x, y=self.data[:, i])