The Morris water maze is one of the most used tests in behavioural neuroscience: a rodent swims in a pool of opaque water and learns where a hidden platform sits, using cues around the room. Most tracking packages export the animal's position frame by frame. Most papers then report one number from it, escape latency, the time to reach the platform.
Latency is a weak measure on its own. An animal can get faster by swimming in circles at a fixed distance from the wall, by swimming faster, or by giving up on the wall sooner, none of which needs a memory of where the platform is. The measures that tell those apart are all simple arithmetic on the track, so here they are in plain NumPy.
The input
Three arrays of equal length: time t in seconds, and x, y in centimetres with the pool centre at (0, 0). The platform centre is (px, py) with radius r_plat. If your tracker exports pixels, calibrate first: cm = px_value * pool_diameter_cm / pool_diameter_px, after subtracting the pool centre.
The module
"""Water maze measures from a tracked path.
Input: arrays of time (s), x and y (cm), with the pool centre at (0, 0).
"""
import numpy as np
def path_length(x, y):
return float(np.sum(np.hypot(np.diff(x), np.diff(y))))
def latency(t, x, y, px, py, r_plat):
"""Time of the first sample inside the platform zone, or None."""
inside = np.hypot(x - px, y - py) <= r_plat
return float(t[np.argmax(inside)] - t[0]) if inside.any() else None
def active_speed(t, x, y, still=2.0):
"""Mean speed (cm/s) over samples moving faster than `still` cm/s."""
v = np.hypot(np.diff(x), np.diff(y)) / np.diff(t)
moving = v > still
return float(v[moving].mean()) if moving.any() else 0.0
def proximity(t, x, y, px, py, step=1.0):
"""Gallagher-style mean distance to the goal, sampled every `step` s."""
ts = np.arange(t[0], t[-1] + 1e-9, step)
xs, ys = np.interp(ts, t, x), np.interp(ts, t, y)
return float(np.mean(np.hypot(xs - px, ys - py)))
def cumulative_search_error(t, x, y, px, py, step=1.0):
"""Summed distance to goal minus the sum for an ideal direct swim
from the same start at the animal's own mean speed."""
ts = np.arange(t[0], t[-1] + 1e-9, step)
xs, ys = np.interp(ts, t, x), np.interp(ts, t, y)
actual = np.sum(np.hypot(xs - px, ys - py))
d0 = np.hypot(x[0] - px, y[0] - py)
speed = path_length(x, y) / (t[-1] - t[0])
ideal = np.clip(d0 - speed * (ts - ts[0]), 0, None)
return float(actual - ideal.sum())
def quadrant_times(x, y, px, py):
"""Share of samples in each quadrant (pool centre at 0, 0). Assumes an
even sampling rate."""
target = np.arctan2(py, px)
ang = (np.arctan2(y, x) - target + np.pi / 4) % (2 * np.pi)
q = (ang // (np.pi / 2)).astype(int)
shares = np.bincount(q, minlength=4) / len(q)
return {"target": shares[0], "adjacent_ccw": shares[1],
"opposite": shares[2], "adjacent_cw": shares[3]}
def crossings(x, y, px, py, r_plat):
"""Entries into the platform zone (useful in a probe trial)."""
inside = np.hypot(x - px, y - py) <= r_plat
return int(np.sum(inside[1:] & ~inside[:-1]) + inside[0])
def thigmotaxis(x, y, r_pool, ring=0.1):
"""Share of samples in the outer ring (default: outer 10% of radius)."""
return float(np.mean(np.hypot(x, y) >= r_pool * (1 - ring)))
def heading_error(t, x, y, px, py, window=(0.5, 1.5)):
"""Absolute angle (deg) between the early movement direction and the
straight line from that point to the goal."""
i0, i1 = np.searchsorted(t, t[0] + window[0]), np.searchsorted(t, t[0] + window[1])
mv = np.array([x[i1] - x[i0], y[i1] - y[i0]])
to_goal = np.array([px - x[i0], py - y[i0]])
cosang = mv @ to_goal / (np.linalg.norm(mv) * np.linalg.norm(to_goal))
return float(np.degrees(np.arccos(np.clip(cosang, -1, 1))))
def path_efficiency(x, y):
"""Straight-line distance start to end over the distance swum."""
return float(np.hypot(x[-1] - x[0], y[-1] - y[0]) / path_length(x, y))
What each one tells you
- Path length and active speed: if one group is slower, its latencies will be longer with no memory problem at all. Report speed, and use active speed (excluding floating) rather than a raw average. More on that in path length and swim speed.
- Proximity is the mean distance to the goal, sampled once a second, from Gallagher, Burwell and Burchinal (1993). It gives credit for near misses, which platform crossings do not. See the Gallagher proximity measure.
- Cumulative search error sums that distance and subtracts what a direct swim from the same start would have accumulated, so far start points are not penalised. Walkthrough: cumulative search error.
- Heading error is the angle between the first movement and the line to the goal. A small angle from every start point is strong evidence of a place memory. The window matters (here 0.5 to 1.5 s after release); fix it before you look at data. See heading angle.
- Quadrant time in a probe trial (platform removed) has chance at 25 percent. Report opposite and adjacent quadrants too, so a general bias is not mistaken for memory. See zone and quadrant analysis.
- Crossings count entries into the old platform zone in a probe.
- Thigmotaxis, wall-hugging, is time in an outer ring. It explains many slow latencies. The ring width changes the number, so fix and report it. See thigmotaxis.
- Path efficiency is the straight-line distance over the distance swum.
Try it
demo.py builds a simulated swim (not real data) in a 150 cm pool with a 10 cm platform, starting at the south wall:
import numpy as np
from mwm_measures import *
fps, r_pool = 25, 75
px, py, r_plat = 30.0, 30.0, 5.0
t = np.arange(0, 20, 1 / fps)
rng = np.random.default_rng(1)
x = np.empty_like(t); y = np.empty_like(t)
x[0], y[0] = 0.0, -70.0
for i in range(1, len(t)):
gx, gy = px - x[i-1], py - y[i-1]
d = np.hypot(gx, gy)
step = np.array([gx, gy]) / max(d, 1e-9) * 0.6 + rng.normal(0, 0.8, 2)
x[i], y[i] = x[i-1] + step[0], y[i-1] + step[1]
if np.hypot(x[i], y[i]) > r_pool:
x[i], y[i] = np.array([x[i], y[i]]) * r_pool / np.hypot(x[i], y[i])
lat = latency(t, x, y, px, py, r_plat)
n = int(lat * fps) + 1 if lat else len(t)
t, x, y = t[:n], x[:n], y[:n]
print(f"proximity {proximity(t, x, y, px, py):.1f} cm")
Output of the full demo:
latency 7.6 s
path length 197 cm
active speed 25.8 cm/s
proximity 59.8 cm
search error 214 cm
heading error 7 deg
path efficiency 0.51
thigmotaxis 2%
quadrants {'target': '27%', 'adjacent_ccw': '0%', 'opposite': '0%', 'adjacent_cw': '73%'}
A fairly direct swim: small heading error, little wall time, and most of the path spent in the target quadrant and the clockwise quadrant it crossed from the start.
Caveats
- Sampling: proximity and search error assume a steady sampling rate; the functions resample to 1 s, so dropped frames matter less, but report your frame rate and lost-frame percentage.
- Quadrant time counts samples, so it assumes even spacing.
- Strategy classification (circling, chaining, scanning, directed search) is the next step and needs more than ten lines; see search strategies.
Further reading
- Vorhees CV, Williams MT (2006). Morris water maze: procedures for assessing spatial and related forms of learning and memory. Nature Protocols 1:848-858.
- Gallagher M, Burwell R, Burchinal M (1993). Severity of spatial learning impairment in aging. Behavioral Neuroscience 107:618-626.
- Maei HR et al. (2009). What is the most sensitive measure of water maze probe test performance? Frontiers in Integrative Neuroscience 3:4.
- Our checklist for choosing water maze software.
Morris Water Maze Software Guide (morriswatermazesoftware.com) is a free site of short films on every common maze measure. Published by watermaze.org.
Top comments (0)