Permalink
Browse files

updated graphs, fixed some bugs

  • Loading branch information...
1 parent 1ad51b2 commit 7b006d2f21a75903e018ba9175a843f571ef05b8 @bahniks committed Feb 18, 2014
View
@@ -1,7 +1,7 @@
#! python3
"""
Carousel Maze Manager - a program for analysis of data from behavioral neuroscience tasks
-Copyright 2013 Štěpán Bahník
+Copyright 2013, 2014 Štěpán Bahník
This file is part of Carousel Maze Manager.
View
@@ -242,8 +242,12 @@ def _processArenaFile(self, infile):
self.interpolated.add(count)
self.data[count] += filling
count += 1
-
- self.data[count] += line[2:]
+
+ try:
+ self.data[count] += line[2:]
+ # in case of different lengths of arena and room frame files
+ except IndexError:
+ break
# wrong points
if (line[2] != 0 or line[3] != 0) and missing == []:
@@ -270,6 +274,10 @@ def _processArenaFile(self, infile):
* missCounter + before[1]
missing = []
+ # in case of different lengths of arena and room frame files
+ if count != len(self.data) - 1:
+ self.data = self.data[:count]
+
if missing != []:
for missLines in missing:
self.data[missLines][7:9] = before
View
@@ -22,6 +22,7 @@
from time import time
from math import cos, sin, radians, degrees, atan2, floor
+
import os
import os.path
@@ -58,6 +59,7 @@ def __init__(self, root):
self.entrancesVar = StringVar()
self.selectedPVar = StringVar()
self.selectedParameter = StringVar()
+ self.graphParameter = StringVar()
self.timeVar = StringVar()
self.totDistanceVar = StringVar()
self.totEntrancesVar = StringVar()
@@ -441,9 +443,6 @@ def playFun(self):
self.timeFrame.changeState("disabled")
self.showTrack["state"] = "disabled"
self.saveBut.state(["disabled"])
-
- if self.animate == "stop":
- self.changedTime(0)
self.animate = "" # status of the animation - '', 'pause', 'stop'
@@ -889,20 +888,18 @@ def graphPopUp(self, event):
return
menu = Menu(self, tearoff = 0)
- menu.add_command(label = "Show periodicity",
- command = lambda: self.graph.drawParameter(self.cm, "periodicity"))
- menu.add_command(label = "Show mobility",
- command = lambda: self.graph.drawParameter(self.cm, "mobility"))
- menu.add_command(label = "Show immobility",
- command = lambda: self.graph.drawParameter(self.cm, "immobility"))
- menu.add_command(label = "Show entrances",
- command = lambda: self.graph.drawParameter(self.cm, "entrances"))
- menu.add_command(label = "Show shocks",
- command = lambda: self.graph.drawParameter(self.cm, "shocks"))
- menu.add_command(label = "Show bad points",
- command = lambda: self.graph.drawParameter(self.cm, "bad points"))
- menu.add_command(label = "Show thigmotaxis",
- command = lambda: self.graph.drawParameter(self.cm, "thigmotaxis"))
+ parameters = {"CM": ("periodicity", "mobility", "immobility", "entrances", "shocks",
+ "bad points", "thigmotaxis"),
+ "MWM": ("mobility", "immobility", "bad points", "thigmotaxis", "passes"),
+ "OF": ("mobility", "immobility", "bad points", "thigmotaxis")}
+ parameters["CMSF"] = parameters["CM"]
+
+ for parameter in parameters[m.mode]:
+ menu.add_radiobutton(label = "Show {}".format(parameter),
+ variable = self.graphParameter, value = parameter,
+ command = lambda: self.graph.drawParameter(
+ self.cm, self.graphParameter.get()))
+
menu.add_separator()
menu.add_command(label = "Don't show anything",
command = lambda: self.graph.drawParameter(self.cm, None))
@@ -757,6 +757,8 @@ def getDirectory(self):
initial = FileStorageFrame.lastOpenedDirectory[m.mode]
else:
initial = optionGet("FileDirectory", os.getcwd(), "str")
+ # tkinter has a problem with unicode characters in intialdir
+ # (only here, not in askopenfilenames dialog)
selected = askdirectory(initialdir = initial)
if os.path.isdir(selected):
FileStorageFrame.lastOpenedDirectory[m.mode] = selected
View
@@ -119,7 +119,7 @@ def drawTimes(self, times):
def drawParameter(self, cm, parameter):
- "computes selected parameter to be drawn on top of the graph"
+ "computes selected parameter to be drawn on top of the graph"
if self.drawnParameter:
self.delete("parameter")
@@ -163,16 +163,22 @@ def drawParameter(self, cm, parameter):
self.drawPeriods(mobility)
elif parameter == "thigmotaxis":
percentSize = optionGet("ThigmotaxisPercentSize", 20, ["int", "float"])
- border = cm.radius * (1 - (percentSize / 100))
start = cm.findStart(self.minTime / 60000)
periods = []
outside = False
t0 = self.minTime
+ border = cm.radius * (1 - (percentSize / 100))
+ if m.mode == "OF":
+ x0, x1 = cm.radius - cm.centerX, cm.centerX + cm.radius
+ y0, y1 = cm.radius - cm.centerY, cm.centerY + cm.radius
+ def distance(line):
+ return cm.radius - min([line[2] - x0, x1 - line[2], line[3] - y0, y1 - line[3]])
+ else:
+ def distance(line):
+ return ((line[2] - cm.centerX)**2 + (line[3] - cm.centerY)**2)**0.5
for content in cm.data[start:]:
if content[1] <= self.maxTime:
- distance = ((content[2] - cm.centerX)**2 +\
- (content[3] - cm.centerY)**2)**0.5
- if distance >= border:
+ if distance(content) >= border:
if not outside:
t0 = content[1]
outside = True
@@ -214,6 +220,21 @@ def drawParameter(self, cm, parameter):
entrances.append(content[1])
prev = 2
self.drawTimes(entrances)
+ elif parameter == "passes":
+ passes = []
+ prev = 0
+ for content in cm.data:
+ if content[5] == 0 and prev != 2:
+ continue
+ elif content[5] == 0 and prev == 2:
+ if content[5] == 0:
+ prev = 0
+ elif content[5] > 0 and content[5] != 5 and prev == 2:
+ continue
+ elif content[5] > 0 and content[5] != 5 and prev != 2:
+ passes.append(content[1])
+ prev = 2
+ self.drawTimes(passes)
elif parameter == "bad points":
if cm.interpolated:
sortd = sorted(cm.interpolated)
@@ -484,7 +505,7 @@ def CM_loaded(self, cm, initTime = 0, minTime = 0, maxTime = "max"):
self.compute(cm)
# drawing lines representing the sector
- if m.mode == "CM":
+ if "CM" in m.mode:
wid = cm.width
y1 = ((360 - (wid / 2)) / 360) * self.height
y2 = ((wid / 2) / 360) * self.height
View
@@ -131,10 +131,11 @@ def main():
import os
import os.path
svg = SVG(300, 300)
- cm = CM(os.path.join(os.getcwd(), "TestingFiles", "14rNO465_Arena.dat"))
- svg.drawAAPA(cm, "room", scale = 3, boundary = True, sector = True, shocks = True)
- svg.save("test.svg")
- os.startfile("test.svg")
+ cm = CM(os.path.join(os.getcwd(), "TestingFiles", "09aNO465_Arena.dat"))
+ svg.drawAAPA(cm, "room", boundary = True, sector = True, shocks = True)
+ output = os.path.join(os.getcwd(), "TestingFiles", "test.svg")
+ svg.save(output)
+ os.startfile(output)
View
@@ -117,6 +117,7 @@ def getAvgDistance(self, time = 1, startTime = 0, x = "platform", y = "platform"
y = self.platformY if y == "platform" else y
if removeBeginning:
+ # pravdepodobne muze pouzivat time to first pass
T1 = 0
for content in self.data[start:]:
if not 0 < content[5] < 3:
@@ -790,4 +790,4 @@ def showFun(self):
def resultsFun(self):
"opens a file with results"
- os.startfile(self.root.saveToFrame.saveToVar.get())
+ os.startfile(self.root.log.saveTo)
View
@@ -21,8 +21,8 @@ def version():
return ['0', '4', '0']
def date():
- return "9 February 2014"
+ return "18 February 2014"
def copyleft():
- return "2013-2014"
+ return "2013, 2014"

0 comments on commit 7b006d2

Please sign in to comment.