From 7b006d2f21a75903e018ba9175a843f571ef05b8 Mon Sep 17 00:00:00 2001 From: Stepan Bahnik Date: Wed, 19 Feb 2014 00:05:04 +0100 Subject: [PATCH] updated graphs, fixed some bugs --- CM Manager.py | 2 +- Stuff/Modules/cm.py | 12 ++++++++++-- Stuff/Modules/explorer.py | 31 ++++++++++++++----------------- Stuff/Modules/filestorage.py | 2 ++ Stuff/Modules/graphs.py | 33 +++++++++++++++++++++++++++------ Stuff/Modules/image.py | 9 +++++---- Stuff/Modules/mwm.py | 1 + Stuff/Modules/processor.py | 2 +- Stuff/Modules/version.py | 4 ++-- 9 files changed, 63 insertions(+), 33 deletions(-) diff --git a/CM Manager.py b/CM Manager.py index b276296..01ece59 100644 --- a/CM Manager.py +++ b/CM Manager.py @@ -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. diff --git a/Stuff/Modules/cm.py b/Stuff/Modules/cm.py index 9fa1144..0959c73 100644 --- a/Stuff/Modules/cm.py +++ b/Stuff/Modules/cm.py @@ -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 diff --git a/Stuff/Modules/explorer.py b/Stuff/Modules/explorer.py index b3e8be1..b1863e7 100644 --- a/Stuff/Modules/explorer.py +++ b/Stuff/Modules/explorer.py @@ -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)) diff --git a/Stuff/Modules/filestorage.py b/Stuff/Modules/filestorage.py index 4a0585b..a05ea96 100644 --- a/Stuff/Modules/filestorage.py +++ b/Stuff/Modules/filestorage.py @@ -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 diff --git a/Stuff/Modules/graphs.py b/Stuff/Modules/graphs.py index d28de65..35b8578 100644 --- a/Stuff/Modules/graphs.py +++ b/Stuff/Modules/graphs.py @@ -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 diff --git a/Stuff/Modules/image.py b/Stuff/Modules/image.py index 23e681a..e383951 100644 --- a/Stuff/Modules/image.py +++ b/Stuff/Modules/image.py @@ -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) diff --git a/Stuff/Modules/mwm.py b/Stuff/Modules/mwm.py index 0074c75..fe22734 100644 --- a/Stuff/Modules/mwm.py +++ b/Stuff/Modules/mwm.py @@ -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: diff --git a/Stuff/Modules/processor.py b/Stuff/Modules/processor.py index 8404f1d..3470567 100644 --- a/Stuff/Modules/processor.py +++ b/Stuff/Modules/processor.py @@ -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) diff --git a/Stuff/Modules/version.py b/Stuff/Modules/version.py index d0b13bc..ed8a8c9 100644 --- a/Stuff/Modules/version.py +++ b/Stuff/Modules/version.py @@ -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"