Permalink
Browse files

added a top parameter line in images

  • Loading branch information...
1 parent 4134f07 commit 0e8267a39a9e63faa2d7839e235da699df4ca969 @bahniks committed Mar 11, 2015
Showing with 225 additions and 109 deletions.
  1. +14 −7 Stuff/Modules/explorer.py
  2. +107 −58 Stuff/Modules/graphs.py
  3. +80 −39 Stuff/Modules/image.py
  4. +24 −5 Stuff/Modules/options.py
View
@@ -30,7 +30,7 @@
from showtracks import ShowTracks
from filestorage import FileStorageFrame
from commonframes import TimeFrame, returnName
-from image import svgSave
+from image import svgSave, ImagesOptions
from processor import ProgressWindow
from optionget import optionGet
from graphs import getGraphTypes, Graphs, SvgGraph, SpeedGraph, DistanceFromCenterGraph
@@ -125,6 +125,8 @@ def __init__(self, root):
state = "disabled")
self.saveBut = ttk.Button(self.saveImagesLF, text = "Save", command = self.saveImages,
state = "disabled")
+ self.optionBut = ttk.Button(self.saveImagesLF, text = "Options",
+ command = self.imagesOptions)
# checkbuttons
self.removeReflections = ttk.Checkbutton(self.optionsLF, text = "Remove reflections",
@@ -226,7 +228,8 @@ def __init__(self, root):
self.playBut.grid(column = 0, row = 0, sticky = (N, S), padx = 2, pady = 2)
self.pauseBut.grid(column = 1, row = 0, sticky = (N, S), padx = 2, pady = 2)
self.stopBut.grid(column = 2, row = 0, sticky = (N, S), padx = 2, pady = 2)
- self.saveBut.grid(column = 1, row = 2, sticky = E)
+ self.saveBut.grid(column = 2, row = 2, sticky = E)
+ self.optionBut.grid(column = 0, row = 2, sticky = W, columnspan = 2)
self.removeReflections.grid(column = 1, row = 0, padx = 3, pady = 2, sticky = (N, W))
self.showTail.grid(column = 1, row = 2, padx = 3, pady = 2, sticky = (N, W))
@@ -259,8 +262,8 @@ def __init__(self, root):
self.timeSc.grid(column = 0, row = 2, columnspan = 7, sticky = (E, W), pady = 4, padx = 2)
self.speedSc.grid(column = 0, row = 0, sticky = (N, S, E, W), pady = 3)
- self.saveWhatCombo.grid(column = 1, row = 0)
- self.saveWhichFilesCombo.grid(column = 1, row = 1)
+ self.saveWhatCombo.grid(column = 1, row = 0, columnspan = 2)
+ self.saveWhichFilesCombo.grid(column = 1, row = 1, columnspan = 2)
# statusBar binding
self.statusBar.bind("<Double-1>", self._statusBarDoubleclick)
@@ -290,6 +293,10 @@ def __init__(self, root):
child.bind("<v>", lambda e: self.stopBut.invoke())
+ def imagesOptions(self):
+ ImagesOptions(self)
+
+
def saveImages(self):
"saves images for selected files"
files = self._returnSelectedFiles()
@@ -781,8 +788,8 @@ def _drawTrack(self):
fill = "black", width = 2)
if self.showShocksVar.get():
- indices = slice(2,4) if m.mode == "CA" else slice(7,9)
- fun = self.roomCanv.create_oval if m.mode == "CA" else self.arenaCanv.create_oval
+ indices = slice(2,4) if m.mode == "CM" else slice(7,9)
+ fun = self.roomCanv.create_oval if m.mode == "CM" else self.arenaCanv.create_oval
shocks = [line[indices] for count, line in enumerate(self.cm.data) if
self.minTime <= line[1] <= self.maxTime and line[6] > 0 and
@@ -892,7 +899,7 @@ def changedGraph(self):
drawnParameter = self.graph.drawnParameter
self.graph = eval(self.graphTypeVar.get())
self.graph.drawnParameter = drawnParameter
- self.graph.grid(column = 0, row = 4, columnspan = 7, padx = 2, pady = 5, sticky = (E, W))
+ self.graph.grid(column = 0, row = 4, columnspan = 7, padx = 2, pady = 5)
self.graph.bind("<Button-1>", self.graphClick)
self.graph.bind("<Button-3>", self.graphPopUp)
if self.initialized:
View
@@ -92,25 +92,26 @@ def drawParameter(self, cm, parameter, purpose = "graph"):
self.drawnParameter = parameter
if parameter == "periodicity":
- self.drawPeriods(cm.getPeriodicity(forGraph = True, time = self.maxTime / 60000,
- startTime = self.minTime / 60000,
- minSpeed = optionGet('MinSpeedPeriodicity',
- 10, ['int', 'float']),
- skip = optionGet('SkipPeriodicity', 12, ['int']),
- smooth = optionGet('SmoothPeriodicity', 2, ['int']),
- minTime = optionGet('MinTimePeriodicity', 9,
- ['int', 'float', 'list'])))
+ periodicity = cm.getPeriodicity(forGraph = True, time = self.maxTime / 60000,
+ startTime = self.minTime / 60000,
+ minSpeed = optionGet('MinSpeedPeriodicity',
+ 10, ['int', 'float']),
+ skip = optionGet('SkipPeriodicity', 12, ['int']),
+ smooth = optionGet('SmoothPeriodicity', 2, ['int']),
+ minTime = optionGet('MinTimePeriodicity', 9,
+ ['int', 'float', 'list']))
+ return self.drawPeriods(periodicity)
elif parameter == "immobility":
- self.drawPeriods(cm.getMaxTimeOfImmobility(forGraph = True,
- time = self.maxTime / 60000,
- startTime = self.minTime / 60000,
- minSpeed = optionGet(
- 'MinSpeedMaxTimeImmobility', 10,
- ['int', 'float']),
- skip = optionGet('SkipMaxTimeImmobility',
- 12, 'int'),
- smooth = optionGet(
- 'SmoothMaxTimeImmobility', 2, 'int')))
+ immobility = cm.getMaxTimeOfImmobility(forGraph = True,
+ time = self.maxTime / 60000,
+ startTime = self.minTime / 60000,
+ minSpeed = optionGet('MinSpeedMaxTimeImmobility',
+ 10, ['int', 'float']),
+ skip = optionGet('SkipMaxTimeImmobility',
+ 12, 'int'),
+ smooth = optionGet('SmoothMaxTimeImmobility',
+ 2, 'int'))
+ return self.drawPeriods(immobility)
elif parameter == "mobility":
immobility = cm.getMaxTimeOfImmobility(forGraph = True, time = self.maxTime / 60000,
startTime = self.minTime / 60000,
@@ -126,7 +127,7 @@ def drawParameter(self, cm, parameter, purpose = "graph"):
t1 = times[0]
mobility.append((t0, t1))
t0 = times[1]
- self.drawPeriods(mobility)
+ return self.drawPeriods(mobility)
elif parameter == "thigmotaxis":
percentSize = optionGet("ThigmotaxisPercentSize", 20, ["int", "float"])
start = cm.findStart(self.minTime / 60000)
@@ -156,7 +157,7 @@ def distance(line):
break
if outside:
periods.append((t0, self.maxTime))
- self.drawPeriods(periods)
+ return self.drawPeriods(periods)
elif parameter == "shocks":
shocks = []
prev = 0
@@ -214,8 +215,8 @@ def distance(line):
start = wrong
prev = wrong
wrongs.append((start, prev))
- self.drawPeriods([(cm.data[wrong[0] - 1][1], cm.data[wrong[1] - 1][1]) for\
- wrong in wrongs])
+ bps = [(cm.data[wrong[0] - 1][1], cm.data[wrong[1] - 1][1]) for wrong in wrongs]
+ return self.drawPeriods(bps)
elif parameter == "strategies":
rows = optionGet('rowsStrategies', 25, 'int')
minSpeed = optionGet('minSpeedStrategies', 10, ['int', 'float'])
@@ -232,10 +233,18 @@ def distance(line):
"reaction_counterclockwise": "red",
"reaction_clockwise": "goldenrod1",
"center": "wheat4"}
- for strategy, periods in strategies.items():
- self.drawPeriods(periods, color = colors[strategy], width = 240)
- self.lower("parameter")
-
+ if purpose == "graph":
+ for strategy, periods in strategies.items():
+ self.drawPeriods(periods, color = colors[strategy], width = 240)
+ self.lower("parameter")
+ else:
+ for strategy, periods in strategies.items():
+ if strategy == "immobile":
+ continue
+ self.drawPeriods(periods, color = colors[strategy].replace("_", "").rstrip("14"),
+ width = 240, toReturn = False)
+ return self.returnPeriods()
+
def drawPeriods(self, periods, color = "red", width = 3):
"draws selected parameter on top of the graph"
@@ -296,9 +305,9 @@ def __init__(self, parent, cm, width = 600, height = 120):
self.width = width
self.drawnParameter = None
self.parent = parent
+ self.periodText = ""
self.__class__.__bases__ = (self.__class__.__bases__[1], self.__class__.__bases__[0])
-
def __del__(self):
self.__class__.__bases__ = (self.__class__.__bases__[1], self.__class__.__bases__[0])
@@ -312,11 +321,13 @@ def saveGraph(self, cm):
return self.points, self.maxY, self.furtherText
- def drawPeriods(self, periods, color = "red", width = 3):
+ def drawPeriods(self, periods, color = "red", width = 8, toReturn = True):
"draws selected parameter on top of the graph"
if not periods:
- return
+ return ""
timeSpread = (self.maxTime - self.minTime)
+ text = ""
+ line = '<line x1="{0}" y1="{1}" x2="{2}" y2="{1}" stroke="{3}" stroke-width="{4}"/>\n'
for period in periods:
if period[0] > self.minTime and period[1] < self.maxTime:
begin = period[0]
@@ -329,11 +340,17 @@ def drawPeriods(self, periods, color = "red", width = 3):
end = self.maxTime
else:
continue
- self.create_line(((begin - self.minTime) * self.width / timeSpread,
- 0.03 * self.height,
- (end - self.minTime) * self.width / timeSpread,
- 0.03 * self.height),
- fill = color, width = width, tags = "parameter")
+ text += line.format((begin - self.minTime) * self.width / timeSpread,
+ (width/480) * self.height,
+ (end - self.minTime) * self.width / timeSpread,
+ color, width/2)
+ self.periodText += text
+ if toReturn:
+ return self.periodText
+
+
+ def returnPeriods(self):
+ return self.periodText
def drawTimes(self, times):
@@ -345,7 +362,7 @@ def drawTimes(self, times):
for time in times:
if self.minTime < time < self.maxTime:
x = (time - self.minTime) * self.width / timeSpread
- text += '<line x1="{0}" y1="0" x2="{0}" y2="5" stroke="red"/>'.format(x)
+ text += '<line x1="{0}" y1="0" x2="{0}" y2="5" stroke="red"/>\n'.format(x)
return text
@@ -421,14 +438,24 @@ def CM_loaded(self, cm, initTime = 0, minTime = 0, maxTime = "max"):
self.drawGraph(maxY = self.maxY, valueList = self.points)
+ def addYticks(self):
+ at = []
+ labels = []
+ for i in range((self.maxY // 20) + 1):
+ at.append(i*20 / self.maxY)
+ labels.append(str(i*20))
+ return at, labels
+
+
+ def getYlabel(self):
+ return "Speed [m/s]"
+
class DistanceFromCenterGraph(Graphs, SvgGraph):
"graph depicting distance from center of arena during the session"
- def __init__(self, parent, cm = None, purpose = "graph"):
- if purpose == "graph":
- Graphs.__init__(self, parent)
- else:
- SvgGraph.__init__(self, parent, cm)
+ def __init__(self, parent, cm = None, purpose = "graph", width = 600):
+ self.primaryParent = Graphs if purpose == "graph" else SvgGraph
+ self.primaryParent.__init__(self, parent, cm = cm, width = width)
def writeFurtherText(self):
@@ -445,6 +472,7 @@ def compute(self, cm, smooth = 10):
start = cm.findStart(self.minTime / 60000)
self.radius = cm.radius
+ self.resolution = cm.trackerResolution
Cx, Cy = cm.centerX, cm.centerY
if m.mode == "RA":
@@ -473,16 +501,28 @@ def CM_loaded(self, cm, initTime = 0, minTime = 0, maxTime = "max"):
self.create_line((0, 10, self.width, 10), fill = "grey")
self.drawGraph(maxY = self.maxY, valueList = self.points)
-
+
+
+ def addYticks(self):
+ at = []
+ labels = []
+ maxYcm = self.maxY / self.resolution
+ for i in range((int(maxYcm) // 20) + 1):
+ at.append(i*20 / maxYcm)
+ labels.append(str(i*20))
+ return at, labels
+
+
+ def getYlabel(self):
+ return "Distance [cm]"
+
class DistanceFromPlatformGraph(Graphs, SvgGraph):
"graph depicting distance from platform during the MWM session"
- def __init__(self, parent, cm = None, purpose = "graph"):
- if purpose == "graph":
- Graphs.__init__(self, parent)
- else:
- SvgGraph.__init__(self, parent, cm)
+ def __init__(self, parent, cm = None, purpose = "graph", width = 600):
+ self.primaryParent = Graphs if purpose == "graph" else SvgGraph
+ self.primaryParent.__init__(self, parent, cm = cm, width = width)
def writeFurtherText(self):
@@ -520,12 +560,13 @@ def CM_loaded(self, cm, initTime = 0, minTime = 0, maxTime = "max"):
self.drawGraph(maxY = self.maxY, valueList = self.points)
-
+
class DistanceFromRobotGraph(DistanceFromPlatformGraph):
"graph depicting distance from the robot during the RA session"
- def __init__(self, parent, cm = None, purpose = "graph"):
- super().__init__(parent = parent, cm = cm, purpose = purpose)
+ def __init__(self, parent, cm = None, purpose = "graph", width = 600):
+ self.primaryParent = Graphs if purpose == "graph" else SvgGraph
+ self.primaryParent.__init__(self, parent, cm = cm, width = width)
def compute(self, cm, smooth = 10):
@@ -537,18 +578,17 @@ def compute(self, cm, smooth = 10):
for line in cm.data[start:] if line[1] <= self.maxTime]
self.maxY = cm.radius * 2
-
+
class AngleGraph(Graphs, SvgGraph):
"graph depicting angle relative to the center of shock zone during the session"
- def __init__(self, parent, cm = None, purpose = "graph"):
- if purpose == "graph":
- Graphs.__init__(self, parent)
- else:
- SvgGraph.__init__(self, parent, cm)
- self.maxTime = eval(self.parent.timeFrame.timeVar.get()) * 60000
- self.minTime = eval(self.parent.timeFrame.startTimeVar.get()) * 60000
+ def __init__(self, parent, cm = None, purpose = "graph", width = 600):
+ self.primaryParent = Graphs if purpose == "graph" else SvgGraph
+ self.primaryParent.__init__(self, parent, cm = cm, width = width)
+
+ self.maxTime = eval(self.parent.timeFrame.timeVar.get()) * 60000
+ self.minTime = eval(self.parent.timeFrame.startTimeVar.get()) * 60000
def compute(self, cm):
@@ -625,7 +665,7 @@ def saveGraph(self, cm):
self.compute(cm)
wid = cm.width
- size = (600, 120)
+ size = (self.width, self.height)
maxX = len(self.angles) - self.crosses
text = ""
@@ -668,3 +708,12 @@ def _addLine(self, points):
text += '" style = "fill:none;stroke:black"/>\n'
return text
+
+ def addYticks(self):
+ at = [0, 0.5, 1]
+ labels = ["0", "180", "360"]
+ return at, labels
+
+
+ def getYlabel(self):
+ return "Angle [deg]"
Oops, something went wrong.

0 comments on commit 0e8267a

Please sign in to comment.