This repository has been archived by the owner on Jul 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gui_residualsgraph.py
67 lines (58 loc) · 2.91 KB
/
gui_residualsgraph.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
from PyQt4 import QtCore, QtGui
class ResidualsGraph(QtGui.QGraphicsItemGroup):
def __init__(self, data, parent=None):
super(ResidualsGraph, self).__init__(parent)
self.data = data
self.child = QtGui.QGraphicsItemGroup()
self.child.setParentItem(self)
def setSize(self, width, height):
self.width = width
self.height = height
def recreateFromData(self):
# Remove all subitems.
self.removeFromGroup(self.child)
self.scene().removeItem(self.child)
self.child = QtGui.QGraphicsItemGroup()
self.child.setParentItem(self)
# Do nothing if no fit exists.
if len(self.data.fitdata.residuals.values) == 0:
return
timeModifier = self.width / float(self.data.timeSpan)
residualsModifier = self.height / float(self.data.fitdata.residuals.span)
lastTime = None
lastResidual = None
for t in range(0, self.data.fitTimePointer[1] - self.data.fitTimePointer[0] + 1):
time = (self.data.time[self.data.fitTimePointer[0] + t] - self.data.minTime) * timeModifier
residual = self.height - (self.data.fitdata.residuals.values[t] - self.data.fitdata.residuals.min) * residualsModifier
if lastTime is not None:
line = QtGui.QGraphicsLineItem(QtCore.QLineF(lastTime, lastResidual, time, residual))
line.setParentItem(self.child)
lastTime = time
lastResidual = residual
# Draw zero line
zeroResidualY = self.height + self.data.fitdata.residuals.min * residualsModifier
if zeroResidualY >= 0 and zeroResidualY < self.height:
line = QtGui.QGraphicsLineItem(QtCore.QLineF(0, zeroResidualY, self.width, zeroResidualY))
line.setParentItem(self.child)
def resizeFromData(self):
# Do nothing if no fit exists.
if len(self.data.fitdata.residuals.values) == 0:
return
timeModifier = self.width / float(self.data.timeSpan)
residualsModifier = self.height / float(self.data.fitdata.residuals.span)
lastTime = None
lastResidual = None
children = self.child.childItems()
for t in range(0, self.data.fitTimePointer[1] - self.data.fitTimePointer[0] + 1):
time = (self.data.time[self.data.fitTimePointer[0] + t] - self.data.minTime) * timeModifier
residual = self.height - (self.data.fitdata.residuals.values[t] - self.data.fitdata.residuals.min) * residualsModifier
if lastTime is not None:
line = QtCore.QLineF(lastTime, lastResidual, time, residual)
children[t - 1].setLine(line)
lastTime = time
lastResidual = residual
# Update zero line
oldLine = children[-1].line()
line = QtCore.QLineF(oldLine.x1(), oldLine.y1(),
self.width, oldLine.y2())
children[-1].setLine(line)