Permalink
Browse files

finished viewing strategies in explorer

  • Loading branch information...
1 parent c5d0b17 commit 0d26dc4483bb66c6f3eef2b9c6c24230c36a7cec @bahniks committed Aug 5, 2014
Showing with 58 additions and 15 deletions.
  1. +24 −11 Stuff/Modules/cm.py
  2. +1 −1 Stuff/Modules/explorer.py
  3. +22 −2 Stuff/Modules/graphs.py
  4. +10 −0 Stuff/Modules/parameters.py
  5. +1 −1 Stuff/Modules/version.py
View
@@ -1019,21 +1019,23 @@ def findStart(self, startTime):
return self._findStartHelper(0, len(self.data), startTime)
- def recognizeAfterShockStrategy(self, i0, i1, minAngle = 15):
+ def recognizeAfterShockStrategy(self, i0, i1, minAngle):
cx, cy = self.centerX, self.centerY
x0, y0 = self.data[i0][self.indices]
x1, y1 = self.data[i1][self.indices]
+ t0, t1 = self.data[i0][1], self.data[i1][1]
angle = ((degrees(atan2(x1 - cx, y1 - cy + 0.0000001)) -
degrees(atan2(x0 - cx, y0 - cy + 0.0000001)) + 180) % 360) - 180
- if angle > minAngle:
+ angleSpeed = (angle * 1000) / (t1 - t0)
+ if angleSpeed > minAngle:
return "reaction_counterclockwise"
- elif angle < -minAngle:
+ elif angleSpeed < -minAngle:
return "reaction_clockwise"
else:
return "no_reaction"
- def recognizeStrategy(self, i0, i1, minSpeed = 10, percentSize = 20):
+ def recognizeStrategy(self, i0, i1, minSpeed, percentSize):
x0, y0 = self.data[i0][self.indices]
x1, y1 = self.data[i1][self.indices]
t0, t1 = self.data[i0][1], self.data[i1][1]
@@ -1058,12 +1060,12 @@ def recognizeStrategy(self, i0, i1, minSpeed = 10, percentSize = 20):
return "immobile"
- def getStrategies(self, time = 20, startTime = 0, rows = 25, minSpeed = 10, minAngle = 15,
- borderPercentSize = 20):
- i1 = self.data[self.findStart(time)][0]
+ def getStrategies(self, time = 20, startTime = 0, rows = 25, minSpeed = 10, minAngle = 7,
+ borderPercentSize = 50, indices = False):
+ i1, t1 = self.data[self.findStart(time)][0:2]
time = time * 60000
start = self.findStart(startTime)
- i0 = self.data[start][0]
+ i0, t0 = self.data[start][0:2]
shocks = deque(self.getShocks(time = time, startTime = startTime, indices = True))
@@ -1072,7 +1074,7 @@ def getStrategies(self, time = 20, startTime = 0, rows = 25, minSpeed = 10, minA
lastStrategy = self.recognizeStrategy(i0, nextShock, minSpeed, borderPercentSize)
else:
lastStrategy = self.recognizeStrategy(i0, i0 + rows, minSpeed, borderPercentSize)
- beginning = i0
+ beginning = i0 if indices else t0
strategies = defaultdict(list)
adjust = False
@@ -1093,15 +1095,26 @@ def getStrategies(self, time = 20, startTime = 0, rows = 25, minSpeed = 10, minA
strategy = self.recognizeStrategy(i, i + rows, minSpeed, borderPercentSize)
if lastStrategy != strategy:
- strategies[lastStrategy].append((beginning, i))
- beginning = i
+ if indices:
+ strategies[lastStrategy].append((beginning, i))
+ beginning = i
+ else:
+ t = self.data[i - 1][1]
+ strategies[lastStrategy].append((beginning, t))
+ beginning = t
lastStrategy = strategy
if adjust:
i = nextShock
adjust = False
else:
i += rows
+
+ if indices:
+ strategies[lastStrategy].append((beginning, i1))
+ else:
+ t = self.data[i1 - 1][1]
+ strategies[lastStrategy].append((beginning, t))
return strategies
@@ -962,7 +962,7 @@ def graphPopUp(self, event):
menu = Menu(self, tearoff = 0)
parameters = {"CM": ("periodicity", "mobility", "immobility", "entrances", "shocks",
- "bad points", "thigmotaxis"),
+ "bad points", "thigmotaxis", "strategies"),
"MWM": ("mobility", "immobility", "bad points", "thigmotaxis", "passes"),
"OF": ("mobility", "immobility", "bad points", "thigmotaxis"),
"RA": ("mobility", "immobility", "entrances", "shocks", "bad points",
View
@@ -84,7 +84,7 @@ def CM_loaded(self, CM, minTime, maxTime, initTime):
self.drawParameter(cm = CM, parameter = self.drawnParameter)
- def drawPeriods(self, periods):
+ def drawPeriods(self, periods, color = "red", width = 3):
"draws selected parameter on top of the graph"
if not periods:
return
@@ -105,7 +105,7 @@ def drawPeriods(self, periods):
0.03 * self.height,
(end - self.minTime) * self.width / timeSpread,
0.03 * self.height),
- fill = "red", width = 3, tags = "parameter")
+ fill = color, width = width, tags = "parameter")
def drawTimes(self, times):
@@ -252,6 +252,26 @@ def distance(line):
wrongs.append((start, prev))
self.drawPeriods([(cm.data[wrong[0] - 1][1], cm.data[wrong[1] - 1][1]) for\
wrong in wrongs])
+ elif parameter == "strategies":
+ rows = optionGet('rowsStrategies', 25, 'int')
+ minSpeed = optionGet('minSpeedStrategies', 10, ['int', 'float'])
+ minAngle = optionGet('minAngleStrategies', 15, ['int', 'float'])
+ borderPercentSize = optionGet('borderPercentSizeStrategies', 20, ['int', 'float'])
+ strategies = cm.getStrategies(time = self.maxTime / 60000,
+ startTime = self.minTime / 60000,
+ rows = rows, minSpeed = minSpeed, minAngle = minAngle,
+ borderPercentSize = borderPercentSize)
+ colors = {"counterclockwise": "green",
+ "clockwise": "dodger blue",
+ "no_reaction": "deep pink",
+ "immobile": "white",
+ "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")
+
@@ -97,6 +97,16 @@ def __init__(self):
self["Real minimum time"] = Par("realMinimumTime", "info", {})
self["Real maximum time"] = Par("realMaximumTime", "info", {})
self["Room frame filename"] = Par("getRoomName", "info", {})
+ self["Strategies"] = Par("getStrategies", "experimental", {
+ "rows": (Opt('rowsStrategies', 25, 'int'),
+ "Length of time bins [in rows]"),
+ "minSpeed": (Opt('minSpeedStrategies', 10, ['int', 'float']),
+ "Minimum speed counted [in cm/s]"),
+ "minAngle": (Opt('minAngleStrategies', 7, ['int', 'float']),
+ "Minimum angle counted (after shock) [in °/s]"),
+ "borderPercentSize": (Opt('borderPercentSizeStrategies', 50, ['int', 'float']),
+ "Annulus width [in percents]")
+ })
#self.findParameters()
View
@@ -21,7 +21,7 @@ def version():
return ['0', '4', '0']
def date():
- return "4 August 2014"
+ return "5 August 2014"
def copyleft():
return "2013, 2014"

0 comments on commit 0d26dc4

Please sign in to comment.