Permalink
Browse files

parameters for robot avoidance

  • Loading branch information...
1 parent dc78ad5 commit b4b58742311c271cfbe4227efa5a22a788359bff @bahniks committed Apr 27, 2014
Showing with 91 additions and 25 deletions.
  1. +21 −15 Stuff/Modules/cm.py
  2. +2 −2 Stuff/Modules/mode.py
  3. +27 −5 Stuff/Modules/parameters.py
  4. +40 −2 Stuff/Modules/ra.py
  5. +1 −1 Stuff/Modules/version.py
View
@@ -469,8 +469,9 @@ def getThigmotaxis(self, time = 20, startTime = 0, percentSize = 20):
center = 0
for content in self.data[start:]:
- if content[1] <= time:
- distance = ((content[2] - self.centerX)**2 + (content[3] - self.centerY)**2)**0.5
+ if content[1] <= time:
+ x, y = content[self.indices]
+ distance = sqrt((x - self.centerX)**2 + (y - self.centerY)**2)
if distance >= border:
periphery += 1
else:
@@ -480,7 +481,7 @@ def getThigmotaxis(self, time = 20, startTime = 0, percentSize = 20):
def getAngleBoxes(self, time = 20, startTime = 0, width = "default", results = "condensed",
- center = "target"):
+ center = "target", indices = slice(2,4)):
"""returns proportion of time spent in angle boxes of width 'boxWidth' (provided in
degreess)
first item is centered in center of shock zone - by default it means that
@@ -491,20 +492,23 @@ def getAngleBoxes(self, time = 20, startTime = 0, width = "default", results = "
if width == "default":
width = self.width
- time = time * 60000
+ time *= 60000
start = self.findStart(startTime)
if center == "target":
sectorCenterAngle = self.centerAngle
elif center == "opposite":
sectorCenterAngle = self.centerAngle + 180
else:
- sectorCenterAngle = self.centerAngle + center
+ if self.centerAngle:
+ sectorCenterAngle = self.centerAngle + center
+ else:
+ sectorCenterAngle = center
angles = [0] * int(360 / width)
for content in self.data[start:]:
if content[1] <= time:
- angle = (degrees(self._angle(content[2], content[3])) - sectorCenterAngle +
+ angle = (degrees(self._angle(*content[indices])) - sectorCenterAngle +
(width / 2) + 360) % 360
angles[int(angle // width)] += 1
@@ -542,14 +546,14 @@ def _angle(self, x, y):
return atan2(self.centerY - y, x - self.centerX + 0.000000001)
- def getDirectionalMean(self, time = 20, startTime = 0):
+ def getDirectionalMean(self, time = 20, startTime = 0, indices = slice(2,4)):
"returns directional mean angle in room frame"
time = time * 60000
start = self.findStart(startTime)
- num = sum([sin(self._angle(content[2], content[3])) for content in self.data[start:] if
+ num = sum([sin(self._angle(*content[indices])) for content in self.data[start:] if
content[1] < time])
- den = sum([cos(self._angle(content[2], content[3])) for content in self.data[start:] if
+ den = sum([cos(self._angle(*content[indices])) for content in self.data[start:] if
content[1] < time])
if den == 0:
@@ -560,14 +564,14 @@ def getDirectionalMean(self, time = 20, startTime = 0):
return format(result, "0.2f")
- def getCircularVariance(self, time = 20, startTime = 0):
+ def getCircularVariance(self, time = 20, startTime = 0, indices = slice(2,4)):
"return circular variance of angle in room frame (has values between 0 and 1 inclusive)"
- circMean = radians(float(self.getDirectionalMean(time, startTime)))
+ circMean = radians(float(self.getDirectionalMean(time, startTime, indices = indices)))
time = time * 60000
start = self.findStart(startTime)
- R = sum([cos(self._angle(content[2], content[3]) - circMean) for content in
+ R = sum([cos(self._angle(*content[indices]) - circMean) for content in
self.data[start:] if content[1] < time])
circVar = 1 - R / len([1 for content in self.data[start:] if content[1] < time])
@@ -816,8 +820,10 @@ def findReflections(self, time = 20, startTime = 0, results = "both"):
def _computeSpeed(self, row1, row2):
- speed = ((row1[7] - row2[7])**2 + (row1[8] - row2[8])**2)**0.5 / \
- ((abs(row2[1] - row1[1]) / 1000) * self.trackerResolution)
+ x1, y1 = row1[self.indices]
+ x2, y2 = row2[self.indices]
+ speed = (sqrt((x1 - x2)**2 + (y1 - y2)**2) /
+ ((abs(row2[1] - row1[1]) / 1000) * self.trackerResolution))
return speed # cm/s
def _findSame(self, indices, points):
@@ -871,7 +877,7 @@ def removeReflections(self, points = None, deleteSame = True, bothframes = True)
# finds data points that share coordinates with more than two points with reflections
if deleteSame:
missing |= self._returnSame(missing)
-
+
missing = sorted(missing)
if missing:
View
@@ -54,13 +54,13 @@
fullname["RA"] = "Robot avoidance"
pairing = {"CM": ("Arena", "Room"),
- "RA": ("Rat", "Rob")} # zmenit pokud se bude menit pojmenovani !!!
+ "RA": ("Rat", "Robot")}
time = {"CM": 20,
"MWM": 1,
"OF": 10,
"CMSF": 20,
- "RA": 20} # zkontrolovat
+ "RA": 20}
def changeMode(newMode):
@@ -209,14 +209,36 @@ def __init__(self):
class ParametersRA(OrderedDict):
def __init__(self):
super().__init__()
+ ra = {"Total distance",
+ "Maximum time avoided",
+ "Time to first",
+ "Entrances",
+ "Shocks",
+ "Thigmotaxis",
+ "Directional mean",
+ "Circular variance",
+ "Mean distance from center",
+ "Maximum time of immobility",
+ "Proportion of time moving",
+ "Real minimum time",
+ "Real maximum time"}
for name, parameter in ParametersCM().items():
- self[name] = parameter
-## if name not in ("Room frame filename",):
-## self[name] = parameter
-
-
+ if name in ra:
+ self[name] = parameter
+
+ self["Time in sectors"] = Par("getAngleBoxes", "advanced", {
+ "width": (Opt('WidthParTimeInSectors', 90, ['int', 'float']),
+ "Width of sector [in degrees]"),
+ "center": (Opt('CenterParTimeInSectors', 0, ['int', 'float']),
+ "Center of sector [in degrees]")
+ })
+ self["Median speed after shock"] = Par("getSpeedAfterShock", "experimental", {
+ "after": (Opt('SkipSpeedAfterShock', 25, ['int']),
+ "Computed from every [in rows]")
+ })
+ self["Robot filename"] = Par("getRoomName", "info", {})
View
@@ -24,6 +24,7 @@
from cm import CM
+from funcs import median
class RA(CM):
@@ -73,9 +74,9 @@ def _setRoomName(self, name): # ZMENIT rob na robot???
if name == "auto":
splitname = os.path.split(self.nameA)
if splitname[1].count("Rat") > 0:
- self.nameR = os.path.join(splitname[0], splitname[1].replace("Rat", "Rob"))
+ self.nameR = os.path.join(splitname[0], splitname[1].replace("Rat", "Robot"))
elif splitname[1].count("rat") > 0:
- self.nameR = os.path.join(splitname[0], splitname[1].replace("rat", "rob"))
+ self.nameR = os.path.join(splitname[0], splitname[1].replace("rat", "robot"))
else:
raise IOError
else:
@@ -134,3 +135,40 @@ def _removalCondition(self, row, i, before, reflection):
row + i in self.interpolated))
+ def getCircularVariance(self, *args, indices = slice(7,9), **kwargs):
+ return super().getCircularVariance(*args, indices = indices, **kwargs)
+
+ def getDirectionalMean(self, *args, indices = slice(7,9), **kwargs):
+ return super().getDirectionalMean(*args, indices = indices, **kwargs)
+
+
+ def getSpeedAfterShock(self, time = 20, startTime = 0, after = 25):
+ "returns median speed that the rat travelled 'after' points after shock"
+ time = time * 60000
+ start = self.findStart(startTime)
+
+ shocks = [content[0] for content in self.data[start:] if
+ content[5] == 2 and content[1] < time]
+ if shocks:
+ selected = [shocks[0]]
+ prev = shocks[0]
+ for shock in shocks[1:]:
+ if shock - prev > after:
+ selected.append(shock)
+ prev = shock
+ else:
+ return "NA"
+
+ speeds = []
+ for shock in selected:
+ if len(self.data) <= shock + after:
+ break
+ speeds.append(self._computeSpeed(self.data[shock], self.data[shock + after]))
+
+ return format(median(speeds), "0.2f")
+
+ def getAngleBoxes(self, *args, indices = slice(7,9), **kwargs):
+ return super().getAngleBoxes(*args, indices = indices, **kwargs)
+
+
+
View
@@ -21,7 +21,7 @@ def version():
return ['0', '4', '0']
def date():
- return "26 April 2014"
+ return "27 April 2014"
def copyleft():
return "2013, 2014"

0 comments on commit b4b5874

Please sign in to comment.